@@ -264,8 +264,7 @@ bool GenericTypeOrExtensionWhereOrBodyPortion::lookupMembersOf(
264
264
auto nt = scope->getCorrespondingNominalTypeDecl ().getPtrOrNull ();
265
265
if (!nt)
266
266
return false ;
267
- auto selfDC = computeSelfDC (history);
268
- return consumer.lookInMembers (selfDC, scope->getDeclContext ().get (), nt,
267
+ return consumer.lookInMembers (scope->getDeclContext ().get (), nt,
269
268
[&](Optional<bool > initialIsCascadingUse) {
270
269
return ASTScopeImpl::computeIsCascadingUse (
271
270
history, initialIsCascadingUse)
@@ -456,69 +455,6 @@ bool ASTScopeImpl::lookupLocalBindingsInPattern(const Pattern *p,
456
455
return isDone;
457
456
}
458
457
459
- #pragma mark computeSelfDC
460
-
461
- NullablePtr<DeclContext>
462
- GenericTypeOrExtensionWhereOrBodyPortion::computeSelfDC (
463
- ArrayRef<const ASTScopeImpl *> history) {
464
- ASTScopeAssert (history.size () != 0 , " includes current scope" );
465
- size_t i = history.size () - 1 ; // skip last entry (this scope)
466
- while (i != 0 ) {
467
- Optional<NullablePtr<DeclContext>> maybeSelfDC =
468
- history[--i]->computeSelfDCForParent ();
469
- if (maybeSelfDC) {
470
- // If we've found a selfDC, we'll definitely be returning something.
471
- // However, we may have captured 'self' somewhere down the tree, so we
472
- // can't return outright without checking the nested scopes.
473
- NullablePtr<DeclContext> nestedCapturedSelfDC =
474
- checkNestedScopesForSelfCapture (history, i);
475
- return nestedCapturedSelfDC ? nestedCapturedSelfDC : *maybeSelfDC;
476
- }
477
- }
478
- return nullptr ;
479
- }
480
-
481
- #pragma mark checkNestedScopesForSelfCapture
482
-
483
- NullablePtr<DeclContext>
484
- GenericTypeOrExtensionWhereOrBodyPortion::checkNestedScopesForSelfCapture (
485
- ArrayRef<const ASTScopeImpl *> history, size_t start) {
486
- NullablePtr<DeclContext> innerCapturedSelfDC;
487
- // Start with the next scope down the tree.
488
- size_t j = start;
489
-
490
- // Note: even though having this loop nested inside the while loop from
491
- // GenericTypeOrExtensionWhereOrBodyPortion::computeSelfDC may appear to
492
- // result in quadratic blowup, complexity actually remains linear with respect
493
- // to the size of history. This relies on the fact that
494
- // GenericTypeOrExtensionScope::computeSelfDCForParent returns a null pointer,
495
- // which will cause this method to bail out of the search early. Thus, this
496
- // method is called once per type body in the lookup history, and will not
497
- // end up re-checking the bodies of nested types that have already been
498
- // covered by earlier calls, so the total impact of this method across all
499
- // calls in a single lookup is O(n).
500
- while (j != 0 ) {
501
- auto *entry = history[--j];
502
- Optional<NullablePtr<DeclContext>> selfDCForParent =
503
- entry->computeSelfDCForParent ();
504
-
505
- // If we encounter a scope that should cause us to forget the self
506
- // context (such as a nested type), bail out and use whatever the
507
- // the last inner captured context was.
508
- if (selfDCForParent && (*selfDCForParent).isNull ())
509
- break ;
510
-
511
- // Otherwise, if we have a captured self context for this scope, then
512
- // remember it since it is now the innermost scope we have encountered.
513
- NullablePtr<DeclContext> capturedSelfDC = entry->capturedSelfDC ();
514
- if (!capturedSelfDC.isNull ())
515
- innerCapturedSelfDC = entry->capturedSelfDC ();
516
-
517
- // Continue searching in the next scope down.
518
- }
519
- return innerCapturedSelfDC;
520
- }
521
-
522
458
#pragma mark compute isCascadingUse
523
459
524
460
Optional<bool > ASTScopeImpl::computeIsCascadingUse (
@@ -587,65 +523,6 @@ NullablePtr<const ASTScopeImpl> ASTScopeImpl::ancestorWithDeclSatisfying(
587
523
return nullptr ;
588
524
}
589
525
590
- #pragma mark computeSelfDCForParent
591
-
592
- // If the lookup depends on implicit self, selfDC is its context.
593
- // (Names in extensions never depend on self.)
594
- // Lookup can propagate it up from, say a method to the enclosing type body.
595
-
596
- // By default, propagate the selfDC up to a NomExt decl, body,
597
- // or where clause
598
- Optional<NullablePtr<DeclContext>>
599
- ASTScopeImpl::computeSelfDCForParent () const {
600
- return None;
601
- }
602
-
603
- // Forget the "self" declaration:
604
- Optional<NullablePtr<DeclContext>>
605
- GenericTypeOrExtensionScope::computeSelfDCForParent () const {
606
- return NullablePtr<DeclContext>();
607
- }
608
-
609
- Optional<NullablePtr<DeclContext>>
610
- PatternEntryInitializerScope::computeSelfDCForParent () const {
611
- // Pattern binding initializers are only interesting insofar as they
612
- // affect lookup in an enclosing nominal type or extension thereof.
613
- if (auto *ic = getPatternEntry ().getInitContext ()) {
614
- if (auto *bindingInit = dyn_cast<PatternBindingInitializer>(ic)) {
615
- // Lazy variable initializer contexts have a 'self' parameter for
616
- // instance member lookup.
617
- if (bindingInit->getImplicitSelfDecl ()) {
618
- return NullablePtr<DeclContext>(bindingInit);
619
- }
620
- }
621
- }
622
- return None;
623
- }
624
-
625
- Optional<NullablePtr<DeclContext>>
626
- FunctionBodyScope::computeSelfDCForParent () const {
627
- if (decl->getDeclContext ()->isTypeContext ())
628
- return NullablePtr<DeclContext>(decl);
629
- return None;
630
- }
631
-
632
- #pragma mark capturedSelfDC
633
-
634
- // Closures may explicitly capture the self param, in which case the lookup
635
- // should use the closure as the context for implicit self lookups.
636
-
637
- // By default, there is no such context to return.
638
- NullablePtr<DeclContext> ASTScopeImpl::capturedSelfDC () const {
639
- return NullablePtr<DeclContext>();
640
- }
641
-
642
- // Closures track this information explicitly.
643
- NullablePtr<DeclContext> ClosureParametersScope::capturedSelfDC () const {
644
- if (closureExpr->capturesSelfEnablingImplictSelf ())
645
- return NullablePtr<DeclContext>(closureExpr);
646
- return NullablePtr<DeclContext>();
647
- }
648
-
649
526
#pragma mark ifUnknownIsCascadingUseAccordingTo
650
527
651
528
static bool isCascadingUseAccordingTo (const DeclContext *const dc) {
0 commit comments