Commit 2e213425 authored by Tobias Tebbi's avatar Tobias Tebbi Committed by Commit Bot

[torque] make CPP generation deterministic by sorting changed variables

I suspect that the non-deterministic order of changed variables in the
generated Label constructor calls is what causes non-deterministic
builds, since this is the only change I observed locally in the
generated .cc files.

Drive-by cleanup: follow style-guide by avoiding mutable ref parameter.

Bug: chromium:867308
Change-Id: I137af359df570ee11b95cb620ace179bf93481c5
Reviewed-on: https://chromium-review.googlesource.com/1148729Reviewed-by: 's avatarDaniel Clifford <danno@chromium.org>
Commit-Queue: Tobias Tebbi <tebbi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#54687}
parent 8addba1f
......@@ -1232,7 +1232,7 @@ Callable* ImplementationVisitor::LookupCall(const std::string& name,
}
void ImplementationVisitor::GetFlattenedStructsVars(
const Variable* base, std::set<const Variable*>& vars) {
const Variable* base, std::set<const Variable*>* vars) {
const Type* type = base->type();
if (base->IsConst()) return;
if (type->IsStructType()) {
......@@ -1243,7 +1243,7 @@ void ImplementationVisitor::GetFlattenedStructsVars(
Variable::cast(declarations()->LookupValue(field_var_name)), vars);
}
} else {
vars.insert(base);
vars->insert(base);
}
}
......@@ -1253,11 +1253,18 @@ void ImplementationVisitor::GenerateChangedVarsFromControlSplit(AstNode* node) {
node, declarations()->GetCurrentSpecializationTypeNamesVector());
std::set<const Variable*> flattened_vars;
for (auto v : changed_vars) {
GetFlattenedStructsVars(v, flattened_vars);
GetFlattenedStructsVars(v, &flattened_vars);
}
std::vector<const Variable*> flattened_vars_sorted(flattened_vars.begin(),
flattened_vars.end());
auto compare_variables = [](const Variable* a, const Variable* b) {
return a->value() < b->value();
};
std::sort(flattened_vars_sorted.begin(), flattened_vars_sorted.end(),
compare_variables);
source_out() << "{";
PrintCommaSeparatedList(source_out(), flattened_vars,
[&](const Variable* v) { return v->value(); });
PrintCommaSeparatedList(source_out(), flattened_vars_sorted,
[](const Variable* v) { return v->value(); });
source_out() << "}";
}
......
......@@ -173,7 +173,7 @@ class ImplementationVisitor : public FileVisitor {
bool GenerateChangedVarFromControlSplit(const Variable* v, bool first = true);
void GetFlattenedStructsVars(const Variable* base,
std::set<const Variable*>& vars);
std::set<const Variable*>* vars);
void GenerateChangedVarsFromControlSplit(AstNode* node);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment