Closed kheradmand closed 1 year ago
The problem may be related to kframework/k#1950 because there is a similar unexpected non-determinism a few steps before the crash.
In addition, when I remove rule if ( B:BoolExpr ) C:ControlBlock Rest:ControlStatements => if ( B ) C else { .ControlStatements } Rest [macro]
, there is no crash.
It is very suspicious that the symbol Lbl'UndsUndsUnds'TEST-SYNTAX'Unds'ControlStatements'Unds'ControlStatement'Unds'ControlStatements{}
is not a constructor.
I confirmed my suspicion: Lbl'UndsUndsUnds'TEST-SYNTAX'Unds'ControlStatements'Unds'ControlStatement'Unds'ControlStatements
is given the macro
attribute and so not given the constructor
attribute. I'm sending this back to the frontend.
@kheradmand actually, I think you may be able to fix this pretty simply by just changing the macro
rule to not use the list-concat symbol as well.
rule if ( B:BoolExpr ) C:ControlBlock => if ( B ) C else { .ControlStatements } [macro]
Notice how Rest
is removed.
@ehildenb Thanks! Using your suggestion does prevent the crash (I also prevented it by removing the macro). However I opened this issue due to the crash itself (per the crash message).
I'm not sure if the crash is due to an internal problem or a user error. In any case, a more informative warning or error message would be nice as there was no easy way (that I know) to find out that the crash was due to using this macro (took about two full weeks of trial and error in a moderately sized definition to pinpoint it). Once it was pinpointed, the "fix" was easy.
I'm not sure if the crash is due to an internal problem or a user error.
It is due to user error. The root cause is that requiring the macro
attribute on the rule
allows for this kind of "action at a distance". The frontend should make it hard to do this by accident, by requiring the macro
attribute on the syntax
.
The frontend now correctly outputs a warning:
% kompile --backend haskell test.k
[Warning] Compiler: The attribute [macro] has been deprecated on rules. Use
this label on syntax declarations instead.
Source(/home/dev/src/k/test.k)
Location(37,13,37,115)
37 | rule if ( B:BoolExpr ) C:ControlBlock Rest:ControlStatements => if
( B ) C else { .ControlStatements } Rest [macro]
.
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
And krun
still crashes as expected. The following definition works:
module TEST-SYNTAX
imports ID
imports BOOL
syntax ControlFunctionDeclaration ::= "control" Id ControlBlock
syntax ControlBlock ::= "{" ControlStatements "}"
syntax ControlStatements ::= List{ControlStatement,""} [klabel(controlStatements)]
syntax ControlStatement ::=
ApplyTableCall
| IfElseStatement
syntax ApplyTableCall ::= "apply" "(" TableName ")" ";"
syntax IfElseStatement ::=
"if" "(" BoolExpr ")" ControlBlock [macro]
| "if" "(" BoolExpr ")" ControlBlock ElseBlock
syntax ElseBlock ::= "else" ControlBlock | "else" IfElseStatement
syntax BoolExpr ::= Bool
syntax TableName ::= Id
endmodule
module TEST
imports DOMAINS
imports TEST-SYNTAX
configuration
<k> @evalStatements($PGM:ControlStatements) </k>
<ts> .List </ts>
syntax KItem ::= "@evalStatements" "(" ControlStatements ")" | "@evalStatement" "(" ControlStatement ")"
rule @evalStatements(S:ControlStatement Rest:ControlStatements) => @evalStatement(S) ~> @evalStatements(Rest)
rule @evalStatements(.ControlStatements) => .K
rule @evalStatement(S) => S
rule if ( B:BoolExpr ) C:ControlBlock => if ( B ) C else { .ControlStatements }
rule if (true) {C1} else {_} => @evalStatements(C1)
syntax KResult ::= Bool
endmodule
You get:
% kompile --backend haskell test.k
% krun input.test
<generatedTop>
<k>
apply ( t ) ; ~> @evalStatements ( .ControlStatements ) ~> @evalStatements ( .ControlStatements ) ~> .
</k>
<ts>
.List
</ts>
</generatedTop>
Note the changes I had to make to the definition:
imports BOOL
to TEST-SYNTAX
.macro
symbol to the if(_){_}
production.REST
, which is not under the macro production.Closing this as resolved, as the frontend is correctly reporting the problem to the user now.
Version
Module
intput.test
Steps:
kore-exec.tar.gz