From b3e3327b39fe8d5bfa41454816e4f3d62bef90cb Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Sun, 14 Apr 2024 23:23:59 -0700 Subject: [PATCH 1/2] Do not repeat types names in text output For types that do not have explicit names, we generate index-based names in the printer. However, we did not previously ensure that the generated types were not already used as explicit names, so it was possible to print the same name for multiple types, which is not valid. Fix the problem by skipping indices that are already used as type names. Fixes #6492. --- src/passes/Print.cpp | 42 ++++++++++++--- test/lit/passes/O4_disable-bulk-memory.wast | 2 +- test/lit/passes/coalesce-locals.wast | 8 +-- test/lit/passes/dae-optimizing.wast | 6 ++- test/lit/passes/flatten_all-features.wast | 14 ++--- test/lit/passes/fpcast-emu.wast | 4 +- test/lit/passes/instrument-memory.wast | 10 ++-- test/lit/passes/instrument-memory64.wast | 10 ++-- .../lit/passes/optimize-instructions-mvp.wast | 4 +- test/lld/duplicate_imports.wat.out | 16 +++--- test/passes/func-metrics.txt | 2 +- test/passes/post-emscripten.txt | 12 ++--- test/passes/precompute_all-features.txt | 54 +++++++++---------- ...-unused-names_remove-unused-brs_vacuum.txt | 2 +- ...nfunction-module-elements_all-features.txt | 2 +- test/passes/simplify-locals_all-features.txt | 46 ++++++++-------- ...ll-features_disable-exception-handling.txt | 46 ++++++++-------- 17 files changed, 153 insertions(+), 127 deletions(-) diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 68a2e4cb6ab..82b8841ed31 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -152,19 +152,45 @@ struct PrintSExpression : public UnifiedExpressionVisitor { // user-provided names and the fallback indexed names. struct TypePrinter : TypeNameGeneratorBase { PrintSExpression& parent; - IndexedTypeNameGenerator<> fallback; + DefaultTypeNameGenerator fallback; + std::unordered_map fallbackNames; TypePrinter(PrintSExpression& parent, const std::vector& types) - : parent(parent), fallback(types) {} + : parent(parent) { + if (!parent.currModule) { + return; + } + std::unordered_set usedNames; + for (auto& [_, names] : parent.currModule->typeNames) { + usedNames.insert(names.name); + } + size_t i = 0; + // Use indices for any remaining type names, skipping any that are already + // used. + for (auto type : types) { + if (parent.currModule->typeNames.count(type)) { + ++i; + continue; + } + Name name; + do { + name = std::to_string(i++); + } while (usedNames.count(name)); + fallbackNames[type] = {name, {}}; + } + } TypeNames getNames(HeapType type) { - if (parent.currModule) { - if (auto it = parent.currModule->typeNames.find(type); - it != parent.currModule->typeNames.end()) { - return it->second; - } + if (!parent.currModule) { + return fallback.getNames(type); + } + if (auto it = parent.currModule->typeNames.find(type); + it != parent.currModule->typeNames.end()) { + return it->second; } - return fallback.getNames(type); + auto it = fallbackNames.find(type); + assert(it != fallbackNames.end()); + return it->second; } Name getName(HeapType type) { return getNames(type).name; } diff --git a/test/lit/passes/O4_disable-bulk-memory.wast b/test/lit/passes/O4_disable-bulk-memory.wast index 63bb0ea406c..0cafb1d5da5 100644 --- a/test/lit/passes/O4_disable-bulk-memory.wast +++ b/test/lit/passes/O4_disable-bulk-memory.wast @@ -50,7 +50,7 @@ (type $7 (func (param i32 i32 i32))) ;; CHECK: (type $11 (func (param i32))) - ;; CHECK: (type $3 (func (param f64 f64 f64 f64 f64 f64 f64) (result i32))) + ;; CHECK: (type $12 (func (param f64 f64 f64 f64 f64 f64 f64) (result i32))) ;; CHECK: (type $8 (func (result f64))) (type $8 (func (result f64))) diff --git a/test/lit/passes/coalesce-locals.wast b/test/lit/passes/coalesce-locals.wast index f195c368189..5441c3fd6ec 100644 --- a/test/lit/passes/coalesce-locals.wast +++ b/test/lit/passes/coalesce-locals.wast @@ -12,7 +12,7 @@ ;; CHECK: (type $FUNCSIG$iii (func (param i32 i32) (result i32))) - ;; CHECK: (type $4 (func (param f64 i32) (result i64))) + ;; CHECK: (type $5 (func (param f64 i32) (result i64))) ;; CHECK: (type $3 (func (param i32 f32))) @@ -22,11 +22,11 @@ (type $2 (func)) (type $3 (func (param i32 f32))) (type $4 (func (param i32))) - ;; CHECK: (type $7 (func (param i32) (result i32))) + ;; CHECK: (type $8 (func (param i32) (result i32))) - ;; CHECK: (type $8 (func (param i32 i32))) + ;; CHECK: (type $9 (func (param i32 i32))) - ;; CHECK: (type $9 (func (result f64))) + ;; CHECK: (type $10 (func (result f64))) ;; CHECK: (import "env" "_emscripten_autodebug_i32" (func $_emscripten_autodebug_i32 (param i32 i32) (result i32))) (import "env" "_emscripten_autodebug_i32" (func $_emscripten_autodebug_i32 (param i32 i32) (result i32))) diff --git a/test/lit/passes/dae-optimizing.wast b/test/lit/passes/dae-optimizing.wast index cb15d55cb07..b9b7e7e2e2b 100644 --- a/test/lit/passes/dae-optimizing.wast +++ b/test/lit/passes/dae-optimizing.wast @@ -4,10 +4,12 @@ ;; RUN: foreach %s %t wasm-opt --dae-optimizing -S -o - | filecheck %s (module - ;; CHECK: (type $0 (func (result i32))) (type $0 (func (param f32) (result f32))) - ;; CHECK: (type $1 (func (result f32))) (type $1 (func (param f64 f32 f32 f64 f32 i64 f64) (result i32))) + ;; CHECK: (type $3 (func (result i32))) + + ;; CHECK: (type $4 (func (result f32))) + ;; CHECK: (type $2 (func (param f64 f32 f32 f64 f32 i32 i32 f64) (result i32))) (type $2 (func (param f64 f32 f32 f64 f32 i32 i32 f64) (result i32))) ;; CHECK: (global $global$0 (mut i32) (i32.const 10)) diff --git a/test/lit/passes/flatten_all-features.wast b/test/lit/passes/flatten_all-features.wast index aa3dc7578d8..2ba7c695437 100644 --- a/test/lit/passes/flatten_all-features.wast +++ b/test/lit/passes/flatten_all-features.wast @@ -14,11 +14,11 @@ (type $2 (func (result i32))) ;; CHECK: (type $3 (func (param i32) (result i32))) (type $3 (func (param i32) (result i32))) - ;; CHECK: (type $4 (func (result f32))) - (type $4 (func (param i64 i64) (result i64))) - ;; CHECK: (type $4 (func (param i64 i64) (result i64))) + ;; CHECK: (type $5 (func (result f32))) - ;; CHECK: (type $6 (func (result anyref))) + ;; CHECK: (type $4 (func (param i64 i64) (result i64))) + (type $4 (func (param i64 i64) (result i64))) + ;; CHECK: (type $7 (func (result anyref))) ;; CHECK: (global $x (mut i32) (i32.const 0)) (global $x (mut i32) (i32.const 0)) @@ -833,7 +833,7 @@ (i32.const 0) ) ) - ;; CHECK: (func $a17 (type $4) (result f32) + ;; CHECK: (func $a17 (type $5) (result f32) ;; CHECK-NEXT: (local $var$0 f32) ;; CHECK-NEXT: (local $1 f32) ;; CHECK-NEXT: (local $2 f32) @@ -921,7 +921,7 @@ ) ) ) - ;; CHECK: (func $a19 (type $4) (result f32) + ;; CHECK: (func $a19 (type $5) (result f32) ;; CHECK-NEXT: (block $label$0 ;; CHECK-NEXT: (block $label$1 ;; CHECK-NEXT: (unreachable) @@ -3585,7 +3585,7 @@ ;; targets an outer branch whose return type is a supertype of the br_if's ;; value type, we need the value to be set into two locals: one with the outer ;; block's type, and one with its value type. - ;; CHECK: (func $subtype (type $6) (result anyref) + ;; CHECK: (func $subtype (type $7) (result anyref) ;; CHECK-NEXT: (local $0 eqref) ;; CHECK-NEXT: (local $1 anyref) ;; CHECK-NEXT: (local $2 nullref) diff --git a/test/lit/passes/fpcast-emu.wast b/test/lit/passes/fpcast-emu.wast index 167e57d2607..8ded8264724 100644 --- a/test/lit/passes/fpcast-emu.wast +++ b/test/lit/passes/fpcast-emu.wast @@ -297,7 +297,7 @@ (type $0 (func (param i64))) ;; CHECK: (type $1 (func (param f32) (result i64))) (type $1 (func (param f32) (result i64))) - ;; CHECK: (type $1 (func (param i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64) (result i64))) + ;; CHECK: (type $2 (func (param i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64 i64) (result i64))) ;; CHECK: (global $global$0 (mut i32) (i32.const 10)) (global $global$0 (mut i32) (i32.const 10)) @@ -312,7 +312,7 @@ ;; CHECK-NEXT: (global.set $global$0 ;; CHECK-NEXT: (i32.const 0) ;; CHECK-NEXT: ) - ;; CHECK-NEXT: (call_indirect (type $1) + ;; CHECK-NEXT: (call_indirect (type $2) ;; CHECK-NEXT: (br $label$1 ;; CHECK-NEXT: (i64.const 4294967295) ;; CHECK-NEXT: ) diff --git a/test/lit/passes/instrument-memory.wast b/test/lit/passes/instrument-memory.wast index 74b1e75d42d..f776d2af13f 100644 --- a/test/lit/passes/instrument-memory.wast +++ b/test/lit/passes/instrument-memory.wast @@ -7,15 +7,15 @@ (memory 256 256) ;; CHECK: (type $1 (func)) (type $1 (func)) - ;; CHECK: (type $1 (func (param i32 i32 i32 i32) (result i32))) + ;; CHECK: (type $2 (func (param i32 i32 i32 i32) (result i32))) - ;; CHECK: (type $2 (func (param i32 i32) (result i32))) + ;; CHECK: (type $3 (func (param i32 i32) (result i32))) - ;; CHECK: (type $3 (func (param i32 i64) (result i64))) + ;; CHECK: (type $4 (func (param i32 i64) (result i64))) - ;; CHECK: (type $4 (func (param i32 f32) (result f32))) + ;; CHECK: (type $5 (func (param i32 f32) (result f32))) - ;; CHECK: (type $5 (func (param i32 f64) (result f64))) + ;; CHECK: (type $6 (func (param i32 f64) (result f64))) ;; CHECK: (import "env" "load_ptr" (func $load_ptr (param i32 i32 i32 i32) (result i32))) diff --git a/test/lit/passes/instrument-memory64.wast b/test/lit/passes/instrument-memory64.wast index 1f3be75d57c..5ceb37fe22c 100644 --- a/test/lit/passes/instrument-memory64.wast +++ b/test/lit/passes/instrument-memory64.wast @@ -7,15 +7,15 @@ (memory i64 256 256) ;; CHECK: (type $1 (func)) (type $1 (func)) - ;; CHECK: (type $1 (func (param i32 i32 i64 i64) (result i64))) + ;; CHECK: (type $2 (func (param i32 i32 i64 i64) (result i64))) - ;; CHECK: (type $2 (func (param i32 i32) (result i32))) + ;; CHECK: (type $3 (func (param i32 i32) (result i32))) - ;; CHECK: (type $3 (func (param i32 i64) (result i64))) + ;; CHECK: (type $4 (func (param i32 i64) (result i64))) - ;; CHECK: (type $4 (func (param i32 f32) (result f32))) + ;; CHECK: (type $5 (func (param i32 f32) (result f32))) - ;; CHECK: (type $5 (func (param i32 f64) (result f64))) + ;; CHECK: (type $6 (func (param i32 f64) (result f64))) ;; CHECK: (import "env" "load_ptr" (func $load_ptr (param i32 i32 i64 i64) (result i64))) diff --git a/test/lit/passes/optimize-instructions-mvp.wast b/test/lit/passes/optimize-instructions-mvp.wast index b618cf200ad..43da637e826 100644 --- a/test/lit/passes/optimize-instructions-mvp.wast +++ b/test/lit/passes/optimize-instructions-mvp.wast @@ -2,10 +2,8 @@ ;; RUN: wasm-opt %s --optimize-instructions --mvp-features -S -o - | filecheck %s (module - ;; CHECK: (type $0 (func (result i32))) - (type $0 (func (param i32 i64))) - ;; CHECK: (type $0 (func (param i32 i64))) + (type $0 (func (param i32 i64))) ;; CHECK: (import "a" "b" (func $get-f64 (result f64))) (import "a" "b" (func $get-f64 (result f64))) diff --git a/test/lld/duplicate_imports.wat.out b/test/lld/duplicate_imports.wat.out index db7d1ff29f4..7e49b393cc4 100644 --- a/test/lld/duplicate_imports.wat.out +++ b/test/lld/duplicate_imports.wat.out @@ -1,13 +1,13 @@ (module - (type $0 (func (param i32 f32 f64) (result f32))) - (type $1 (func (param i32 f64 f64) (result f32))) + (type $3 (func (param i32 f32 f64) (result f32))) + (type $4 (func (param i32 f64 f64) (result f32))) (type $0 (func (param i32) (result i32))) (type $1 (func (result i32))) (type $2 (func)) - (type $5 (func (param f32 f64) (result f32))) - (type $6 (func (param f64 f64) (result f32))) - (type $7 (func (param i64) (result i32))) - (type $8 (func (param i32 i32) (result i32))) + (type $8 (func (param f32 f64) (result f32))) + (type $9 (func (param f64 f64) (result f32))) + (type $10 (func (param i64) (result i32))) + (type $11 (func (param i32 i32) (result i32))) (import "env" "puts" (func $puts1 (param i32) (result i32))) (import "env" "invoke_ffd" (func $invoke_ffd (param i32 f32 f64) (result f32))) (import "env" "invoke_ffd" (func $invoke_ffd2 (param i32 f64 f64) (result f32))) @@ -37,14 +37,14 @@ (nop) ) (func $dynCall_ffd (param $fptr i32) (param $0 f32) (param $1 f64) (result f32) - (call_indirect (type $5) + (call_indirect (type $8) (local.get $0) (local.get $1) (local.get $fptr) ) ) (func $dynCall_fdd (param $fptr i32) (param $0 f64) (param $1 f64) (result f32) - (call_indirect (type $6) + (call_indirect (type $9) (local.get $0) (local.get $1) (local.get $fptr) diff --git a/test/passes/func-metrics.txt b/test/passes/func-metrics.txt index 8921b6977b4..afd6afe0724 100644 --- a/test/passes/func-metrics.txt +++ b/test/passes/func-metrics.txt @@ -35,7 +35,7 @@ func: ifs Drop : 6 If : 4 (module - (type $0 (func)) + (type $1 (func)) (type $0 (func (param i32))) (global $glob i32 (i32.const 1337)) (memory $0 256 256) diff --git a/test/passes/post-emscripten.txt b/test/passes/post-emscripten.txt index 6b80f9e3b56..186cdeb7675 100644 --- a/test/passes/post-emscripten.txt +++ b/test/passes/post-emscripten.txt @@ -1,7 +1,7 @@ (module - (type $0 (func (param i32 f32))) - (type $1 (func (param i32 i32 f32))) - (type $2 (func)) + (type $1 (func (param i32 f32))) + (type $2 (func (param i32 i32 f32))) + (type $3 (func)) (import "env" "invoke_vif" (func $invoke_vif (param i32 i32 f32))) (memory $0 256 256) (table $0 7 7 funcref) @@ -68,9 +68,9 @@ ) ) (module - (type $0 (func (param i32 i32 f32))) - (type $1 (func)) - (type $2 (func (param i32 f32))) + (type $1 (func (param i32 i32 f32))) + (type $2 (func)) + (type $3 (func (param i32 f32))) (import "env" "glob" (global $glob i32)) (import "env" "invoke_vif" (func $invoke_vif (param i32 i32 f32))) (memory $0 256 256) diff --git a/test/passes/precompute_all-features.txt b/test/passes/precompute_all-features.txt index 8021136f2d6..2ec32c90710 100644 --- a/test/passes/precompute_all-features.txt +++ b/test/passes/precompute_all-features.txt @@ -1,11 +1,11 @@ (module - (type $0 (func)) - (type $1 (func (result i32))) - (type $2 (func (result f64))) + (type $1 (func)) + (type $2 (func (result i32))) + (type $3 (func (result f64))) (type $0 (func (param i32))) - (type $4 (func (result v128))) - (type $5 (func (result i32 i64))) - (type $6 (func (result externref))) + (type $5 (func (result v128))) + (type $6 (func (result i32 i64))) + (type $7 (func (result externref))) (global $global i32 (i32.const 1)) (global $global-mut (mut i32) (i32.const 2)) (memory $m 512 512) @@ -93,7 +93,7 @@ (i32.const 0) ) ) - (func $ret (type $1) (result i32) + (func $ret (type $2) (result i32) (if (call $ret) (then @@ -112,7 +112,7 @@ ) (i32.const 1) ) - (func $noret (type $0) + (func $noret (type $1) (if (call $ret) (then @@ -120,7 +120,7 @@ ) ) ) - (func $refinalize-br-condition-unreachable (type $0) + (func $refinalize-br-condition-unreachable (type $1) (block $label$1 (drop (br_if $label$1 @@ -129,7 +129,7 @@ ) ) ) - (func $br_if-condition-is-block-i32-but-unreachable-so-refinalize-tricky (type $0) + (func $br_if-condition-is-block-i32-but-unreachable-so-refinalize-tricky (type $1) (drop (block $label$1 (result i32) (drop @@ -144,7 +144,7 @@ ) ) ) - (func $reuse-br-value (type $2) (result f64) + (func $reuse-br-value (type $3) (result f64) (block $label$0 (result f64) (i32.store8 (i32.const 1919623207) @@ -175,7 +175,7 @@ (f64.const 4776014875438170098655851e156) ) ) - (func $refinalize-two-breaks-one-unreachable (type $0) + (func $refinalize-two-breaks-one-unreachable (type $1) (drop (block $label$0 (result i64) (block @@ -198,7 +198,7 @@ ) ) ) - (func $one-break-value-and-it-is-unreachable (type $2) (result f64) + (func $one-break-value-and-it-is-unreachable (type $3) (result f64) (local $var$0 i32) (block $label$6 (block @@ -209,16 +209,16 @@ ) ) ) - (func $global-notprecomputable (type $1) (result i32) + (func $global-notprecomputable (type $2) (result i32) (i32.add (i32.const 1) (global.get $global-mut) ) ) - (func $global-precomputable (type $1) (result i32) + (func $global-precomputable (type $2) (result i32) (i32.const 2) ) - (func $global-partiallyprecomputable (type $1) (result i32) + (func $global-partiallyprecomputable (type $2) (result i32) (i32.sub (i32.add (i32.const 1) @@ -227,49 +227,49 @@ (i32.const 2) ) ) - (func $simd-precompute (type $4) (result v128) + (func $simd-precompute (type $5) (result v128) (v128.const i32x4 0x00000000 0x00000000 0x00000000 0x00000000) ) - (func $no-memory-init-precompute (type $0) + (func $no-memory-init-precompute (type $1) (memory.init $0 (i32.const 512) (i32.const 0) (i32.const 12) ) ) - (func $no-data-drop-precompute (type $0) + (func $no-data-drop-precompute (type $1) (data.drop $0) ) - (func $no-memory-copy-precompute (type $0) + (func $no-memory-copy-precompute (type $1) (memory.copy (i32.const 512) (i32.const 0) (i32.const 12) ) ) - (func $no-memory-fill-precompute (type $0) + (func $no-memory-fill-precompute (type $1) (memory.fill (i32.const 512) (i32.const 0) (i32.const 12) ) ) - (func $tuple-precompute (type $5) (result i32 i64) + (func $tuple-precompute (type $6) (result i32 i64) (tuple.make 2 (i32.const 42) (i64.const 42) ) ) - (func $loop-precompute (type $1) (result i32) + (func $loop-precompute (type $2) (result i32) (i32.const 1) ) - (func $reftype-test (type $6) (result externref) + (func $reftype-test (type $7) (result externref) (ref.null noextern) ) - (func $dummy (type $0) + (func $dummy (type $1) (nop) ) - (func $br_reuse_node (type $0) + (func $br_reuse_node (type $1) (drop (block $l0 (result f32) (drop @@ -301,7 +301,7 @@ ) ) (drop - (block $l4 (result (ref null $0)) + (block $l4 (result (ref null $1)) (drop (block $l5 (global.set $global-mut diff --git a/test/passes/remove-unused-names_remove-unused-brs_vacuum.txt b/test/passes/remove-unused-names_remove-unused-brs_vacuum.txt index 2a157dcf98c..8b5a963725a 100644 --- a/test/passes/remove-unused-names_remove-unused-brs_vacuum.txt +++ b/test/passes/remove-unused-names_remove-unused-brs_vacuum.txt @@ -7,7 +7,7 @@ (type $7 (func (param i32 i32))) (type $1 (func (param f64) (result i32))) (type $13 (func (param i32 i32 i32 i32 i32))) - (type $8 (func (param i32) (result i64))) + (type $16 (func (param i32) (result i64))) (import "env" "memory" (memory $0 256)) (import "env" "table" (table $timport$0 18 18 funcref)) (import "env" "ABORT" (global $import$2 i32)) diff --git a/test/passes/remove-unused-nonfunction-module-elements_all-features.txt b/test/passes/remove-unused-nonfunction-module-elements_all-features.txt index 88998c6ca3b..e125373d8d8 100644 --- a/test/passes/remove-unused-nonfunction-module-elements_all-features.txt +++ b/test/passes/remove-unused-nonfunction-module-elements_all-features.txt @@ -342,7 +342,7 @@ ) ) (module - (type $0 (func (param i64))) + (type $1 (func (param i64))) (type $0 (func (param i32))) (tag $e1 (param i64)) (export "e1" (tag $e1)) diff --git a/test/passes/simplify-locals_all-features.txt b/test/passes/simplify-locals_all-features.txt index 36a635e2973..0b7b4b70530 100644 --- a/test/passes/simplify-locals_all-features.txt +++ b/test/passes/simplify-locals_all-features.txt @@ -4,20 +4,20 @@ (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) (type $6 (func (param i32 i32 i32 i32 i32 i32))) - (type $5 (func (param i32 i32 i32) (result i32))) + (type $7 (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) - (type $7 (func (param i32 i32) (result i32))) - (type $8 (func (param f32))) + (type $9 (func (param i32 i32) (result i32))) + (type $10 (func (param f32))) (type $4 (func (param i32))) - (type $10 (func (param i32 i32))) - (type $11 (func (param i64))) - (type $12 (func (param i32 f64 f64 f32 i32) (result f64))) + (type $12 (func (param i32 i32))) + (type $13 (func (param i64))) + (type $14 (func (param i32 f64 f64 f32 i32) (result f64))) (import "env" "waka" (func $waka (type $FUNCSIG$v))) (import "env" "waka_int" (func $waka_int (type $FUNCSIG$i) (result i32))) (import "env" "i64sub" (func $_i64Subtract (type $FUNCSIG$iiiii) (param i32 i32 i32 i32) (result i32))) (import "env" "moddi" (func $___udivmoddi4 (type $FUNCSIG$iiiiii) (param i32 i32 i32 i32 i32) (result i32))) - (import "env" "lp" (func $lp (type $7) (param i32 i32) (result i32))) - (import "fuzzing-support" "log-f32" (func $fimport$0 (type $8) (param f32))) + (import "env" "lp" (func $lp (type $9) (param i32 i32) (result i32))) + (import "fuzzing-support" "log-f32" (func $fimport$0 (type $10) (param f32))) (global $global$0 (mut i32) (i32.const 10)) (memory $0 256 256) (func $contrast (type $FUNCSIG$v) @@ -792,7 +792,7 @@ (local.get $i1) ) ) - (func $no-out-of-label (type $10) (param $x i32) (param $y i32) + (func $no-out-of-label (type $12) (param $x i32) (param $y i32) (nop) (local.set $x (loop $moar (result i32) @@ -847,7 +847,7 @@ ) ) ) - (func $drop-if-value (type $5) (param $x i32) (param $y i32) (param $z i32) (result i32) + (func $drop-if-value (type $7) (param $x i32) (param $y i32) (param $z i32) (result i32) (local $temp i32) (drop (if (result i32) @@ -879,7 +879,7 @@ (i32.const 0) ) ) - (func $drop-br_if (type $5) (param $label i32) (param $$cond2 i32) (param $$$0151 i32) (result i32) + (func $drop-br_if (type $7) (param $label i32) (param $$cond2 i32) (param $$$0151 i32) (result i32) (nop) (local.tee $label (block $label$break$L4 (result i32) @@ -922,7 +922,7 @@ (local.get $x) ) ) - (func $if-return-but-unreachable (type $11) (param $var$0 i64) + (func $if-return-but-unreachable (type $13) (param $var$0 i64) (if (unreachable) (then @@ -1135,7 +1135,7 @@ ) ) ) - (func $update-getCounter (type $12) (param $0 i32) (param $1 f64) (param $2 f64) (param $3 f32) (param $4 i32) (result f64) + (func $update-getCounter (type $14) (param $0 i32) (param $1 f64) (param $2 f64) (param $3 f32) (param $4 i32) (result f64) (global.set $global$0 (i32.sub (global.get $global$0) @@ -1215,14 +1215,14 @@ (type $5 (func (param i32) (result i32))) (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) (type $4 (func (param i32))) - (type $5 (func (param f32))) - (type $6 (func (param i32 i32))) - (type $7 (func (result f64))) - (type $8 (func (param i32 i32) (result f64))) - (type $9 (func (param i32 i32) (result i32))) + (type $7 (func (param f32))) + (type $8 (func (param i32 i32))) + (type $9 (func (result f64))) + (type $10 (func (param i32 i32) (result f64))) + (type $11 (func (param i32 i32) (result i32))) (import "fuzzing-support" "log1" (func $fimport$0 (type $FUNCSIG$i) (result i32))) (import "fuzzing-support" "log2" (func $fimport$1 (type $4) (param i32))) - (import "fuzzing-support" "log3" (func $fimport$2 (type $5) (param f32))) + (import "fuzzing-support" "log3" (func $fimport$2 (type $7) (param f32))) (global $global$0 (mut i32) (i32.const 10)) (memory $0 256 256 shared) (func $nonatomics (type $FUNCSIG$i) (result i32) @@ -1663,7 +1663,7 @@ (local.get $x) ) ) - (func $loop-copies (type $6) (param $x i32) (param $y i32) + (func $loop-copies (type $8) (param $x i32) (param $y i32) (loop $loop (nop) (drop @@ -1674,7 +1674,7 @@ ) ) ) - (func $proper-type (type $7) (result f64) + (func $proper-type (type $9) (result f64) (local $var$0 i32) (local $var$2 f64) (local.set $var$0 @@ -1686,7 +1686,7 @@ ) (local.get $var$2) ) - (func $multi-pass-get-equivs-right (type $8) (param $var$0 i32) (param $var$1 i32) (result f64) + (func $multi-pass-get-equivs-right (type $10) (param $var$0 i32) (param $var$1 i32) (result f64) (local $var$2 i32) (nop) (i32.store @@ -1717,7 +1717,7 @@ ) ) ) - (func $set-tee-need-one-of-them (type $9) (param $var$0 i32) (param $var$1 i32) (result i32) + (func $set-tee-need-one-of-them (type $11) (param $var$0 i32) (param $var$1 i32) (result i32) (local $var$2 i32) (local $var$3 i32) (local.set $var$2 diff --git a/test/passes/simplify-locals_all-features_disable-exception-handling.txt b/test/passes/simplify-locals_all-features_disable-exception-handling.txt index f14253c3e73..e6986b1a7f7 100644 --- a/test/passes/simplify-locals_all-features_disable-exception-handling.txt +++ b/test/passes/simplify-locals_all-features_disable-exception-handling.txt @@ -4,20 +4,20 @@ (type $FUNCSIG$i (func (result i32))) (type $FUNCSIG$iiiii (func (param i32 i32 i32 i32) (result i32))) (type $6 (func (param i32 i32 i32 i32 i32 i32))) - (type $5 (func (param i32 i32 i32) (result i32))) + (type $7 (func (param i32 i32 i32) (result i32))) (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) - (type $7 (func (param i32 i32) (result i32))) - (type $8 (func (param f32))) + (type $9 (func (param i32 i32) (result i32))) + (type $10 (func (param f32))) (type $4 (func (param i32))) - (type $10 (func (param i32 i32))) - (type $11 (func (param i64))) - (type $12 (func (param i32 f64 f64 f32 i32) (result f64))) + (type $12 (func (param i32 i32))) + (type $13 (func (param i64))) + (type $14 (func (param i32 f64 f64 f32 i32) (result f64))) (import "env" "waka" (func $waka (type $FUNCSIG$v))) (import "env" "waka_int" (func $waka_int (type $FUNCSIG$i) (result i32))) (import "env" "i64sub" (func $_i64Subtract (type $FUNCSIG$iiiii) (param i32 i32 i32 i32) (result i32))) (import "env" "moddi" (func $___udivmoddi4 (type $FUNCSIG$iiiiii) (param i32 i32 i32 i32 i32) (result i32))) - (import "env" "lp" (func $lp (type $7) (param i32 i32) (result i32))) - (import "fuzzing-support" "log-f32" (func $fimport$0 (type $8) (param f32))) + (import "env" "lp" (func $lp (type $9) (param i32 i32) (result i32))) + (import "fuzzing-support" "log-f32" (func $fimport$0 (type $10) (param f32))) (global $global$0 (mut i32) (i32.const 10)) (memory $0 256 256) (func $contrast (type $FUNCSIG$v) @@ -786,7 +786,7 @@ (local.get $i1) ) ) - (func $no-out-of-label (type $10) (param $x i32) (param $y i32) + (func $no-out-of-label (type $12) (param $x i32) (param $y i32) (nop) (local.set $x (loop $moar (result i32) @@ -841,7 +841,7 @@ ) ) ) - (func $drop-if-value (type $5) (param $x i32) (param $y i32) (param $z i32) (result i32) + (func $drop-if-value (type $7) (param $x i32) (param $y i32) (param $z i32) (result i32) (local $temp i32) (drop (if (result i32) @@ -873,7 +873,7 @@ (i32.const 0) ) ) - (func $drop-br_if (type $5) (param $label i32) (param $$cond2 i32) (param $$$0151 i32) (result i32) + (func $drop-br_if (type $7) (param $label i32) (param $$cond2 i32) (param $$$0151 i32) (result i32) (nop) (local.tee $label (block $label$break$L4 (result i32) @@ -916,7 +916,7 @@ (local.get $x) ) ) - (func $if-return-but-unreachable (type $11) (param $var$0 i64) + (func $if-return-but-unreachable (type $13) (param $var$0 i64) (if (unreachable) (then @@ -1129,7 +1129,7 @@ ) ) ) - (func $update-getCounter (type $12) (param $0 i32) (param $1 f64) (param $2 f64) (param $3 f32) (param $4 i32) (result f64) + (func $update-getCounter (type $14) (param $0 i32) (param $1 f64) (param $2 f64) (param $3 f32) (param $4 i32) (result f64) (global.set $global$0 (i32.sub (global.get $global$0) @@ -1209,14 +1209,14 @@ (type $5 (func (param i32) (result i32))) (type $FUNCSIG$iiiiii (func (param i32 i32 i32 i32 i32) (result i32))) (type $4 (func (param i32))) - (type $5 (func (param f32))) - (type $6 (func (param i32 i32))) - (type $7 (func (result f64))) - (type $8 (func (param i32 i32) (result f64))) - (type $9 (func (param i32 i32) (result i32))) + (type $7 (func (param f32))) + (type $8 (func (param i32 i32))) + (type $9 (func (result f64))) + (type $10 (func (param i32 i32) (result f64))) + (type $11 (func (param i32 i32) (result i32))) (import "fuzzing-support" "log1" (func $fimport$0 (type $FUNCSIG$i) (result i32))) (import "fuzzing-support" "log2" (func $fimport$1 (type $4) (param i32))) - (import "fuzzing-support" "log3" (func $fimport$2 (type $5) (param f32))) + (import "fuzzing-support" "log3" (func $fimport$2 (type $7) (param f32))) (global $global$0 (mut i32) (i32.const 10)) (memory $0 256 256 shared) (func $nonatomics (type $FUNCSIG$i) (result i32) @@ -1657,7 +1657,7 @@ (local.get $x) ) ) - (func $loop-copies (type $6) (param $x i32) (param $y i32) + (func $loop-copies (type $8) (param $x i32) (param $y i32) (loop $loop (nop) (drop @@ -1668,7 +1668,7 @@ ) ) ) - (func $proper-type (type $7) (result f64) + (func $proper-type (type $9) (result f64) (local $var$0 i32) (local $var$2 f64) (local.set $var$0 @@ -1680,7 +1680,7 @@ ) (local.get $var$2) ) - (func $multi-pass-get-equivs-right (type $8) (param $var$0 i32) (param $var$1 i32) (result f64) + (func $multi-pass-get-equivs-right (type $10) (param $var$0 i32) (param $var$1 i32) (result f64) (local $var$2 i32) (nop) (i32.store @@ -1711,7 +1711,7 @@ ) ) ) - (func $set-tee-need-one-of-them (type $9) (param $var$0 i32) (param $var$1 i32) (result i32) + (func $set-tee-need-one-of-them (type $11) (param $var$0 i32) (param $var$1 i32) (result i32) (local $var$2 i32) (local $var$3 i32) (local.set $var$2 From 022bd4b670d0c86053d0a84d879937536386892c Mon Sep 17 00:00:00 2001 From: Thomas Lively Date: Mon, 15 Apr 2024 12:10:17 -0700 Subject: [PATCH 2/2] fix incorrect assertion --- src/passes/Print.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/src/passes/Print.cpp b/src/passes/Print.cpp index 82b8841ed31..e2d0e112645 100644 --- a/src/passes/Print.cpp +++ b/src/passes/Print.cpp @@ -181,16 +181,23 @@ struct PrintSExpression : public UnifiedExpressionVisitor { } TypeNames getNames(HeapType type) { - if (!parent.currModule) { - return fallback.getNames(type); - } - if (auto it = parent.currModule->typeNames.find(type); - it != parent.currModule->typeNames.end()) { - return it->second; + if (parent.currModule) { + if (auto it = parent.currModule->typeNames.find(type); + it != parent.currModule->typeNames.end()) { + return it->second; + } + // In principle we should always have at least a fallback name for every + // type in the module, so this lookup should never fail. In practice, + // though, the `printExpression` variants deliberately avoid walking the + // module to find unnamed types so they can be safely used in a + // function-parallel context. That means we can have a module but not + // have generated the fallback names, so this lookup can fail, in which + // case we generate a name on demand. + if (auto it = fallbackNames.find(type); it != fallbackNames.end()) { + return it->second; + } } - auto it = fallbackNames.find(type); - assert(it != fallbackNames.end()); - return it->second; + return fallback.getNames(type); } Name getName(HeapType type) { return getNames(type).name; }