Skip to content
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

BREAKING CHANGE: Avoid collisions between static class/namespace members #2804

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/loader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ export function demangle(exports, extendedExports = {}) {
: exports["__setArgumentsLength"] || exports["__setargc"] || (() => { /* nop */ });
for (let internalName of Object.keys(exports)) {
const elem = exports[internalName];
let parts = internalName.split(".");
let parts = internalName.split(/\.|::/g);
let curr = extendedExports;
while (parts.length > 1) {
let part = parts.shift();
Expand Down
1,018 changes: 509 additions & 509 deletions src/builtins.ts

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,18 @@ export const PARENT_SUBST = "..";
export const GETTER_PREFIX = "get:";
/** Function name prefix used for setters. */
export const SETTER_PREFIX = "set:";
/** Delimiter used between class names and instance members. */
/**
* Delimiter used between class names and instance members, as well as
* interface names and virtual members.
*/
export const INSTANCE_DELIMITER = "#";
/** Delimiter used between class and namespace names and static members. */
/**
* Delimiter used between class names and static members, as well as enum
* names and enum members.
*/
export const STATIC_DELIMITER = ".";
/** Delimiter used between namespace names and namespace members. */
export const NAMESPACE_DELIMITER = "::";
/** Delimiter used between a function and its inner elements. */
export const INNER_DELIMITER = "~";
/** Substitution used to indicate a library directory. */
Expand Down
17 changes: 16 additions & 1 deletion src/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
PATH_DELIMITER,
STATIC_DELIMITER,
INSTANCE_DELIMITER,
NAMESPACE_DELIMITER,
GETTER_PREFIX,
SETTER_PREFIX,
INNER_DELIMITER,
Expand Down Expand Up @@ -5093,12 +5094,26 @@ export function mangleInternalName(
parent = parent.parent;
// fall-through
}
default: {
case ElementKind.Enum:
case ElementKind.InterfacePrototype:
case ElementKind.Interface:
case ElementKind.ClassPrototype:
case ElementKind.Class: {
return (
mangleInternalName(parent.name, parent.parent, parent.is(CommonFlags.Instance), asGlobal) +
(isInstance ? INSTANCE_DELIMITER : STATIC_DELIMITER) + name
);
}
case ElementKind.Namespace: {
return (
mangleInternalName(parent.name, parent.parent, false, asGlobal) +
NAMESPACE_DELIMITER + name
);
}
default: {
assert(false);
return "";
}
}
}

Expand Down
36 changes: 18 additions & 18 deletions tests/compiler/binary.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
local.get $out
return
)
(func $~lib/math/NativeMath.pow (param $x f64) (param $y f64) (result f64)
(func $~lib/math/NativeMath::pow (param $x f64) (param $y f64) (result f64)
(local $x|2 f64)
(local $y|3 f64)
(local $sign_bias i32)
Expand Down Expand Up @@ -1284,7 +1284,7 @@
end
return
)
(func $~lib/math/NativeMathf.mod (param $x f32) (param $y f32) (result f32)
(func $~lib/math/NativeMathf::mod (param $x f32) (param $y f32) (result f32)
(local $ux i32)
(local $uy i32)
(local $ex i32)
Expand Down Expand Up @@ -1533,7 +1533,7 @@
f32.reinterpret_i32
return
)
(func $~lib/math/NativeMathf.pow (param $x f32) (param $y f32) (result f32)
(func $~lib/math/NativeMathf::pow (param $x f32) (param $y f32) (result f32)
(local $x|2 f32)
(local $y|3 f32)
(local $signBias i32)
Expand Down Expand Up @@ -2197,7 +2197,7 @@
end
return
)
(func $~lib/math/NativeMath.mod (param $x f64) (param $y f64) (result f64)
(func $~lib/math/NativeMath::mod (param $x f64) (param $y f64) (result f64)
(local $ux i64)
(local $uy i64)
(local $ex i64)
Expand Down Expand Up @@ -2684,7 +2684,7 @@
global.get $binary/I
f64.convert_i64_s
f64.const 1
call $~lib/math/NativeMath.pow
call $~lib/math/NativeMath::pow
drop
global.get $binary/I
i64.const 1
Expand Down Expand Up @@ -2757,7 +2757,7 @@
global.get $binary/I
f64.convert_i64_s
f64.const 1
call $~lib/math/NativeMath.pow
call $~lib/math/NativeMath::pow
i64.trunc_sat_f64_s
global.set $binary/I
global.get $binary/I
Expand Down Expand Up @@ -2866,11 +2866,11 @@
drop
global.get $binary/f
f32.const 1
call $~lib/math/NativeMathf.mod
call $~lib/math/NativeMathf::mod
drop
global.get $binary/f
f32.const 1
call $~lib/math/NativeMathf.pow
call $~lib/math/NativeMathf::pow
drop
global.get $binary/f
f32.const 1
Expand Down Expand Up @@ -2914,11 +2914,11 @@
global.set $binary/f
global.get $binary/f
f32.const 1
call $~lib/math/NativeMathf.mod
call $~lib/math/NativeMathf::mod
global.set $binary/f
global.get $binary/f
f32.const 1
call $~lib/math/NativeMathf.pow
call $~lib/math/NativeMathf::pow
global.set $binary/f
global.get $binary/f
f32.const 1
Expand All @@ -2934,11 +2934,11 @@
global.set $binary/f
global.get $binary/f
f32.const 1
call $~lib/math/NativeMathf.mod
call $~lib/math/NativeMathf::mod
global.set $binary/f
global.get $binary/f
f32.const 1
call $~lib/math/NativeMathf.pow
call $~lib/math/NativeMathf::pow
global.set $binary/f
global.get $binary/F
f64.const 1
Expand Down Expand Up @@ -2982,11 +2982,11 @@
drop
global.get $binary/F
f64.const 1
call $~lib/math/NativeMath.mod
call $~lib/math/NativeMath::mod
drop
global.get $binary/F
f64.const 1
call $~lib/math/NativeMath.pow
call $~lib/math/NativeMath::pow
drop
global.get $binary/F
f64.const 1
Expand Down Expand Up @@ -3030,11 +3030,11 @@
global.set $binary/F
global.get $binary/F
f64.const 1
call $~lib/math/NativeMath.mod
call $~lib/math/NativeMath::mod
global.set $binary/F
global.get $binary/F
f64.const 1
call $~lib/math/NativeMath.pow
call $~lib/math/NativeMath::pow
global.set $binary/F
global.get $binary/F
f64.const 1
Expand All @@ -3050,11 +3050,11 @@
global.set $binary/F
global.get $binary/F
f64.const 1
call $~lib/math/NativeMath.mod
call $~lib/math/NativeMath::mod
global.set $binary/F
global.get $binary/F
f64.const 1
call $~lib/math/NativeMath.pow
call $~lib/math/NativeMath::pow
global.set $binary/F
)
(func $~start
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/bindings/esm.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ async function instantiate(module, imports = {}) {
})();
},
"console.log"(text) {
// ~lib/bindings/dom/console.log(~lib/string/String) => void
// ~lib/bindings/dom/console::log(~lib/string/String) => void
text = __liftString(text >>> 0);
console.log(text);
},
"Math.E": (
// ~lib/bindings/dom/Math.E: f64
// ~lib/bindings/dom/Math::E: f64
Math.E
),
"Math.log"(x) {
// ~lib/bindings/dom/Math.log(f64) => f64
// ~lib/bindings/dom/Math::log(f64) => f64
return Math.log(x);
},
"globalThis.globalThis": (
Expand Down
20 changes: 10 additions & 10 deletions tests/compiler/bindings/esm.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
(type $16 (func (param i32 i32 i32) (result i32)))
(type $17 (func (param i32 i32 i64)))
(type $18 (func (param i32 i32) (result f32)))
(import "env" "Math.E" (global $~lib/bindings/dom/Math.E f64))
(import "env" "Math.E" (global $~lib/bindings/dom/Math::E f64))
(import "env" "globalThis" (global $bindings/esm/immutableGlobal externref))
(import "env" "globalThis.globalThis" (global $bindings/esm/immutableGlobalNested externref))
(import "env" "trace" (func $~lib/builtins/trace (param i32 i32 f64 f64 f64 f64 f64)))
(import "env" "console.log" (func $~lib/bindings/dom/console.log (param i32)))
(import "env" "Math.log" (func $~lib/bindings/dom/Math.log (param f64) (result f64)))
(import "env" "console.log" (func $~lib/bindings/dom/console::log (param i32)))
(import "env" "Math.log" (func $~lib/bindings/dom/Math::log (param f64) (result f64)))
(import "env" "Date.getTimezoneOffset" (func $bindings/esm/Date_getTimezoneOffset (result i32)))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
(global $bindings/esm/plainGlobal i32 (i32.const 1))
Expand All @@ -37,8 +37,8 @@
(global $bindings/esm/ConstEnum.TWO i32 (i32.const 2))
(global $bindings/esm/ConstEnum.THREE i32 (i32.const 3))
(global $bindings/esm/fn i32 (i32.const 96))
(global $~lib/builtins/u32.MAX_VALUE i32 (i32.const -1))
(global $~lib/builtins/u64.MAX_VALUE i64 (i64.const -1))
(global $~lib/builtins/u32::MAX_VALUE i32 (i32.const -1))
(global $~lib/builtins/u64::MAX_VALUE i64 (i64.const -1))
(global $~lib/shared/runtime/Runtime.Stub i32 (i32.const 0))
(global $~lib/shared/runtime/Runtime.Minimal i32 (i32.const 1))
(global $~lib/shared/runtime/Runtime.Incremental i32 (i32.const 2))
Expand Down Expand Up @@ -137,11 +137,11 @@
return
)
(func $bindings/esm/getMaxUnsigned32 (result i32)
global.get $~lib/builtins/u32.MAX_VALUE
global.get $~lib/builtins/u32::MAX_VALUE
return
)
(func $bindings/esm/getMaxUnsigned64 (result i64)
global.get $~lib/builtins/u64.MAX_VALUE
global.get $~lib/builtins/u64::MAX_VALUE
return
)
(func $~lib/rt/common/OBJECT#get:rtSize (param $this i32) (result i32)
Expand Down Expand Up @@ -3126,9 +3126,9 @@
local.get $0
i32.store
local.get $0
call $~lib/bindings/dom/console.log
global.get $~lib/bindings/dom/Math.E
call $~lib/bindings/dom/Math.log
call $~lib/bindings/dom/console::log
global.get $~lib/bindings/dom/Math::E
call $~lib/bindings/dom/Math::log
drop
global.get $bindings/esm/immutableGlobal
drop
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/bindings/esm.release.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ async function instantiate(module, imports = {}) {
})();
},
"console.log"(text) {
// ~lib/bindings/dom/console.log(~lib/string/String) => void
// ~lib/bindings/dom/console::log(~lib/string/String) => void
text = __liftString(text >>> 0);
console.log(text);
},
"Math.E": (
// ~lib/bindings/dom/Math.E: f64
// ~lib/bindings/dom/Math::E: f64
Math.E
),
"Math.log"(x) {
// ~lib/bindings/dom/Math.log(f64) => f64
// ~lib/bindings/dom/Math::log(f64) => f64
return Math.log(x);
},
"globalThis.globalThis": (
Expand Down
12 changes: 6 additions & 6 deletions tests/compiler/bindings/esm.release.wat
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
(type $10 (func (param i64 i64) (result i64)))
(type $11 (func (result i64)))
(type $12 (func (param i32 i32 i32 i32)))
(import "env" "Math.E" (global $~lib/bindings/dom/Math.E f64))
(import "env" "Math.E" (global $~lib/bindings/dom/Math::E f64))
(import "env" "trace" (func $~lib/builtins/trace (param i32 i32 f64 f64 f64 f64 f64)))
(import "env" "console.log" (func $~lib/bindings/dom/console.log (param i32)))
(import "env" "Math.log" (func $~lib/bindings/dom/Math.log (param f64) (result f64)))
(import "env" "console.log" (func $~lib/bindings/dom/console::log (param i32)))
(import "env" "Math.log" (func $~lib/bindings/dom/Math::log (param f64) (result f64)))
(import "env" "Date.getTimezoneOffset" (func $bindings/esm/Date_getTimezoneOffset (result i32)))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
(global $bindings/esm/plainGlobal i32 (i32.const 1))
Expand Down Expand Up @@ -2112,9 +2112,9 @@
i32.const 1184
i32.store
i32.const 1184
call $~lib/bindings/dom/console.log
global.get $~lib/bindings/dom/Math.E
call $~lib/bindings/dom/Math.log
call $~lib/bindings/dom/console::log
global.get $~lib/bindings/dom/Math::E
call $~lib/bindings/dom/Math::log
drop
call $bindings/esm/Date_getTimezoneOffset
drop
Expand Down
6 changes: 3 additions & 3 deletions tests/compiler/bindings/raw.debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ export async function instantiate(module, imports = {}) {
})();
},
"console.log"(text) {
// ~lib/bindings/dom/console.log(~lib/string/String) => void
// ~lib/bindings/dom/console::log(~lib/string/String) => void
text = __liftString(text >>> 0);
console.log(text);
},
"Math.E": (
// ~lib/bindings/dom/Math.E: f64
// ~lib/bindings/dom/Math::E: f64
Math.E
),
"Math.log"(x) {
// ~lib/bindings/dom/Math.log(f64) => f64
// ~lib/bindings/dom/Math::log(f64) => f64
return Math.log(x);
},
"globalThis.globalThis": (
Expand Down
20 changes: 10 additions & 10 deletions tests/compiler/bindings/raw.debug.wat
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
(type $16 (func (param i32 i32 i32) (result i32)))
(type $17 (func (param i32 i32 i64)))
(type $18 (func (param i32 i32) (result f32)))
(import "env" "Math.E" (global $~lib/bindings/dom/Math.E f64))
(import "env" "Math.E" (global $~lib/bindings/dom/Math::E f64))
(import "env" "globalThis" (global $bindings/esm/immutableGlobal externref))
(import "env" "globalThis.globalThis" (global $bindings/esm/immutableGlobalNested externref))
(import "env" "trace" (func $~lib/builtins/trace (param i32 i32 f64 f64 f64 f64 f64)))
(import "env" "console.log" (func $~lib/bindings/dom/console.log (param i32)))
(import "env" "Math.log" (func $~lib/bindings/dom/Math.log (param f64) (result f64)))
(import "env" "console.log" (func $~lib/bindings/dom/console::log (param i32)))
(import "env" "Math.log" (func $~lib/bindings/dom/Math::log (param f64) (result f64)))
(import "env" "Date.getTimezoneOffset" (func $bindings/esm/Date_getTimezoneOffset (result i32)))
(import "env" "abort" (func $~lib/builtins/abort (param i32 i32 i32 i32)))
(global $bindings/esm/plainGlobal i32 (i32.const 1))
Expand All @@ -37,8 +37,8 @@
(global $bindings/esm/ConstEnum.TWO i32 (i32.const 2))
(global $bindings/esm/ConstEnum.THREE i32 (i32.const 3))
(global $bindings/esm/fn i32 (i32.const 96))
(global $~lib/builtins/u32.MAX_VALUE i32 (i32.const -1))
(global $~lib/builtins/u64.MAX_VALUE i64 (i64.const -1))
(global $~lib/builtins/u32::MAX_VALUE i32 (i32.const -1))
(global $~lib/builtins/u64::MAX_VALUE i64 (i64.const -1))
(global $~lib/shared/runtime/Runtime.Stub i32 (i32.const 0))
(global $~lib/shared/runtime/Runtime.Minimal i32 (i32.const 1))
(global $~lib/shared/runtime/Runtime.Incremental i32 (i32.const 2))
Expand Down Expand Up @@ -140,11 +140,11 @@
return
)
(func $bindings/esm/getMaxUnsigned32 (result i32)
global.get $~lib/builtins/u32.MAX_VALUE
global.get $~lib/builtins/u32::MAX_VALUE
return
)
(func $bindings/esm/getMaxUnsigned64 (result i64)
global.get $~lib/builtins/u64.MAX_VALUE
global.get $~lib/builtins/u64::MAX_VALUE
return
)
(func $~lib/rt/common/OBJECT#get:rtSize (param $this i32) (result i32)
Expand Down Expand Up @@ -3129,9 +3129,9 @@
local.get $0
i32.store
local.get $0
call $~lib/bindings/dom/console.log
global.get $~lib/bindings/dom/Math.E
call $~lib/bindings/dom/Math.log
call $~lib/bindings/dom/console::log
global.get $~lib/bindings/dom/Math::E
call $~lib/bindings/dom/Math::log
drop
global.get $bindings/esm/immutableGlobal
drop
Expand Down
Loading