Skip to content

Commit 92f1361

Browse files
authored
Merge pull request #61429 from LucianoPAlmeida/opaque-parameters-crash
[AST] Move generic parameter logic for accessor decl from parser to GenericParamListRequest
2 parents b461801 + a95f60e commit 92f1361

File tree

13 files changed

+153
-216
lines changed

13 files changed

+153
-216
lines changed

include/swift/AST/Decl.h

Lines changed: 20 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7142,32 +7142,24 @@ class AccessorDecl final : public FuncDecl {
71427142
AccessorKind accessorKind, AbstractStorageDecl *storage,
71437143
SourceLoc staticLoc, StaticSpellingKind staticSpelling,
71447144
bool async, SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc,
7145-
bool hasImplicitSelfDecl, GenericParamList *genericParams,
7146-
DeclContext *parent)
7147-
: FuncDecl(DeclKind::Accessor,
7148-
staticLoc, staticSpelling, /*func loc*/ declLoc,
7149-
/*name*/ Identifier(), /*name loc*/ declLoc,
7150-
async, asyncLoc, throws, throwsLoc,
7151-
hasImplicitSelfDecl, genericParams, parent),
7152-
AccessorKeywordLoc(accessorKeywordLoc),
7153-
Storage(storage) {
7145+
bool hasImplicitSelfDecl, DeclContext *parent)
7146+
: FuncDecl(DeclKind::Accessor, staticLoc, staticSpelling,
7147+
/*func loc*/ declLoc,
7148+
/*name*/ Identifier(), /*name loc*/ declLoc, async, asyncLoc,
7149+
throws, throwsLoc, hasImplicitSelfDecl,
7150+
/*genericParams*/ nullptr, parent),
7151+
AccessorKeywordLoc(accessorKeywordLoc), Storage(storage) {
71547152
assert(!async || accessorKind == AccessorKind::Get
71557153
&& "only get accessors can be async");
71567154
Bits.AccessorDecl.AccessorKind = unsigned(accessorKind);
71577155
}
71587156

7159-
static AccessorDecl *createImpl(ASTContext &ctx,
7160-
SourceLoc declLoc,
7161-
SourceLoc accessorKeywordLoc,
7162-
AccessorKind accessorKind,
7163-
AbstractStorageDecl *storage,
7164-
SourceLoc staticLoc,
7165-
StaticSpellingKind staticSpelling,
7166-
bool async, SourceLoc asyncLoc,
7167-
bool throws, SourceLoc throwsLoc,
7168-
GenericParamList *genericParams,
7169-
DeclContext *parent,
7170-
ClangNode clangNode);
7157+
static AccessorDecl *
7158+
createImpl(ASTContext &ctx, SourceLoc declLoc, SourceLoc accessorKeywordLoc,
7159+
AccessorKind accessorKind, AbstractStorageDecl *storage,
7160+
SourceLoc staticLoc, StaticSpellingKind staticSpelling, bool async,
7161+
SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc,
7162+
DeclContext *parent, ClangNode clangNode);
71717163

