@@ -32,7 +32,7 @@ using namespace swift;
32
32
namespace {
33
33
34
34
class FindCapturedVars : public ASTWalker {
35
- TypeChecker &TC ;
35
+ ASTContext &Context ;
36
36
SmallVector<CapturedValue, 4 > Captures;
37
37
llvm::SmallDenseMap<ValueDecl*, unsigned , 4 > captureEntryNumber;
38
38
SourceLoc GenericParamCaptureLoc;
@@ -44,12 +44,12 @@ class FindCapturedVars : public ASTWalker {
44
44
bool NoEscape, ObjC;
45
45
46
46
public:
47
- FindCapturedVars (TypeChecker &tc ,
47
+ FindCapturedVars (ASTContext &Context ,
48
48
SourceLoc CaptureLoc,
49
49
DeclContext *CurDC,
50
50
bool NoEscape,
51
51
bool ObjC)
52
- : TC(tc ), CaptureLoc(CaptureLoc), CurDC(CurDC),
52
+ : Context(Context ), CaptureLoc(CaptureLoc), CurDC(CurDC),
53
53
NoEscape (NoEscape), ObjC(ObjC) {}
54
54
55
55
CaptureInfo getCaptureInfo () const {
@@ -71,7 +71,7 @@ class FindCapturedVars : public ASTWalker {
71
71
if (Captures.empty ())
72
72
result.setCaptures (None);
73
73
else
74
- result.setCaptures (TC. Context .AllocateCopy (Captures));
74
+ result.setCaptures (Context.AllocateCopy (Captures));
75
75
76
76
return result;
77
77
}
@@ -219,7 +219,7 @@ class FindCapturedVars : public ASTWalker {
219
219
// can safely ignore them.
220
220
// FIXME(TapExpr): This is probably caused by the scoping
221
221
// algorithm's ignorance of TapExpr. We should fix that.
222
- if (D->getBaseName () == D-> getASTContext () .Id_dollarInterpolation )
222
+ if (D->getBaseName () == Context .Id_dollarInterpolation )
223
223
return { false , DRE };
224
224
225
225
// Capture the generic parameters of the decl, unless it's a
@@ -273,14 +273,14 @@ class FindCapturedVars : public ASTWalker {
273
273
// This is not supported since nominal types cannot capture values.
274
274
if (auto NTD = dyn_cast<NominalTypeDecl>(TmpDC)) {
275
275
if (DC->isLocalContext ()) {
276
- TC .diagnose (DRE->getLoc (), diag::capture_across_type_decl,
277
- NTD->getDescriptiveKind (),
278
- D->getBaseName ().getIdentifier ());
276
+ Context. Diags .diagnose (DRE->getLoc (), diag::capture_across_type_decl,
277
+ NTD->getDescriptiveKind (),
278
+ D->getBaseName ().getIdentifier ());
279
279
280
- TC. diagnose ( NTD->getLoc (), diag::kind_declared_here,
281
- DescriptiveDeclKind::Type);
280
+ NTD->diagnose ( diag::kind_declared_here,
281
+ DescriptiveDeclKind::Type);
282
282
283
- TC. diagnose (D, diag::decl_declared_here, D->getFullName ());
283
+ D-> diagnose (diag::decl_declared_here, D->getFullName ());
284
284
return { false , DRE };
285
285
}
286
286
}
@@ -328,7 +328,7 @@ class FindCapturedVars : public ASTWalker {
328
328
}
329
329
330
330
void propagateCaptures (AnyFunctionRef innerClosure, SourceLoc captureLoc) {
331
- TC. computeCaptures (innerClosure);
331
+ TypeChecker:: computeCaptures (innerClosure);
332
332
333
333
auto &captureInfo = innerClosure.getCaptureInfo ();
334
334
@@ -597,7 +597,8 @@ void TypeChecker::computeCaptures(AnyFunctionRef AFR) {
597
597
if (!AFR.getBody ())
598
598
return ;
599
599
600
- FindCapturedVars finder (*this ,
600
+ auto &Context = AFR.getAsDeclContext ()->getASTContext ();
601
+ FindCapturedVars finder (Context,
601
602
AFR.getLoc (),
602
603
AFR.getAsDeclContext (),
603
604
AFR.isKnownNoEscape (),
@@ -624,27 +625,29 @@ void TypeChecker::computeCaptures(AnyFunctionRef AFR) {
624
625
if (AFD && finder.getGenericParamCaptureLoc ().isValid ()) {
625
626
if (auto Clas = AFD->getParent ()->getSelfClassDecl ()) {
626
627
if (Clas->usesObjCGenericsModel ()) {
627
- diagnose (AFD->getLoc (),
628
- diag::objc_generic_extension_using_type_parameter);
628
+ AFD->diagnose (diag::objc_generic_extension_using_type_parameter);
629
629
630
630
// If it's possible, suggest adding @objc.
631
631
Optional<ForeignErrorConvention> errorConvention;
632
632
if (!AFD->isObjC () &&
633
633
isRepresentableInObjC (AFD, ObjCReason::MemberOfObjCMembersClass,
634
634
errorConvention)) {
635
- diagnose ( AFD->getLoc (),
635
+ AFD->diagnose (
636
636
diag::objc_generic_extension_using_type_parameter_try_objc)
637
637
.fixItInsert (AFD->getAttributeInsertionLoc (false ), " @objc " );
638
638
}
639
639
640
- diagnose (finder.getGenericParamCaptureLoc (),
641
- diag::objc_generic_extension_using_type_parameter_here);
640
+ Context.Diags .diagnose (
641
+ finder.getGenericParamCaptureLoc (),
642
+ diag::objc_generic_extension_using_type_parameter_here);
642
643
}
643
644
}
644
645
}
645
646
}
646
647
647
648
void TypeChecker::checkPatternBindingCaptures (NominalTypeDecl *typeDecl) {
649
+ auto &ctx = typeDecl->getASTContext ();
650
+
648
651
for (auto member : typeDecl->getMembers ()) {
649
652
// Ignore everything other than PBDs.
650
653
auto *PBD = dyn_cast<PatternBindingDecl>(member);
@@ -659,16 +662,16 @@ void TypeChecker::checkPatternBindingCaptures(NominalTypeDecl *typeDecl) {
659
662
if (init == nullptr )
660
663
continue ;
661
664
662
- FindCapturedVars finder (* this ,
665
+ FindCapturedVars finder (ctx ,
663
666
init->getLoc (),
664
667
PBD->getInitContext (i),
665
668
/* NoEscape=*/ false ,
666
669
/* ObjC=*/ false );
667
670
init->walk (finder);
668
671
669
672
if (finder.getDynamicSelfCaptureLoc ().isValid ()) {
670
- diagnose (finder.getDynamicSelfCaptureLoc (),
671
- diag::dynamic_self_stored_property_init);
673
+ ctx. Diags . diagnose (finder.getDynamicSelfCaptureLoc (),
674
+ diag::dynamic_self_stored_property_init);
672
675
}
673
676
674
677
auto captures = finder.getCaptureInfo ();
0 commit comments