Skip to content

Commit e8eab41

Browse files
committed
RequirementMachine: Store the current generic signature
1 parent 5670098 commit e8eab41

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

include/swift/AST/RequirementMachine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class RequirementMachine final {
4949
void addGenericSignature(CanGenericSignature sig);
5050

5151
bool isComplete() const;
52-
void computeCompletion(CanGenericSignature sig);
52+
void computeCompletion();
5353

5454
public:
5555
~RequirementMachine();

lib/AST/RequirementMachine/RequirementMachine.cpp

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,14 +229,22 @@ struct RequirementMachine::Implementation {
229229
RewriteContext Context;
230230
RewriteSystem System;
231231
EquivalenceClassMap Map;
232+
CanGenericSignature Sig;
232233
bool Complete = false;
233234

234235
explicit Implementation(ASTContext &ctx)
235236
: Context(ctx),
236237
System(Context),
237238
Map(Context, System.getProtocols()) {}
239+
void dump(llvm::raw_ostream &out);
238240
};
239241

242+
void RequirementMachine::Implementation::dump(llvm::raw_ostream &out) {
243+
out << "Requirement machine for " << Sig << "\n";
244+
System.dump(out);
245+
Map.dump(out);
246+
}
247+
240248
RequirementMachine::RequirementMachine(ASTContext &ctx) : Context(ctx) {
241249
Impl = new Implementation(ctx);
242250
}
@@ -246,6 +254,8 @@ RequirementMachine::~RequirementMachine() {
246254
}
247255

248256
void RequirementMachine::addGenericSignature(CanGenericSignature sig) {
257+
Impl->Sig = sig;
258+
249259
PrettyStackTraceGenericSignature debugStack("building rewrite system for", sig);
250260

251261
auto *Stats = Context.Stats;
@@ -270,7 +280,7 @@ void RequirementMachine::addGenericSignature(CanGenericSignature sig) {
270280
Impl->System.initialize(std::move(builder.Rules),
271281
std::move(builder.Protocols));
272282

273-
computeCompletion(sig);
283+
computeCompletion();
274284

275285
if (Context.LangOpts.DebugRequirementMachine) {
276286
llvm::dbgs() << "}\n";
@@ -279,7 +289,7 @@ void RequirementMachine::addGenericSignature(CanGenericSignature sig) {
279289

280290
/// Attempt to obtain a confluent rewrite system using the completion
281291
/// procedure.
282-
void RequirementMachine::computeCompletion(CanGenericSignature sig) {
292+
void RequirementMachine::computeCompletion() {
283293
while (true) {
284294
// First, run the Knuth-Bendix algorithm to resolve overlapping rules.
285295
auto result = Impl->System.computeConfluentCompletion(
@@ -298,13 +308,13 @@ void RequirementMachine::computeCompletion(CanGenericSignature sig) {
298308
break;
299309

300310
case RewriteSystem::CompletionResult::MaxIterations:
301-
llvm::errs() << "Generic signature " << sig
311+
llvm::errs() << "Generic signature " << Impl->Sig
302312
<< " exceeds maximum completion step count\n";
303313
Impl->System.dump(llvm::errs());
304314
abort();
305315

306316
case RewriteSystem::CompletionResult::MaxDepth:
307-
llvm::errs() << "Generic signature " << sig
317+
llvm::errs() << "Generic signature " << Impl->Sig
308318
<< " exceeds maximum completion depth\n";
309319
Impl->System.dump(llvm::errs());
310320
abort();
@@ -351,8 +361,7 @@ bool RequirementMachine::isComplete() const {
351361
}
352362

353363
void RequirementMachine::dump(llvm::raw_ostream &out) const {
354-
Impl->System.dump(out);
355-
Impl->Map.dump(out);
364+
Impl->dump(out);
356365
}
357366

358367
bool RequirementMachine::requiresClass(Type depType) const {
@@ -450,4 +459,4 @@ bool RequirementMachine::areSameTypeParameterInContext(Type depType1,
450459
Impl->System.simplify(term2);
451460

452461
return (term1 == term2);
453-
}
462+
}

0 commit comments

Comments
 (0)