Skip to content

Commit 0c74e48

Browse files
authored
Merge pull request #12107 from apple/revert-12097-gsb-nested-type-lookup
Revert "[GSB] Centralize, clean up, and cache nested type name lookup"
2 parents 2129101 + 8f5d8aa commit 0c74e48

17 files changed

+312
-288
lines changed

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 14 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -215,15 +215,6 @@ class GenericSignatureBuilder {
215215
/// a superclass requirement.
216216
bool isConformanceSatisfiedBySuperclass(ProtocolDecl *proto) const;
217217

218-
/// Lookup a nested type with the given name within this equivalence
219-
/// class.
220-
///
221-
/// \param otherConcreteTypes If non-null, will be filled in the all of the
222-
/// concrete types we found (other than the result) with the same name.
223-
TypeDecl *lookupNestedType(
224-
Identifier name,
225-
SmallVectorImpl<TypeDecl *> *otherConcreteTypes = nullptr);
226-
227218
/// Dump a debugging representation of this equivalence class.
228219
void dump(llvm::raw_ostream &out) const;
229220

@@ -241,17 +232,6 @@ class GenericSignatureBuilder {
241232
/// anchor was cached.
242233
unsigned numMembers;
243234
} archetypeAnchorCache;
244-
245-
/// Describes a cached nested type.
246-
struct CachedNestedType {
247-
unsigned numConformancesPresent;
248-
CanType superclassPresent;
249-
llvm::TinyPtrVector<TypeDecl *> types;
250-
};
251-
252-
/// Cached nested-type information, which contains the best declaration
253-
/// for a given name.
254-
llvm::SmallDenseMap<Identifier, CachedNestedType> nestedTypeNameCache;
255235
};
256236

257237
friend class RequirementSource;
@@ -542,6 +522,9 @@ class GenericSignatureBuilder {
542522
/// \brief Add all of a generic signature's parameters and requirements.
543523
void addGenericSignature(GenericSignature *sig);
544524

525+
/// \brief Build the generic signature.
526+
GenericSignature *getGenericSignature();
527+
545528
/// Infer requirements from the given type, recursively.
546529
///
547530
/// This routine infers requirements from a type that occurs within the
@@ -575,13 +558,11 @@ class GenericSignatureBuilder {
575558
/// \brief Finalize the set of requirements and compute the generic
576559
/// signature.
577560
///
578-
/// After this point, one cannot introduce new requirements, and the
579-
/// generic signature builder no longer has valid state.
561+
/// After this point, one cannot introduce new requirements.
580562
GenericSignature *computeGenericSignature(
581563
SourceLoc loc,
582-
bool allowConcreteGenericParams = false) &&;
564+
bool allowConcreteGenericParams = false);
583565

584-
private:
585566
/// Finalize the set of requirements, performing any remaining checking
586567
/// required before generating archetypes.
587568
///
@@ -591,7 +572,6 @@ class GenericSignatureBuilder {
591572
ArrayRef<GenericTypeParamType *> genericParams,
592573
bool allowConcreteGenericParams=false);
593574

594-
public:
595575
/// Process any delayed requirements that can be handled now.
596576
void processDelayedRequirements();
597577

@@ -1510,12 +1490,6 @@ class GenericSignatureBuilder::PotentialArchetype {
15101490
return parentOrBuilder.dyn_cast<PotentialArchetype *>();
15111491
}
15121492

1513-
/// Retrieve the type declaration to which this nested type was resolved.
1514-
TypeDecl *getResolvedType() const {
1515-
assert(getParent() && "Not an associated type");
1516-
return identifier.assocTypeOrConcrete;
1517-
}
1518-
15191493
/// Retrieve the associated type to which this potential archetype
15201494
/// has been resolved.
15211495
AssociatedTypeDecl *getResolvedAssociatedType() const {
@@ -1658,8 +1632,13 @@ class GenericSignatureBuilder::PotentialArchetype {
16581632
ArchetypeResolutionKind kind,
16591633
GenericSignatureBuilder &builder);
16601634

1661-
/// \brief Retrieve (or create) a nested type with a known type.
1662-
PotentialArchetype *getNestedType(TypeDecl *type,
1635+
/// \brief Retrieve (or create) a nested type with a known associated type.
1636+
PotentialArchetype *getNestedType(AssociatedTypeDecl *assocType,
1637+
GenericSignatureBuilder &builder);
1638+
1639+
/// \brief Retrieve (or create) a nested type with a known concrete type
1640+
/// declaration.
1641+
PotentialArchetype *getNestedType(TypeDecl *concreteDecl,
16631642
GenericSignatureBuilder &builder);
16641643

16651644
/// \brief Retrieve (or create) a nested type that is the current best
@@ -1679,8 +1658,8 @@ class GenericSignatureBuilder::PotentialArchetype {
16791658
/// type or typealias of the given protocol, unless the \c kind implies that
16801659
/// a potential archetype should not be created if it's missing.
16811660
PotentialArchetype *updateNestedTypeForConformance(
1682-
TypeDecl *type,
1683-
ArchetypeResolutionKind kind);
1661+
PointerUnion<AssociatedTypeDecl *, TypeDecl *> type,
1662+
ArchetypeResolutionKind kind);
16841663

16851664
/// Update the named nested type when we know this type conforms to the given
16861665
/// protocol.

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4591,7 +4591,7 @@ CanGenericSignature ASTContext::getExistentialSignature(CanType existential,
45914591
GenericSignatureBuilder::FloatingRequirementSource::forAbstract();
45924592
builder.addRequirement(requirement, source, nullptr);
45934593

4594-
CanGenericSignature genericSig(std::move(builder).computeGenericSignature(SourceLoc()));
4594+
CanGenericSignature genericSig(builder.computeGenericSignature(SourceLoc()));
45954595

45964596
auto result = Impl.ExistentialSignatures.insert(
45974597
std::make_pair(existential, genericSig));

lib/AST/Builtins.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,7 @@ namespace {
491491
Builder.addGenericParameter(gp);
492492
}
493493

494-
auto GenericSig =
495-
std::move(Builder).computeGenericSignature(SourceLoc());
494+
auto GenericSig = Builder.computeGenericSignature(SourceLoc());
496495
GenericEnv = GenericSig->createGenericEnvironment(*ctx.TheBuiltinModule);
497496
}
498497

lib/AST/Decl.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3419,8 +3419,7 @@ void ProtocolDecl::computeRequirementSignature() {
34193419
nullptr);
34203420

34213421
// Compute and record the signature.
3422-
auto requirementSig =
3423-
std::move(builder).computeGenericSignature(SourceLoc());
3422+
auto requirementSig = builder.computeGenericSignature(SourceLoc());
34243423
RequirementSignature = requirementSig->getRequirements().data();
34253424
assert(RequirementSignature != nullptr);
34263425
NumRequirementsInSignature = requirementSig->getRequirements().size();

0 commit comments

Comments
 (0)