From 3412cef049f40a3f90cac4d74a48e732db7f0f4d Mon Sep 17 00:00:00 2001 From: CountBleck Date: Fri, 21 Jul 2023 19:59:41 +0530 Subject: [PATCH 1/8] Update the fixtures for the bindings/esm and bindings/raw tests --- tests/compiler/bindings/esm.debug.wat | 87 ++++++++++++------------ tests/compiler/bindings/esm.release.wat | 88 +++++++++++++------------ tests/compiler/bindings/raw.debug.wat | 87 ++++++++++++------------ tests/compiler/bindings/raw.release.wat | 88 +++++++++++++------------ 4 files changed, 180 insertions(+), 170 deletions(-) diff --git a/tests/compiler/bindings/esm.debug.wat b/tests/compiler/bindings/esm.debug.wat index fc771caa73..095fc5393f 100644 --- a/tests/compiler/bindings/esm.debug.wat +++ b/tests/compiler/bindings/esm.debug.wat @@ -1147,7 +1147,7 @@ if i32.const 0 i32.const 672 - i32.const 378 + i32.const 382 i32.const 14 call $~lib/builtins/abort unreachable @@ -1193,7 +1193,7 @@ if i32.const 0 i32.const 672 - i32.const 385 + i32.const 389 i32.const 16 call $~lib/builtins/abort unreachable @@ -1226,7 +1226,7 @@ if i32.const 0 i32.const 672 - i32.const 398 + i32.const 402 i32.const 5 call $~lib/builtins/abort unreachable @@ -1470,7 +1470,7 @@ if i32.const 0 i32.const 672 - i32.const 560 + i32.const 562 i32.const 3 call $~lib/builtins/abort unreachable @@ -1799,7 +1799,7 @@ if i32.const 336 i32.const 672 - i32.const 459 + i32.const 461 i32.const 29 call $~lib/builtins/abort unreachable @@ -1808,6 +1808,26 @@ call $~lib/rt/tlsf/computeSize return ) + (func $~lib/rt/tlsf/roundSize (param $size i32) (result i32) + local.get $size + i32.const 536870910 + i32.lt_u + if (result i32) + local.get $size + i32.const 1 + i32.const 27 + local.get $size + i32.clz + i32.sub + i32.shl + i32.add + i32.const 1 + i32.sub + else + local.get $size + end + return + ) (func $~lib/rt/tlsf/searchBlock (param $root i32) (param $size i32) (result i32) (local $fl i32) (local $sl i32) @@ -1837,24 +1857,13 @@ local.set $sl else local.get $size - i32.const 536870910 - i32.lt_u - if (result i32) - local.get $size - i32.const 1 - i32.const 27 - local.get $size - i32.clz - i32.sub - i32.shl - i32.add - i32.const 1 - i32.sub - else - local.get $size - end + call $~lib/rt/tlsf/roundSize local.set $requestSize - i32.const 31 + i32.const 4 + i32.const 8 + i32.mul + i32.const 1 + i32.sub local.get $requestSize i32.clz i32.sub @@ -1892,7 +1901,7 @@ if i32.const 0 i32.const 672 - i32.const 330 + i32.const 334 i32.const 14 call $~lib/builtins/abort unreachable @@ -1963,7 +1972,7 @@ if i32.const 0 i32.const 672 - i32.const 343 + i32.const 347 i32.const 18 call $~lib/builtins/abort unreachable @@ -2026,6 +2035,14 @@ (local $pagesAfter i32) i32.const 0 drop + local.get $size + i32.const 256 + i32.ge_u + if + local.get $size + call $~lib/rt/tlsf/roundSize + local.set $size + end memory.size $0 local.set $pagesBefore local.get $size @@ -2047,22 +2064,6 @@ i32.add local.set $size local.get $size - i32.const 536870910 - i32.lt_u - if - local.get $size - i32.const 1 - i32.const 27 - local.get $size - i32.clz - i32.sub - i32.shl - i32.const 1 - i32.sub - i32.add - local.set $size - end - local.get $size i32.const 65535 i32.add i32.const 65535 @@ -2128,7 +2129,7 @@ if i32.const 0 i32.const 672 - i32.const 357 + i32.const 361 i32.const 14 call $~lib/builtins/abort unreachable @@ -2243,7 +2244,7 @@ if i32.const 0 i32.const 672 - i32.const 497 + i32.const 499 i32.const 16 call $~lib/builtins/abort unreachable @@ -2263,7 +2264,7 @@ if i32.const 0 i32.const 672 - i32.const 499 + i32.const 501 i32.const 14 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/bindings/esm.release.wat b/tests/compiler/bindings/esm.release.wat index 7ea107e5e0..43a90778b0 100644 --- a/tests/compiler/bindings/esm.release.wat +++ b/tests/compiler/bindings/esm.release.wat @@ -741,7 +741,7 @@ if i32.const 0 i32.const 1696 - i32.const 378 + i32.const 382 i32.const 14 call $~lib/builtins/abort unreachable @@ -766,7 +766,7 @@ if i32.const 0 i32.const 1696 - i32.const 385 + i32.const 389 i32.const 16 call $~lib/builtins/abort unreachable @@ -794,7 +794,7 @@ if i32.const 0 i32.const 1696 - i32.const 398 + i32.const 402 i32.const 5 call $~lib/builtins/abort unreachable @@ -1161,7 +1161,7 @@ if i32.const 0 i32.const 1696 - i32.const 560 + i32.const 562 i32.const 3 call $~lib/builtins/abort unreachable @@ -1245,7 +1245,7 @@ if i32.const 0 i32.const 1696 - i32.const 330 + i32.const 334 i32.const 14 call $~lib/builtins/abort unreachable @@ -1297,7 +1297,7 @@ if i32.const 0 i32.const 1696 - i32.const 343 + i32.const 347 i32.const 18 call $~lib/builtins/abort unreachable @@ -1386,7 +1386,7 @@ call $~lib/rt/tlsf/initialize end global.get $~lib/rt/tlsf/ROOT - local.set $3 + local.set $4 local.get $0 i32.const 16 i32.add @@ -1396,12 +1396,12 @@ if i32.const 1360 i32.const 1696 - i32.const 459 + i32.const 461 i32.const 29 call $~lib/builtins/abort unreachable end - local.get $3 + local.get $4 i32.const 12 local.get $2 i32.const 19 @@ -1422,50 +1422,54 @@ memory.size $0 local.tee $2 local.get $5 - i32.const 4 - local.get $3 - i32.load $0 offset=1568 - local.get $2 - i32.const 16 - i32.shl - i32.const 4 - i32.sub - i32.ne - i32.shl - i32.add - local.tee $4 - i32.const 536870910 - i32.lt_u + i32.const 256 + i32.ge_u if (result i32) - local.get $4 + local.get $5 i32.const 1 i32.const 27 - local.get $4 + local.get $5 i32.clz i32.sub i32.shl + i32.add i32.const 1 i32.sub - i32.add + local.get $5 + local.get $5 + i32.const 536870910 + i32.lt_u + select else - local.get $4 + local.get $5 end + i32.const 4 + local.get $4 + i32.load $0 offset=1568 + local.get $2 + i32.const 16 + i32.shl + i32.const 4 + i32.sub + i32.ne + i32.shl + i32.add i32.const 65535 i32.add i32.const -65536 i32.and i32.const 16 i32.shr_u - local.tee $4 + local.tee $3 local.get $2 - local.get $4 + local.get $3 i32.gt_s select memory.grow $0 i32.const 0 i32.lt_s if - local.get $4 + local.get $3 memory.grow $0 i32.const 0 i32.lt_s @@ -1473,7 +1477,7 @@ unreachable end end - local.get $3 + local.get $4 local.get $2 i32.const 16 i32.shl @@ -1482,7 +1486,7 @@ i64.const 16 i64.shl call $~lib/rt/tlsf/addMemory - local.get $3 + local.get $4 local.get $5 call $~lib/rt/tlsf/searchBlock local.tee $2 @@ -1490,7 +1494,7 @@ if i32.const 0 i32.const 1696 - i32.const 497 + i32.const 499 i32.const 16 call $~lib/builtins/abort unreachable @@ -1505,17 +1509,17 @@ if i32.const 0 i32.const 1696 - i32.const 499 + i32.const 501 i32.const 14 call $~lib/builtins/abort unreachable end - local.get $3 + local.get $4 local.get $2 call $~lib/rt/tlsf/removeBlock local.get $2 i32.load $0 - local.set $4 + local.set $3 local.get $5 i32.const 4 i32.add @@ -1524,12 +1528,12 @@ if i32.const 0 i32.const 1696 - i32.const 357 + i32.const 361 i32.const 14 call $~lib/builtins/abort unreachable end - local.get $4 + local.get $3 i32.const -4 i32.and local.get $5 @@ -1540,7 +1544,7 @@ if local.get $2 local.get $5 - local.get $4 + local.get $3 i32.const 2 i32.and i32.or @@ -1550,19 +1554,19 @@ i32.add local.get $5 i32.add - local.tee $4 + local.tee $3 local.get $6 i32.const 4 i32.sub i32.const 1 i32.or i32.store $0 - local.get $3 local.get $4 + local.get $3 call $~lib/rt/tlsf/insertBlock else local.get $2 - local.get $4 + local.get $3 i32.const -2 i32.and i32.store $0 diff --git a/tests/compiler/bindings/raw.debug.wat b/tests/compiler/bindings/raw.debug.wat index 169584997b..d2c5453dc1 100644 --- a/tests/compiler/bindings/raw.debug.wat +++ b/tests/compiler/bindings/raw.debug.wat @@ -1150,7 +1150,7 @@ if i32.const 0 i32.const 672 - i32.const 378 + i32.const 382 i32.const 14 call $~lib/builtins/abort unreachable @@ -1196,7 +1196,7 @@ if i32.const 0 i32.const 672 - i32.const 385 + i32.const 389 i32.const 16 call $~lib/builtins/abort unreachable @@ -1229,7 +1229,7 @@ if i32.const 0 i32.const 672 - i32.const 398 + i32.const 402 i32.const 5 call $~lib/builtins/abort unreachable @@ -1473,7 +1473,7 @@ if i32.const 0 i32.const 672 - i32.const 560 + i32.const 562 i32.const 3 call $~lib/builtins/abort unreachable @@ -1802,7 +1802,7 @@ if i32.const 336 i32.const 672 - i32.const 459 + i32.const 461 i32.const 29 call $~lib/builtins/abort unreachable @@ -1811,6 +1811,26 @@ call $~lib/rt/tlsf/computeSize return ) + (func $~lib/rt/tlsf/roundSize (param $size i32) (result i32) + local.get $size + i32.const 536870910 + i32.lt_u + if (result i32) + local.get $size + i32.const 1 + i32.const 27 + local.get $size + i32.clz + i32.sub + i32.shl + i32.add + i32.const 1 + i32.sub + else + local.get $size + end + return + ) (func $~lib/rt/tlsf/searchBlock (param $root i32) (param $size i32) (result i32) (local $fl i32) (local $sl i32) @@ -1840,24 +1860,13 @@ local.set $sl else local.get $size - i32.const 536870910 - i32.lt_u - if (result i32) - local.get $size - i32.const 1 - i32.const 27 - local.get $size - i32.clz - i32.sub - i32.shl - i32.add - i32.const 1 - i32.sub - else - local.get $size - end + call $~lib/rt/tlsf/roundSize local.set $requestSize - i32.const 31 + i32.const 4 + i32.const 8 + i32.mul + i32.const 1 + i32.sub local.get $requestSize i32.clz i32.sub @@ -1895,7 +1904,7 @@ if i32.const 0 i32.const 672 - i32.const 330 + i32.const 334 i32.const 14 call $~lib/builtins/abort unreachable @@ -1966,7 +1975,7 @@ if i32.const 0 i32.const 672 - i32.const 343 + i32.const 347 i32.const 18 call $~lib/builtins/abort unreachable @@ -2029,6 +2038,14 @@ (local $pagesAfter i32) i32.const 0 drop + local.get $size + i32.const 256 + i32.ge_u + if + local.get $size + call $~lib/rt/tlsf/roundSize + local.set $size + end memory.size $0 local.set $pagesBefore local.get $size @@ -2050,22 +2067,6 @@ i32.add local.set $size local.get $size - i32.const 536870910 - i32.lt_u - if - local.get $size - i32.const 1 - i32.const 27 - local.get $size - i32.clz - i32.sub - i32.shl - i32.const 1 - i32.sub - i32.add - local.set $size - end - local.get $size i32.const 65535 i32.add i32.const 65535 @@ -2131,7 +2132,7 @@ if i32.const 0 i32.const 672 - i32.const 357 + i32.const 361 i32.const 14 call $~lib/builtins/abort unreachable @@ -2246,7 +2247,7 @@ if i32.const 0 i32.const 672 - i32.const 497 + i32.const 499 i32.const 16 call $~lib/builtins/abort unreachable @@ -2266,7 +2267,7 @@ if i32.const 0 i32.const 672 - i32.const 499 + i32.const 501 i32.const 14 call $~lib/builtins/abort unreachable diff --git a/tests/compiler/bindings/raw.release.wat b/tests/compiler/bindings/raw.release.wat index 6a02844128..c83fe21937 100644 --- a/tests/compiler/bindings/raw.release.wat +++ b/tests/compiler/bindings/raw.release.wat @@ -741,7 +741,7 @@ if i32.const 0 i32.const 1696 - i32.const 378 + i32.const 382 i32.const 14 call $~lib/builtins/abort unreachable @@ -766,7 +766,7 @@ if i32.const 0 i32.const 1696 - i32.const 385 + i32.const 389 i32.const 16 call $~lib/builtins/abort unreachable @@ -794,7 +794,7 @@ if i32.const 0 i32.const 1696 - i32.const 398 + i32.const 402 i32.const 5 call $~lib/builtins/abort unreachable @@ -1161,7 +1161,7 @@ if i32.const 0 i32.const 1696 - i32.const 560 + i32.const 562 i32.const 3 call $~lib/builtins/abort unreachable @@ -1245,7 +1245,7 @@ if i32.const 0 i32.const 1696 - i32.const 330 + i32.const 334 i32.const 14 call $~lib/builtins/abort unreachable @@ -1297,7 +1297,7 @@ if i32.const 0 i32.const 1696 - i32.const 343 + i32.const 347 i32.const 18 call $~lib/builtins/abort unreachable @@ -1386,7 +1386,7 @@ call $~lib/rt/tlsf/initialize end global.get $~lib/rt/tlsf/ROOT - local.set $3 + local.set $4 local.get $0 i32.const 16 i32.add @@ -1396,12 +1396,12 @@ if i32.const 1360 i32.const 1696 - i32.const 459 + i32.const 461 i32.const 29 call $~lib/builtins/abort unreachable end - local.get $3 + local.get $4 i32.const 12 local.get $2 i32.const 19 @@ -1422,50 +1422,54 @@ memory.size $0 local.tee $2 local.get $5 - i32.const 4 - local.get $3 - i32.load $0 offset=1568 - local.get $2 - i32.const 16 - i32.shl - i32.const 4 - i32.sub - i32.ne - i32.shl - i32.add - local.tee $4 - i32.const 536870910 - i32.lt_u + i32.const 256 + i32.ge_u if (result i32) - local.get $4 + local.get $5 i32.const 1 i32.const 27 - local.get $4 + local.get $5 i32.clz i32.sub i32.shl + i32.add i32.const 1 i32.sub - i32.add + local.get $5 + local.get $5 + i32.const 536870910 + i32.lt_u + select else - local.get $4 + local.get $5 end + i32.const 4 + local.get $4 + i32.load $0 offset=1568 + local.get $2 + i32.const 16 + i32.shl + i32.const 4 + i32.sub + i32.ne + i32.shl + i32.add i32.const 65535 i32.add i32.const -65536 i32.and i32.const 16 i32.shr_u - local.tee $4 + local.tee $3 local.get $2 - local.get $4 + local.get $3 i32.gt_s select memory.grow $0 i32.const 0 i32.lt_s if - local.get $4 + local.get $3 memory.grow $0 i32.const 0 i32.lt_s @@ -1473,7 +1477,7 @@ unreachable end end - local.get $3 + local.get $4 local.get $2 i32.const 16 i32.shl @@ -1482,7 +1486,7 @@ i64.const 16 i64.shl call $~lib/rt/tlsf/addMemory - local.get $3 + local.get $4 local.get $5 call $~lib/rt/tlsf/searchBlock local.tee $2 @@ -1490,7 +1494,7 @@ if i32.const 0 i32.const 1696 - i32.const 497 + i32.const 499 i32.const 16 call $~lib/builtins/abort unreachable @@ -1505,17 +1509,17 @@ if i32.const 0 i32.const 1696 - i32.const 499 + i32.const 501 i32.const 14 call $~lib/builtins/abort unreachable end - local.get $3 + local.get $4 local.get $2 call $~lib/rt/tlsf/removeBlock local.get $2 i32.load $0 - local.set $4 + local.set $3 local.get $5 i32.const 4 i32.add @@ -1524,12 +1528,12 @@ if i32.const 0 i32.const 1696 - i32.const 357 + i32.const 361 i32.const 14 call $~lib/builtins/abort unreachable end - local.get $4 + local.get $3 i32.const -4 i32.and local.get $5 @@ -1540,7 +1544,7 @@ if local.get $2 local.get $5 - local.get $4 + local.get $3 i32.const 2 i32.and i32.or @@ -1550,19 +1554,19 @@ i32.add local.get $5 i32.add - local.tee $4 + local.tee $3 local.get $6 i32.const 4 i32.sub i32.const 1 i32.or i32.store $0 - local.get $3 local.get $4 + local.get $3 call $~lib/rt/tlsf/insertBlock else local.get $2 - local.get $4 + local.get $3 i32.const -2 i32.and i32.store $0 From 8f0dbc109caa11ebef9ecb0ada6699958e42ef39 Mon Sep 17 00:00:00 2001 From: CountBleck Date: Fri, 21 Jul 2023 22:14:06 +0530 Subject: [PATCH 2/8] Ensure all tests are compiled and diffed regardless of ASC_FEATURES This change makes ASC_FEATURES only affect whether the instantiate step is executed, and not whether tests are compiled and fixtures checked. --- tests/compiler.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/tests/compiler.js b/tests/compiler.js index 1095bc4e4c..17b8fabeec 100644 --- a/tests/compiler.js +++ b/tests/compiler.js @@ -151,7 +151,6 @@ async function runTest(basename) { config.features.forEach(feature => { if (!features.includes(feature) && !features.includes("*")) { missing_features.push(feature); - return; // from forEach } let featureConfig = featuresConfig[feature]; if (featureConfig.asc_flags) { @@ -166,13 +165,8 @@ async function runTest(basename) { if (v8_no_flags) v8_no_flags += " "; v8_no_flags += "--no-" + flag.substring(2); }); - v8.setFlagsFromString(v8_flags); } }); - if (missing_features.length) { - console.log("- " + stdoutColors.yellow("feature SKIPPED") + " (" + missing_features.join(", ") + ")\n"); - return prepareResult(SKIPPED, "feature not enabled: " + missing_features.join(", ")); - } } if (config.asc_flags) { config.asc_flags.forEach(flag => { asc_flags.push(...flag.split(" ")); }); @@ -284,6 +278,13 @@ async function runTest(basename) { } compileRelease.end(SUCCESS); + if (missing_features.length) { + console.log("- " + stdoutColors.yellow("instantiate SKIPPED") + ": " + missing_features.join(", ") + " not enabled\n"); + return prepareResult(SKIPPED, "feature not enabled: " + missing_features.join(", ")); + } else if (v8_flags) { + v8.setFlagsFromString(v8_flags); + } + const debugBuffer = fs.readFileSync(path.join(basedir, basename + ".debug.wasm")); const releaseBuffer = stdout.toBuffer(); const instantiateDebug = section("instantiate debug"); From 85707fd5b63a09c6a68144c2d7fae78e07dd80ff Mon Sep 17 00:00:00 2001 From: CountBleck Date: Fri, 21 Jul 2023 22:34:32 +0530 Subject: [PATCH 3/8] Ensure the bindings tests are instantiated in CI Although the previous commit ensures the fixtures match for all tests requiring ASC_FEATURES, this commit ensures these tests can be instantiated. The list of tests to check will (for now) remain a whitelist, but since the fixtures of *all* tests are checked by CI, the PR breaking any excluded test can be found via `git blame` or `git log`. --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 79091199fd..70c5ae7442 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -83,7 +83,7 @@ jobs: env: ASC_FEATURES: threads,reference-types,gc,exception-handling run: | - npm run test:compiler features/threads features/reference-types features/gc features/exception-handling + npm run test:compiler features/threads features/reference-types features/gc features/exception-handling bindings/esm bindings/raw runtimes: name: "Runtimes" runs-on: ubuntu-latest From a726f89ef6df3ee7c23d8fb6ee94a58e51aa8f3d Mon Sep 17 00:00:00 2001 From: CountBleck Date: Fri, 14 Jul 2023 07:08:29 +0530 Subject: [PATCH 4/8] Use Pascal case for enums in the tokenizer test Although the rest of the compiler switched to Pascal case, this small test didn't. This equally small fix makes the test work again (instead of spamming "Identifier"). --- tests/tokenizer.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tests/tokenizer.js b/tests/tokenizer.js index 8999ff68ce..a81df43467 100644 --- a/tests/tokenizer.js +++ b/tests/tokenizer.js @@ -7,22 +7,22 @@ const dirname = path.dirname(fileURLToPath(import.meta.url)); const file = process.argv.length > 2 ? process.argv[2] : path.join(dirname, "..", "src", "tokenizer.ts"); const text = fs.readFileSync(file).toString(); -const source = new Source(SourceKind.ENTRY, "tokenizer.ts", text); +const source = new Source(SourceKind.Entry, "tokenizer.ts", text); const tn = new Tokenizer(source); do { const token = tn.next(); const range = tn.range(); process.stdout.write(Token[token] + " @ " + source.lineAt(range.start) + ":" + source.columnAt()); - if (token == Token.IDENTIFIER) { + if (token == Token.Identifier) { process.stdout.write(" > " + tn.readIdentifier()); - } else if (token == Token.INTEGERLITERAL) { + } else if (token == Token.IntegerLiteral) { process.stdout.write(" > " + tn.readInteger()); - } else if (token == Token.FLOATLITERAL) { + } else if (token == Token.FloatLiteral) { process.stdout.write(" > " + tn.readFloat()); - } else if (token == Token.STRINGLITERAL) { + } else if (token == Token.StringLiteral) { process.stdout.write(" > " + tn.readString()); - } else if (token == Token.ENDOFFILE) { + } else if (token == Token.EndOfFile) { process.stdout.write("\n"); break; } else { From 7403509cfee66eb7089da3d4687ec44bb698799e Mon Sep 17 00:00:00 2001 From: CountBleck Date: Sun, 23 Jul 2023 20:56:40 +0530 Subject: [PATCH 5/8] Update the fixtures for the bindings/noExportRuntime and std/math tests --- .../bindings/noExportRuntime.debug.js | 2 +- .../bindings/noExportRuntime.release.js | 2 +- tests/compiler/std/math.release.wat | 36 +++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/compiler/bindings/noExportRuntime.debug.js b/tests/compiler/bindings/noExportRuntime.debug.js index dda4a04e3d..9db98d97b4 100644 --- a/tests/compiler/bindings/noExportRuntime.debug.js +++ b/tests/compiler/bindings/noExportRuntime.debug.js @@ -159,7 +159,7 @@ export const { isArrayOfArray, returnsArrayOfArray, takesNonPlainObject, - takesFunction + takesFunction, } = await (async url => instantiate( await (async () => { try { return await globalThis.WebAssembly.compileStreaming(globalThis.fetch(url)); } diff --git a/tests/compiler/bindings/noExportRuntime.release.js b/tests/compiler/bindings/noExportRuntime.release.js index c35c9f8ef1..de99664237 100644 --- a/tests/compiler/bindings/noExportRuntime.release.js +++ b/tests/compiler/bindings/noExportRuntime.release.js @@ -159,7 +159,7 @@ export const { isArrayOfArray, returnsArrayOfArray, takesNonPlainObject, - takesFunction + takesFunction, } = await (async url => instantiate( await (async () => { try { return await globalThis.WebAssembly.compileStreaming(globalThis.fetch(url)); } diff --git a/tests/compiler/std/math.release.wat b/tests/compiler/std/math.release.wat index 2af003d42d..233a263ee1 100644 --- a/tests/compiler/std/math.release.wat +++ b/tests/compiler/std/math.release.wat @@ -49900,7 +49900,7 @@ call $~lib/builtins/abort unreachable end - f64.const nan:0x8000000000000 + f64.const -nan:0x8000000000000 f64.const nan:0x8000000000000 f64.const 0 call $std/math/check @@ -49944,7 +49944,7 @@ call $~lib/builtins/abort unreachable end - f64.const nan:0x8000000000000 + f64.const -nan:0x8000000000000 f64.const nan:0x8000000000000 f64.const 0 call $std/math/check @@ -49966,7 +49966,7 @@ call $~lib/builtins/abort unreachable end - f64.const nan:0x8000000000000 + f64.const -nan:0x8000000000000 f64.const nan:0x8000000000000 f64.const 0 call $std/math/check @@ -50032,7 +50032,7 @@ call $~lib/builtins/abort unreachable end - f64.const nan:0x8000000000000 + f64.const -nan:0x8000000000000 f64.const nan:0x8000000000000 f64.const 0 call $std/math/check @@ -50098,7 +50098,7 @@ call $~lib/builtins/abort unreachable end - f64.const nan:0x8000000000000 + f64.const -nan:0x8000000000000 f64.const nan:0x8000000000000 f64.const 0 call $std/math/check @@ -50164,7 +50164,7 @@ call $~lib/builtins/abort unreachable end - f64.const nan:0x8000000000000 + f64.const -nan:0x8000000000000 f64.const nan:0x8000000000000 f64.const 0 call $std/math/check @@ -50252,7 +50252,7 @@ call $~lib/builtins/abort unreachable end - f64.const nan:0x8000000000000 + f64.const -nan:0x8000000000000 f64.const nan:0x8000000000000 f64.const 0 call $std/math/check @@ -50362,7 +50362,7 @@ call $~lib/builtins/abort unreachable end - f64.const nan:0x8000000000000 + f64.const -nan:0x8000000000000 f64.const nan:0x8000000000000 f64.const 0 call $std/math/check @@ -50516,7 +50516,7 @@ call $~lib/builtins/abort unreachable end - f64.const nan:0x8000000000000 + f64.const -nan:0x8000000000000 f64.const nan:0x8000000000000 f64.const 0 call $std/math/check @@ -51748,7 +51748,7 @@ call $~lib/builtins/abort unreachable end - f32.const nan:0x400000 + f32.const -nan:0x400000 f32.const nan:0x400000 f32.const 0 call $std/math/check @@ -51774,7 +51774,7 @@ call $~lib/builtins/abort unreachable end - f32.const nan:0x400000 + f32.const -nan:0x400000 f32.const nan:0x400000 f32.const 0 call $std/math/check @@ -51787,7 +51787,7 @@ call $~lib/builtins/abort unreachable end - f32.const nan:0x400000 + f32.const -nan:0x400000 f32.const nan:0x400000 f32.const 0 call $std/math/check @@ -51826,7 +51826,7 @@ call $~lib/builtins/abort unreachable end - f32.const nan:0x400000 + f32.const -nan:0x400000 f32.const nan:0x400000 f32.const 0 call $std/math/check @@ -51865,7 +51865,7 @@ call $~lib/builtins/abort unreachable end - f32.const nan:0x400000 + f32.const -nan:0x400000 f32.const nan:0x400000 f32.const 0 call $std/math/check @@ -51904,7 +51904,7 @@ call $~lib/builtins/abort unreachable end - f32.const nan:0x400000 + f32.const -nan:0x400000 f32.const nan:0x400000 f32.const 0 call $std/math/check @@ -51956,7 +51956,7 @@ call $~lib/builtins/abort unreachable end - f32.const nan:0x400000 + f32.const -nan:0x400000 f32.const nan:0x400000 f32.const 0 call $std/math/check @@ -52021,7 +52021,7 @@ call $~lib/builtins/abort unreachable end - f32.const nan:0x400000 + f32.const -nan:0x400000 f32.const nan:0x400000 f32.const 0 call $std/math/check @@ -52047,7 +52047,7 @@ call $~lib/builtins/abort unreachable end - f32.const nan:0x400000 + f32.const -nan:0x400000 f32.const nan:0x400000 f32.const 0 call $std/math/check From 22ea45c6c452a6c738c7726a0c6acbb842258070 Mon Sep 17 00:00:00 2001 From: CountBleck Date: Sun, 23 Jul 2023 20:24:55 +0530 Subject: [PATCH 6/8] Compare WAT and bindings fixtures for both debug and release builds This commit changes compiler tests such that WAT fixtures are compared in release builds as well. Moreover, the JS and (D)TS bindings are now compared as well, for both debug and release builds. These changes should ensure changes to Binaryen or bindings generation that affect the release WAT or JS/TS bindings respectively must update the broken compiler tests as well. --- tests/compiler.js | 153 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 116 insertions(+), 37 deletions(-) diff --git a/tests/compiler.js b/tests/compiler.js index 17b8fabeec..863787a533 100644 --- a/tests/compiler.js +++ b/tests/compiler.js @@ -80,10 +80,11 @@ if (args.help) { const features = process.env.ASC_FEATURES ? process.env.ASC_FEATURES.split(",") : []; const featuresConfig = require("./features.json"); const basedir = path.join(dirname, "compiler"); +process.chdir(basedir); // Gets a list of all relevant tests function getTests() { - let tests = glob.sync("**/!(_*).ts", { cwd: basedir }) + let tests = glob.sync("**/!(_*).ts") .map(name => name.replace(/\.ts$/, "")) .filter(name => !name.endsWith(".d") && !name.includes("node_modules")); if (argv.length) { // run matching tests only @@ -134,6 +135,8 @@ async function runTest(basename) { const stdout = asc.createMemoryStream(); const stderr = asc.createMemoryStream(chunk => process.stderr.write(chunk.toString().replace(/^(?!$)/mg, " "))); stderr.isTTY = true; + const dummy = new Map(); + const writeFile = Map.prototype.set.bind(dummy); let asc_flags = []; let asc_rtrace = !!config.asc_rtrace; let v8_flags = ""; @@ -143,10 +146,107 @@ async function runTest(basename) { // Makes sure to reset the environment after function prepareResult(code, message = null) { if (v8_no_flags) v8.setFlagsFromString(v8_no_flags); - if (!args.createBinary) fs.unlink(path.join(basedir, basename + ".debug.wasm"), err => { /* nop */ }); + // Delete the .wasm files in case the subsequent run doesn't specify the + // --createBinary flag, thereby preventing confusion. Also, the .debug.wasm + // file is used by the bindings/esm test. + if (!args.createBinary) { + fs.unlink(basename + ".debug.wasm", err => { /* nop */ }); + fs.unlink(basename + ".release.wasm", err => { /* nop */ }); + } return { code, message }; } + function afterCompile(mode) { + // The ESM bindings test requires the .wasm file to be present. The file is + // promptly deleted after the test has completed, unless --createBinary is + // specified. + { + const filename = `${basename}.${mode}.wasm`; + fs.writeFileSync(filename, dummy.get(filename)); + } + + const compareFixture = section("compare fixture"); + const fixtureExtensions = ["wat", "js", "d.ts"]; + + if (args.create) { + for (const extension of fixtureExtensions) { + const filename = `${basename}.${mode}.${extension}`; + if (!dummy.has(filename)) { + fs.unlink(filename, err => { /* nop */ }); + continue; + } + fs.writeFileSync(filename, dummy.get(filename)); + console.log(" " + stdoutColors.yellow(`Created fixture ${filename}`)); + } + compareFixture.end(SKIPPED); + return; + } + + // Displaying the diffs in console for release fixtures isn't usually + // meaningful, so release fixtures are compared as if --noDiff was passed. + if (args.noDiff || mode === "release") { + for (const extension of fixtureExtensions) { + const filename = `${basename}.${mode}.${extension}`; + const actual = ( + dummy.has(filename) && + dummy.get(filename).replace(/\r\n/g, "\n") + ); + const expected = ( + fs.existsSync(filename) && + fs.readFileSync(filename, { encoding: "utf8" }).replace(/\r\n/g, "\n") + ); + + // If a fixture/generated file is missing, false will be compared to a + // string. If both are missing, nothing happens below (as it should). + if (actual !== expected) { + compareFixture.end(FAILURE); + return prepareResult(FAILURE, "fixture mismatch"); + } + } + compareFixture.end(SUCCESS); + return; + } + + let failed = false; + + for (const extension of fixtureExtensions) { + const filename = `${basename}.${mode}.${extension}`; + const actualExists = dummy.has(filename); + const expectedExists = fs.existsSync(filename); + + if (!actualExists && !expectedExists) { + // Neither exists, which is perfectly fine. Carry on. + continue; + } else if (actualExists != expectedExists) { + const message = actualExists + ? `Fixture ${filename} is missing!` + : `File ${filename} was not generated!`; + + console.log(" " + stdoutColors.yellow(message)); + failed = true; + continue; + } + + const actual = dummy.has(filename) && dummy.get(filename).replace(/\r\n/g, "\n"); + const expected = ( + fs.existsSync(filename) && + fs.readFileSync(filename, { encoding: "utf8" }).replace(/\r\n/g, "\n") + ); + + const diffResult = diff(filename, expected, actual); + if (diffResult !== null) { + console.log(diffResult); + failed = true; + } + } + + if (failed) { + compareFixture.end(FAILURE); + return prepareResult(FAILURE, "fixture mismatch"); + } + compareFixture.end(SUCCESS); + } + if (config.features) { config.features.forEach(feature => { if (!features.includes(feature) && !features.includes("*")) { @@ -176,15 +276,14 @@ async function runTest(basename) { { const cmd = [ basename + ".ts", - "--baseDir", basedir, "--debug", - "--textFile" // -> stdout + "--outFile", basename + ".debug.wasm", + "--textFile", basename + ".debug.wat" ]; if (asc_flags) cmd.push(...asc_flags); - cmd.push("--outFile", basename + ".debug.wasm"); if (args.noColors) cmd.push("--noColors"); const compileDebug = section("compile debug"); - const { error } = await asc.main(cmd, { stdout, stderr }); + const { error } = await asc.main(cmd, { stdout, stderr, writeFile }); let expectStderr = config.stderr; if (error) { @@ -224,50 +323,28 @@ async function runTest(basename) { return prepareResult(SUCCESS); } - const compareFixture = section("compare fixture"); - const actual = stdout.toString().replace(/\r\n/g, "\n"); - if (args.create) { - fs.writeFileSync(path.join(basedir, basename + ".debug.wat"), actual, { encoding: "utf8" }); - console.log(" " + stdoutColors.yellow("Created fixture")); - compareFixture.end(SKIPPED); - } else { - const expected = fs.readFileSync(path.join(basedir, basename + ".debug.wat"), { encoding: "utf8" }).replace(/\r\n/g, "\n"); - if (args.noDiff) { - if (expected != actual) { - compareFixture.end(FAILURE); - return prepareResult(FAILURE, "fixture mismatch"); - } - } else { - let diffs = diff(basename + ".debug.wat", expected, actual); - if (diffs !== null) { - console.log(diffs); - compareFixture.end(FAILURE); - return prepareResult(FAILURE, "fixture mismatch"); - } - } - compareFixture.end(SUCCESS); - } + const afterCompileResult = afterCompile("debug"); + if (afterCompileResult) return afterCompileResult; } stdout.length = 0; stderr.length = 0; - const gluePath = path.join(basedir, basename + ".js"); + const gluePath = basename + ".js"; const glue = fs.existsSync(gluePath) ? await import(pathToFileURL(gluePath)) : {}; // Build release { const cmd = [ basename + ".ts", - "--baseDir", basedir, - "--outFile", // -> stdout + "--outFile", basename + ".release.wasm", + "--textFile", basename + ".release.wat", "-O" ]; if (asc_flags) cmd.push(...asc_flags); - if (args.create) cmd.push("--textFile", basename + ".release.wat"); if (args.noColors) cmd.push("--noColors"); const compileRelease = section("compile release"); - const { error } = await asc.main(cmd, { stdout: stdout, stderr: stderr }); + const { error } = await asc.main(cmd, { stdout, stderr, writeFile }); if (error) { stderr.write("---\n"); @@ -278,6 +355,9 @@ async function runTest(basename) { } compileRelease.end(SUCCESS); + const afterCompileResult = afterCompile("release"); + if (afterCompileResult) return afterCompileResult; + if (missing_features.length) { console.log("- " + stdoutColors.yellow("instantiate SKIPPED") + ": " + missing_features.join(", ") + " not enabled\n"); return prepareResult(SKIPPED, "feature not enabled: " + missing_features.join(", ")); @@ -285,8 +365,8 @@ async function runTest(basename) { v8.setFlagsFromString(v8_flags); } - const debugBuffer = fs.readFileSync(path.join(basedir, basename + ".debug.wasm")); - const releaseBuffer = stdout.toBuffer(); + const debugBuffer = dummy.get(basename + ".debug.wasm"); + const releaseBuffer = dummy.get(basename + ".release.wasm"); const instantiateDebug = section("instantiate debug"); if (config.skipInstantiate) { instantiateDebug.end(SKIPPED); @@ -313,7 +393,6 @@ async function runTest(basename) { if (asc_rtrace) { const cmd = [ basename + ".ts", - "--baseDir", basedir, "--outFile", // -> stdout "--debug", "--use", "ASC_RTRACE=1", From 77aad42234ed8717d8a16d61fa884300ba66eb67 Mon Sep 17 00:00:00 2001 From: CountBleck Date: Sun, 23 Jul 2023 20:39:52 +0530 Subject: [PATCH 7/8] Fix the signature for `writeFile` so `contents` also includes `string`s --- cli/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cli/index.d.ts b/cli/index.d.ts index c2666db31f..16e070529e 100644 --- a/cli/index.d.ts +++ b/cli/index.d.ts @@ -165,7 +165,7 @@ export interface APIOptions { /** Reads a file from disk (or memory). */ readFile?: (filename: string, baseDir: string) => (string | null) | Promise; /** Writes a file to disk (or memory). */ - writeFile?: (filename: string, contents: Uint8Array, baseDir: string) => void | Promise; + writeFile?: (filename: string, contents: Uint8Array | string, baseDir: string) => void | Promise; /** Lists all files within a directory. */ listFiles?: (dirname: string, baseDir: string) => (string[] | null) | Promise; /** Handler for diagnostic messages. */ From 453c3b3406f0a98a0d94c51a10bd0e66545133bc Mon Sep 17 00:00:00 2001 From: CountBleck Date: Mon, 31 Jul 2023 14:28:16 +0530 Subject: [PATCH 8/8] Make IntelliSense complain less about symbols being redeclared in tests No longer shall VS Code cry about interface I in class-implements.ts already being declared in infer-type.ts and static-array.ts! By the power of forcing ESM detection! --- tests/compiler/tsconfig.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/compiler/tsconfig.json b/tests/compiler/tsconfig.json index 50bf8535c3..9807551662 100644 --- a/tests/compiler/tsconfig.json +++ b/tests/compiler/tsconfig.json @@ -1,7 +1,8 @@ { "extends": "../../std/assembly.json", "compilerOptions": { - "module": "ES6" + "module": "ES6", + "moduleDetection": "force" }, "include": [ "./**/*.ts"