Skip to content
Merged
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
14 changes: 3 additions & 11 deletions src/passes/ReorderTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ namespace wasm {
namespace {

struct ReorderingTypeRewriter : GlobalTypeRewriter {
using InfoMap = InsertOrderedMap<HeapType, ModuleUtils::HeapTypeInfo>;

InfoMap& typeInfo;

// Use a simpler cost calculation so the effects can be seen with smaller test
// cases.
bool forTesting;
Expand All @@ -45,8 +41,8 @@ struct ReorderingTypeRewriter : GlobalTypeRewriter {
static constexpr float maxFactor = 1.0;
static constexpr Index numFactors = 21;

ReorderingTypeRewriter(Module& wasm, InfoMap& typeInfo, bool forTesting)
: GlobalTypeRewriter(wasm), typeInfo(typeInfo), forTesting(forTesting) {}
ReorderingTypeRewriter(Module& wasm, bool forTesting)
: GlobalTypeRewriter(wasm), forTesting(forTesting) {}

std::vector<HeapType> getSortedTypes(PredecessorGraph preds) override {
auto numTypes = preds.size();
Expand Down Expand Up @@ -150,11 +146,7 @@ struct ReorderTypes : Pass {
Fatal() << "ReorderTypes requires --closed-world";
}

// Collect the use counts for each type.
auto typeInfo = ModuleUtils::collectHeapTypeInfo(
*module, ModuleUtils::TypeInclusion::BinaryTypes);

ReorderingTypeRewriter(*module, typeInfo, forTesting).update();
ReorderingTypeRewriter(*module, forTesting).update();
}
};

Expand Down
25 changes: 25 additions & 0 deletions test/lit/passes/reorder-types.wast
Original file line number Diff line number Diff line change
Expand Up @@ -391,3 +391,28 @@
(local (ref $Y))
)
)

(module
;; Regression test. ReorderTypes used to collect the types used in the binary
;; for their counts, which in this case includes $multi because it is part of
;; the rec group. However, GlobalTypeRewriter separately collected only the
;; used IR types, which includes a standalone function type instead of $multi.
;; The sort then tried to lookup the count for the standalone function type
;; and crashed when it couldn't find it.
(rec
(type $multi (func (result (ref $A) (ref $B))))
;; CHECK: (rec
;; CHECK-NEXT: (type $A (sub (struct)))
(type $A (sub (struct)))
;; CHECK: (type $B (sub $A (struct)))
(type $B (sub $A (struct)))
)
;; CHECK: (func $test (type $3) (param $0 i32) (result (ref $A) (ref $B))
;; CHECK-NEXT: (unreachable)
;; CHECK-NEXT: )
(func $test (param i32) (result (ref $A) (ref $B))
(block (type $multi) (result (ref $A) (ref $B))
(unreachable)
)
)
)