-
Notifications
You must be signed in to change notification settings - Fork 2
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
lang: add explicit type widening (As
)
#122
Merged
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
019c36f
spec: add the semantics/grammar for `As`
zerbina 226501f
source2il: implement `As`
zerbina deed0e7
tests: add tests for `As`
zerbina 2868ba3
tests: simplify existing union tests
zerbina b310b13
Merge branch 'main' into source-lang-as
zerbina cad0e96
tests: add missing test output specs
zerbina a660ef7
spec: adjust the dynamic `As` semantics
zerbina 424535a
tests: add two more tests for `As`
zerbina 7ef3398
source2il: make sure to always copy
zerbina 5450caa
spectest: update the known-issue list
zerbina ac7fe30
Merge branch 'main' into source-lang-as
zerbina 80a2c47
spec: handle `As` in `update`
zerbina 9724ee6
spectest: update the known issues list
zerbina File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
discard """ | ||
output: "1 : (IntTy)" | ||
""" | ||
(As 1 (IntTy)) |
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,4 @@ | ||
discard """ | ||
reject: true | ||
""" | ||
(As 1 (VoidTy)) |
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,4 @@ | ||
discard """ | ||
reject: true | ||
""" | ||
(As 1 (UnitTy)) |
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,5 +1,4 @@ | ||
discard """ | ||
output: "100 : (UnionTy (IntTy) (FloatTy))" | ||
""" | ||
(ProcDecl (Ident "a") (UnionTy (IntTy) (FloatTy)) (Params) | ||
(Return (IntVal 100))) | ||
(As 100 (UnionTy (IntTy) (FloatTy))) |
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,5 +1,4 @@ | ||
discard """ | ||
output: "1.5 : (UnionTy (IntTy) (FloatTy))" | ||
""" | ||
(ProcDecl (Ident "a") (UnionTy (IntTy) (FloatTy)) (Params) | ||
(Return (FloatVal 1.5))) | ||
(As 1.5 (UnionTy (IntTy) (FloatTy))) |
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,5 +1,4 @@ | ||
discard """ | ||
output: "100 : (UnionTy (IntTy))" | ||
""" | ||
(ProcDecl (Ident "a") (UnionTy (IntTy)) (Params) | ||
(Return (IntVal 100))) | ||
(As 100 (UnionTy (IntTy))) |
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,5 +1,4 @@ | ||
discard """ | ||
reject: true | ||
""" | ||
(ProcDecl (Ident "a") (UnionTy (IntTy) (IntTy)) (Params) | ||
(Return (IntVal 100))) | ||
(As 100 (UnionTy (IntTy) (IntTy))) |
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,13 +1,6 @@ | ||
discard """ | ||
description: "Ensure types unify for an if-expression" | ||
""" | ||
(Module | ||
(ProcDecl (Ident "p") (UnionTy (IntTy) (FloatTy)) (Params) | ||
(Return (IntVal 100))) | ||
|
||
(ProcDecl (Ident "test") (UnionTy (IntTy) (FloatTy)) (Params) | ||
(Return | ||
(If (Ident "true") | ||
(FloatVal 0.5) | ||
(Call (Ident "p"))))) | ||
) | ||
(If (Ident "true") | ||
(FloatVal 0.5) | ||
(As (IntVal 100) (UnionTy (IntTy) (FloatTy))))) |
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,13 +1,6 @@ | ||
discard """ | ||
description: "Ensure types unify for an if-expression" | ||
""" | ||
(Module | ||
(ProcDecl (Ident "p") (UnionTy (IntTy) (FloatTy)) (Params) | ||
(Return (IntVal 100))) | ||
|
||
(ProcDecl (Ident "test") (UnionTy (IntTy) (FloatTy)) (Params) | ||
(Return | ||
(If (Ident "false") | ||
(Call (Ident "p")) | ||
(FloatVal 0.5)))) | ||
) | ||
(If (Ident "false") | ||
(As (IntVal 100) (UnionTy (IntTy) (FloatTy))) | ||
(FloatVal 0.5)))) |
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,12 +1,8 @@ | ||
discard """ | ||
output: "1.5 : (UnionTy (IntTy) (FloatTy))" | ||
""" | ||
(Module | ||
(ProcDecl (Ident "union") (UnionTy (IntTy) (FloatTy)) (Params) | ||
(Return (IntVal 100))) | ||
|
||
(ProcDecl (Ident "test") (UnionTy (IntTy) (FloatTy)) (Params) | ||
(Exprs | ||
(Decl (Ident "x") (Call (Ident "union"))) | ||
(Asgn (Ident "x") (FloatVal 1.5)) | ||
(Return (Ident "x"))))) | ||
(Exprs | ||
(Decl (Ident "x") | ||
(As (IntVal 100) (UnionTy (IntTy) (FloatTy)))) | ||
(Asgn (Ident "x") (FloatVal 1.5)) | ||
(Ident "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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
discard """ | ||
output: "(array 1 2 3) : (UnionTy (IntTy) (SeqTy (IntTy)))" | ||
""" | ||
(Module | ||
(ProcDecl union (UnionTy (IntTy) (SeqTy (IntTy))) (Params) | ||
(Return 1)) | ||
(ProcDecl main (UnionTy (IntTy) (SeqTy (IntTy))) (Params) | ||
(Exprs | ||
(Decl x (Seq (IntTy) 1 2 3)) | ||
(Decl y (Call union)) | ||
(Asgn y x) | ||
(Asgn (At x 0) 4) | ||
(Return y)))) | ||
(Exprs | ||
(Decl x (Seq (IntTy) 1 2 3)) | ||
(Decl y | ||
(As 1 (UnionTy (IntTy) (SeqTy (IntTy))))) | ||
(Asgn y x) | ||
(Asgn (At x 0) 4) | ||
y) |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 still learning to read the source, but it seems that lvalue-ness and mutability dropping isn't there, I'm guessing it can't be represented?
I guess the drop is required right now because if we're actually widening the bits then a new location would be required?
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 there, albeit not easy to spot.
exprToIL
(the enclosing procedure) returns anExprType
, which is a type + qualifiers (ExprFlags
, currently a bunch of flags), where the qualifiers track both mutability and lvalue-ness.If the qualifiers were to be kept, the result assignment would look like this:
Yep, that's the idea. If no widening takes place, then no new location is needed, so the lvalue-ness and mutability could be kept, but I decided against it because:
As
does (the same problem exists in NimSkull with lvalue conversions)This doesn't have to (nor should it have to) be the final decision, however. If it turns out that the current rules are problematic (for whatever reason), we should alter them.