Fix scheduling non-determinism (#7120 partial) (#7162)

This commit is contained in:
Geza Lore 2026-03-01 12:44:59 +00:00 committed by GitHub
parent 77ce9cec1e
commit 97838325cd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 13 additions and 4 deletions

View File

@ -827,10 +827,18 @@ std::unordered_map<const AstSenTree*, AstSenTree*>
cloneMapWithNewTriggerReferences(const std::unordered_map<const AstSenTree*, AstSenTree*>& map,
AstVarScope* vscp) {
AstTopScope* const topScopep = v3Global.rootp()->topScopep();
// Copy map
std::unordered_map<const AstSenTree*, AstSenTree*> newMap{map};
// Label global SenTrees by the order they are in the Ast
const VNUser1InUse user1InUse;
int n = 0;
for (AstNode* nodep = topScopep->senTreesp(); nodep; nodep = nodep->nextp()) nodep->user1(++n);
// Sort map by key order for determinism
using Pair = std::pair<const AstSenTree*, AstSenTree*>;
std::vector<Pair> pairs{map.begin(), map.end()};
std::sort(pairs.begin(), pairs.end(), [](const Pair& a, const Pair& b) { //
return a.first->user1() < b.first->user1();
});
// Replace references in each mapped value with a reference to the given vscp
for (auto& pair : newMap) {
for (Pair& pair : pairs) {
pair.second = pair.second->cloneTree(false);
pair.second->foreach([&](AstVarRef* refp) {
UASSERT_OBJ(refp->access() == VAccess::READ, refp, "Should be read ref");
@ -839,7 +847,8 @@ cloneMapWithNewTriggerReferences(const std::unordered_map<const AstSenTree*, Ast
});
topScopep->addSenTreesp(pair.second);
}
return newMap;
// Convert back to map
return std::unordered_map<const AstSenTree*, AstSenTree*>{pairs.begin(), pairs.end()};
}
//============================================================================