Skip to content

Commit 22816b0

Browse files
committed
RequirementMachine: Skip more work in concretizeNestedTypesFromConcreteParent()
1 parent aef6e7c commit 22816b0

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

lib/AST/RequirementMachine/PropertyMap.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace llvm {
3535

3636
namespace swift {
3737

38+
class ProtocolConformance;
3839
class ProtocolDecl;
3940
enum class RequirementKind : unsigned;
4041

@@ -172,7 +173,8 @@ class PropertyMap {
172173
using ConcreteTypeInDomain = std::pair<CanType, ArrayRef<const ProtocolDecl *>>;
173174
llvm::DenseMap<ConcreteTypeInDomain, Term> ConcreteTypeInDomainMap;
174175

175-
llvm::DenseSet<std::pair<unsigned, unsigned>> ConcreteConformanceRules;
176+
llvm::DenseMap<std::pair<unsigned, unsigned>, ProtocolConformance *>
177+
ConcreteConformances;
176178

177179
DebugOptions Debug;
178180

lib/AST/RequirementMachine/PropertyUnification.cpp

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,18 @@ void PropertyMap::concretizeNestedTypesFromConcreteParent(
503503
auto *proto = conformsTo[i];
504504
unsigned conformanceRuleID = conformsToRules[i];
505505

506+
// If we've already processed this pair of rules, record the conformance
507+
// and move on.
508+
//
509+
// This occurs when a pair of rules are inherited from the property map
510+
// entry for this key's suffix.
511+
auto pair = std::make_pair(concreteRuleID, conformanceRuleID);
512+
auto found = ConcreteConformances.find(pair);
513+
if (found != ConcreteConformances.end()) {
514+
conformances.push_back(found->second);
515+
continue;
516+
}
517+
506518
// FIXME: Either remove the ModuleDecl entirely from conformance lookup,
507519
// or pass the correct one down in here.
508520
auto *module = proto->getParentModule();
@@ -539,20 +551,17 @@ void PropertyMap::concretizeNestedTypesFromConcreteParent(
539551
// opaque result type?
540552
assert(!conformance.isAbstract());
541553

554+
// Save this conformance for later.
542555
auto *concrete = conformance.getConcrete();
556+
auto inserted = ConcreteConformances.insert(
557+
std::make_pair(pair, concrete));
558+
assert(inserted.second);
559+
(void) inserted;
543560

544561
// Record the conformance for use by
545562
// PropertyBag::getConformsToExcludingSuperclassConformances().
546563
conformances.push_back(concrete);
547564

548-
// All subsequent logic just records new rewrite rules, and can be
549-
// skipped if we've already processed this pair of rules.
550-
if (!ConcreteConformanceRules.insert(
551-
std::make_pair(concreteRuleID, conformanceRuleID)).second) {
552-
// We've already processed this pair of rules.
553-
continue;
554-
}
555-
556565
auto concreteConformanceSymbol = Symbol::forConcreteConformance(
557566
concreteType, substitutions, proto, Context);
558567

0 commit comments

Comments
 (0)