Skip to content

Commit 97ed28a

Browse files
committed
RequirementMachine: simplify() supports appending to an existing rewrite path
This is for convenience with the subsequent change to addRule().
1 parent b01e97f commit 97ed28a

File tree

1 file changed

+14
-10
lines changed

1 file changed

+14
-10
lines changed

lib/AST/RequirementMachine/RewriteSystem.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,12 @@ bool RewriteSystem::simplify(MutableTerm &term, RewritePath *path) const {
264264
bool changed = false;
265265

266266
MutableTerm original;
267-
RewritePath forDebug;
268-
if (Debug.contains(DebugFlags::Simplify)) {
267+
RewritePath subpath;
269268

269+
bool debug = false;
270+
if (Debug.contains(DebugFlags::Simplify)) {
270271
original = term;
271-
if (!path)
272-
path = &forDebug;
272+
debug = true;
273273
}
274274

275275
while (true) {
@@ -290,9 +290,9 @@ bool RewriteSystem::simplify(MutableTerm &term, RewritePath *path) const {
290290

291291
term.rewriteSubTerm(from, to, rule.getRHS());
292292

293-
if (path) {
294-
path->add(RewriteStep::forRewriteRule(startOffset, endOffset, *ruleID,
295-
/*inverse=*/false));
293+
if (path || debug) {
294+
subpath.add(RewriteStep::forRewriteRule(startOffset, endOffset, *ruleID,
295+
/*inverse=*/false));
296296
}
297297

298298
changed = true;
@@ -308,17 +308,21 @@ bool RewriteSystem::simplify(MutableTerm &term, RewritePath *path) const {
308308
break;
309309
}
310310

311-
if (Debug.contains(DebugFlags::Simplify)) {
311+
if (debug) {
312312
if (changed) {
313313
llvm::dbgs() << "= Simplified " << original << " to " << term << " via ";
314-
(path == nullptr ? &forDebug : path)->dump(llvm::dbgs(), original, *this);
314+
subpath.dump(llvm::dbgs(), original, *this);
315315
llvm::dbgs() << "\n";
316316
} else {
317317
llvm::dbgs() << "= Irreducible term: " << term << "\n";
318318
}
319319
}
320320

321-
assert(path == nullptr || changed != path->empty());
321+
if (path != nullptr) {
322+
assert(changed != subpath.empty());
323+
path->append(subpath);
324+
}
325+
322326
return changed;
323327
}
324328

0 commit comments

Comments
 (0)