-
-
Notifications
You must be signed in to change notification settings - Fork 672
Fix compiler crash when certain operators used on types #2 #2293
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
Closed
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 hidden or 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 hidden or 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,53 @@ | ||
{ | ||
"asc_flags": [ | ||
], | ||
"stderr": [ | ||
"AS234: Expression does not compile to a value at runtime.", "++Foo;", | ||
"TS2469: The '++' operator cannot be applied to type 'void'.", "++Foo;", | ||
"AS234: Expression does not compile to a value at runtime.", "Foo += 1;", | ||
"TS2469: The '+' operator cannot be applied to type 'void'.", "Foo += 1;", | ||
"AS234: Expression does not compile to a value at runtime.", "Foo--;", | ||
"TS2469: The '--' operator cannot be applied to type 'void'.", "Foo--;", | ||
"AS234: Expression does not compile to a value at runtime.", "--Foo;", | ||
"TS2469: The '--' operator cannot be applied to type 'void'.", "--Foo;", | ||
"AS234: Expression does not compile to a value at runtime.", "Foo -= 1;", | ||
"TS2469: The '-' operator cannot be applied to type 'void'.", "Foo -= 1;", | ||
"AS234: Expression does not compile to a value at runtime.", "Array++;", | ||
"TS2469: The '++' operator cannot be applied to type 'void'.", "Array++;", | ||
"AS234: Expression does not compile to a value at runtime.", "++Array;", | ||
"TS2469: The '++' operator cannot be applied to type 'void'.", "++Array;", | ||
"AS234: Expression does not compile to a value at runtime.", "Array += 1;", | ||
"TS2469: The '+' operator cannot be applied to type 'void'.", "Array += 1;", | ||
"AS234: Expression does not compile to a value at runtime.", "Array--;", | ||
"TS2469: The '--' operator cannot be applied to type 'void'.", "Array--;", | ||
"AS234: Expression does not compile to a value at runtime.", "--Array;", | ||
"TS2469: The '--' operator cannot be applied to type 'void'.", "--Array;", | ||
"AS234: Expression does not compile to a value at runtime.", "Array -= 1;", | ||
"TS2469: The '-' operator cannot be applied to type 'void'.", "Array -= 1;", | ||
"AS234: Expression does not compile to a value at runtime.", "const a = (Foo++);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const a = (Foo++);", | ||
"AS234: Expression does not compile to a value at runtime.", "const b = (++Foo);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const b = (++Foo);", | ||
"AS234: Expression does not compile to a value at runtime.", "const c = (Foo += 1);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const c = (Foo += 1);", | ||
"AS234: Expression does not compile to a value at runtime.", "const d = (Foo--);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const d = (Foo--);", | ||
"AS234: Expression does not compile to a value at runtime.", "const e = (--Foo);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const e = (--Foo);", | ||
"AS234: Expression does not compile to a value at runtime.", "const f = (Foo -= 1);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const f = (Foo -= 1);", | ||
"AS234: Expression does not compile to a value at runtime.", "const g = (Array++);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const g = (Array++);", | ||
"AS234: Expression does not compile to a value at runtime.", "const h = (++Array);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const h = (++Array);", | ||
"AS234: Expression does not compile to a value at runtime.", "const i = (Array += 1);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const i = (Array += 1);", | ||
"AS234: Expression does not compile to a value at runtime.", "const j = (Array--);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const j = (Array--);", | ||
"AS234: Expression does not compile to a value at runtime.", "const k = (--Array);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const k = (--Array);", | ||
"AS234: Expression does not compile to a value at runtime.", "const l = (Array -= 1);", | ||
"TS2322: Type 'i32' is not assignable to type 'void'.", "const l = (Array -= 1);", | ||
"EOF" | ||
] | ||
} |
This file contains hidden or 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,39 @@ | ||
/* eslint-disable no-class-assign */ | ||
/* eslint-disable no-global-assign */ | ||
|
||
class Foo {} | ||
|
||
Foo++; | ||
++Foo; | ||
Foo += 1; | ||
|
||
Foo--; | ||
--Foo; | ||
Foo -= 1; | ||
|
||
Array++; | ||
++Array; | ||
Array += 1; | ||
|
||
Array--; | ||
--Array; | ||
Array -= 1; | ||
|
||
const a = (Foo++); | ||
const b = (++Foo); | ||
const c = (Foo += 1); | ||
|
||
const d = (Foo--); | ||
const e = (--Foo); | ||
const f = (Foo -= 1); | ||
|
||
|
||
const g = (Array++); | ||
const h = (++Array); | ||
const i = (Array += 1); | ||
|
||
const j = (Array--); | ||
const k = (--Array); | ||
const l = (Array -= 1); | ||
|
||
ERROR("EOF"); |
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.
Iirc,
.exceptVoid
makes sure that ifcontextualType
is somehowvoid
(could be a result of a previous error), thatcompileExpression
here doesn't produce adrop
, an expression that is never, say, assignable to a local, which would lead to validation errors in Binaryen. A way to test whether this leads to problems with the change could be a test for++someFunctionReturningVoid()
.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.
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, that's already good. Then I wonder if there is still a way to produce a
void
type using a variable or property access, perhaps via a previous error. The general idea is that we don't want Binaryen to blow up but to diagnose every possible error ourselves. Do you know why exactly this is blowing up with.exceptVoid
in place?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, because there is a missing check. I am adding a new commit right now.
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.
Taking a step back, am I assuming correctly that the use of
.exceptVoid
prevents a fix inmakeAssignment
? If so, what istarget.kind
inmakeAssignment
with.exceptVoid
in place and does commenting out theassert
being hit still produce the expected diagnostic?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.
Hmm, what about removing the last
assert
inmakeAssignment
and add a default case?Essentially I am not sure about the
.exceptVoid
change as it seems unrelated. If something goes wrong when compiling with.exceptVoid
, this would already produce an error before the resulting compiled expression is returned (here the case: AS234, just not diagnosed because anassert
is hit before diagnostics are printed), with the compiled expression not really mattering anymore, except that it cannot be adrop
, which.exceptVoid
prevents. The alternative is ofc to add a bunch of late checks, but that seems good to avoid.Unfortunately, though, my modification only works for
++String
from the initial example, but not++i32
, but the latter is probably a separate bug related toi32(...)
being a builtin function.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.
Why doesn't
Foo += 1
use.exceptVoid
? My changes directly reflect the former's implementation; they are, in essence, the same thing. Do all of those compound operators need changing?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.
My concern is mostly that
.exceptVoid
seems unrelated in this PR, so that the fix can be simpler (no additional late checks). It might be the case that.exceptVoid
can be removed, or it might not be the case, but I'm hesitant to make this call here.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 insist on this asymmetry? If
Foo
can be void, then what happens when there isFoo += 1
instead ofFoo++
? I lean towards either removing.exceptVoid
or changing the implementation of all compound operators. I'm fine with either of the aforementioned.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'd be fine to thoroughly investigate the asymmetry separately I think. If
Foo +=1
does not use.exceptVoid
, it seems that it should to be sure. Other than that it doesn't seem necessary to remove.exceptVoid
as it serves a purpose, even if the issue it prevents is untypical.