-
-
Notifications
You must be signed in to change notification settings - Fork 40
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
Variants in the type checker #1847
Conversation
Codecov Report
@@ Coverage Diff @@
## unstable #1847 +/- ##
============================================
+ Coverage 76.69% 76.76% +0.07%
============================================
Files 391 392 +1
Lines 12005 12038 +33
Branches 550 579 +29
============================================
+ Hits 9207 9241 +34
+ Misses 2798 2797 -1
Continue to review full report at Codecov.
|
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! Some small changes suggested and some questions where I'm unclear, but overall awesome, and I'm psyched to see this landing :D
@@ -110,6 +110,23 @@ class TestAnnotationParser extends AnyFunSuite with Checkers { | |||
.map(r => fail("Expected a failure. Found: " + r)) | |||
} | |||
|
|||
test("parse variants in type aliases") { | |||
val extractedText = | |||
"""MESSAGE =""" + "\n" + """ Req({ ask: Int }) """ + "\n" + """ | Ack({ success: Bool })""" |
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.
Seem like this could be a lot clearer using a multi-line string, no?
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.
For sure. The problem is that stripMargin
is using |
as a delimiter. So the tests were breaking. I could not find a better solution :(
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.
Oh I see! I think we can do
"""MESSAGE =""" + "\n" + """ Req({ ask: Int }) """ + "\n" + """ | Ack({ success: Bool })""" | |
"""#MESSAGE = | |
#| Req({ ask: Int }) | |
#| Ack({ success: Bool })""".stripMargin('#') |
Or using whatever char might be better in place of #
.
I'd suggest making this change improves readability enough that it would be worth making the change here, but i won't block on it.
tla-types/src/main/scala/at/forsyte/apalache/tla/typecheck/etc/ToEtcExpr.scala
Outdated
Show resolved
Hide resolved
tla-types/src/main/scala/at/forsyte/apalache/tla/typecheck/etc/ToEtcExpr.scala
Outdated
Show resolved
Hide resolved
tla-types/src/main/scala/at/forsyte/apalache/tla/typecheck/etc/ToEtcExpr.scala
Outdated
Show resolved
Hide resolved
tla-types/src/main/scala/at/forsyte/apalache/tla/typecheck/etc/ToEtcExpr.scala
Outdated
Show resolved
Hide resolved
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, this new syntax is awesome 😄
tla-io/src/test/scala/at/forsyte/apalache/tla/imp/TestSanyImporterStandardModules.scala
Outdated
Show resolved
Hide resolved
tla-types/src/main/scala/at/forsyte/apalache/tla/typecheck/etc/ToEtcExpr.scala
Outdated
Show resolved
Hide resolved
Co-authored-by: Shon Feder <shon@informal.systems> Co-authored-by: Gabriela Moreira <gabrielamoreiramafra@gmail.com>
@@ -156,6 +157,15 @@ class TestCommentPreprocessor extends AnyFunSuite with Checkers { | |||
hasAnnotationsWhenNonEmpty("""(* aaa *)""") | |||
} | |||
|
|||
test("accept pipe") { | |||
val extractedText = | |||
"""@typeAlias: MESSAGE = { tag: "req", ask: Int }""" + "\n" + """ | { tag: "ack", success: Bool };""" |
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.
Could also be cleaned up here using stripMargin
This PR implements support for the variant type. On the way of implementing it, I have found the proposed syntax too inconvenient to work with, both at the user level and the implementation level. I have refactored it, similar to what was suggested earlier by @shonfeder. This will need an update to the ADRs in follow-up PRs. What is done here:
Variant1(Int) | Variant2({ value: Int, success: Bool})
. SeeDefaultType1Parser
.Variants.tla
.SanyImporter
to support the new API.ToEtcExpr
, which implements the type checking rules.make fmt-fix
(or had formatting run automatically on all files edited)