[PATCH 14/26] rv/rvgen: remove redundant initial_state removal

Wander Lairson Costa posted 26 patches 2 weeks, 5 days ago
There is a newer version of this series
[PATCH 14/26] rv/rvgen: remove redundant initial_state removal
Posted by Wander Lairson Costa 2 weeks, 5 days ago
Remove an unnecessary and incorrect list removal operation in the
automata state variable processing. The code attempted to remove
initial_state from the states list, but this element was never
added to the list in the first place. States with the __init_
prefix are explicitly excluded from the states list during the
parsing loop, with only the initial_state variable being set
from them.

Calling remove() on an element that does not exist in a list
raises a ValueError. This code would have failed during execution
when processing any DOT file containing an initial state marker.
The subsequent insert operation at index 0 correctly adds the
initial_state to the beginning of the states list, making the
removal operation both incorrect and redundant.

Signed-off-by: Wander Lairson Costa <wander@redhat.com>
---
 tools/verification/rvgen/rvgen/automata.py | 1 -
 1 file changed, 1 deletion(-)

diff --git a/tools/verification/rvgen/rvgen/automata.py b/tools/verification/rvgen/rvgen/automata.py
index 7841a6e70bad2..b302af3e5133e 100644
--- a/tools/verification/rvgen/rvgen/automata.py
+++ b/tools/verification/rvgen/rvgen/automata.py
@@ -111,7 +111,6 @@ class Automata:
             cursor += 1
 
         states = sorted(set(states))
-        states.remove(initial_state)
 
         # Insert the initial state at the beginning of the states
         states.insert(0, initial_state)
-- 
2.52.0
Re: [PATCH 14/26] rv/rvgen: remove redundant initial_state removal
Posted by Gabriele Monaco 2 weeks, 5 days ago
On Mon, 2026-01-19 at 17:45 -0300, Wander Lairson Costa wrote:
> Remove an unnecessary and incorrect list removal operation in the
> automata state variable processing. The code attempted to remove
> initial_state from the states list, but this element was never
> added to the list in the first place. States with the __init_
> prefix are explicitly excluded from the states list during the
> parsing loop, with only the initial_state variable being set
> from them.

The initial state is not the state with __init_, but the state pointed to by
that, the purpose of removing it after sorting and putting it back is for it to
be the first (we may argue there are better ways to do that, but it works).

After this change, the initial state is duplicated..
I think we should just drop this.

Thanks,
Gabriele

> 
> Calling remove() on an element that does not exist in a list
> raises a ValueError. This code would have failed during execution
> when processing any DOT file containing an initial state marker.
> The subsequent insert operation at index 0 correctly adds the
> initial_state to the beginning of the states list, making the
> removal operation both incorrect and redundant.
> 
> Signed-off-by: Wander Lairson Costa <wander@redhat.com>
> ---
>  tools/verification/rvgen/rvgen/automata.py | 1 -
>  1 file changed, 1 deletion(-)
> 
> diff --git a/tools/verification/rvgen/rvgen/automata.py
> b/tools/verification/rvgen/rvgen/automata.py
> index 7841a6e70bad2..b302af3e5133e 100644
> --- a/tools/verification/rvgen/rvgen/automata.py
> +++ b/tools/verification/rvgen/rvgen/automata.py
> @@ -111,7 +111,6 @@ class Automata:
>              cursor += 1
>  
>          states = sorted(set(states))
> -        states.remove(initial_state)
>  
>          # Insert the initial state at the beginning of the states
>          states.insert(0, initial_state)
Re: [PATCH 14/26] rv/rvgen: remove redundant initial_state removal
Posted by Wander Lairson Costa 2 weeks, 5 days ago
On Tue, Jan 20, 2026 at 09:01:01AM +0100, Gabriele Monaco wrote:
> On Mon, 2026-01-19 at 17:45 -0300, Wander Lairson Costa wrote:
> > Remove an unnecessary and incorrect list removal operation in the
> > automata state variable processing. The code attempted to remove
> > initial_state from the states list, but this element was never
> > added to the list in the first place. States with the __init_
> > prefix are explicitly excluded from the states list during the
> > parsing loop, with only the initial_state variable being set
> > from them.
> 
> The initial state is not the state with __init_, but the state pointed to by
> that, the purpose of removing it after sorting and putting it back is for it to
> be the first (we may argue there are better ways to do that, but it works).
> 
> After this change, the initial state is duplicated..
> I think we should just drop this.

Ah, now I understood the reasoning, thanks. I will drop the patch.

> 
> Thanks,
> Gabriele
> 
> > 
> > Calling remove() on an element that does not exist in a list
> > raises a ValueError. This code would have failed during execution
> > when processing any DOT file containing an initial state marker.
> > The subsequent insert operation at index 0 correctly adds the
> > initial_state to the beginning of the states list, making the
> > removal operation both incorrect and redundant.
> > 
> > Signed-off-by: Wander Lairson Costa <wander@redhat.com>
> > ---
> >  tools/verification/rvgen/rvgen/automata.py | 1 -
> >  1 file changed, 1 deletion(-)
> > 
> > diff --git a/tools/verification/rvgen/rvgen/automata.py
> > b/tools/verification/rvgen/rvgen/automata.py
> > index 7841a6e70bad2..b302af3e5133e 100644
> > --- a/tools/verification/rvgen/rvgen/automata.py
> > +++ b/tools/verification/rvgen/rvgen/automata.py
> > @@ -111,7 +111,6 @@ class Automata:
> >              cursor += 1
> >  
> >          states = sorted(set(states))
> > -        states.remove(initial_state)
> >  
> >          # Insert the initial state at the beginning of the states
> >          states.insert(0, initial_state)
>