-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add attribute-based overloading (#3985)
This PR is the next step towards the changes suggested in #3966; having added a new syntax for the `symbol(_)` attribute in #3978, we can now address the second use of `klabel(_)` (marking overloaded sets of symbols). The changes in this PR are as follows: * Add a new attribute `overload(_)` that behaves identically to the current semantics of `klabel(_)` with respect to the construction of the overload partial ordering, but that does not participate in the _naming_ of symbols. * Add checks for the new attribute: * Disallow `klabel(_)` and `overload(_)` on the same production; overload sets must be converted fully to use the new mechanism. * Warn when an overload set of only one production is generated. * Document the semantics of overloading in the user manual based on our conversations in #3966. * Add a new integration test that checks a simple example of overloading works as expected to disambiguate parses. Once this PR is merged, we can begin the long process of deprecating `klabel(_)` and `symbol`! --------- Co-authored-by: rv-jenkins <[email protected]>
- Loading branch information
1 parent
62ce57b
commit f259d22
Showing
16 changed files
with
218 additions
and
17 deletions.
There are no files selected for viewing
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
11 changes: 11 additions & 0 deletions
11
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module SINGLETONOVERLOAD-SYNTAX | ||
endmodule | ||
|
||
module SINGLETONOVERLOAD | ||
imports ID | ||
|
||
syntax LVal ::= L() [unused] | ||
| LVal "." Id [unused, overload(_.)] | ||
syntax Exp ::= LVal | ||
| Exp "." Id [unused, overload(_._)] | ||
endmodule |
11 changes: 11 additions & 0 deletions
11
k-distribution/tests/regression-new/checkWarns/singletonOverload.k.out
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
[Error] Compiler: Production has an `overload(_)` attribute but is not an overload of any other production. | ||
Source(singletonOverload.k) | ||
Location(8,19,8,53) | ||
8 | | LVal "." Id [unused, overload(_.)] | ||
. ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
[Error] Compiler: Production has an `overload(_)` attribute but is not an overload of any other production. | ||
Source(singletonOverload.k) | ||
Location(10,19,10,54) | ||
10 | | Exp "." Id [unused, overload(_._)] | ||
. ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
[Error] Compiler: Had 2 structural errors. |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module OVERLOADKLABEL | ||
imports ID | ||
syntax Exp ::= LVal | ||
| Exp "." Id [klabel(_._), overload(_._)] | ||
syntax LVal ::= LVal "." Id [overload(_._)] | ||
endmodule |
6 changes: 6 additions & 0 deletions
6
k-distribution/tests/regression-new/checks/overloadKLabel.k.out
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[Error] Compiler: The attributes `klabel(_)` and `overload(_)` may not occur together. | ||
Source(overloadKLabel.k) | ||
Location(4,19,4,59) | ||
4 | | Exp "." Id [klabel(_._), overload(_._)] | ||
. ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
[Error] Compiler: Had 1 structural errors. |
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
DEF=test | ||
EXT=test | ||
TESTDIR=. | ||
KOMPILE_FLAGS=--syntax-module TEST | ||
|
||
include ../../../include/kframework/ktest.mak |
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
E().x |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<k> | ||
E ( ) . x ~> .K | ||
</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 |
---|---|---|
@@ -0,0 +1 @@ | ||
L().x |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<k> | ||
done ( ) ~> .K | ||
</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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module TEST | ||
imports ID | ||
|
||
syntax LVal ::= L() | ||
syntax Exp ::= E() | ||
| LVal | ||
|
||
syntax Exp ::= Exp "." Id [overload(_._)] | ||
syntax LVal ::= LVal "." Id [overload(_._)] | ||
|
||
syntax KItem ::= done() | ||
rule _:LVal => done() | ||
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
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