Skip to content

Commit 91ab25d

Browse files
committed
RequirementMachine: Update completion worklist inside addRule()
1 parent 194eb29 commit 91ab25d

File tree

2 files changed

+16
-25
lines changed

2 files changed

+16
-25
lines changed

include/swift/AST/RewriteSystem.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ class Rule final {
247247
class RewriteSystem final {
248248
std::vector<Rule> Rules;
249249
ProtocolGraph Protos;
250+
std::deque<std::pair<unsigned, unsigned>> Worklist;
250251

251252
unsigned DebugSimplify : 1;
252253
unsigned DebugAdd : 1;

lib/AST/RewriteSystem.cpp

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -255,8 +255,18 @@ bool RewriteSystem::addRule(Term lhs, Term rhs) {
255255
rhs.dump(llvm::dbgs());
256256
llvm::dbgs() << "\n";
257257
}
258+
259+
unsigned i = Rules.size();
258260
Rules.emplace_back(lhs, rhs);
259261

262+
for (unsigned j : indices(Rules)) {
263+
if (i == j)
264+
continue;
265+
266+
Worklist.emplace_back(i, j);
267+
Worklist.emplace_back(j, i);
268+
}
269+
260270
return true;
261271
}
262272

@@ -301,23 +311,11 @@ bool RewriteSystem::simplify(Term &term) const {
301311
}
302312

303313
RewriteSystem::CompletionResult
304-
RewriteSystem::computeConfluentCompletion(
305-
unsigned maxIterations,
306-
unsigned maxDepth) {
307-
std::deque<std::pair<unsigned, unsigned>> worklist;
308-
309-
for (unsigned i : indices(Rules)) {
310-
for (unsigned j : indices(Rules)) {
311-
if (i == j)
312-
continue;
313-
314-
worklist.emplace_back(i, j);
315-
}
316-
}
317-
318-
while (!worklist.empty()) {
319-
auto pair = worklist.front();
320-
worklist.pop_front();
314+
RewriteSystem::computeConfluentCompletion(unsigned maxIterations,
315+
unsigned maxDepth) {
316+
while (!Worklist.empty()) {
317+
auto pair = Worklist.front();
318+
Worklist.pop_front();
321319

322320
Term first;
323321

@@ -351,14 +349,6 @@ RewriteSystem::computeConfluentCompletion(
351349
if (newRule.getDepth() > maxDepth)
352350
return CompletionResult::MaxDepth;
353351

354-
for (unsigned j : indices(Rules)) {
355-
if (i == j)
356-
continue;
357-
358-
worklist.emplace_back(i, j);
359-
worklist.emplace_back(j, i);
360-
}
361-
362352
for (unsigned j : indices(Rules)) {
363353
if (i == j)
364354
continue;

0 commit comments

Comments
 (0)