diff options
author | Alon Zakai <azakai@google.com> | 2024-04-09 12:39:11 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-09 12:39:11 -0700 |
commit | 0ee46de2e3073609c062af98e5f8c13b9f5f5284 (patch) | |
tree | b1550aacc132074a778bd882d1957a3269eb0fc7 /src/passes/Asyncify.cpp | |
parent | 102c3633d2378457dae1f5e239fd63ad80eefb92 (diff) | |
download | binaryen-0ee46de2e3073609c062af98e5f8c13b9f5f5284.tar.gz binaryen-0ee46de2e3073609c062af98e5f8c13b9f5f5284.tar.bz2 binaryen-0ee46de2e3073609c062af98e5f8c13b9f5f5284.zip |
Asyncify: Fix nondeterminism in verbose logging (#6479)
#6457 added a test that exposed existing nondeterminism.
Diffstat (limited to 'src/passes/Asyncify.cpp')
-rw-r--r-- | src/passes/Asyncify.cpp | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/src/passes/Asyncify.cpp b/src/passes/Asyncify.cpp index b74c1d7ae..1ba764387 100644 --- a/src/passes/Asyncify.cpp +++ b/src/passes/Asyncify.cpp @@ -711,21 +711,34 @@ public: handleAddList(scanner.map); } + // The order of propagation in |propagateBack| is non-deterministic, so sort + // the loggings we intend to do. + std::vector<std::string> loggings; + scanner.propagateBack([](const Info& info) { return info.canChangeState; }, [](const Info& info) { return !info.isBottomMostRuntime && !info.inRemoveList; }, [](Info& info) { info.canChangeState = true; }, - [verbose](const Info& info, Function* reason) { + [&](const Info& info, Function* reason) { if (verbose) { - std::cout << "[asyncify] " << info.name - << " can change the state due to " - << reason->name << "\n"; + std::stringstream str; + str << "[asyncify] " << info.name + << " can change the state due to " + << reason->name << "\n"; + loggings.push_back(str.str()); } }, scanner.IgnoreNonDirectCalls); + if (!loggings.empty()) { + std::sort(loggings.begin(), loggings.end()); + for (auto& logging : loggings) { + std::cout << logging; + } + } + map.swap(scanner.map); if (!onlyListInput.empty()) { |