Skip to content

Commit adb82a5

Browse files
committed
Sema: Check generic parameter attributes in typeCheckDecl()
We were previously doing it in the validateDecl() path, which is unnecessary, because they're all invalid. So move the "checking" to typeCheckDecl() so we only do it for primary files.
1 parent 2100278 commit adb82a5

File tree

3 files changed

+14
-26
lines changed

3 files changed

+14
-26
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -502,11 +502,13 @@ static void checkInheritanceClause(
502502
/// Check the inheritance clauses generic parameters along with any
503503
/// requirements stored within the generic parameter list.
504504
static void checkGenericParams(GenericParamList *genericParams,
505-
DeclContext *owningDC) {
505+
DeclContext *owningDC,
506+
TypeChecker &tc) {
506507
if (!genericParams)
507508
return;
508509

509510
for (auto gp : *genericParams) {
511+
tc.checkDeclAttributesEarly(gp);
510512
checkInheritanceClause(gp);
511513
}
512514

@@ -645,7 +647,7 @@ TypeChecker::handleSILGenericParams(GenericParamList *genericParams,
645647

646648
for (unsigned i = 0, e = nestedList.size(); i < e; i++) {
647649
auto genericParams = nestedList.rbegin()[i];
648-
prepareGenericParamList(genericParams, DC);
650+
genericParams->configureGenericParamDepth();
649651

650652
parentEnv = checkGenericEnvironment(genericParams, DC, parentSig,
651653
/*allowConcreteGenericParams=*/true,
@@ -2379,7 +2381,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
23792381

23802382
if (!SD->isInvalid()) {
23812383
TC.checkReferencedGenericParams(SD);
2382-
checkGenericParams(SD->getGenericParams(), SD);
2384+
checkGenericParams(SD->getGenericParams(), SD, TC);
23832385
TC.checkProtocolSelfRequirements(SD);
23842386
}
23852387

@@ -2488,7 +2490,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
24882490

24892491
checkUnsupportedNestedType(ED);
24902492
TC.validateDecl(ED);
2491-
checkGenericParams(ED->getGenericParams(), ED);
2493+
checkGenericParams(ED->getGenericParams(), ED, TC);
24922494

24932495
{
24942496
// Check for circular inheritance of the raw type.
@@ -2525,7 +2527,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
25252527
checkUnsupportedNestedType(SD);
25262528

25272529
TC.validateDecl(SD);
2528-
checkGenericParams(SD->getGenericParams(), SD);
2530+
checkGenericParams(SD->getGenericParams(), SD, TC);
25292531

25302532
TC.addImplicitConstructors(SD);
25312533

@@ -2653,7 +2655,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
26532655

26542656
TC.validateDecl(CD);
26552657
TC.requestSuperclassLayout(CD);
2656-
checkGenericParams(CD->getGenericParams(), CD);
2658+
checkGenericParams(CD->getGenericParams(), CD, TC);
26572659

26582660
{
26592661
// Check for circular inheritance.
@@ -2898,7 +2900,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
28982900
TC.validateDecl(FD);
28992901

29002902
if (!FD->isInvalid()) {
2901-
checkGenericParams(FD->getGenericParams(), FD);
2903+
checkGenericParams(FD->getGenericParams(), FD, TC);
29022904
TC.checkReferencedGenericParams(FD);
29032905
TC.checkProtocolSelfRequirements(FD);
29042906
}
@@ -2976,8 +2978,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
29762978
}
29772979
}
29782980

2979-
if (auto genericParams = ED->getGenericParams())
2980-
checkGenericParams(genericParams, ED);
2981+
checkGenericParams(ED->getGenericParams(), ED, TC);
29812982

29822983
validateAttributes(TC, ED);
29832984

@@ -3025,7 +3026,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
30253026
TC.validateDecl(CD);
30263027

30273028
if (!CD->isInvalid()) {
3028-
checkGenericParams(CD->getGenericParams(), CD);
3029+
checkGenericParams(CD->getGenericParams(), CD, TC);
30293030
TC.checkReferencedGenericParams(CD);
30303031
TC.checkProtocolSelfRequirements(CD);
30313032
}

lib/Sema/TypeCheckGeneric.cpp

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,6 @@ TypeChecker::gatherGenericParamBindingsText(
144144
return result.str().str();
145145
}
146146

147-
void
148-
TypeChecker::prepareGenericParamList(GenericParamList *gp,
149-
DeclContext *dc) {
150-
gp->configureGenericParamDepth();
151-
for (auto paramDecl : *gp)
152-
checkDeclAttributesEarly(paramDecl);
153-
}
154-
155147
/// Add the generic parameter types from the given list to the vector.
156148
static void addGenericParamTypes(GenericParamList *gpList,
157149
SmallVectorImpl<GenericTypeParamType *> &params) {
@@ -472,7 +464,7 @@ computeGenericFuncSignature(TypeChecker &tc, AbstractFunctionDecl *func) {
472464
// Do some initial configuration of the generic parameter lists that's
473465
// required in all cases.
474466
gp->setOuterParameters(dc->getGenericParamsOfContext());
475-
tc.prepareGenericParamList(gp, func);
467+
gp->configureGenericParamDepth();
476468

477469
// Accessors can always use the generic context of their storage
478470
// declarations. This is a compile-time optimization since it lets us
@@ -608,7 +600,7 @@ TypeChecker::validateGenericSubscriptSignature(SubscriptDecl *subscript) {
608600
GenericSignature *sig;
609601
if (auto *gp = subscript->getGenericParams()) {
610602
gp->setOuterParameters(dc->getGenericParamsOfContext());
611-
prepareGenericParamList(gp, subscript);
603+
gp->configureGenericParamDepth();
612604

613605
// Create the generic signature builder.
614606
GenericSignatureBuilder builder(Context);
@@ -775,8 +767,7 @@ void TypeChecker::validateGenericTypeSignature(GenericTypeDecl *typeDecl) {
775767
}
776768

777769
gp->setOuterParameters(dc->getGenericParamsOfContext());
778-
779-
prepareGenericParamList(gp, typeDecl);
770+
gp->configureGenericParamDepth();
780771

781772
// For a protocol, compute the requirement signature first. It will be used
782773
// by clients of the protocol.

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,10 +1129,6 @@ class TypeChecker final : public LazyResolver {
11291129
/// Infer default value witnesses for all requirements in the given protocol.
11301130
void inferDefaultWitnesses(ProtocolDecl *proto);
11311131

1132-
/// Perform semantic checks on the given generic parameter list.
1133-
void prepareGenericParamList(GenericParamList *genericParams,
1134-
DeclContext *dc);
1135-
11361132
/// Compute the generic signature, generic environment and interface type
11371133
/// of a generic function.
11381134
void validateGenericFuncSignature(AbstractFunctionDecl *func);

0 commit comments

Comments
 (0)