Skip to content

Commit 11cb13b

Browse files
committed
BREAKING CHANGE: Avoid collisions between static class/namespace members
This commit changes the delimiter between namespaces and their members from "." to "::" in internal names. The new delimiter certainly feels very un-JavaScript-y, but the meaning is still recognizable, and these names aren't exposed to users in most cases anyway. Still, this is a breaking change, as it affects the import names for `declare namespace` members (as seen in tests/compiler/declare.js), and transform authors will also need to update their code accordingly. Fixes AssemblyScript#2793.
1 parent d142ac8 commit 11cb13b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+4140
-4117
lines changed

lib/loader/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ export function demangle(exports, extendedExports = {}) {
371371
: exports["__setArgumentsLength"] || exports["__setargc"] || (() => { /* nop */ });
372372
for (let internalName of Object.keys(exports)) {
373373
const elem = exports[internalName];
374-
let parts = internalName.split(".");
374+
let parts = internalName.split(/\.|::/g);
375375
let curr = extendedExports;
376376
while (parts.length > 1) {
377377
let part = parts.shift();

src/builtins.ts

+509-509
Large diffs are not rendered by default.

src/common.ts

+10-2
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,18 @@ export const PARENT_SUBST = "..";
9494
export const GETTER_PREFIX = "get:";
9595
/** Function name prefix used for setters. */
9696
export const SETTER_PREFIX = "set:";
97-
/** Delimiter used between class names and instance members. */
97+
/**
98+
* Delimiter used between class names and instance members, as well as
99+
* interface names and virtual members.
100+
*/
98101
export const INSTANCE_DELIMITER = "#";
99-
/** Delimiter used between class and namespace names and static members. */
102+
/**
103+
* Delimiter used between class names and static members, as well as enum
104+
* names and enum members.
105+
*/
100106
export const STATIC_DELIMITER = ".";
107+
/** Delimiter used between namespace names and namespace members. */
108+
export const NAMESPACE_DELIMITER = "::";
101109
/** Delimiter used between a function and its inner elements. */
102110
export const INNER_DELIMITER = "~";
103111
/** Substitution used to indicate a library directory. */

src/program.ts

+16-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
PATH_DELIMITER,
4040
STATIC_DELIMITER,
4141
INSTANCE_DELIMITER,
42+
NAMESPACE_DELIMITER,
4243
GETTER_PREFIX,
4344
SETTER_PREFIX,
4445
INNER_DELIMITER,
@@ -5093,12 +5094,26 @@ export function mangleInternalName(
50935094
parent = parent.parent;
50945095
// fall-through
50955096
}
5096-
default: {
5097+
case ElementKind.Enum:
5098+
case ElementKind.InterfacePrototype:
5099+
case ElementKind.Interface:
5100+
case ElementKind.ClassPrototype:
5101+
case ElementKind.Class: {
50975102
return (
50985103
mangleInternalName(parent.name, parent.parent, parent.is(CommonFlags.Instance), asGlobal) +
50995104
(isInstance ? INSTANCE_DELIMITER : STATIC_DELIMITER) + name
51005105
);
51015106
}
5107+
case ElementKind.Namespace: {
5108+
return (
5109+
mangleInternalName(parent.name, parent.parent, false, asGlobal) +
5110+
NAMESPACE_DELIMITER + name
5111+
);
5112+
}
5113+
default: {
5114+
assert(false);
5115+
return "";
5116+
}
51025117
}
51035118
}
51045119

tests/compiler/binary.debug.wat

+18-18
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@
240240
local.get $out
241241
return
242242
)
243-
(func $~lib/math/NativeMath.pow (param $x f64) (param $y f64) (result f64)
243+
(func $~lib/math/NativeMath::pow (param $x f64) (param $y f64) (result f64)
244244
(local $x|2 f64)
245245
(local $y|3 f64)
246246
(local $sign_bias i32)
@@ -1284,7 +1284,7 @@
12841284
end
12851285
return
12861286
)
1287-
(func $~lib/math/NativeMathf.mod (param $x f32) (param $y f32) (result f32)
1287+
(func $~lib/math/NativeMathf::mod (param $x f32) (param $y f32) (result f32)
12881288
(local $ux i32)
12891289
(local $uy i32)
12901290
(local $ex i32)
@@ -1533,7 +1533,7 @@
15331533
f32.reinterpret_i32
15341534
return
15351535
)
1536-
(func $~lib/math/NativeMathf.pow (param $x f32) (param $y f32) (result f32)
1536+
(func $~lib/math/NativeMathf::pow (param $x f32) (param $y f32) (result f32)
15371537
(local $x|2 f32)
15381538
(local $y|3 f32)
15391539
(local $signBias i32)
@@ -2197,7 +2197,7 @@
21972197
end
21982198
return
21992199
)
2200-
(func $~lib/math/NativeMath.mod (param $x f64) (param $y f64) (result f64)
2200+
(func $~lib/math/NativeMath::mod (param $x f64) (param $y f64) (result f64)
22012201
(local $ux i64)
22022202
(local $uy i64)
22032203
(local $ex i64)
@@ -2684,7 +2684,7 @@
26842684
global.get $binary/I
26852685
f64.convert_i64_s
26862686
f64.const 1
2687-
call $~lib/math/NativeMath.pow
2687+
call $~lib/math/NativeMath::pow
26882688
drop
26892689
global.get $binary/I
26902690
i64.const 1
@@ -2757,7 +2757,7 @@
27572757
global.get $binary/I
27582758
f64.convert_i64_s
27592759
f64.const 1
2760-
call $~lib/math/NativeMath.pow
2760+
call $~lib/math/NativeMath::pow
27612761
i64.trunc_sat_f64_s
27622762
global.set $binary/I
27632763
global.get $binary/I
@@ -2866,11 +2866,11 @@
28662866
drop
28672867
global.get $binary/f
28682868
f32.const 1
2869-
call $~lib/math/NativeMathf.mod
2869+
call $~lib/math/NativeMathf::mod
28702870
drop
28712871
global.get $binary/f
28722872
f32.const 1
2873-
call $~lib/math/NativeMathf.pow
2873+
call $~lib/math/NativeMathf::pow
28742874
drop
28752875
global.get $binary/f
28762876
f32.const 1
@@ -2914,11 +2914,11 @@
29142914
global.set $binary/f
29152915
global.get $binary/f
29162916
f32.const 1
2917-
call $~lib/math/NativeMathf.mod
2917+
call $~lib/math/NativeMathf::mod
29182918
global.set $binary/f
29192919
global.get $binary/f
29202920
f32.const 1
2921-
call $~lib/math/NativeMathf.pow
2921+
call $~lib/math/NativeMathf::pow
29222922
global.set $binary/f
29232923
global.get $binary/f
29242924
f32.const 1
@@ -2934,11 +2934,11 @@
29342934
global.set $binary/f
29352935
global.get $binary/f
29362936
f32.const 1
2937-
call $~lib/math/NativeMathf.mod
2937+
call $~lib/math/NativeMathf::mod
29382938
global.set $binary/f
29392939
global.get $binary/f
29402940
f32.const 1
2941-
call $~lib/math/NativeMathf.pow
2941+
call $~lib/math/NativeMathf::pow
29422942
global.set $binary/f
29432943
global.get $binary/F
29442944
f64.const 1
@@ -2982,11 +2982,11 @@
29822982
drop
29832983
global.get $binary/F
29842984
f64.const 1
2985-
call $~lib/math/NativeMath.mod
2985+
call $~lib/math/NativeMath::mod
29862986
drop
29872987
global.get $binary/F
29882988
f64.const 1
2989-
call $~lib/math/NativeMath.pow
2989+
call $~lib/math/NativeMath::pow
29902990
drop
29912991
global.get $binary/F
29922992
f64.const 1
@@ -3030,11 +3030,11 @@
30303030
global.set $binary/F
30313031
global.get $binary/F
30323032
f64.const 1
3033-
call $~lib/math/NativeMath.mod
3033+
call $~lib/math/NativeMath::mod
30343034
global.set $binary/F
30353035
global.get $binary/F
30363036
f64.const 1
3037-
call $~lib/math/NativeMath.pow
3037+
call $~lib/math/NativeMath::pow
30383038
global.set $binary/F
30393039
global.get $binary/F
30403040
f64.const 1
@@ -3050,11 +3050,11 @@
30503050
global.set $binary/F
30513051
global.get $binary/F
30523052
f64.const 1
3053-
call $~lib/math/NativeMath.mod
3053+
call $~lib/math/NativeMath::mod
30543054
global.set $binary/F
30553055
global.get $binary/F
30563056
f64.const 1
3057-
call $~lib/math/NativeMath.pow
3057+
call $~lib/math/NativeMath::pow
30583058
global.set $binary/F
30593059
)
30603060
(func $~start

tests/compiler/bindings/esm.debug.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ async function instantiate(module, imports = {}) {
1010
})();
1111
},
1212
"console.log"(text) {
13-
// ~lib/bindings/dom/console.log(~lib/string/String) => void
13+
// ~lib/bindings/dom/console::log(~lib/string/String) => void
1414
text = __liftString(text >>> 0);
1515
console.log(text);
1616
},
1717
"Math.E": (
18-
// ~lib/bindings/dom/Math.E: f64
18+
// ~lib/bindings/dom/Math::E: f64
1919
Math.E
2020
),
2121
"Math.log"(x) {
22-
// ~lib/bindings/dom/Math.log(f64) => f64
22+
// ~lib/bindings/dom/Math::log(f64) => f64
2323
return Math.log(x);
2424
},
2525
"globalThis.globalThis": (

tests/compiler/bindings/esm.debug.wat

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
(type $16 (func (param i32 i32 i32) (result i32)))
1919
(type $17 (func (param i32 i32 i64)))
2020
(type $18 (func (param i32 i32) (result f32)))
21-
(import "env" "Math.E" (global $~lib/bindings/dom/Math.E f64))
21+
(import "env" "Math.E" (global $~lib/bindings/dom/Math::E f64))
2222
(import "env" "globalThis" (global $bindings/esm/immutableGlobal externref))
2323
(import "env" "globalThis.globalThis" (global $bindings/esm/immutableGlobalNested externref))
2424
(import "env" "trace" (func $~lib/builtins/trace (param i32 i32 f64 f64 f64 f64 f64)))
25-
(import "env" "console.log" (func $~lib/bindings/dom/console.log (param i32)))
26-
(import "env" "Math.log" (func $~lib/bindings/dom/Math.log (param f64) (result f64)))
25+
(import "env" "console.log" (func $~lib/bindings/dom/console::log (param i32)))
26+
(import "env" "Math.log" (func $~lib/bindings/dom/Math::log (param f64) (result f64)))
2727
(import "env" "Date.getTimezoneOffset" (func $bindings/esm/Date_getTimezoneOffset (result i32)))
2828
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
2929
(global $bindings/esm/plainGlobal i32 (i32.const 1))
@@ -37,8 +37,8 @@
3737
(global $bindings/esm/ConstEnum.TWO i32 (i32.const 2))
3838
(global $bindings/esm/ConstEnum.THREE i32 (i32.const 3))
3939
(global $bindings/esm/fn i32 (i32.const 96))
40-
(global $~lib/builtins/u32.MAX_VALUE i32 (i32.const -1))
41-
(global $~lib/builtins/u64.MAX_VALUE i64 (i64.const -1))
40+
(global $~lib/builtins/u32::MAX_VALUE i32 (i32.const -1))
41+
(global $~lib/builtins/u64::MAX_VALUE i64 (i64.const -1))
4242
(global $~lib/shared/runtime/Runtime.Stub i32 (i32.const 0))
4343
(global $~lib/shared/runtime/Runtime.Minimal i32 (i32.const 1))
4444
(global $~lib/shared/runtime/Runtime.Incremental i32 (i32.const 2))
@@ -137,11 +137,11 @@
137137
return
138138
)
139139
(func $bindings/esm/getMaxUnsigned32 (result i32)
140-
global.get $~lib/builtins/u32.MAX_VALUE
140+
global.get $~lib/builtins/u32::MAX_VALUE
141141
return
142142
)
143143
(func $bindings/esm/getMaxUnsigned64 (result i64)
144-
global.get $~lib/builtins/u64.MAX_VALUE
144+
global.get $~lib/builtins/u64::MAX_VALUE
145145
return
146146
)
147147
(func $~lib/rt/common/OBJECT#get:rtSize (param $this i32) (result i32)
@@ -3126,9 +3126,9 @@
31263126
local.get $0
31273127
i32.store
31283128
local.get $0
3129-
call $~lib/bindings/dom/console.log
3130-
global.get $~lib/bindings/dom/Math.E
3131-
call $~lib/bindings/dom/Math.log
3129+
call $~lib/bindings/dom/console::log
3130+
global.get $~lib/bindings/dom/Math::E
3131+
call $~lib/bindings/dom/Math::log
31323132
drop
31333133
global.get $bindings/esm/immutableGlobal
31343134
drop

tests/compiler/bindings/esm.release.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ async function instantiate(module, imports = {}) {
1010
})();
1111
},
1212
"console.log"(text) {
13-
// ~lib/bindings/dom/console.log(~lib/string/String) => void
13+
// ~lib/bindings/dom/console::log(~lib/string/String) => void
1414
text = __liftString(text >>> 0);
1515
console.log(text);
1616
},
1717
"Math.E": (
18-
// ~lib/bindings/dom/Math.E: f64
18+
// ~lib/bindings/dom/Math::E: f64
1919
Math.E
2020
),
2121
"Math.log"(x) {
22-
// ~lib/bindings/dom/Math.log(f64) => f64
22+
// ~lib/bindings/dom/Math::log(f64) => f64
2323
return Math.log(x);
2424
},
2525
"globalThis.globalThis": (

tests/compiler/bindings/esm.release.wat

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@
1212
(type $10 (func (param i64 i64) (result i64)))
1313
(type $11 (func (result i64)))
1414
(type $12 (func (param i32 i32 i32 i32)))
15-
(import "env" "Math.E" (global $~lib/bindings/dom/Math.E f64))
15+
(import "env" "Math.E" (global $~lib/bindings/dom/Math::E f64))
1616
(import "env" "trace" (func $~lib/builtins/trace (param i32 i32 f64 f64 f64 f64 f64)))
17-
(import "env" "console.log" (func $~lib/bindings/dom/console.log (param i32)))
18-
(import "env" "Math.log" (func $~lib/bindings/dom/Math.log (param f64) (result f64)))
17+
(import "env" "console.log" (func $~lib/bindings/dom/console::log (param i32)))
18+
(import "env" "Math.log" (func $~lib/bindings/dom/Math::log (param f64) (result f64)))
1919
(import "env" "Date.getTimezoneOffset" (func $bindings/esm/Date_getTimezoneOffset (result i32)))
2020
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
2121
(global $bindings/esm/plainGlobal i32 (i32.const 1))
@@ -2112,9 +2112,9 @@
21122112
i32.const 1184
21132113
i32.store
21142114
i32.const 1184
2115-
call $~lib/bindings/dom/console.log
2116-
global.get $~lib/bindings/dom/Math.E
2117-
call $~lib/bindings/dom/Math.log
2115+
call $~lib/bindings/dom/console::log
2116+
global.get $~lib/bindings/dom/Math::E
2117+
call $~lib/bindings/dom/Math::log
21182118
drop
21192119
call $bindings/esm/Date_getTimezoneOffset
21202120
drop

tests/compiler/bindings/raw.debug.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ export async function instantiate(module, imports = {}) {
1010
})();
1111
},
1212
"console.log"(text) {
13-
// ~lib/bindings/dom/console.log(~lib/string/String) => void
13+
// ~lib/bindings/dom/console::log(~lib/string/String) => void
1414
text = __liftString(text >>> 0);
1515
console.log(text);
1616
},
1717
"Math.E": (
18-
// ~lib/bindings/dom/Math.E: f64
18+
// ~lib/bindings/dom/Math::E: f64
1919
Math.E
2020
),
2121
"Math.log"(x) {
22-
// ~lib/bindings/dom/Math.log(f64) => f64
22+
// ~lib/bindings/dom/Math::log(f64) => f64
2323
return Math.log(x);
2424
},
2525
"globalThis.globalThis": (

tests/compiler/bindings/raw.debug.wat

+10-10
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
(type $16 (func (param i32 i32 i32) (result i32)))
1919
(type $17 (func (param i32 i32 i64)))
2020
(type $18 (func (param i32 i32) (result f32)))
21-
(import "env" "Math.E" (global $~lib/bindings/dom/Math.E f64))
21+
(import "env" "Math.E" (global $~lib/bindings/dom/Math::E f64))
2222
(import "env" "globalThis" (global $bindings/esm/immutableGlobal externref))
2323
(import "env" "globalThis.globalThis" (global $bindings/esm/immutableGlobalNested externref))
2424
(import "env" "trace" (func $~lib/builtins/trace (param i32 i32 f64 f64 f64 f64 f64)))
25-
(import "env" "console.log" (func $~lib/bindings/dom/console.log (param i32)))
26-
(import "env" "Math.log" (func $~lib/bindings/dom/Math.log (param f64) (result f64)))
25+
(import "env" "console.log" (func $~lib/bindings/dom/console::log (param i32)))
26+
(import "env" "Math.log" (func $~lib/bindings/dom/Math::log (param f64) (result f64)))
2727
(import "env" "Date.getTimezoneOffset" (func $bindings/esm/Date_getTimezoneOffset (result i32)))
2828
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
2929
(global $bindings/esm/plainGlobal i32 (i32.const 1))
@@ -37,8 +37,8 @@
3737
(global $bindings/esm/ConstEnum.TWO i32 (i32.const 2))
3838
(global $bindings/esm/ConstEnum.THREE i32 (i32.const 3))
3939
(global $bindings/esm/fn i32 (i32.const 96))
40-
(global $~lib/builtins/u32.MAX_VALUE i32 (i32.const -1))
41-
(global $~lib/builtins/u64.MAX_VALUE i64 (i64.const -1))
40+
(global $~lib/builtins/u32::MAX_VALUE i32 (i32.const -1))
41+
(global $~lib/builtins/u64::MAX_VALUE i64 (i64.const -1))
4242
(global $~lib/shared/runtime/Runtime.Stub i32 (i32.const 0))
4343
(global $~lib/shared/runtime/Runtime.Minimal i32 (i32.const 1))
4444
(global $~lib/shared/runtime/Runtime.Incremental i32 (i32.const 2))
@@ -140,11 +140,11 @@
140140
return
141141
)
142142
(func $bindings/esm/getMaxUnsigned32 (result i32)
143-
global.get $~lib/builtins/u32.MAX_VALUE
143+
global.get $~lib/builtins/u32::MAX_VALUE
144144
return
145145
)
146146
(func $bindings/esm/getMaxUnsigned64 (result i64)
147-
global.get $~lib/builtins/u64.MAX_VALUE
147+
global.get $~lib/builtins/u64::MAX_VALUE
148148
return
149149
)
150150
(func $~lib/rt/common/OBJECT#get:rtSize (param $this i32) (result i32)
@@ -3129,9 +3129,9 @@
31293129
local.get $0
31303130
i32.store
31313131
local.get $0
3132-
call $~lib/bindings/dom/console.log
3133-
global.get $~lib/bindings/dom/Math.E
3134-
call $~lib/bindings/dom/Math.log
3132+
call $~lib/bindings/dom/console::log
3133+
global.get $~lib/bindings/dom/Math::E
3134+
call $~lib/bindings/dom/Math::log
31353135
drop
31363136
global.get $bindings/esm/immutableGlobal
31373137
drop

0 commit comments

Comments
 (0)