71727164
Optional<bool> getCachedIsTransparent() const {
71737165
if (Bits.AccessorDecl.IsTransparentComputed)
@@ -7183,21 +7175,15 @@ class AccessorDecl final : public FuncDecl {
71837175
AbstractStorageDecl *storage,
71847176
StaticSpellingKind staticSpelling,
71857177
bool async, bool throws,
7186-
GenericParamList *genericParams,
71877178
Type fnRetType, DeclContext *parent);
71887179

7189-
static AccessorDecl *create(ASTContext &ctx, SourceLoc declLoc,
7190-
SourceLoc accessorKeywordLoc,
7191-
AccessorKind accessorKind,
7192-
AbstractStorageDecl *storage,
7193-
SourceLoc staticLoc,
7194-
StaticSpellingKind staticSpelling,
7195-
bool async, SourceLoc asyncLoc,
7196-
bool throws, SourceLoc throwsLoc,
7197-
GenericParamList *genericParams,
7198-
ParameterList *parameterList,
7199-
Type fnRetType, DeclContext *parent,
7200-
ClangNode clangNode = ClangNode());
7180+
static AccessorDecl *
7181+
create(ASTContext &ctx, SourceLoc declLoc, SourceLoc accessorKeywordLoc,
7182+
AccessorKind accessorKind, AbstractStorageDecl *storage,
7183+
SourceLoc staticLoc, StaticSpellingKind staticSpelling, bool async,
7184+
SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc,
7185+
ParameterList *parameterList, Type fnRetType, DeclContext *parent,
7186+
ClangNode clangNode = ClangNode());
72017187

72027188
SourceLoc getAccessorKeywordLoc() const { return AccessorKeywordLoc; }
72037189

include/swift/Parse/Parser.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1242,10 +1242,8 @@ class Parser {
12421242
bool HasLetOrVarKeyword = true);
12431243

12441244
struct ParsedAccessors;
1245-
ParserStatus parseGetSet(ParseDeclOptions Flags,
1246-
GenericParamList *GenericParams,
1247-
ParameterList *Indices, TypeRepr *ResultType,
1248-
ParsedAccessors &accessors,
1245+
ParserStatus parseGetSet(ParseDeclOptions Flags, ParameterList *Indices,
1246+
TypeRepr *ResultType, ParsedAccessors &accessors,
12491247
AbstractStorageDecl *storage, SourceLoc StaticLoc);
12501248
ParserResult<VarDecl> parseDeclVarGetSet(PatternBindingEntry &entry,
12511249
ParseDeclOptions Flags,

lib/AST/Decl.cpp

Lines changed: 28 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8560,28 +8560,22 @@ bool FuncDecl::isStatic() const {
85608560
false);
85618561
}
85628562

8563-
AccessorDecl *AccessorDecl::createImpl(ASTContext &ctx,
8564-
SourceLoc declLoc,
8565-
SourceLoc accessorKeywordLoc,
8566-
AccessorKind accessorKind,
8567-
AbstractStorageDecl *storage,
8568-
SourceLoc staticLoc,
8569-
StaticSpellingKind staticSpelling,
8570-
bool async, SourceLoc asyncLoc,
8571-
bool throws, SourceLoc throwsLoc,
8572-
GenericParamList *genericParams,
8573-
DeclContext *parent,
8574-
ClangNode clangNode) {
8563+
AccessorDecl *AccessorDecl::createImpl(
8564+
ASTContext &ctx, SourceLoc declLoc, SourceLoc accessorKeywordLoc,
8565+
AccessorKind accessorKind, AbstractStorageDecl *storage,
8566+
SourceLoc staticLoc, StaticSpellingKind staticSpelling, bool async,
8567+
SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc, DeclContext *parent,
8568+
ClangNode clangNode) {
85758569
bool hasImplicitSelfDecl = parent->isTypeContext();
85768570
size_t size = sizeof(AccessorDecl) + (hasImplicitSelfDecl
85778571
? sizeof(ParamDecl *)
85788572
: 0);
85798573
void *buffer = allocateMemoryForDecl<AccessorDecl>(ctx, size,
85808574
!clangNode.isNull());
85818575
auto D = ::new (buffer)
8582-
AccessorDecl(declLoc, accessorKeywordLoc, accessorKind,
8583-
storage, staticLoc, staticSpelling, async, asyncLoc, throws, throwsLoc,
8584-
hasImplicitSelfDecl, genericParams, parent);
8576+
AccessorDecl(declLoc, accessorKeywordLoc, accessorKind, storage,
8577+
staticLoc, staticSpelling, async, asyncLoc, throws,
8578+
throwsLoc, hasImplicitSelfDecl, parent);
85858579
if (clangNode)
85868580
D->setClangNode(clangNode);
85878581
if (hasImplicitSelfDecl)
@@ -8590,38 +8584,30 @@ AccessorDecl *AccessorDecl::createImpl(ASTContext &ctx,
85908584
return D;
85918585
}
85928586

8593-
AccessorDecl *
8594-
AccessorDecl::createDeserialized(ASTContext &ctx, AccessorKind accessorKind,
8595-
AbstractStorageDecl *storage,
8596-
StaticSpellingKind staticSpelling,
8597-
bool async, bool throws, GenericParamList *genericParams,
8598-
Type fnRetType, DeclContext *parent) {
8587+
AccessorDecl *AccessorDecl::createDeserialized(
8588+
ASTContext &ctx, AccessorKind accessorKind, AbstractStorageDecl *storage,
8589+
StaticSpellingKind staticSpelling, bool async, bool throws, Type fnRetType,
8590+
DeclContext *parent) {
85998591
assert(fnRetType && "Deserialized result type must not be null");
86008592
auto *const D = AccessorDecl::createImpl(
86018593
ctx, SourceLoc(), SourceLoc(), accessorKind, storage, SourceLoc(),
8602-
staticSpelling, async, SourceLoc(), throws, SourceLoc(), genericParams, parent, ClangNode());
8594+
staticSpelling, async, SourceLoc(), throws, SourceLoc(), parent,
8595+
ClangNode());
86038596
D->setResultInterfaceType(fnRetType);
86048597
return D;
86058598
}
86068599

8607-
AccessorDecl *AccessorDecl::create(ASTContext &ctx,
8608-
SourceLoc declLoc,
8609-
SourceLoc accessorKeywordLoc,
8610-
AccessorKind accessorKind,
8611-
AbstractStorageDecl *storage,
8612-
SourceLoc staticLoc,
8613-
StaticSpellingKind staticSpelling,
8614-
bool async, SourceLoc asyncLoc,
8615-
bool throws, SourceLoc throwsLoc,
8616-
GenericParamList *genericParams,
8617-
ParameterList * bodyParams,
8618-
Type fnRetType,
8619-
DeclContext *parent,
8620-
ClangNode clangNode) {
8600+
AccessorDecl *
8601+
AccessorDecl::create(ASTContext &ctx, SourceLoc declLoc,
8602+
SourceLoc accessorKeywordLoc, AccessorKind accessorKind,
8603+
AbstractStorageDecl *storage, SourceLoc staticLoc,
8604+
StaticSpellingKind staticSpelling, bool async,
8605+
SourceLoc asyncLoc, bool throws, SourceLoc throwsLoc,
8606+
ParameterList *bodyParams, Type fnRetType,
8607+
DeclContext *parent, ClangNode clangNode) {
86218608
auto *D = AccessorDecl::createImpl(
8622-
ctx, declLoc, accessorKeywordLoc, accessorKind, storage,
8623-
staticLoc, staticSpelling, async, asyncLoc, throws, throwsLoc,
8624-
genericParams, parent, clangNode);
8609+
ctx, declLoc, accessorKeywordLoc, accessorKind, storage, staticLoc,
8610+
staticSpelling, async, asyncLoc, throws, throwsLoc, parent, clangNode);
86258611
D->setParameters(bodyParams);
86268612
D->setResultInterfaceType(fnRetType);
86278613
return D;
@@ -9524,7 +9510,6 @@ bool ActorIsolation::isDistributedActor() const {
95249510
return getKind() == ActorInstance && getActor()->isDistributedActor();
95259511
}
95269512

9527-
BuiltinTupleDecl::BuiltinTupleDecl(Identifier Name,
9528-
DeclContext *Parent)
9529-
: NominalTypeDecl(DeclKind::BuiltinTuple, Parent, Name, SourceLoc(),
9530-
ArrayRef<InheritedEntry>(), nullptr) {}
9513+
BuiltinTupleDecl::BuiltinTupleDecl(Identifier Name, DeclContext *Parent)
9514+
: NominalTypeDecl(DeclKind::BuiltinTuple, Parent, Name, SourceLoc(),
9515+
ArrayRef<InheritedEntry>(), nullptr) {}

lib/AST/NameLookup.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2961,6 +2961,20 @@ GenericParamListRequest::evaluate(Evaluator &evaluator, GenericContext *value) c
29612961
return result;
29622962
}
29632963

2964+
// AccessorDecl generic parameter list is the same of its storage
2965+
// context.
2966+
if (auto *AD = dyn_cast<AccessorDecl>(value)) {
2967+
auto *GC = AD->getStorage()->getAsGenericContext();
2968+
if (!GC)
2969+
return nullptr;
2970+
2971+
auto *GP = GC->getGenericParams();
2972+
if (!GP)
2973+
return nullptr;
2974+
2975+
return GP->clone(AD->getDeclContext());
2976+
}
2977+
29642978
auto parsedGenericParams = value->getParsedGenericParams();
29652979

29662980
// Create implicit generic parameters due to opaque parameters, if we need

lib/ClangImporter/ClangImporter.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4775,9 +4775,7 @@ makeBaseClassMemberAccessors(DeclContext *declContext,
47754775
StaticSpellingKind::None, // TODO: we should handle static vars.
47764776
/*Async=*/false, /*AsyncLoc=*/SourceLoc(),
47774777
/*Throws=*/false,
4778-
/*ThrowsLoc=*/SourceLoc(),
4779-
/*GenericParams=*/nullptr, bodyParams, computedType,
4780-
declContext);
4778+
/*ThrowsLoc=*/SourceLoc(), bodyParams, computedType, declContext);
47814779
getterDecl->setIsTransparent(true);
47824780
getterDecl->setAccess(AccessLevel::Public);
47834781
getterDecl->setBodySynthesizer(synthesizeBaseClassFieldGetterBody,
@@ -4809,9 +4807,8 @@ makeBaseClassMemberAccessors(DeclContext *declContext,
48094807
StaticSpellingKind::None, // TODO: we should handle static vars.
48104808
/*Async=*/false, /*AsyncLoc=*/SourceLoc(),
48114809
/*Throws=*/false,
4812-
/*ThrowsLoc=*/SourceLoc(),
4813-
/*GenericParams=*/nullptr, setterBodyParams,
4814-
TupleType::getEmpty(ctx), declContext);
4810+
/*ThrowsLoc=*/SourceLoc(), setterBodyParams, TupleType::getEmpty(ctx),
4811+
declContext);
48154812
setterDecl->setIsTransparent(true);
48164813
setterDecl->setAccess(AccessLevel::Public);
48174814
setterDecl->setBodySynthesizer(synthesizeBaseClassFieldSetterBody,

lib/ClangImporter/ImportDecl.cpp

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -106,15 +106,13 @@ static FuncDecl *createFuncOrAccessor(ClangImporter::Implementation &impl,
106106
ClangNode clangNode) {
107107
FuncDecl *decl;
108108
if (accessorInfo) {
109-
decl = AccessorDecl::create(impl.SwiftContext, funcLoc,
110-
/*accessorKeywordLoc*/ SourceLoc(),
111-
accessorInfo->Kind, accessorInfo->Storage,
112-
/*StaticLoc*/ SourceLoc(),
113-
StaticSpellingKind::None,
114-
async, /*AsyncLoc=*/SourceLoc(),
115-
throws, /*ThrowsLoc=*/SourceLoc(),
116-
genericParams, bodyParams,
117-
resultTy, dc, clangNode);
109+
decl = AccessorDecl::create(
110+
impl.SwiftContext, funcLoc,
111+
/*accessorKeywordLoc*/ SourceLoc(), accessorInfo->Kind,
112+
accessorInfo->Storage,
113+
/*StaticLoc*/ SourceLoc(), StaticSpellingKind::None, async,
114+
/*AsyncLoc=*/SourceLoc(), throws, /*ThrowsLoc=*/SourceLoc(), bodyParams,
115+
resultTy, dc, clangNode);
118116
} else {
119117
decl = FuncDecl::createImported(impl.SwiftContext, funcLoc, name, nameLoc,
120118
async, throws, bodyParams, resultTy,
@@ -599,19 +597,15 @@ static bool addErrorDomain(NominalTypeDecl *swiftDecl,
599597

600598
auto *params = ParameterList::createEmpty(C);
601599

602-
auto getterDecl = AccessorDecl::create(C,
603-
/*FuncLoc=*/SourceLoc(),
604-
/*AccessorKeywordLoc=*/SourceLoc(),
605-
AccessorKind::Get,
606-
errorDomainPropertyDecl,
607-
/*StaticLoc=*/SourceLoc(),
608-
StaticSpellingKind::None,
609-
/*Async=*/false, /*AsyncLoc=*/SourceLoc(),
610-
/*Throws=*/false,
611-
/*ThrowsLoc=*/SourceLoc(),
612-
/*GenericParams=*/nullptr,
613-
params,
614-
stringTy, swiftDecl);
600+
auto getterDecl = AccessorDecl::create(
601+
C,
602+
/*FuncLoc=*/SourceLoc(),
603+
/*AccessorKeywordLoc=*/SourceLoc(), AccessorKind::Get,
604+
errorDomainPropertyDecl,
605+
/*StaticLoc=*/SourceLoc(), StaticSpellingKind::None,
606+
/*Async=*/false, /*AsyncLoc=*/SourceLoc(),
607+
/*Throws=*/false,
608+
/*ThrowsLoc=*/SourceLoc(), params, stringTy, swiftDecl);
615609
getterDecl->setIsObjC(false);
616610
getterDecl->setIsDynamic(false);
617611
getterDecl->setIsTransparent(false);

0 commit comments

Comments
 (0)