From 59079bc41ac83c7a22a818c48bf74ee507e82766 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 31 Mar 2023 09:58:27 -0700 Subject: [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). --- src/passes/SignaturePruning.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'src') 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 allInfo; // Map heap types to all functions with that type. - std::unordered_map> sigFuncs; + InsertOrderedMap> 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) { -- cgit v1.2.3