-
-
Notifications
You must be signed in to change notification settings - Fork 673
Fix const enum compilation failure #1120
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
Conversation
I believe the underlying idea was that if one has an enum like enum A {
A
} that the value of enum A {
B = 2;
C;
} that the value of C would become Regarding the PR specifically, it is not possible to reuse the same expression as a member of two different expressions, so if Looks like there should instead be a case where if the enum is |
You say it isn't possible, but the code seems to work 🤔 here's the example that wasn't previously working: // foo.ts
export const enum Foo {
Boo1, Boo2, Boo3, Boo4
}
// main.ts
import { Foo } from './foo';
export function test(): i32 {
return Foo.Boo1 + Foo.Boo2 + Foo.Boo3 + Foo.Boo4);
} With this change it compiles and outputs: What's the scenario where this fails? Not sure I understand |
Not reusing the same expression multiple times is a Binaryen convention. From their README:
|
Ah I see. Back to the drawing board, I'll look into what you suggested above. Thanks for the review |
48803d1
to
46e30b1
Compare
46e30b1
to
7cd0562
Compare
This should be ready for review again |
479b944
to
cd36d28
Compare
compilation failure
cd36d28
to
7dcaa7e
Compare
Thank you! :) |
Issue: #574
If you tried to use a const enum with multiple members, you would receive a compilation failure.
This was because the compiler relied upon each enum value to be registered as a global value in order to determine what the next enum value was. As a result, when we inlined the enum values and did not register that global value, compilation would fail.
To fix this, I've changed this method around a bit to rely upon the last expression value used (held in
initExpr
) rather than trying to load from the global store.I'm not sure why it was implemented the way it was originally- it's possible that there is some tradeoff involved here I'm unaware of which causes reading from the global store to be faster/more efficient than simply reusing the last expression statement used in the loop. This certainly seems to work from a functional perspective 🤷♂