-
Notifications
You must be signed in to change notification settings - Fork 97
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
Fix and simplify lub/glb #2360
Fix and simplify lub/glb #2360
Conversation
This PR does not affect the produced WebAssembly code. |
With @crusso on vacation, anybody else wants to review this? |
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.
Not 100% confident on everything, in particular not subtyping on functions with type bounds, so another review by @crusso might improve quality. But if you want to get this out, here is a LGTM
| _, [] -> if rel == lubs then [] else fs1 | ||
| [], _ -> if rel == lubs then [] else fs2 |
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.
| _, [] -> if rel == lubs then [] else fs1 | |
| [], _ -> if rel == lubs then [] else fs2 | |
| _, [] -> if rel == glbs then fs1 else [] | |
| [], _ -> if rel == glbs then fs2 else [] |
More symmetric with both cons_if
below, and with combine_tags
This seems fishy to me, though I don't think its new behaviour: As expected:
So a var field never subtypes a non-var field, as expected. Except we do allow it if the super type field has type
And thus also:
If |
Yes, that matches what the subtype relation has always defined. We have discussed restricting it before. Originally the liberal rule was nice, because it made lubs/glbs fully defined and compositional. But with the advent of Typ, that's out the window anyway. So I went ahead and changed that as part of this PR, i.e., Also tweaked tests to prevent more liberal subtyping than intended. |
{x : Nat} | ||
and | ||
{var x : Nat} | ||
{x : Any} | ||
{} |
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.
Are there some words missing between the last two types in this error message or has run.sh just stripped them out?
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.
Yes, this is some artefact due to our test scripts. IIRC, @kritzcreek first ran into this a while ago and might be able to tell you more.
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.
Yeah it's one of the regexes in run.sh
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.
Do you remember which one? I can't spot one that would cause this.
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.
It's matching at common supertype
with:
^ *at '
from here (I think):
Line 64 in 198c0ea
grep -a -E -v '^Raised by|^Raised at|^Re-raised at|^Re-Raised at|^Called from|^ *at ' $1 | |
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.
OK, not a real bug then
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.
Okay, this annoyed me, so I tweaked the regexp to not misfire on the error message. Seems to work. :)
| Some fs -> Obj (s1, fs) | ||
) | ||
| Func (s1, c1, bs1, args1, res1), Func (s2, c2, bs2, args2, res2) when | ||
(try Obj (s1, combine_fields rel lubs glbs tf1 tf2) |
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'm not too crazy about the use of exceptions for this - meant to be spec-like - can you not have combine_fields
and (for arrays) a combine_element
function that handles the special second class types, sans exceptions, and just assert on the second class types in combine
?
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.
Yeah, I went back and forth on how to handle the partiality here. This way, its simplest and the structure of the function remains parallel to all others, especially sub, which is valuable. If we wanted a different structure, then that should apply everywhere and better be reflected in the type definition itself.
Not too worried about the spec aspect in this case -- these are algorithms that wouldn't appear in a spec. Their declarative spec is that of a lub/glb wrt the subtype relation.
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.
Fair enough.
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
Thanks Claudio! Now please turn off this damn computer! |
Refactor lub and glb into a single unified operation and a few fixes:
While here, also removed subtyping between second-class types like Mut and Typ and Any/Non.
Fixes #515 (up to other potential pretty printing changes).