Skip to content

Commit cf78384

Browse files
authored
Merge pull request #12075 from apple/revert-12062-make-fewer-gsbs
Revert "Create fewer generic signature builders"
2 parents acfdf9e + 00f44ce commit cf78384

25 files changed

+471
-630
lines changed

include/swift/AST/ASTContext.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -846,16 +846,6 @@ class ASTContext {
846846
/// not necessarily loaded.
847847
void getVisibleTopLevelClangModules(SmallVectorImpl<clang::Module*> &Modules) const;
848848

849-
private:
850-
/// Register the given generic signature builder to be used as the canonical
851-
/// generic signature builder for the given signature, if we don't already
852-
/// have one.
853-
void registerGenericSignatureBuilder(GenericSignature *sig,
854-
ModuleDecl &module,
855-
GenericSignatureBuilder &&builder);
856-
friend class GenericSignatureBuilder;
857-
858-
public:
859849
/// Retrieve or create the stored generic signature builder for the given
860850
/// canonical generic signature and module.
861851
GenericSignatureBuilder *getOrCreateGenericSignatureBuilder(CanGenericSignature sig,

include/swift/AST/Decl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4591,7 +4591,7 @@ class ParamDecl : public VarDecl {
45914591
/// Clone constructor, allocates a new ParamDecl identical to the first.
45924592
/// Intentionally not defined as a typical copy constructor to avoid
45934593
/// accidental copies.
4594-
ParamDecl(ParamDecl *PD, bool withTypes);
4594+
ParamDecl(ParamDecl *PD);
45954595

45964596
/// Retrieve the argument (API) name for this function parameter.
45974597
Identifier getArgumentName() const { return ArgumentName; }

include/swift/AST/GenericSignatureBuilder.h

Lines changed: 14 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -215,14 +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(Identifier name,
224-
SmallVectorImpl<TypeDecl *> *otherConcreteTypes);
225-
226218
/// Dump a debugging representation of this equivalence class.
227219
void dump(llvm::raw_ostream &out) const;
228220

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

256237
friend class RequirementSource;
@@ -541,6 +522,9 @@ class GenericSignatureBuilder {
541522
/// \brief Add all of a generic signature's parameters and requirements.
542523
void addGenericSignature(GenericSignature *sig);
543524

525+
/// \brief Build the generic signature.
526+
GenericSignature *getGenericSignature();
527+
544528
/// Infer requirements from the given type, recursively.
545529
///
546530
/// This routine infers requirements from a type that occurs within the
@@ -574,14 +558,11 @@ class GenericSignatureBuilder {
574558
/// \brief Finalize the set of requirements and compute the generic
575559
/// signature.
576560
///
577-
/// After this point, one cannot introduce new requirements, and the
578-
/// generic signature builder no longer has valid state.
561+
/// After this point, one cannot introduce new requirements.
579562
GenericSignature *computeGenericSignature(
580-
ModuleDecl &module,
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

@@ -1495,12 +1475,6 @@ class GenericSignatureBuilder::PotentialArchetype {
14951475
return pa->parentOrBuilder.get<GenericSignatureBuilder *>();
14961476
}
14971477

1498-
// Replace the generic signature builder.
1499-
void replaceBuilder(GenericSignatureBuilder *builder) {
1500-
assert(parentOrBuilder.is<GenericSignatureBuilder *>());
1501-
parentOrBuilder = builder;
1502-
}
1503-
15041478
friend class GenericSignatureBuilder;
15051479
friend class GenericSignature;
15061480

@@ -1516,12 +1490,6 @@ class GenericSignatureBuilder::PotentialArchetype {
15161490
return parentOrBuilder.dyn_cast<PotentialArchetype *>();
15171491
}
15181492

1519-
/// Retrieve the type declaration to which this nested type was resolved.
1520-
TypeDecl *getResolvedType() const {
1521-
assert(getParent() && "Not an associated type");
1522-
return identifier.assocTypeOrConcrete;
1523-
}
1524-
15251493
/// Retrieve the associated type to which this potential archetype
15261494
/// has been resolved.
15271495
AssociatedTypeDecl *getResolvedAssociatedType() const {
@@ -1664,8 +1632,13 @@ class GenericSignatureBuilder::PotentialArchetype {
16641632
ArchetypeResolutionKind kind,
16651633
GenericSignatureBuilder &builder);
16661634

1667-
/// \brief Retrieve (or create) a nested type with a known type.
1668-
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,
16691642
GenericSignatureBuilder &builder);
16701643

16711644
/// \brief Retrieve (or create) a nested type that is the current best
@@ -1685,8 +1658,8 @@ class GenericSignatureBuilder::PotentialArchetype {
16851658
/// type or typealias of the given protocol, unless the \c kind implies that
16861659
/// a potential archetype should not be created if it's missing.
16871660
PotentialArchetype *updateNestedTypeForConformance(
1688-
TypeDecl *type,
1689-
ArchetypeResolutionKind kind);
1661+
PointerUnion<AssociatedTypeDecl *, TypeDecl *> type,
1662+
ArchetypeResolutionKind kind);
16901663

16911664
/// Update the named nested type when we know this type conforms to the given
16921665
/// protocol.

include/swift/AST/ParameterList.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,15 +128,9 @@ class alignas(ParamDecl *) ParameterList final :
128128
Implicit = 0x01,
129129
/// The cloned pattern is for an inherited constructor; mark default
130130
/// arguments as inherited, and mark unnamed arguments as named.
131-
Inherited = 0x02,
132-
/// The cloned pattern will strip type information.
133-
WithoutTypes = 0x04,
131+
Inherited = 0x02
134132
};
135-
136-
friend OptionSet<CloneFlags> operator|(CloneFlags flag1, CloneFlags flag2) {
137-
return OptionSet<CloneFlags>(flag1) | flag2;
138-
}
139-
133+
140134
/// Make a duplicate copy of this parameter list. This allocates copies of
141135
/// the ParamDecls, so they can be reparented into a new DeclContext.
142136
ParameterList *clone(const ASTContext &C,

lib/AST/ASTContext.cpp

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
#include "clang/Lex/HeaderSearch.h"
4444
#include "clang/Lex/Preprocessor.h"
4545
#include "llvm/ADT/DenseMap.h"
46-
#include "llvm/ADT/Statistic.h"
4746
#include "llvm/ADT/StringMap.h"
4847
#include "llvm/ADT/StringSwitch.h"
4948
#include "llvm/Support/Allocator.h"
@@ -53,12 +52,6 @@
5352

5453
using namespace swift;
5554

56-
#define DEBUG_TYPE "ASTContext"
57-
STATISTIC(NumRegisteredGenericSignatureBuilders,
58-
"# of generic signature builders successfully registered");
59-
STATISTIC(NumRegisteredGenericSignatureBuildersAlready,
60-
"# of generic signature builders already registered");
61-
6255
/// Define this to 1 to enable expensive assertions of the
6356
/// GenericSignatureBuilder.
6457
#define SWIFT_GSB_EXPENSIVE_ASSERTIONS 0
@@ -1430,22 +1423,6 @@ void ASTContext::getVisibleTopLevelClangModules(
14301423
collectAllModules(Modules);
14311424
}
14321425

1433-
void ASTContext::registerGenericSignatureBuilder(
1434-
GenericSignature *sig,
1435-
ModuleDecl &module,
1436-
GenericSignatureBuilder &&builder) {
1437-
auto canSig = sig->getCanonicalSignature();
1438-
auto known = Impl.GenericSignatureBuilders.find({canSig, &module});
1439-
if (known != Impl.GenericSignatureBuilders.end()) {
1440-
++NumRegisteredGenericSignatureBuildersAlready;
1441-
return;
1442-
}
1443-
1444-
++NumRegisteredGenericSignatureBuilders;
1445-
Impl.GenericSignatureBuilders[{canSig, &module}] =
1446-
llvm::make_unique<GenericSignatureBuilder>(std::move(builder));
1447-
}
1448-
14491426
GenericSignatureBuilder *ASTContext::getOrCreateGenericSignatureBuilder(
14501427
CanGenericSignature sig,
14511428
ModuleDecl *mod) {
@@ -4614,7 +4591,7 @@ CanGenericSignature ASTContext::getExistentialSignature(CanType existential,
46144591
GenericSignatureBuilder::FloatingRequirementSource::forAbstract();
46154592
builder.addRequirement(requirement, source, nullptr);
46164593

4617-
CanGenericSignature genericSig(std::move(builder).computeGenericSignature(*mod, SourceLoc()));
4594+
CanGenericSignature genericSig(builder.computeGenericSignature(SourceLoc()));
46184595

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

lib/AST/Builtins.cpp

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

494-
auto GenericSig =
495-
std::move(Builder).computeGenericSignature(*ctx.TheBuiltinModule,
496-
SourceLoc());
494+
auto GenericSig = Builder.computeGenericSignature(SourceLoc());
497495
GenericEnv = GenericSig->createGenericEnvironment(*ctx.TheBuiltinModule);
498496
}
499497

lib/AST/Decl.cpp

Lines changed: 4 additions & 9 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(*module, SourceLoc());
3422+
auto requirementSig = builder.computeGenericSignature(SourceLoc());
34243423
RequirementSignature = requirementSig->getRequirements().data();
34253424
assert(RequirementSignature != nullptr);
34263425
NumRequirementsInSignature = requirementSig->getRequirements().size();
@@ -4218,22 +4217,18 @@ ParamDecl::ParamDecl(Specifier specifier,
42184217

42194218
/// Clone constructor, allocates a new ParamDecl identical to the first.
42204219
/// Intentionally not defined as a copy constructor to avoid accidental copies.
4221-
ParamDecl::ParamDecl(ParamDecl *PD, bool withTypes)
4220+
ParamDecl::ParamDecl(ParamDecl *PD)
42224221
: VarDecl(DeclKind::Param, /*IsStatic*/false, PD->getSpecifier(),
42234222
/*IsCaptureList*/false, PD->getNameLoc(), PD->getName(),
4224-
PD->hasType() && withTypes? PD->getType() : Type(),
4225-
PD->getDeclContext()),
4223+
PD->hasType() ? PD->getType() : Type(), PD->getDeclContext()),
42264224
ArgumentName(PD->getArgumentName()),
42274225
ArgumentNameLoc(PD->getArgumentNameLoc()),
42284226
SpecifierLoc(PD->getSpecifierLoc()),
42294227
DefaultValueAndIsVariadic(nullptr, PD->DefaultValueAndIsVariadic.getInt()),
42304228
IsTypeLocImplicit(PD->IsTypeLocImplicit),
42314229
defaultArgumentKind(PD->defaultArgumentKind) {
42324230
typeLoc = PD->getTypeLoc().clone(PD->getASTContext());
4233-
if (!withTypes && typeLoc.getTypeRepr())
4234-
typeLoc.setType(Type());
4235-
4236-
if (withTypes && PD->hasInterfaceType())
4231+
if (PD->hasInterfaceType())
42374232
setInterfaceType(PD->getInterfaceType());
42384233
}
42394234

0 commit comments

Comments
 (0)