@@ -981,8 +981,9 @@ bool WitnessChecker::findBestWitness(
981
981
bool anyFromUnconstrainedExtension;
982
982
numViable = 0 ;
983
983
984
- // FIXME: Remove dependnecy on the lazy resolver.
985
- auto *TC = static_cast <TypeChecker *>(getASTContext ().getLazyResolver ());
984
+ // FIXME: Remove dependency on the lazy resolver.
985
+ auto *TC = static_cast <TypeChecker *>(
986
+ requirement->getASTContext ().getLazyResolver ());
986
987
for (Attempt attempt = Regular; numViable == 0 && attempt != Done;
987
988
attempt = static_cast <Attempt>(attempt + 1 )) {
988
989
SmallVector<ValueDecl *, 4 > witnesses;
@@ -1265,7 +1266,7 @@ RequirementCheck WitnessChecker::checkWitness(ValueDecl *requirement,
1265
1266
// / having this wrapper can help issue a fixit that inserts protocol stubs from
1266
1267
// / multiple protocols under checking.
1267
1268
class swift ::MultiConformanceChecker {
1268
- TypeChecker &TC ;
1269
+ ASTContext &Context ;
1269
1270
llvm::SmallVector<ValueDecl*, 16 > UnsatisfiedReqs;
1270
1271
llvm::SmallVector<ConformanceChecker, 4 > AllUsedCheckers;
1271
1272
llvm::SmallVector<NormalProtocolConformance*, 4 > AllConformances;
@@ -1279,9 +1280,9 @@ class swift::MultiConformanceChecker {
1279
1280
// / Determine whether the given requirement was left unsatisfied.
1280
1281
bool isUnsatisfiedReq (NormalProtocolConformance *conformance, ValueDecl *req);
1281
1282
public:
1282
- MultiConformanceChecker (TypeChecker &TC): TC(TC) {}
1283
+ MultiConformanceChecker (ASTContext &ctx) : Context(ctx) {}
1283
1284
1284
- ASTContext &getASTContext () const { return TC. Context ; }
1285
+ ASTContext &getASTContext () const { return Context; }
1285
1286
1286
1287
// / Add a conformance into the batched checker.
1287
1288
void addConformance (NormalProtocolConformance *conformance) {
@@ -4221,7 +4222,7 @@ operator()(CanType dependentType, Type conformingReplacementType,
4221
4222
}
4222
4223
4223
4224
void TypeChecker::checkConformance (NormalProtocolConformance *conformance) {
4224
- MultiConformanceChecker checker (* this );
4225
+ MultiConformanceChecker checker (conformance-> getProtocol ()-> getASTContext () );
4225
4226
checker.addConformance (conformance);
4226
4227
checker.checkAllConformances ();
4227
4228
}
@@ -4522,10 +4523,8 @@ static bool shouldWarnAboutPotentialWitness(
4522
4523
}
4523
4524
4524
4525
// / Diagnose a potential witness.
4525
- static void diagnosePotentialWitness (TypeChecker &tc,
4526
- NormalProtocolConformance *conformance,
4527
- ValueDecl *req,
4528
- ValueDecl *witness,
4526
+ static void diagnosePotentialWitness (NormalProtocolConformance *conformance,
4527
+ ValueDecl *req, ValueDecl *witness,
4529
4528
AccessLevel access) {
4530
4529
auto proto = cast<ProtocolDecl>(req->getDeclContext ());
4531
4530
@@ -4538,7 +4537,9 @@ static void diagnosePotentialWitness(TypeChecker &tc,
4538
4537
// Describe why the witness didn't satisfy the requirement.
4539
4538
WitnessChecker::RequirementEnvironmentCache oneUseCache;
4540
4539
auto dc = conformance->getDeclContext ();
4541
- auto match = matchWitness (tc, oneUseCache, conformance->getProtocol (),
4540
+ // FIXME: Remove dependency on the lazy resolver.
4541
+ auto *TC = static_cast <TypeChecker *>(req->getASTContext ().getLazyResolver ());
4542
+ auto match = matchWitness (*TC, oneUseCache, conformance->getProtocol (),
4542
4543
conformance, dc, req, witness);
4543
4544
if (match.Kind == MatchKind::ExactMatch &&
4544
4545
req->isObjC () && !witness->isObjC ()) {
@@ -4819,7 +4820,8 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
4819
4820
&diagnostics);
4820
4821
4821
4822
// The conformance checker bundle that checks all conformances in the context.
4822
- MultiConformanceChecker groupChecker (*this );
4823
+ auto &Context = dc->getASTContext ();
4824
+ MultiConformanceChecker groupChecker (Context);
4823
4825
4824
4826
bool anyInvalid = false ;
4825
4827
for (auto conformance : conformances) {
@@ -4899,11 +4901,11 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
4899
4901
auto diagID = differentlyConditional
4900
4902
? diag::redundant_conformance_adhoc_conditional
4901
4903
: diag::redundant_conformance_adhoc;
4902
- diagnose (diag.Loc , diagID, dc->getDeclaredInterfaceType (),
4903
- diag.Protocol ->getName (),
4904
- existingModule->getName () ==
4905
- extendedNominal->getParentModule ()->getName (),
4906
- existingModule->getName ());
4904
+ Context. Diags . diagnose (diag.Loc , diagID, dc->getDeclaredInterfaceType (),
4905
+ diag.Protocol ->getName (),
4906
+ existingModule->getName () ==
4907
+ extendedNominal->getParentModule ()->getName (),
4908
+ existingModule->getName ());
4907
4909
4908
4910
// Complain about any declarations in this extension whose names match
4909
4911
// a requirement in that protocol.
@@ -4928,18 +4930,18 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
4928
4930
if (valueIsType != requirementIsType)
4929
4931
continue ;
4930
4932
4931
- diagnose (value, diag::redundant_conformance_witness_ignored,
4932
- value->getDescriptiveKind (), value->getFullName (),
4933
- diag.Protocol ->getFullName ());
4933
+ value-> diagnose (diag::redundant_conformance_witness_ignored,
4934
+ value->getDescriptiveKind (), value->getFullName (),
4935
+ diag.Protocol ->getFullName ());
4934
4936
break ;
4935
4937
}
4936
4938
}
4937
4939
} else {
4938
4940
auto diagID = differentlyConditional
4939
4941
? diag::redundant_conformance_conditional
4940
4942
: diag::redundant_conformance;
4941
- diagnose (diag.Loc , diagID, dc->getDeclaredInterfaceType (),
4942
- diag.Protocol ->getName ());
4943
+ Context. Diags . diagnose (diag.Loc , diagID, dc->getDeclaredInterfaceType (),
4944
+ diag.Protocol ->getName ());
4943
4945
}
4944
4946
4945
4947
// Special case: explain that 'RawRepresentable' conformance
@@ -4951,18 +4953,19 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
4951
4953
diag.Protocol ) &&
4952
4954
enumDecl->hasRawType () &&
4953
4955
enumDecl->getInherited ()[0 ].getSourceRange ().isValid ()) {
4954
- diagnose (enumDecl->getInherited ()[0 ].getSourceRange ().Start ,
4955
- diag::enum_declares_rawrep_with_raw_type,
4956
- dc->getDeclaredInterfaceType (), enumDecl->getRawType ());
4956
+ auto inheritedLoc = enumDecl->getInherited ()[0 ].getSourceRange ().Start ;
4957
+ Context.Diags .diagnose (
4958
+ inheritedLoc, diag::enum_declares_rawrep_with_raw_type,
4959
+ dc->getDeclaredInterfaceType (), enumDecl->getRawType ());
4957
4960
continue ;
4958
4961
}
4959
4962
}
4960
4963
4961
- diagnose (existingDecl, diag::declared_protocol_conformance_here,
4962
- dc->getDeclaredInterfaceType (),
4963
- static_cast <unsigned >(diag.ExistingKind ),
4964
- diag.Protocol ->getName (),
4965
- diag.ExistingExplicitProtocol ->getName ());
4964
+ existingDecl-> diagnose (diag::declared_protocol_conformance_here,
4965
+ dc->getDeclaredInterfaceType (),
4966
+ static_cast <unsigned >(diag.ExistingKind ),
4967
+ diag.Protocol ->getName (),
4968
+ diag.ExistingExplicitProtocol ->getName ());
4966
4969
}
4967
4970
4968
4971
// If there were any unsatisfied requirements, check whether there
@@ -5034,8 +5037,7 @@ void TypeChecker::checkConformancesInContext(DeclContext *dc,
5034
5037
bool diagnosed = false ;
5035
5038
for (auto conformance : conformances) {
5036
5039
if (conformance->getProtocol () == req->getDeclContext ()) {
5037
- diagnosePotentialWitness (*this ,
5038
- conformance->getRootNormalConformance (),
5040
+ diagnosePotentialWitness (conformance->getRootNormalConformance (),
5039
5041
req, value, defaultAccess);
5040
5042
diagnosed = true ;
5041
5043
break ;
0 commit comments