Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimizing IR copying #10718

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,16 @@ public Module runModule(Module ir, ModuleContext moduleContext) {
}
return binding;
});
return ir.copy(
ir.imports(),
ir.exports(),
newBindings,
ir.location(),
ir.passData(),
ir.diagnostics(),
ir.id());
if (newBindings != ir.bindings())
return ir.copy(
ir.imports(),
ir.exports(),
newBindings,
ir.location(),
ir.passData(),
ir.diagnostics(),
ir.id());
else return ir;
}

/** Not supported on a single expression. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,14 +131,16 @@ public Module runModule(Module moduleIr, ModuleContext moduleContext) {
? moduleIr.exports()
: CollectionConverters.asScala(exportErrors).toList();

return moduleIr.copy(
convertedImports,
convertedExports,
moduleIr.bindings(),
moduleIr.location(),
moduleIr.passData(),
moduleIr.diagnostics(),
moduleIr.id());
if (convertedImports != moduleIr.imports() || convertedExports != moduleIr.exports())
return moduleIr.copy(
convertedImports,
convertedExports,
moduleIr.bindings(),
moduleIr.location(),
moduleIr.passData(),
moduleIr.diagnostics(),
moduleIr.id());
else return moduleIr;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,16 @@ public Module runModule(Module ir, ModuleContext moduleContext) {
var newBindings =
ir.bindings()
.map(binding -> binding.mapExpressions(expr -> processExpression(expr, bindingsMap)));
return ir.copy(
ir.imports(),
ir.exports(),
newBindings,
ir.location(),
ir.passData(),
ir.diagnostics(),
ir.id());
if (newBindings != ir.bindings())
return ir.copy(
ir.imports(),
ir.exports(),
newBindings,
ir.location(),
ir.passData(),
ir.diagnostics(),
ir.id());
else return ir;
}

/** Not supported for expressions. */
Expand All @@ -94,32 +96,35 @@ private Expression processExpression(Expression expr, BindingsMap bindingsMap) {
var newBranches =
caseExpr.branches().map(branch -> processCaseBranch(branch, bindingsMap)).toSeq();
var newScrutinee = processExpression(caseExpr.scrutinee(), bindingsMap);
yield caseExpr.copy(
newScrutinee,
newBranches,
caseExpr.isNested(),
caseExpr.location(),
caseExpr.passData(),
caseExpr.diagnostics(),
caseExpr.id());
if (newBranches != caseExpr.branches() || newScrutinee != caseExpr.scrutinee())
yield caseExpr.copy(
newScrutinee,
newBranches,
caseExpr.isNested(),
caseExpr.location(),
caseExpr.passData(),
caseExpr.diagnostics(),
caseExpr.id());
else yield expr;
}
case Name name -> processName(name, bindingsMap);
default -> expr.mapExpressions(e -> processExpression(e, bindingsMap));
};
}

private Branch processCaseBranch(Branch branch, BindingsMap bindingsMap) {
var pat = branch.pattern();
var newPat = processCasePattern(pat, bindingsMap);
var newPat = processCasePattern(branch.pattern(), bindingsMap);
var newExpr = processExpression(branch.expression(), bindingsMap);
return branch.copy(
newPat,
newExpr,
branch.terminalBranch(),
branch.location(),
branch.passData(),
branch.diagnostics(),
branch.id());
if (newPat != branch.pattern() || newExpr != branch.expression())
return branch.copy(
newPat,
newExpr,
branch.terminalBranch(),
branch.location(),
branch.passData(),
branch.diagnostics(),
branch.id());
else return branch;
}

private Pattern processCasePattern(Pattern pattern, BindingsMap bindingsMap) {
Expand Down
Loading
Loading