Skip to content

Commit 2338c43

Browse files
committed
AST: Fix extension binding for @_specializedExtension hack
1 parent db7d1e7 commit 2338c43

File tree

1 file changed

+28
-12
lines changed

1 file changed

+28
-12
lines changed

lib/AST/NameLookup.cpp

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,7 +1044,8 @@ namespace {
10441044
/// the given parsed type representation.
10451045
static DirectlyReferencedTypeDecls
10461046
directReferencesForTypeRepr(Evaluator &evaluator, ASTContext &ctx,
1047-
TypeRepr *typeRepr, DeclContext *dc);
1047+
TypeRepr *typeRepr, DeclContext *dc,
1048+
bool allowUsableFromInline=false);
10481049

10491050
/// Retrieve the set of type declarations that are directly referenced from
10501051
/// the given type.
@@ -2325,7 +2326,8 @@ resolveTypeDeclsToNominal(Evaluator &evaluator,
23252326
static DirectlyReferencedTypeDecls
23262327
directReferencesForUnqualifiedTypeLookup(DeclNameRef name,
23272328
SourceLoc loc, DeclContext *dc,
2328-
LookupOuterResults lookupOuter) {
2329+
LookupOuterResults lookupOuter,
2330+
bool allowUsableFromInline=false) {
23292331
// In a protocol or protocol extension, the 'where' clause can refer to
23302332
// associated types without 'Self' qualification:
23312333
//
@@ -2359,6 +2361,9 @@ directReferencesForUnqualifiedTypeLookup(DeclNameRef name,
23592361
if (lookupOuter == LookupOuterResults::Included)
23602362
options |= UnqualifiedLookupFlags::IncludeOuterResults;
23612363

2364+
if (allowUsableFromInline)
2365+
options |= UnqualifiedLookupFlags::IncludeUsableFromInline;
2366+
23622367
auto &ctx = dc->getASTContext();
23632368
auto descriptor = UnqualifiedLookupDescriptor(name, dc, loc, options);
23642369
auto lookup = evaluateOrDefault(ctx.evaluator,
@@ -2388,7 +2393,8 @@ directReferencesForQualifiedTypeLookup(Evaluator &evaluator,
23882393
ASTContext &ctx,
23892394
ArrayRef<TypeDecl *> baseTypes,
23902395
DeclNameRef name,
2391-
DeclContext *dc) {
2396+
DeclContext *dc,
2397+
bool allowUsableFromInline=false) {
23922398
DirectlyReferencedTypeDecls result;
23932399
auto addResults = [&result](ArrayRef<ValueDecl *> found){
23942400
for (auto decl : found){
@@ -2403,6 +2409,9 @@ directReferencesForQualifiedTypeLookup(Evaluator &evaluator,
24032409
SmallVector<ValueDecl *, 4> members;
24042410
auto options = NL_RemoveNonVisible | NL_OnlyTypes;
24052411

2412+
if (allowUsableFromInline)
2413+
options |= NL_IncludeUsableFromInline;
2414+
24062415
// Look through the type declarations we were given, resolving them down
24072416
// to nominal type declarations, module declarations, and
24082417
SmallVector<ModuleDecl *, 2> moduleDecls;
@@ -2433,7 +2442,7 @@ directReferencesForQualifiedTypeLookup(Evaluator &evaluator,
24332442
static DirectlyReferencedTypeDecls
24342443
directReferencesForIdentTypeRepr(Evaluator &evaluator,
24352444
ASTContext &ctx, IdentTypeRepr *ident,
2436-
DeclContext *dc) {
2445+
DeclContext *dc, bool allowUsableFromInline) {
24372446
DirectlyReferencedTypeDecls current;
24382447

24392448
for (const auto &component : ident->getComponentRange()) {
@@ -2449,7 +2458,8 @@ directReferencesForIdentTypeRepr(Evaluator &evaluator,
24492458
directReferencesForUnqualifiedTypeLookup(component->getNameRef(),
24502459
component->getLoc(),
24512460
dc,
2452-
LookupOuterResults::Excluded);
2461+
LookupOuterResults::Excluded,
2462+
allowUsableFromInline);
24532463

24542464
// If we didn't find anything, fail now.
24552465
if (current.empty())
@@ -2461,7 +2471,8 @@ directReferencesForIdentTypeRepr(Evaluator &evaluator,
24612471
// For subsequent components, perform qualified name lookup.
24622472
current =
24632473
directReferencesForQualifiedTypeLookup(evaluator, ctx, current,
2464-
component->getNameRef(), dc);
2474+
component->getNameRef(), dc,
2475+
allowUsableFromInline);
24652476
if (current.empty())
24662477
return current;
24672478
}
@@ -2472,23 +2483,25 @@ directReferencesForIdentTypeRepr(Evaluator &evaluator,
24722483
static DirectlyReferencedTypeDecls
24732484
directReferencesForTypeRepr(Evaluator &evaluator,
24742485
ASTContext &ctx, TypeRepr *typeRepr,
2475-
DeclContext *dc) {
2486+
DeclContext *dc, bool allowUsableFromInline) {
24762487
switch (typeRepr->getKind()) {
24772488
case TypeReprKind::Array:
24782489
return {1, ctx.getArrayDecl()};
24792490

24802491
case TypeReprKind::Attributed: {
24812492
auto attributed = cast<AttributedTypeRepr>(typeRepr);
24822493
return directReferencesForTypeRepr(evaluator, ctx,
2483-
attributed->getTypeRepr(), dc);
2494+
attributed->getTypeRepr(), dc,
2495+
allowUsableFromInline);
24842496
}
24852497

24862498
case TypeReprKind::Composition: {
24872499
DirectlyReferencedTypeDecls result;
24882500
auto composition = cast<CompositionTypeRepr>(typeRepr);
24892501
for (auto component : composition->getTypes()) {
24902502
auto componentResult =
2491-
directReferencesForTypeRepr(evaluator, ctx, component, dc);
2503+
directReferencesForTypeRepr(evaluator, ctx, component, dc,
2504+
allowUsableFromInline);
24922505
result.insert(result.end(),
24932506
componentResult.begin(),
24942507
componentResult.end());
@@ -2500,7 +2513,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
25002513
case TypeReprKind::GenericIdent:
25012514
case TypeReprKind::SimpleIdent:
25022515
return directReferencesForIdentTypeRepr(evaluator, ctx,
2503-
cast<IdentTypeRepr>(typeRepr), dc);
2516+
cast<IdentTypeRepr>(typeRepr), dc,
2517+
allowUsableFromInline);
25042518

25052519
case TypeReprKind::Dictionary:
25062520
return { 1, ctx.getDictionaryDecl()};
@@ -2509,7 +2523,8 @@ directReferencesForTypeRepr(Evaluator &evaluator,
25092523
auto tupleRepr = cast<TupleTypeRepr>(typeRepr);
25102524
if (tupleRepr->isParenType()) {
25112525
return directReferencesForTypeRepr(evaluator, ctx,
2512-
tupleRepr->getElementType(0), dc);
2526+
tupleRepr->getElementType(0), dc,
2527+
allowUsableFromInline);
25132528
}
25142529
return { };
25152530
}
@@ -2715,7 +2730,8 @@ ExtendedNominalRequest::evaluate(Evaluator &evaluator,
27152730

27162731
ASTContext &ctx = ext->getASTContext();
27172732
DirectlyReferencedTypeDecls referenced =
2718-
directReferencesForTypeRepr(evaluator, ctx, typeRepr, ext->getParent());
2733+
directReferencesForTypeRepr(evaluator, ctx, typeRepr, ext->getParent(),
2734+
ext->isInSpecializeExtensionContext());
27192735

27202736
// Resolve those type declarations to nominal type declarations.
27212737
SmallVector<ModuleDecl *, 2> modulesFound;

0 commit comments

Comments
 (0)