-
-
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
Use type information to simplify membership tests #1406
Conversation
This simplifier rewrites vacuously true set membership tests based on type information.
Codecov Report
@@ Coverage Diff @@
## unstable #1406 +/- ##
============================================
+ Coverage 76.07% 76.08% +0.01%
============================================
Files 338 339 +1
Lines 10962 10985 +23
Branches 546 542 -4
============================================
+ Hits 8339 8358 +19
- Misses 2623 2627 +4
Continue to review full report at Codecov.
|
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/SetMembershipSimplifier.scala
Outdated
Show resolved
Hide resolved
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/SetMembershipSimplifier.scala
Outdated
Show resolved
Hide resolved
Co-authored-by: Kukovec <jure.kukovec@gmail.com>
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'll sign off, since this was the only blocking issue I had, but I'd like to hear @konnov and @shonfeder 's thoughts on #1406 (comment).
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!
Well here we go... there was a bug in the abstraction (membership test with @Kukovec @shonfeder Do you think this is easier to read and maintain than my original solution? |
I don't know how we missed |
At least the OOPSLA encoding already does this, is there any benefit to doing it early? |
I don't remember the details, but we probably do it only for state variables. You can write something like this in TLA+ \E i \in Int:
i \in Nat => ... |
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, though I think you could get away with not doing any checks on the type tags. It's not wrong to check, in any case, but if you ever wanted to write
VARIABLE
\* @type: Int;
x
...
TypeOK == x \in BOOLEAN
Snowcat would reject that outright, since \in
has type constraints.
tla-pp/src/main/scala/at/forsyte/apalache/tla/pp/SetMembershipSimplifier.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.
Great! This PR transforms basic types. How about seq \in Seq(Int)
and fun \in [Int -> Int]
. Perhaps, something could be done about records and tuples too. Having the type information, we can do a lot of interesting simplifications.
Right, I was wondering about it, but was unsure if me might use this in a different context where Snowcat isn't run first. |
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.
Added one more comment.
Addresses #723
Uses type information to simplify membership tests such as
x \in BOOLEAN
,x \in Int
,x \in STRING
,x \in Seq(...)
when we know thatx
has the appropriate type.