-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix "singleton overload" check for user lists (#4129)
When working on #4045, I identified a case in the C Semantics where an overload set was flagged as being singletons (that is, that the productions in the set were not actually overloads of one another). Despite this warning, removing the `overload(_)` attributes broke compilation by producing a parsing ambiguity. It turns out that the issue was a difference between the main module and the _disambiguation module_ produced during the inner parsing process. The disambiguation module adds an additional production ``` Es ::= E ``` for user list sorts `Es` that subsorts the list element sort into the list sort. This means that two productions ``` S ::= f(Es) T ::= f(E) ``` can be overloads of one another. However, this check was only using the overloads induced by the main module and not those used by the disambiguation module. The fix is simply to compute the disambiguation module[^1] and use its overloads for the checks. Doing so requires some changes to the plumbing; the subsorting production is previously only added when `RULE-LISTS` is imported, but we need to short-circuit that code path in this context. This PR includes a regression test minimised from the original example. [^1]: I tried a cheaper fix that just checks parameters of overload-attributed productions to see if they appear in a user list, but this isn't sufficiently general in the case where the overload parameter is actually a sub-/supersort of the user list element, as happens in the C semantics.
- Loading branch information
Showing
4 changed files
with
57 additions
and
9 deletions.
There are no files selected for viewing
23 changes: 22 additions & 1 deletion
23
k-distribution/tests/regression-new/checkWarns/singletonOverload.k
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,32 @@ | ||
module SINGLETONOVERLOAD-SYNTAX | ||
endmodule | ||
|
||
module SINGLETONOVERLOAD | ||
module WARNS | ||
imports ID | ||
|
||
syntax LVal ::= L() [unused] | ||
| LVal "." Id [unused, overload(_.)] | ||
syntax Exp ::= LVal | ||
| Exp "." Id [unused, overload(_._)] | ||
endmodule | ||
|
||
module NOWARNS | ||
imports BOOL | ||
|
||
syntax Foo ::= "foo" | "bar" | ||
syntax Foos ::= List{Foo, ","} | ||
|
||
syntax Bool ::= test(Foo) [function, overload(test)] | ||
| test(Foos) [function, overload(test)] | ||
|
||
rule test(foo) => true | ||
rule test(bar) => false | ||
|
||
rule test(F, Rest) => test(F) andBool test(Rest) | ||
rule test(.Foos) => true | ||
endmodule | ||
|
||
module SINGLETONOVERLOAD | ||
imports WARNS | ||
imports NOWARNS | ||
endmodule |
This file contains 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
This file contains 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
This file contains 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