fix(#622): any-state wildcard fires when composable sub-SM terminates#702
Open
PavelGuzenfeld wants to merge 1 commit into
Open
fix(#622): any-state wildcard fires when composable sub-SM terminates#702PavelGuzenfeld wants to merge 1 commit into
PavelGuzenfeld wants to merge 1 commit into
Conversation
8bd1db5 to
49b5284
Compare
…SM terminates When the outer SM is in a composable sub-state (a struct with public operator(), treated as sm<T>), and the sub-SM handles an event that terminates it (all regions reach X), the outer wildcard transition (`any + event<E> = state<S>`) was never evaluated because the sub-SM's `true` return short-circuited the logical OR. Fix: in `get_state_mapping<sm<T>>::type::execute()`, after the sub-SM handles an event, check `is_terminated()`. If the sub-SM is still running, return immediately. If it has terminated (or never handled the event), give `fallback_event_mapping` (the outer `_` wildcard) a chance to fire. `is_terminated_impl` is updated to use a new `aux::get_id_safe<R,T>` helper that returns -1 (never a valid state ID) when T is not in the SM's state list, making `is_terminated()` safe to call on sub-SMs that have no X-terminating transitions. Adds `test/ft/issue_622_any_state_nested.cpp` with two test cases: - composable sub-SM terminates via e1; outer `any + e1 = state_b` must fire - leaf-only baseline (wildcard always worked for non-composable states)
49b5284 to
050d780
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the outer SM is in a composable sub-state (a
structwith publicoperator(), treated assm<T>) and the sub-SM handles an event that terminates all its regions (reachesX), the outer wildcard transition (any + event<E> = state<S>) was never evaluated.Root cause:
get_state_mapping<sm<T>>::type::execute()short-circuits via||whensub_sm_mapping::execute()returnstrue— sofallback_event_mapping(the outer_wildcard) is never tried, even after the sub-SM has terminated.The author of #622 noted that the same SM declared as
class(privateoperator(), not composable) worked correctly, because non-composable states go through the primaryget_state_mappingtemplate which always tries bothstate_mappingandany_state_mapping.Fix
In
get_state_mapping<sm<T>, TMappings, TUnexpected>::type::execute():get_id_safe<R,T>is added as a variadic-fallback variant ofget_idthat returnsstatic_cast<R>(-1)whenTis not in the state list. This makesis_terminated_implsafe to call on sub-SMs that have noX-terminating transitions (previously it would fail to compile for them). The value-1can never equal a valid (non-negative) state ID, sois_terminated()correctly returnsfalsefor such SMs.Test
test/ft/issue_622_any_state_nested.cpp:any_state_fires_after_nested_sub_sm_terminates: outer SM in composablesub_a;e1terminates the sub-SM and the outer wildcardany + e1 = state_bmust fire → outer SM instate_b.any_state_leaf_baseline: wildcard for non-composable (leaf) states works as before.Verification
static_assertfailure unrelated to this PR, tracked by #698)Closes #622.