Skip to content

Commit 5a8d074

Browse files
committed
[NFC] Adopt TypeBase-isms for GenericSignature
Structurally prevent a number of common anti-patterns involving generic signatures by separating the interface into GenericSignature and the implementation into GenericSignatureBase. In particular, this allows the comparison operators to be deleted which forces callers to canonicalize the signature or ask to compare pointers explicitly.
1 parent d1c87f3 commit 5a8d074

File tree

104 files changed

+780
-631
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+780
-631
lines changed

include/swift/AST/ASTContext.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -857,7 +857,7 @@ class ASTContext final {
857857
/// Register the given generic signature builder to be used as the canonical
858858
/// generic signature builder for the given signature, if we don't already
859859
/// have one.
860-
void registerGenericSignatureBuilder(GenericSignature *sig,
860+
void registerGenericSignatureBuilder(GenericSignature sig,
861861
GenericSignatureBuilder &&builder);
862862
friend class GenericSignatureBuilder;
863863

@@ -876,8 +876,8 @@ class ASTContext final {
876876
CanGenericSignature getExistentialSignature(CanType existential,
877877
ModuleDecl *mod);
878878

879-
GenericSignature *getOverrideGenericSignature(const ValueDecl *base,
880-
const ValueDecl *derived);
879+
GenericSignature getOverrideGenericSignature(const ValueDecl *base,
880+
const ValueDecl *derived);
881881

882882
enum class OverrideGenericSignatureReqCheck {
883883
/// Base method's generic requirements are satisifed by derived method

include/swift/AST/ASTMangler.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -155,20 +155,20 @@ class ASTMangler : public Mangler {
155155
ModuleDecl *Module);
156156

157157
std::string mangleKeyPathGetterThunkHelper(const AbstractStorageDecl *property,
158-
GenericSignature *signature,
158+
GenericSignature signature,
159159
CanType baseType,
160160
SubstitutionMap subs,
161161
ResilienceExpansion expansion);
162162
std::string mangleKeyPathSetterThunkHelper(const AbstractStorageDecl *property,
163-
GenericSignature *signature,
163+
GenericSignature signature,
164164
CanType baseType,
165165
SubstitutionMap subs,
166166
ResilienceExpansion expansion);
167167
std::string mangleKeyPathEqualsHelper(ArrayRef<CanType> indices,
168-
GenericSignature *signature,
168+
GenericSignature signature,
169169
ResilienceExpansion expansion);
170170
std::string mangleKeyPathHashHelper(ArrayRef<CanType> indices,
171-
GenericSignature *signature,
171+
GenericSignature signature,
172172
ResilienceExpansion expansion);
173173

174174
std::string mangleTypeForDebugger(Type decl, const DeclContext *DC);
@@ -289,8 +289,8 @@ class ASTMangler : public Mangler {
289289
///
290290
/// \returns \c true if a generic signature was appended, \c false
291291
/// if it was empty.
292-
bool appendGenericSignature(const GenericSignature *sig,
293-
GenericSignature *contextSig = nullptr);
292+
bool appendGenericSignature(GenericSignature sig,
293+
GenericSignature contextSig = nullptr);
294294

295295
void appendRequirement(const Requirement &reqt);
296296

@@ -316,8 +316,8 @@ class ASTMangler : public Mangler {
316316
void appendBackingInitializerEntity(const VarDecl *var);
317317

318318
CanType getDeclTypeForMangling(const ValueDecl *decl,
319-
GenericSignature *&genericSig,
320-
GenericSignature *&parentGenericSig);
319+
GenericSignature &genericSig,
320+
GenericSignature &parentGenericSig);
321321

322322
void appendDeclType(const ValueDecl *decl, bool isFunctionMangling = false);
323323

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
SWIFT_TYPEID(AncestryFlags)
1919
SWIFT_TYPEID(CtorInitializerKind)
20+
SWIFT_TYPEID(GenericSignature)
2021
SWIFT_TYPEID(PropertyWrapperBackingPropertyInfo)
2122
SWIFT_TYPEID(PropertyWrapperTypeInfo)
2223
SWIFT_TYPEID(Requirement)
@@ -26,7 +27,6 @@ SWIFT_TYPEID(TypePair)
2627
SWIFT_TYPEID_NAMED(CustomAttr *, CustomAttr)
2728
SWIFT_TYPEID_NAMED(Decl *, Decl)
2829
SWIFT_TYPEID_NAMED(GenericParamList *, GenericParamList)
29-
SWIFT_TYPEID_NAMED(GenericSignature *, GenericSignature)
3030
SWIFT_TYPEID_NAMED(GenericTypeParamType *, GenericTypeParamType)
3131
SWIFT_TYPEID_NAMED(InfixOperatorDecl *, InfixOperatorDecl)
3232
SWIFT_TYPEID_NAMED(IterableDeclContext *, IterableDeclContext)

include/swift/AST/AnyFunctionRef.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ class AnyFunctionRef {
198198
llvm_unreachable("unexpected AnyFunctionRef representation");
199199
}
200200

201-
GenericSignature *getGenericSignature() const {
201+
GenericSignature getGenericSignature() const {
202202
if (auto afd = TheFunction.dyn_cast<AbstractFunctionDecl *>()) {
203203
return afd->getGenericSignature();
204204
}

include/swift/AST/Attr.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,27 +1279,27 @@ class SpecializeAttr : public DeclAttribute {
12791279

12801280
private:
12811281
TrailingWhereClause *trailingWhereClause;
1282-
GenericSignature *specializedSignature;
1282+
GenericSignature specializedSignature;
12831283

12841284
SpecializeAttr(SourceLoc atLoc, SourceRange Range,
12851285
TrailingWhereClause *clause, bool exported,
12861286
SpecializationKind kind,
1287-
GenericSignature *specializedSignature);
1287+
GenericSignature specializedSignature);
12881288

12891289
public:
12901290
static SpecializeAttr *create(ASTContext &Ctx, SourceLoc atLoc,
12911291
SourceRange Range, TrailingWhereClause *clause,
12921292
bool exported, SpecializationKind kind,
1293-
GenericSignature *specializedSignature
1293+
GenericSignature specializedSignature
12941294
= nullptr);
12951295

12961296
TrailingWhereClause *getTrailingWhereClause() const;
12971297

1298-
GenericSignature *getSpecializedSgnature() const {
1298+
GenericSignature getSpecializedSgnature() const {
12991299
return specializedSignature;
13001300
}
13011301

1302-
void setSpecializedSignature(GenericSignature *newSig) {
1302+
void setSpecializedSignature(GenericSignature newSig) {
13031303
specializedSignature = newSig;
13041304
}
13051305

include/swift/AST/Decl.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ class alignas(8) _GenericContext {
14971497
TrailingWhereClause *TrailingWhere = nullptr;
14981498

14991499
/// The generic signature of this declaration.
1500-
llvm::PointerIntPair<GenericSignature *, 1, bool> GenericSigAndBit;
1500+
llvm::PointerIntPair<GenericSignature, 1, bool> GenericSigAndBit;
15011501
};
15021502

15031503
class GenericContext : private _GenericContext, public DeclContext {
@@ -1541,7 +1541,7 @@ class GenericContext : private _GenericContext, public DeclContext {
15411541
}
15421542

15431543
/// Retrieve the generic signature for this context.
1544-
GenericSignature *getGenericSignature() const;
1544+
GenericSignature getGenericSignature() const;
15451545

15461546
/// Retrieve the generic context for this context.
15471547
GenericEnvironment *getGenericEnvironment() const;
@@ -1553,7 +1553,7 @@ class GenericContext : private _GenericContext, public DeclContext {
15531553
ArrayRef<Requirement> getGenericRequirements() const;
15541554

15551555
/// Set the generic signature of this context.
1556-
void setGenericSignature(GenericSignature *genericSig);
1556+
void setGenericSignature(GenericSignature genericSig);
15571557

15581558
/// Retrieve the position of any where clause for this context's
15591559
/// generic parameters.
@@ -2857,7 +2857,7 @@ class OpaqueTypeDecl : public GenericTypeDecl {
28572857
/// The generic signature of the opaque interface to the type. This is the
28582858
/// outer generic signature with an added generic parameter representing the
28592859
/// underlying type.
2860-
GenericSignature *OpaqueInterfaceGenericSignature;
2860+
GenericSignature OpaqueInterfaceGenericSignature;
28612861

28622862
/// The generic parameter that represents the underlying type.
28632863
GenericTypeParamType *UnderlyingInterfaceType;
@@ -2874,7 +2874,7 @@ class OpaqueTypeDecl : public GenericTypeDecl {
28742874
OpaqueTypeDecl(ValueDecl *NamingDecl,
28752875
GenericParamList *GenericParams,
28762876
DeclContext *DC,
2877-
GenericSignature *OpaqueInterfaceGenericSignature,
2877+
GenericSignature OpaqueInterfaceGenericSignature,
28782878
GenericTypeParamType *UnderlyingInterfaceType);
28792879

28802880
ValueDecl *getNamingDecl() const { return NamingDecl; }
@@ -2890,7 +2890,7 @@ class OpaqueTypeDecl : public GenericTypeDecl {
28902890
/// function could also be the getter of a storage declaration.
28912891
bool isOpaqueReturnTypeOfFunction(const AbstractFunctionDecl *func) const;
28922892

2893-
GenericSignature *getOpaqueInterfaceGenericSignature() const {
2893+
GenericSignature getOpaqueInterfaceGenericSignature() const {
28942894
return OpaqueInterfaceGenericSignature;
28952895
}
28962896

include/swift/AST/DeclContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ class alignas(1 << DeclContextAlignInBits) DeclContext {
357357

358358
/// Retrieve the innermost generic signature of this context or any
359359
/// of its parents.
360-
GenericSignature *getGenericSignatureOfContext() const;
360+
GenericSignature getGenericSignatureOfContext() const;
361361

362362
/// Retrieve the innermost archetypes of this context or any
363363
/// of its parents.

include/swift/AST/FileUnit.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ class LoadedFile : public FileUnit {
337337
/// \returns \c true if this module file supports retrieving all of the
338338
/// generic signatures, \c false otherwise.
339339
virtual bool getAllGenericSignatures(
340-
SmallVectorImpl<GenericSignature*> &genericSignatures) {
340+
SmallVectorImpl<GenericSignature> &genericSignatures) {
341341
return false;
342342
}
343343

include/swift/AST/GenericEnvironment.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class QueryInterfaceTypeSubstitutions {
5757
///
5858
class alignas(1 << DeclAlignInBits) GenericEnvironment final
5959
: private llvm::TrailingObjects<GenericEnvironment, Type> {
60-
GenericSignature *Signature = nullptr;
60+
GenericSignature Signature = GenericSignature();
6161
GenericSignatureBuilder *Builder = nullptr;
6262

6363
friend TrailingObjects;
@@ -74,7 +74,7 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
7474
/// generic signature.
7575
ArrayRef<Type> getContextTypes() const;
7676

77-
GenericEnvironment(GenericSignature *signature,
77+
GenericEnvironment(GenericSignature signature,
7878
GenericSignatureBuilder *builder);
7979

8080
friend ArchetypeType;
@@ -85,7 +85,7 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
8585
friend QueryInterfaceTypeSubstitutions;
8686

8787
public:
88-
GenericSignature *getGenericSignature() const {
88+
GenericSignature getGenericSignature() const {
8989
return Signature;
9090
}
9191

@@ -94,7 +94,7 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
9494
/// Create a new, "incomplete" generic environment that will be populated
9595
/// by calls to \c addMapping().
9696
static
97-
GenericEnvironment *getIncomplete(GenericSignature *signature,
97+
GenericEnvironment *getIncomplete(GenericSignature signature,
9898
GenericSignatureBuilder *builder);
9999

100100
/// Add a mapping of a generic parameter to a specific type (which may be

0 commit comments

Comments
 (0)