Skip to content

Commit a35ae7a

Browse files
authored
Merge pull request swiftlang#39057 from slavapestov/minor-rqm-tweaks
RequirementMachine: A few minor tweaks
2 parents 6d5b0c7 + 463d591 commit a35ae7a

File tree

3 files changed

+44
-10
lines changed

3 files changed

+44
-10
lines changed

lib/AST/GenericSignature.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -896,15 +896,19 @@ bool GenericSignatureImpl::areSameTypeParameterInContext(Type type1,
896896
auto gsbResult = computeViaGSB();
897897

898898
if (gsbResult != rqmResult) {
899-
llvm::errs() << "RequirementMachine::areSameTypeParameterInContext() is broken\n";
900-
llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n";
901-
llvm::errs() << "First dependent type: "; type1.dump(llvm::errs());
902-
llvm::errs() << "Second dependent type: "; type2.dump(llvm::errs());
903-
llvm::errs() << "\n";
904-
llvm::errs() << "GenericSignatureBuilder says: " << gsbResult << "\n";
905-
llvm::errs() << "RequirementMachine says: " << rqmResult << "\n";
906-
getRequirementMachine()->dump(llvm::errs());
907-
abort();
899+
auto firstConcreteType = getConcreteType(type1);
900+
auto secondConcreteType = getConcreteType(type2);
901+
if (!firstConcreteType->isEqual(secondConcreteType)) {
902+
llvm::errs() << "RequirementMachine::areSameTypeParameterInContext() is broken\n";
903+
llvm::errs() << "Generic signature: " << GenericSignature(this) << "\n";
904+
llvm::errs() << "First dependent type: "; type1.dump(llvm::errs());
905+
llvm::errs() << "Second dependent type: "; type2.dump(llvm::errs());
906+
llvm::errs() << "\n";
907+
llvm::errs() << "GenericSignatureBuilder says: " << gsbResult << "\n";
908+
llvm::errs() << "RequirementMachine says: " << rqmResult << "\n";
909+
getRequirementMachine()->dump(llvm::errs());
910+
abort();
911+
}
908912
}
909913

910914
return rqmResult;

lib/AST/RequirementMachine/GenericSignatureQueries.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,14 @@ RequirementMachine::getConformanceAccessPath(Type type,
517517
return found->second;
518518
}
519519

520-
assert(CurrentConformanceAccessPaths.size() > 0);
520+
if (CurrentConformanceAccessPaths.empty()) {
521+
llvm::errs() << "Failed to find conformance access path for ";
522+
llvm::errs() << type << " " << protocol->getName() << "\n:";
523+
type.dump(llvm::errs());
524+
llvm::errs() << "\n";
525+
dump(llvm::errs());
526+
abort();
527+
}
521528

522529
// The buffer consists of all conformance access paths of length N.
523530
// Swap it out with an empty buffer, and fill it with all paths of

lib/AST/RequirementMachine/RequirementMachine.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,21 @@ void RewriteSystemBuilder::addRequirement(const Requirement &req,
238238

239239
void RequirementMachine::verify(const MutableTerm &term) const {
240240
#ifndef NDEBUG
241+
// If the term is in the generic parameter domain, ensure we have a valid
242+
// generic parameter.
243+
if (term.begin()->getKind() == Symbol::Kind::GenericParam) {
244+
auto *genericParam = term.begin()->getGenericParam();
245+
auto genericParams = Sig.getGenericParams();
246+
auto found = std::find(genericParams.begin(),
247+
genericParams.end(),
248+
genericParam);
249+
if (found == genericParams.end()) {
250+
llvm::errs() << "Bad generic parameter in " << term << "\n";
251+
dump(llvm::errs());
252+
abort();
253+
}
254+
}
255+
241256
MutableTerm erased;
242257

243258
// First, "erase" resolved associated types from the term, and try
@@ -305,6 +320,14 @@ void RequirementMachine::dump(llvm::raw_ostream &out) const {
305320
out << "Requirement machine for " << Sig << "\n";
306321
System.dump(out);
307322
Map.dump(out);
323+
324+
out << "\nConformance access paths:\n";
325+
for (auto pair : ConformanceAccessPaths) {
326+
out << "- " << pair.first.first << " : ";
327+
out << pair.first.second->getName() << " => ";
328+
pair.second.print(out);
329+
out << "\n";
330+
}
308331
}
309332

310333
RequirementMachine::RequirementMachine(RewriteContext &ctx)

0 commit comments

Comments
 (0)