Skip to content

Conversation

walkie
Copy link
Contributor

@walkie walkie commented Sep 30, 2021

About to create a new release for v0.6.0.

This release includes a lot of work on the Rust back-end:

  • New feature: the current state of the machine is stored as a value of a simple enum type, which can be accessed to determine the state of a running machine.

  • New feature: a new follow_rust_naming feature option has been added and enabled by default. This option significantly improves the conformance of generated code with Rust naming conventions and style guidelines.

  • Temporary feature: a new generate_hook_methods feature has been added that generates "hook" methods that are invoked on each transition or change-state. This feature will be removed and replaced in v0.7.0 by the much more comprehensive runtime_support feature currently available in the runtime-support branch.

  • Completed feature: hierarchical state machines. This enables defining states as children of other states. Event handlers on child states may defer to the corresponding handler on a parent state by terminating the child handler with the "continue" terminator :>. The parent handler will be immediately invoked after a child handler that terminates in :>, if the child handler does not otherwise transition or return.

  • Completed feature: change-state transitions. Change-states (->>) are transitions that do not trigger the usual exit/enter events. Previously, this feature only worked for simple states (states without variables, parameters, or enter event arguments). Now it works in all expected scenarios.

  • Completed feature: state stacks/history. This feature enables pushing states (with corresponding state variables and arguments) to a stack. These states can later be returned to by a "pop transition" using the syntax -> $$[-]. This pops a state from the stack and restores the machine to that state.

  • Refactors and simplifies the generated code, particularly the representation of states and the initialization of state contexts.

  • More names in the generated code are now customizable via the config.yaml interface.

  • Significantly improved test coverage and corresponding bug fixes:

    • Initial states are now initialized correctly and may contain state variables and enter parameters.
    • Transitions inside of match or conditional statements now terminate the execution of a handler.
    • Negated conditional statements (?!) now work as expected.
    • ... and many more!

walkie and others added 30 commits August 13, 2021 10:46
This refactoring also does the following:

 * Removes the introspection feature option (this feature is no longer optional)

 * Changes lower_case_states option to lower_case_methods and applies the option to both state handlers and actions. Additionally, this now uses convert_case to turn the actions into more Rust-like snake_case.

 * Breaks some of the very long methods involved in this refactoring into smaller chunks.

All current tests pass. However, it is likely that the refactoring is incomplete since it hasn't been tested with state parameters or branching control flow yet. Next step is to add tests covering these cases and fix any bugs found.
These don't compile because the generated code is incorrect, so they're currently commented out in lib.rs. Also, the state variable test needs comments translated into asserts once the generator is fixed.
These changes should have been included when adding the state parameter tests since they don't compile without them.
This is currently only applied to methods and variables that use state names, but should eventually be extended to apply to all names that use user-provided names as components.
This overhauls state contexts to be consistent with the new state representation. It also fixes several issues related to state variables and event parameters, which rely on state contexts.

Known issue: Many features do not work with initial states, such as state variables. The workaround is to create a trivial initial state with an enter event handler that transitions into the true initial state. Note that this issue existed before the refactor.

Likely issue: The new state and state context representation is untested with the state history feature. I tried to proactively refactor this but it's likely to contain issues. I also did not test this feature before the refactor, so I'm not sure what the status of this feature is.
The default name `e` collides too easily with user-provided variables. Also, this value was hardcoded many places in the generator.
Or at least as close to everywhere as I can manage!
Note that this test revealed an open parser bug, documented briefly in the comments.
Refactor Rust backend to use simpler state representation
Also some minor cleanup of nearby generated code.
Without the parens, this can be interpreted as a bitwise complement when applied to an expression like `x < 10`.
walkie and others added 29 commits September 2, 2021 14:19
Refactor and fix state contexts in Rust backend
This restores and fixes some code that Mark added before the termination tracking stuff.
Manually revert termination tracking work.
Fix and test state history/stack feature
@walkie walkie merged commit 7e0a062 into main Sep 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants