@@ -108,14 +108,14 @@ class AccessControlCheckerBase {
108
108
109
109
public:
110
110
void checkGenericParamAccess (
111
- const GenericParamList *params ,
112
- const Decl *owner ,
111
+ const GenericContext *ownerCtx ,
112
+ const Decl *ownerDecl ,
113
113
AccessScope accessScope,
114
114
AccessLevel contextAccess);
115
115
116
116
void checkGenericParamAccess (
117
- const GenericParamList *params ,
118
- const ValueDecl *owner );
117
+ const GenericContext *ownerCtx ,
118
+ const ValueDecl *ownerDecl );
119
119
};
120
120
121
121
class TypeAccessScopeDiagnoser : private ASTWalker {
@@ -315,10 +315,11 @@ static void highlightOffendingType(InFlightDiagnostic &diag,
315
315
}
316
316
317
317
void AccessControlCheckerBase::checkGenericParamAccess (
318
- const GenericParamList *params ,
319
- const Decl *owner ,
318
+ const GenericContext *ownerCtx ,
319
+ const Decl *ownerDecl ,
320
320
AccessScope accessScope,
321
321
AccessLevel contextAccess) {
322
+ auto params = ownerCtx->getGenericParams ();
322
323
if (!params)
323
324
return ;
324
325
@@ -348,7 +349,7 @@ void AccessControlCheckerBase::checkGenericParamAccess(
348
349
}
349
350
};
350
351
351
- auto *DC = owner ->getDeclContext ();
352
+ auto *DC = ownerDecl ->getDeclContext ();
352
353
353
354
for (auto param : *params) {
354
355
if (param->getInherited ().empty ())
@@ -361,18 +362,17 @@ void AccessControlCheckerBase::checkGenericParamAccess(
361
362
callbackACEK = ACEK::Requirement;
362
363
363
364
checkRequirementAccess (WhereClauseOwner (
364
- owner->getInnermostDeclContext (),
365
- const_cast <GenericParamList *>(params)),
365
+ const_cast <GenericContext *>(ownerCtx)),
366
366
accessScope, DC, callback);
367
367
368
368
if (minAccessScope.isPublic ())
369
369
return ;
370
370
371
371
// FIXME: Promote these to an error in the next -swift-version break.
372
- if (isa<SubscriptDecl>(owner ) || isa<TypeAliasDecl>(owner ))
372
+ if (isa<SubscriptDecl>(ownerDecl ) || isa<TypeAliasDecl>(ownerDecl ))
373
373
downgradeToWarning = DowngradeToWarning::Yes;
374
374
375
- auto &Context = owner ->getASTContext ();
375
+ auto &Context = ownerDecl ->getASTContext ();
376
376
if (checkUsableFromInline) {
377
377
if (!Context.isSwiftVersionAtLeast (5 ))
378
378
downgradeToWarning = DowngradeToWarning::Yes;
@@ -381,7 +381,7 @@ void AccessControlCheckerBase::checkGenericParamAccess(
381
381
if (downgradeToWarning == DowngradeToWarning::Yes)
382
382
diagID = diag::generic_param_usable_from_inline_warn;
383
383
auto diag =
384
- Context.Diags .diagnose (owner , diagID, owner ->getDescriptiveKind (),
384
+ Context.Diags .diagnose (ownerDecl , diagID, ownerDecl ->getDescriptiveKind (),
385
385
accessControlErrorKind == ACEK::Requirement);
386
386
highlightOffendingType (diag, complainRepr);
387
387
return ;
@@ -390,25 +390,25 @@ void AccessControlCheckerBase::checkGenericParamAccess(
390
390
auto minAccess = minAccessScope.accessLevelForDiagnostics ();
391
391
392
392
bool isExplicit =
393
- owner ->getAttrs ().hasAttribute <AccessControlAttr>() ||
394
- isa<ProtocolDecl>(owner-> getDeclContext () );
393
+ ownerDecl ->getAttrs ().hasAttribute <AccessControlAttr>() ||
394
+ isa<ProtocolDecl>(DC );
395
395
auto diagID = diag::generic_param_access;
396
396
if (downgradeToWarning == DowngradeToWarning::Yes)
397
397
diagID = diag::generic_param_access_warn;
398
398
auto diag = Context.Diags .diagnose (
399
- owner , diagID, owner ->getDescriptiveKind (), isExplicit, contextAccess ,
400
- minAccess, isa<FileUnit>(owner-> getDeclContext () ),
399
+ ownerDecl , diagID, ownerDecl ->getDescriptiveKind (), isExplicit,
400
+ contextAccess, minAccess, isa<FileUnit>(DC ),
401
401
accessControlErrorKind == ACEK::Requirement);
402
402
highlightOffendingType (diag, complainRepr);
403
403
}
404
404
405
405
void AccessControlCheckerBase::checkGenericParamAccess (
406
- const GenericParamList *params ,
407
- const ValueDecl *owner ) {
408
- checkGenericParamAccess (params, owner ,
409
- owner ->getFormalAccessScope (nullptr ,
410
- checkUsableFromInline),
411
- owner ->getFormalAccess ());
406
+ const GenericContext *ownerCtx ,
407
+ const ValueDecl *ownerDecl ) {
408
+ checkGenericParamAccess (ownerCtx, ownerDecl ,
409
+ ownerDecl ->getFormalAccessScope (
410
+ nullptr , checkUsableFromInline),
411
+ ownerDecl ->getFormalAccess ());
412
412
}
413
413
414
414
namespace {
@@ -563,7 +563,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
563
563
}
564
564
565
565
void visitTypeAliasDecl (TypeAliasDecl *TAD) {
566
- checkGenericParamAccess (TAD-> getGenericParams () , TAD);
566
+ checkGenericParamAccess (TAD, TAD);
567
567
568
568
checkTypeAccess (TAD->getUnderlyingType (),
569
569
TAD->getUnderlyingTypeRepr (), TAD, /* mayBeInferred*/ false ,
@@ -667,7 +667,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
667
667
}
668
668
669
669
void visitEnumDecl (EnumDecl *ED) {
670
- checkGenericParamAccess (ED-> getGenericParams () , ED);
670
+ checkGenericParamAccess (ED, ED);
671
671
672
672
if (ED->hasRawType ()) {
673
673
Type rawType = ED->getRawType ();
@@ -701,11 +701,11 @@ class AccessControlChecker : public AccessControlCheckerBase,
701
701
}
702
702
703
703
void visitStructDecl (StructDecl *SD) {
704
- checkGenericParamAccess (SD-> getGenericParams () , SD);
704
+ checkGenericParamAccess (SD, SD);
705
705
}
706
706
707
707
void visitClassDecl (ClassDecl *CD) {
708
- checkGenericParamAccess (CD-> getGenericParams () , CD);
708
+ checkGenericParamAccess (CD, CD);
709
709
710
710
if (const NominalTypeDecl *superclassDecl = CD->getSuperclassDecl ()) {
711
711
// Be slightly defensive here in the presence of badly-ordered
@@ -847,7 +847,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
847
847
}
848
848
849
849
void visitSubscriptDecl (SubscriptDecl *SD) {
850
- checkGenericParamAccess (SD-> getGenericParams () , SD);
850
+ checkGenericParamAccess (SD, SD);
851
851
852
852
auto minAccessScope = AccessScope::getPublic ();
853
853
const TypeRepr *complainRepr = nullptr ;
@@ -903,7 +903,7 @@ class AccessControlChecker : public AccessControlCheckerBase,
903
903
void visitAbstractFunctionDecl (AbstractFunctionDecl *fn) {
904
904
bool isTypeContext = fn->getDeclContext ()->isTypeContext ();
905
905
906
- checkGenericParamAccess (fn-> getGenericParams () , fn);
906
+ checkGenericParamAccess (fn, fn);
907
907
908
908
// This must stay in sync with diag::function_type_access.
909
909
enum {
@@ -1175,7 +1175,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1175
1175
}
1176
1176
1177
1177
void visitTypeAliasDecl (TypeAliasDecl *TAD) {
1178
- checkGenericParamAccess (TAD-> getGenericParams () , TAD);
1178
+ checkGenericParamAccess (TAD, TAD);
1179
1179
1180
1180
checkTypeAccess (TAD->getUnderlyingType (),
1181
1181
TAD->getUnderlyingTypeRepr (), TAD, /* mayBeInferred*/ false ,
@@ -1243,7 +1243,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1243
1243
}
1244
1244
1245
1245
void visitEnumDecl (const EnumDecl *ED) {
1246
- checkGenericParamAccess (ED-> getGenericParams () , ED);
1246
+ checkGenericParamAccess (ED, ED);
1247
1247
1248
1248
if (ED->hasRawType ()) {
1249
1249
Type rawType = ED->getRawType ();
@@ -1271,11 +1271,11 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1271
1271
}
1272
1272
1273
1273
void visitStructDecl (StructDecl *SD) {
1274
- checkGenericParamAccess (SD-> getGenericParams () , SD);
1274
+ checkGenericParamAccess (SD, SD);
1275
1275
}
1276
1276
1277
1277
void visitClassDecl (ClassDecl *CD) {
1278
- checkGenericParamAccess (CD-> getGenericParams () , CD);
1278
+ checkGenericParamAccess (CD, CD);
1279
1279
1280
1280
if (CD->hasSuperclass ()) {
1281
1281
const NominalTypeDecl *superclassDecl = CD->getSuperclassDecl ();
@@ -1354,7 +1354,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1354
1354
}
1355
1355
1356
1356
void visitSubscriptDecl (SubscriptDecl *SD) {
1357
- checkGenericParamAccess (SD-> getGenericParams () , SD);
1357
+ checkGenericParamAccess (SD, SD);
1358
1358
1359
1359
for (auto &P : *SD->getIndices ()) {
1360
1360
checkTypeAccess (
@@ -1384,7 +1384,7 @@ class UsableFromInlineChecker : public AccessControlCheckerBase,
1384
1384
void visitAbstractFunctionDecl (AbstractFunctionDecl *fn) {
1385
1385
bool isTypeContext = fn->getDeclContext ()->isTypeContext ();
1386
1386
1387
- checkGenericParamAccess (fn-> getGenericParams () , fn);
1387
+ checkGenericParamAccess (fn, fn);
1388
1388
1389
1389
// This must stay in sync with diag::function_type_usable_from_inline.
1390
1390
enum {
@@ -1566,25 +1566,26 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1566
1566
diagnoseConformance);
1567
1567
}
1568
1568
1569
- void checkGenericParams (const GenericParamList *params,
1570
- const Decl *owner) {
1569
+ void checkGenericParams (const GenericContext *ownerCtx,
1570
+ const ValueDecl *ownerDecl) {
1571
+ const auto params = ownerCtx->getGenericParams ();
1571
1572
if (!params)
1572
1573
return ;
1573
1574
1574
1575
for (auto param : *params) {
1575
1576
if (param->getInherited ().empty ())
1576
1577
continue ;
1577
1578
assert (param->getInherited ().size () == 1 );
1578
- checkType (param->getInherited ().front (), owner,
1579
- getDiagnoseCallback (owner), getDiagnoseCallback (owner));
1579
+ checkType (param->getInherited ().front (), ownerDecl,
1580
+ getDiagnoseCallback (ownerDecl),
1581
+ getDiagnoseCallback (ownerDecl));
1580
1582
}
1581
1583
1582
1584
forAllRequirementTypes (WhereClauseOwner (
1583
- owner->getInnermostDeclContext (),
1584
- const_cast <GenericParamList *>(params)),
1585
+ const_cast <GenericContext *>(ownerCtx)),
1585
1586
[&](Type type, TypeRepr *typeRepr) {
1586
- checkType (type, typeRepr, owner , getDiagnoseCallback (owner ),
1587
- getDiagnoseCallback (owner ));
1587
+ checkType (type, typeRepr, ownerDecl , getDiagnoseCallback (ownerDecl ),
1588
+ getDiagnoseCallback (ownerDecl ));
1588
1589
});
1589
1590
}
1590
1591
@@ -1809,7 +1810,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1809
1810
}
1810
1811
1811
1812
void visitTypeAliasDecl (TypeAliasDecl *TAD) {
1812
- checkGenericParams (TAD-> getGenericParams () , TAD);
1813
+ checkGenericParams (TAD, TAD);
1813
1814
checkType (TAD->getUnderlyingType (),
1814
1815
TAD->getUnderlyingTypeRepr (), TAD, getDiagnoseCallback (TAD),
1815
1816
getDiagnoseCallback (TAD));
@@ -1835,7 +1836,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1835
1836
}
1836
1837
1837
1838
void visitNominalTypeDecl (const NominalTypeDecl *nominal) {
1838
- checkGenericParams (nominal-> getGenericParams () , nominal);
1839
+ checkGenericParams (nominal, nominal);
1839
1840
1840
1841
llvm::for_each (nominal->getInherited (),
1841
1842
[&](TypeLoc nextInherited) {
@@ -1860,7 +1861,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1860
1861
}
1861
1862
1862
1863
void visitSubscriptDecl (SubscriptDecl *SD) {
1863
- checkGenericParams (SD-> getGenericParams () , SD);
1864
+ checkGenericParams (SD, SD);
1864
1865
1865
1866
for (auto &P : *SD->getIndices ()) {
1866
1867
checkType (P->getInterfaceType (), P->getTypeRepr (), SD,
@@ -1871,7 +1872,7 @@ class ExportabilityChecker : public DeclVisitor<ExportabilityChecker> {
1871
1872
}
1872
1873
1873
1874
void visitAbstractFunctionDecl (AbstractFunctionDecl *fn) {
1874
- checkGenericParams (fn-> getGenericParams () , fn);
1875
+ checkGenericParams (fn, fn);
1875
1876
1876
1877
for (auto *P : *fn->getParameters ())
1877
1878
checkType (P->getInterfaceType (), P->getTypeRepr (), fn,
@@ -2011,7 +2012,7 @@ static void checkExtensionGenericParamAccess(const ExtensionDecl *ED) {
2011
2012
}
2012
2013
2013
2014
AccessControlChecker ().checkGenericParamAccess (
2014
- ED-> getGenericParams () , ED, desiredAccessScope, userSpecifiedAccess);
2015
+ ED, ED, desiredAccessScope, userSpecifiedAccess);
2015
2016
}
2016
2017
2017
2018
void swift::checkAccessControl (Decl *D) {
0 commit comments