Skip to content

Commit 927fc3f

Browse files
committed
Merge remote-tracking branch 'origin/master' into master-rebranch
2 parents f9a3c37 + edf2e3b commit 927fc3f

21 files changed

+181
-168
lines changed

include/swift/AST/ASTTypeIDZone.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ SWIFT_TYPEID_NAMED(GenericSignature *, GenericSignature)
3535
SWIFT_TYPEID_NAMED(GenericTypeParamType *, GenericTypeParamType)
3636
SWIFT_TYPEID(Requirement)
3737
SWIFT_TYPEID_NAMED(IterableDeclContext *, IterableDeclContext)
38+
SWIFT_TYPEID_NAMED(GenericParamList *, GenericParamList)

include/swift/AST/ASTTypeIDs.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace swift {
2323

2424
class CustomAttr;
2525
class Decl;
26+
class GenericParamList;
2627
class GenericSignature;
2728
class GenericTypeParamType;
2829
class IterableDeclContext;

include/swift/AST/Decl.h

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1496,7 +1496,7 @@ class alignas(RequirementRepr) TrailingWhereClause final :
14961496
class alignas(8) _GenericContext {
14971497
// Not really public. See GenericContext.
14981498
public:
1499-
GenericParamList *GenericParams = nullptr;
1499+
llvm::PointerIntPair<GenericParamList *, 1, bool> GenericParamsAndBit;
15001500

15011501
/// The trailing where clause.
15021502
///
@@ -1509,16 +1509,16 @@ class alignas(8) _GenericContext {
15091509
};
15101510

15111511
class GenericContext : private _GenericContext, public DeclContext {
1512+
friend class GenericParamListRequest;
1513+
15121514
protected:
1513-
GenericContext(DeclContextKind Kind, DeclContext *Parent)
1514-
: _GenericContext(), DeclContext(Kind, Parent) { }
1515+
GenericContext(DeclContextKind Kind, DeclContext *Parent,
1516+
GenericParamList *Params);
15151517

15161518
public:
15171519
/// Retrieve the set of parameters to a generic context, or null if
15181520
/// this context is not generic.
1519-
GenericParamList *getGenericParams() const { return GenericParams; }
1520-
1521-
void setGenericParams(GenericParamList *GenericParams);
1521+
GenericParamList *getGenericParams() const;
15221522

15231523
/// Determine whether this context has generic parameters
15241524
/// of its own.
@@ -1533,7 +1533,7 @@ class GenericContext : private _GenericContext, public DeclContext {
15331533
/// func p() // isGeneric == false
15341534
/// }
15351535
/// \endcode
1536-
bool isGeneric() const { return GenericParams != nullptr; }
1536+
bool isGeneric() const { return getGenericParams() != nullptr; }
15371537

15381538
/// Retrieve the trailing where clause for this extension, if any.
15391539
TrailingWhereClause *getTrailingWhereClause() const {
@@ -1771,8 +1771,6 @@ class ExtensionDecl final : public GenericContext, public Decl,
17711771
return getValidationState() > ValidationState::CheckingWithValidSignature;
17721772
}
17731773

1774-
void createGenericParamsIfMissing(NominalTypeDecl *nominal);
1775-
17761774
bool hasDefaultAccessLevel() const {
17771775
return Bits.ExtensionDecl.DefaultAndMaxAccessLevel != 0;
17781776
}
@@ -3328,7 +3326,6 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
33283326
GenericTypeDecl(K, DC, name, NameLoc, inherited, GenericParams),
33293327
IterableDeclContext(IterableDeclContextKind::NominalTypeDecl)
33303328
{
3331-
setGenericParams(GenericParams);
33323329
Bits.NominalTypeDecl.AddedImplicitInitializers = false;
33333330
ExtensionGeneration = 0;
33343331
Bits.NominalTypeDecl.HasLazyConformances = false;
@@ -4344,10 +4341,6 @@ class ProtocolDecl final : public NominalTypeDecl {
43444341
/// with the Objective-C runtime.
43454342
StringRef getObjCRuntimeName(llvm::SmallVectorImpl<char> &buffer) const;
43464343

4347-
/// Create the generic parameters of this protocol if they haven't been
4348-
/// created yet.
4349-
void createGenericParamsIfMissing();
4350-
43514344
/// Retrieve the requirements that describe this protocol.
43524345
///
43534346
/// These are the requirements including any inherited protocols
@@ -5437,7 +5430,7 @@ class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
54375430
SourceLoc SubscriptLoc, ParameterList *Indices,
54385431
SourceLoc ArrowLoc, TypeLoc ElementTy, DeclContext *Parent,
54395432
GenericParamList *GenericParams)
5440-
: GenericContext(DeclContextKind::SubscriptDecl, Parent),
5433+
: GenericContext(DeclContextKind::SubscriptDecl, Parent, GenericParams),
54415434
AbstractStorageDecl(DeclKind::Subscript,
54425435
StaticSpelling != StaticSpellingKind::None,
54435436
Parent, Name, SubscriptLoc,
@@ -5446,7 +5439,6 @@ class SubscriptDecl : public GenericContext, public AbstractStorageDecl {
54465439
Indices(nullptr), ElementTy(ElementTy) {
54475440
Bits.SubscriptDecl.StaticSpelling = static_cast<unsigned>(StaticSpelling);
54485441
setIndices(Indices);
5449-
setGenericParams(GenericParams);
54505442
}
54515443

54525444
/// \returns the way 'static'/'class' was spelled in the source.
@@ -5611,11 +5603,10 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
56115603
SourceLoc NameLoc, bool Throws, SourceLoc ThrowsLoc,
56125604
bool HasImplicitSelfDecl,
56135605
GenericParamList *GenericParams)
5614-
: GenericContext(DeclContextKind::AbstractFunctionDecl, Parent),
5606+
: GenericContext(DeclContextKind::AbstractFunctionDecl, Parent, GenericParams),
56155607
ValueDecl(Kind, Parent, Name, NameLoc),
56165608
Body(nullptr), ThrowsLoc(ThrowsLoc) {
56175609
setBodyKind(BodyKind::None);
5618-
setGenericParams(GenericParams);
56195610
Bits.AbstractFunctionDecl.HasImplicitSelfDecl = HasImplicitSelfDecl;
56205611
Bits.AbstractFunctionDecl.Overridden = false;
56215612
Bits.AbstractFunctionDecl.Throws = Throws;
@@ -7267,6 +7258,16 @@ inline void simple_display(llvm::raw_ostream &out,
72677258
simple_display(out, static_cast<const Decl *>(decl));
72687259
}
72697260

7261+
/// Display GenericContext.
7262+
///
7263+
/// The template keeps this sorted down in the overload set relative to the
7264+
/// more concrete overloads with Decl pointers thereby breaking a potential ambiguity.
7265+
template <typename T>
7266+
inline typename std::enable_if<std::is_same<T, GenericContext>::value>::type
7267+
simple_display(llvm::raw_ostream &out, const T *GC) {
7268+
simple_display(out, GC->getAsDecl());
7269+
}
7270+
72707271
/// Display GenericParamList.
72717272
void simple_display(llvm::raw_ostream &out, const GenericParamList *GPL);
72727273

include/swift/AST/NameLookupRequests.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ namespace swift {
2525

2626
class ClassDecl;
2727
class DestructorDecl;
28+
class GenericContext;
29+
class GenericParamList;
2830
class TypeAliasDecl;
2931
class TypeDecl;
3032

@@ -250,6 +252,27 @@ class GetDestructorRequest :
250252
void cacheResult(DestructorDecl *value) const;
251253
};
252254

255+
class GenericParamListRequest :
256+
public SimpleRequest<GenericParamListRequest,
257+
GenericParamList *(GenericContext *),
258+
CacheKind::SeparatelyCached> {
259+
public:
260+
using SimpleRequest::SimpleRequest;
261+
262+
private:
263+
friend SimpleRequest;
264+
265+
// Evaluation.
266+
llvm::Expected<GenericParamList *>
267+
evaluate(Evaluator &evaluator, GenericContext *value) const;
268+
269+
public:
270+
// Separate caching.
271+
bool isCached() const { return true; }
272+
Optional<GenericParamList *> getCachedResult() const;
273+
void cacheResult(GenericParamList *value) const;
274+
};
275+
253276
#define SWIFT_TYPEID_ZONE NameLookup
254277
#define SWIFT_TYPEID_HEADER "swift/AST/NameLookupTypeIDZone.def"
255278
#include "swift/Basic/DefineTypeIDZone.h"

include/swift/AST/NameLookupTypeIDZone.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ SWIFT_REQUEST(NameLookup, CustomAttrNominalRequest,
2121
SWIFT_REQUEST(NameLookup, ExtendedNominalRequest,
2222
NominalTypeDecl *(ExtensionDecl *), SeparatelyCached,
2323
NoLocationInfo)
24+
SWIFT_REQUEST(NameLookup, GenericParamListRequest,
25+
GenericParamList *(GenericContext *), SeparatelyCached,
26+
NoLocationInfo)
2427
SWIFT_REQUEST(NameLookup, GetDestructorRequest, DestructorDecl *(ClassDecl *),
2528
SeparatelyCached, NoLocationInfo)
2629
SWIFT_REQUEST(NameLookup, InheritedDeclsReferencedRequest,

include/swift/Parse/Parser.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1589,7 +1589,7 @@ class Parser {
15891589
AssociatedType
15901590
};
15911591
ParserStatus
1592-
parseFreestandingGenericWhereClause(GenericParamList *&GPList,
1592+
parseFreestandingGenericWhereClause(GenericParamList *GPList,
15931593
WhereClauseKind kind=WhereClauseKind::Declaration);
15941594

15951595
ParserStatus parseGenericWhereClause(

lib/AST/ASTScopeCreation.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -819,7 +819,6 @@ class NodeAdder
819819

820820
NullablePtr<ASTScopeImpl> visitProtocolDecl(ProtocolDecl *e, ASTScopeImpl *p,
821821
ScopeCreator &scopeCreator) {
822-
e->createGenericParamsIfMissing();
823822
return scopeCreator.ifUniqueConstructWithPortionExpandAndInsert<
824823
NominalTypeScope, GenericTypeOrExtensionWholePortion>(p, e);
825824
}

0 commit comments

Comments
 (0)