diff options
author | Alon Zakai <azakai@google.com> | 2020-07-30 11:41:43 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-30 11:41:43 -0700 |
commit | f8cd0ad7e2aa389ac04c5978ed9d654bdcf1e22f (patch) | |
tree | 0108600b45278469bd29f7b18a843afddb271563 /test/wasm2js/switch.2asm.js | |
parent | 4253dae801b7f5526c28c4bbd8cda1d32067344d (diff) | |
download | binaryen-f8cd0ad7e2aa389ac04c5978ed9d654bdcf1e22f.tar.gz binaryen-f8cd0ad7e2aa389ac04c5978ed9d654bdcf1e22f.tar.bz2 binaryen-f8cd0ad7e2aa389ac04c5978ed9d654bdcf1e22f.zip |
wasm2js: Add an "Export" scope for name resolution (#2998)
Previously we used "Top" for both exports and the top level
(which has functions and globals). The warning about name
collisions there was meant only for exports (where if a name
collides and so it must be renamed, means that there will
be an externally-visible oddness for the user). But it applied
to functions too, which could be annoying, and was not
dangerous (at worst, it might be confusing when reading the
emitted JS and seeing NAME_1, NAME_2, but there is no
effect on execution or on exports).
To fix this, add a new Export name scope. This separates
function names from export names. However, it runs into
another issue which is that when checking for a name conflict
we had a big set of all the names in all the scopes. That is,
FOO would only ever be used in one scope, period, and
other appearances of that Name in wasm would get a
suffix. As a result, if an exported function FOO has the name
foo, we'd export it as FOO but name the function FOO_1
which is annoying. To fix that, keep sets of all names in each
scope. When mangling a name we can then only care about
the relevant scope, EXCEPT for local names, which must
also not conflict with function names. That is, this would be
bad:
function foo(bar) {
var bar = 0;
}
function bar() { ..
It's not ok to call a parameter "bar" if there is a function by
that name (well, it could be if it isn't called in that scope).
So when mangling the Local scope, also check the Top one
as well.
The test output changes are due to non-overlapping scopes,
specifically Local and Label. It's fine to have
foo : while(1) {
var foo = 5;
}
Those "foo"s do not conflict.
Fixes emscripten-core/emscripten#11743
Diffstat (limited to 'test/wasm2js/switch.2asm.js')
-rw-r--r-- | test/wasm2js/switch.2asm.js | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/test/wasm2js/switch.2asm.js b/test/wasm2js/switch.2asm.js index 3c2572315..8b6f0223a 100644 --- a/test/wasm2js/switch.2asm.js +++ b/test/wasm2js/switch.2asm.js @@ -58,7 +58,7 @@ function asmFunc(global, env, buffer) { function $1(i, i$hi) { i = i | 0; i$hi = i$hi | 0; - var i64toi32_i32$5 = 0, i64toi32_i32$2 = 0, $7_1 = 0, $7$hi = 0, j = 0, j$hi = 0; + var i64toi32_i32$5 = 0, i64toi32_i32$2 = 0, $7 = 0, $7$hi = 0, j = 0, j$hi = 0; j = 100; j$hi = 0; switch_ : { @@ -73,7 +73,7 @@ function asmFunc(global, env, buffer) { i64toi32_i32$2 = 0; i64toi32_i32$5 = (i64toi32_i32$2 >>> 0 < i >>> 0) + i$hi | 0; i64toi32_i32$5 = 0 - i64toi32_i32$5 | 0; - $7_1 = i64toi32_i32$2 - i | 0; + $7 = i64toi32_i32$2 - i | 0; $7$hi = i64toi32_i32$5; break switch_; case 6: @@ -84,7 +84,7 @@ function asmFunc(global, env, buffer) { case 4: default: i64toi32_i32$5 = j$hi; - $7_1 = j; + $7 = j; $7$hi = i64toi32_i32$5; break switch_; case 7: @@ -92,43 +92,43 @@ function asmFunc(global, env, buffer) { }; } i64toi32_i32$5 = -1; - $7_1 = -5; + $7 = -5; $7$hi = i64toi32_i32$5; } i64toi32_i32$5 = $7$hi; - i64toi32_i32$2 = $7_1; + i64toi32_i32$2 = $7; i64toi32_i32$HIGH_BITS = i64toi32_i32$5; return i64toi32_i32$2 | 0; } function $2(i) { i = i | 0; - var $5 = 0, $6 = 0, $7_1 = 0, $8 = 0, $9 = 0; - $2_1 : { - $1_1 : { - $0_1 : { + var $5 = 0, $6 = 0, $7 = 0, $8 = 0, $9 = 0; + $2 : { + $1 : { + $0 : { default_ : { $5 = Math_imul(2, i); $6 = $5; - $7_1 = $5; + $7 = $5; $8 = $5; $9 = $5; switch (3 & i | 0 | 0) { case 0: - break $0_1; + break $0; case 1: - break $1_1; + break $1; case 2: - break $2_1; + break $2; default: break default_; }; } $6 = 1e3 + $9 | 0; } - $7_1 = 100 + $6 | 0; + $7 = 100 + $6 | 0; } - $8 = 10 + $7_1 | 0; + $8 = 10 + $7 | 0; } return $8 | 0; } @@ -137,15 +137,15 @@ function asmFunc(global, env, buffer) { return 1 | 0; } - function legalstub$1($0_2, $1_2) { - $0_2 = $0_2 | 0; - $1_2 = $1_2 | 0; - var i64toi32_i32$2 = 0, i64toi32_i32$4 = 0, i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, i64toi32_i32$3 = 0, $12 = 0, $13 = 0, $4 = 0, $4$hi = 0, $7$hi = 0, $2_2 = 0, $2$hi = 0; + function legalstub$1($0_1, $1_1) { + $0_1 = $0_1 | 0; + $1_1 = $1_1 | 0; + var i64toi32_i32$2 = 0, i64toi32_i32$4 = 0, i64toi32_i32$0 = 0, i64toi32_i32$1 = 0, i64toi32_i32$3 = 0, $12 = 0, $13 = 0, $4 = 0, $4$hi = 0, $7$hi = 0, $2_1 = 0, $2$hi = 0; i64toi32_i32$0 = 0; - $4 = $0_2; + $4 = $0_1; $4$hi = i64toi32_i32$0; i64toi32_i32$0 = 0; - i64toi32_i32$2 = $1_2; + i64toi32_i32$2 = $1_1; i64toi32_i32$1 = 0; i64toi32_i32$3 = 32; i64toi32_i32$4 = i64toi32_i32$3 & 31 | 0; @@ -164,7 +164,7 @@ function asmFunc(global, env, buffer) { i64toi32_i32$2 = i64toi32_i32$1 | i64toi32_i32$2 | 0; i64toi32_i32$2 = $1(i64toi32_i32$0 | i64toi32_i32$3 | 0 | 0, i64toi32_i32$2 | 0) | 0; i64toi32_i32$0 = i64toi32_i32$HIGH_BITS; - $2_2 = i64toi32_i32$2; + $2_1 = i64toi32_i32$2; $2$hi = i64toi32_i32$0; i64toi32_i32$1 = i64toi32_i32$2; i64toi32_i32$2 = 0; @@ -179,7 +179,7 @@ function asmFunc(global, env, buffer) { } setTempRet0($13 | 0); i64toi32_i32$2 = $2$hi; - return $2_2 | 0; + return $2_1 | 0; } var FUNCTION_TABLE = []; |