-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New handling of startup/shutdown/reset reactions in modes #1169
Conversation
The implementation is complete and this PR and the related ones are ready for review. The benchmark tests still fail because the fix in the benchmark repository is not yet merged. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! The website documentation will also need to be updated.
@@ -134,7 +134,7 @@ TargetDecl: | |||
((parens+='(' (init+=Expression (',' init+=Expression)*)? parens+=')') | |||
| (braces+='{' (init+=Expression (',' init+=Expression)*)? braces+='}') | |||
)? | |||
) ';'? | |||
) (reset?='reset')? ';'? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused about this syntax. What does it mean if a state variable of type foo*
is marked as reset
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also find it a bit strange to see this modifier at the end of the declaration. I think it would make more sense to have it at the beginning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, I'm thinking that a keyword like transient
might be better, because it is a clear adjective and a much less frequently used term in variable names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't reset
already a keyword (for reset transitions)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I always like to be able to effortlessly use programming language syntax in natural language in ways that makes sense. To me, a state ... reset
is awkward, whereas transient state
(or something along those lines) makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see why that's desirable. I still think it's better to have reset state ...
than state ... reset
.
Do you know what the reset behavior is for state variables with a pointer types?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added the reset as a shorthand notation for resetting the state variable in a reset reaction, so I agree with @edwardalee that it should have a connection to it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my mind, I do not consider the reset as an integral component of the state variable but rather a handler added to it, like a deadline or an after delay. I also did not want to draw to much attention to it by putting it first but if you think a reset state
makes more sense, I can change that.
Do you know what the reset behavior is for state variables with a pointer types?
Well, the variable is reset to the initial value provided by the user. I assumed that there always has to be one but if that was a misconception, I will add an error message in case reset
is used without an initial value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handlers go at the end, sure, but this isn't really a handler but a modifier that labels the state as being automatically reset. I suggest we put the reset
in front of the state variable declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good to me, except for the syntax (as pointed out in conversation). If also really like your suggestion to validate that any state variable that is marked as reset indeed has an initial state assigned to it.
org.lflang.ui/src/org/lflang/ui/highlighting/LFSemanticHighlightingCalculator.java
Show resolved
Hide resolved
declaration. Also adjusted test models to new grammar.
Ok
|
Rust benchmark tests currently fail because there are newly added models using |
Is this ready to merge? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes are looking great! My only comment is that the new validator checks should have unit tests. Other than that, this looks ready to merge.
Also fixed bugs in tested rules.
Also corrected display of mode-local state variables.
The basic toText functions include code correspondence tags that are irrelevant and unappealing to the diagram.
=} | ||
|
||
initial mode One { | ||
state counter1:int(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
} | ||
names.add(instantiation.getName()); | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Check(CheckType.FAST) | ||
public void checkMissingStateResetInMode(Reactor reactor) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It appears that a reset
transition is the default, meaning that is no modifier is given in the transition effect, this is to mean that it is a reset transition. This could be confusing, because it may suggest that a "normal" transition is of a different kind than reset
or continue
. We had a similar problem with actions, and decided that it would be better to require a disambiguation from the programmer and thus only allow logical action
or physical action
, and not just action
. I think we should take the same approach here, and enforce this in the validator so we can present a useful error message.
STARTUP='startup' | SHUTDOWN='shutdown' | RESET='reset'; | ||
|
||
enum ModeTransition: | ||
RESET='reset' | HISTORY='continue'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still a bit on the fence about the continue
keyword. If refer to this a "history transition" and label it with an "H" in the diagram, then why don't we just use the history
keyword and avoid all confusion?
@@ -29,6 +29,10 @@ reactor Modal { | |||
state counter1(0) | |||
timer T1(0msec, 250msec) | |||
|
|||
reaction(reset) {= |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -2221,7 +2222,153 @@ public void testUnrecognizedTarget() throws Exception { | |||
"Unrecognized target: Pjthon"); | |||
} | |||
|
|||
|
|||
@Test | |||
public void testInitialMode() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Thanks for putting these in!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks really good. I raised a couple points about syntax, validation, and visual representation. If you have the bandwidth, I would prefer we address these issues as part of this PR... I'm also fine with merging and adding fixes later.
I'll go ahead and merge this in to avoid stalling things any further. I've created issues to track my comments. |
Requires reactor-c PR #79
Requires benchmarks PR #15
Requires benchmarks PR #18
Implies website PR #67
Implies website PR #68
Closes #999
Closes #1048
Implements the following semantics:
TODO: