diff options
author | Alon Zakai <azakai@google.com> | 2023-03-31 09:58:27 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-03-31 09:58:27 -0700 |
commit | 59079bc41ac83c7a22a818c48bf74ee507e82766 (patch) | |
tree | 44c7aeeb773a6fabf9913599957ccc53cc6c0bf3 /src | |
parent | dba0a08963d0452a773b9abbdd789503945c5f43 (diff) | |
download | binaryen-59079bc41ac83c7a22a818c48bf74ee507e82766.tar.gz binaryen-59079bc41ac83c7a22a818c48bf74ee507e82766.tar.bz2 binaryen-59079bc41ac83c7a22a818c48bf74ee507e82766.zip |
[Wasm GC] Fix nondeterminism in SignaturePruning (#5608)
The order of iteration on sigFuncs there can matter, as each time we
prune we end up changing things that can affect other prunings (specifically,
ParamUtils::removeParameter can decide that it can't remove a parameter
based on the effects on arguments, and current limitations in how we handle
that; and pruning can affect effects).
Diffstat (limited to 'src')
-rw-r--r-- | src/passes/SignaturePruning.cpp | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/passes/SignaturePruning.cpp b/src/passes/SignaturePruning.cpp index 292feeca5..cd3f4abf6 100644 --- a/src/passes/SignaturePruning.cpp +++ b/src/passes/SignaturePruning.cpp @@ -35,6 +35,7 @@ #include "ir/type-updating.h" #include "param-utils.h" #include "pass.h" +#include "support/insert_ordered.h" #include "support/sorted_vector.h" #include "wasm-type.h" #include "wasm.h" @@ -98,10 +99,14 @@ struct SignaturePruning : public Pass { std::unordered_map<HeapType, Info> allInfo; // Map heap types to all functions with that type. - std::unordered_map<HeapType, std::vector<Function*>> sigFuncs; + InsertOrderedMap<HeapType, std::vector<Function*>> sigFuncs; + + // Combine all the information we gathered into that map, iterating in a + // deterministic order as we build up vectors where the order matters. + for (auto& f : module->functions) { + auto* func = f.get(); + auto& info = analysis.map[func]; - // Combine all the information we gathered into that map. - for (auto& [func, info] : analysis.map) { // For direct calls, add each call to the type of the function being // called. for (auto* call : info.calls) { |