@@ -3876,7 +3876,7 @@ diagnoseMissingWitnesses(MissingWitnessDiagnosisKind Kind, bool Delayed) {
3876
3876
auto matches = Missing.matches ;
3877
3877
auto nominal = DC->getSelfNominalTypeDecl ();
3878
3878
3879
- diagnoseOrDefer (requirement , true ,
3879
+ getASTContext (). addDelayedConformanceDiag (Conformance , true ,
3880
3880
[requirement, matches, nominal](NormalProtocolConformance *conformance) {
3881
3881
auto dc = conformance->getDeclContext ();
3882
3882
auto *protocol = conformance->getProtocol ();
@@ -4010,8 +4010,7 @@ diagnoseMissingWitnesses(MissingWitnessDiagnosisKind Kind, bool Delayed) {
4010
4010
std::make_unique<DelayedMissingWitnesses>(MissingWitnesses));
4011
4011
} else {
4012
4012
auto Loc = this ->Loc ;
4013
- diagnoseOrDefer (
4014
- LocalMissing[0 ].requirement , true ,
4013
+ getASTContext ().addDelayedConformanceDiag (Conformance, true ,
4015
4014
[InsertFixit, Loc, IsEditorMode, MissingWitnesses](NormalProtocolConformance *Conf) {
4016
4015
InsertFixit (Conf, Loc, IsEditorMode, MissingWitnesses);
4017
4016
});
@@ -4020,8 +4019,8 @@ diagnoseMissingWitnesses(MissingWitnessDiagnosisKind Kind, bool Delayed) {
4020
4019
return true ;
4021
4020
}
4022
4021
case MissingWitnessDiagnosisKind::ErrorOnly: {
4023
- diagnoseOrDefer (
4024
- LocalMissing[ 0 ]. requirement , true , [](NormalProtocolConformance *) {});
4022
+ getASTContext (). addDelayedConformanceDiag (Conformance, true ,
4023
+ [](NormalProtocolConformance *) {});
4025
4024
return true ;
4026
4025
}
4027
4026
case MissingWitnessDiagnosisKind::FixItOnly:
@@ -4125,7 +4124,7 @@ void ConformanceChecker::checkNonFinalClassWitness(ValueDecl *requirement,
4125
4124
!ctor->hasClangNode ()) {
4126
4125
// FIXME: We're not recovering (in the AST), so the Fix-It
4127
4126
// should move.
4128
- diagnoseOrDefer (requirement , false ,
4127
+ getASTContext (). addDelayedConformanceDiag (Conformance , false ,
4129
4128
[ctor, requirement](NormalProtocolConformance *conformance) {
4130
4129
bool inExtension = isa<ExtensionDecl>(ctor->getDeclContext ());
4131
4130
auto &diags = ctor->getASTContext ().Diags ;
@@ -4159,7 +4158,7 @@ void ConformanceChecker::checkNonFinalClassWitness(ValueDecl *requirement,
4159
4158
// References to Self in a position where subclasses cannot do
4160
4159
// the right thing. Complain if the adoptee is a non-final
4161
4160
// class.
4162
- diagnoseOrDefer (requirement , false ,
4161
+ getASTContext (). addDelayedConformanceDiag (Conformance , false ,
4163
4162
[witness, requirement](NormalProtocolConformance *conformance) {
4164
4163
auto proto = conformance->getProtocol ();
4165
4164
auto &diags = proto->getASTContext ().Diags ;
@@ -4187,7 +4186,7 @@ void ConformanceChecker::checkNonFinalClassWitness(ValueDecl *requirement,
4187
4186
}();
4188
4187
4189
4188
if (!hasDynamicSelfResult) {
4190
- diagnoseOrDefer (requirement , false ,
4189
+ getASTContext (). addDelayedConformanceDiag (Conformance , false ,
4191
4190
[witness, requirement](NormalProtocolConformance *conformance) {
4192
4191
auto proto = conformance->getProtocol ();
4193
4192
auto &diags = proto->getASTContext ().Diags ;
@@ -4236,7 +4235,7 @@ void ConformanceChecker::checkNonFinalClassWitness(ValueDecl *requirement,
4236
4235
if (isa<FuncDecl>(witness) || isa<SubscriptDecl>(witness)) {
4237
4236
if (witness->getDeclContext ()->getExtendedProtocolDecl ()) {
4238
4237
if (selfRefInfo.hasCovariantSelfResult && selfRefInfo.assocTypeRef ) {
4239
- diagnoseOrDefer (requirement , false ,
4238
+ getASTContext (). addDelayedConformanceDiag (Conformance , false ,
4240
4239
[witness, requirement](NormalProtocolConformance *conformance) {
4241
4240
auto proto = conformance->getProtocol ();
4242
4241
auto &diags = proto->getASTContext ().Diags ;
@@ -4318,7 +4317,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
4318
4317
requirement->getName () != best.Witness ->getName () &&
4319
4318
!witnessHasImplementsAttrForRequiredName (best.Witness , requirement)) {
4320
4319
4321
- diagnoseOrDefer (requirement , false ,
4320
+ getASTContext (). addDelayedConformanceDiag (Conformance , false ,
4322
4321
[witness, requirement](NormalProtocolConformance *conformance) {
4323
4322
auto proto = conformance->getProtocol ();
4324
4323
auto &diags = proto->getASTContext ().Diags ;
@@ -4350,7 +4349,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
4350
4349
4351
4350
// Avoid relying on the lifetime of 'this'.
4352
4351
const DeclContext *DC = this ->DC ;
4353
- diagnoseOrDefer (requirement , isError,
4352
+ getASTContext (). addDelayedConformanceDiag (Conformance , isError,
4354
4353
[DC, requirement, witness, sendFrom](
4355
4354
NormalProtocolConformance *conformance) {
4356
4355
diagnoseSendabilityErrorBasedOn (conformance->getProtocol (), sendFrom,
@@ -4393,7 +4392,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
4393
4392
4394
4393
// Avoid relying on the lifetime of 'this'.
4395
4394
const DeclContext *DC = this ->DC ;
4396
- diagnoseOrDefer (requirement , false ,
4395
+ getASTContext (). addDelayedConformanceDiag (Conformance , false ,
4397
4396
[DC, witness, check, requirement](
4398
4397
NormalProtocolConformance *conformance) {
4399
4398
auto requiredAccessScope = check.RequiredAccessScope ;
@@ -4426,11 +4425,12 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
4426
4425
}
4427
4426
4428
4427
case CheckKind::UsableFromInline:
4429
- diagnoseOrDefer (requirement, false , DiagnoseUsableFromInline (witness));
4428
+ getASTContext ().addDelayedConformanceDiag (Conformance, false ,
4429
+ DiagnoseUsableFromInline (witness));
4430
4430
break ;
4431
4431
4432
4432
case CheckKind::Availability: {
4433
- diagnoseOrDefer (requirement , false ,
4433
+ getASTContext (). addDelayedConformanceDiag (Conformance , false ,
4434
4434
[witness, requirement, check](
4435
4435
NormalProtocolConformance *conformance) {
4436
4436
// FIXME: The problem may not be the OS version.
@@ -4459,7 +4459,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
4459
4459
case CheckKind::OptionalityConflict: {
4460
4460
auto adjustments = best.OptionalAdjustments ;
4461
4461
4462
- diagnoseOrDefer (requirement , false ,
4462
+ getASTContext (). addDelayedConformanceDiag (Conformance , false ,
4463
4463
[witness, adjustments, requirement](NormalProtocolConformance *conformance) {
4464
4464
auto proto = conformance->getProtocol ();
4465
4465
auto &ctx = witness->getASTContext ();
@@ -4490,7 +4490,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
4490
4490
}
4491
4491
4492
4492
case CheckKind::ConstructorFailability:
4493
- diagnoseOrDefer (requirement , false ,
4493
+ getASTContext (). addDelayedConformanceDiag (Conformance , false ,
4494
4494
[witness, requirement](NormalProtocolConformance *conformance) {
4495
4495
auto ctor = cast<ConstructorDecl>(requirement);
4496
4496
auto witnessCtor = cast<ConstructorDecl>(witness);
@@ -4505,9 +4505,8 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
4505
4505
break ;
4506
4506
4507
4507
case CheckKind::WitnessUnavailable:
4508
- diagnoseOrDefer (requirement, /* isError=*/ true ,
4509
- [witness, requirement](
4510
- NormalProtocolConformance *conformance) {
4508
+ getASTContext ().addDelayedConformanceDiag (Conformance, true ,
4509
+ [witness, requirement](NormalProtocolConformance *conformance) {
4511
4510
auto &diags = witness->getASTContext ().Diags ;
4512
4511
SourceLoc diagLoc = getLocForDiagnosingWitness (conformance, witness);
4513
4512
auto *attr = AvailableAttr::isUnavailable (witness);
@@ -4572,7 +4571,7 @@ ConformanceChecker::resolveWitnessViaLookup(ValueDecl *requirement) {
4572
4571
return ResolveWitnessResult::Missing;
4573
4572
}
4574
4573
4575
- diagnoseOrDefer (requirement , true ,
4574
+ getASTContext (). addDelayedConformanceDiag (Conformance , true ,
4576
4575
[requirement, matches, ignoringNames](
4577
4576
NormalProtocolConformance *conformance) {
4578
4577
auto dc = conformance->getDeclContext ();
@@ -4632,7 +4631,7 @@ ResolveWitnessResult ConformanceChecker::resolveWitnessViaDerivation(
4632
4631
}
4633
4632
4634
4633
// Derivation failed.
4635
- diagnoseOrDefer (requirement , true ,
4634
+ getASTContext (). addDelayedConformanceDiag (Conformance , true ,
4636
4635
[](NormalProtocolConformance *conformance) {
4637
4636
auto proto = conformance->getProtocol ();
4638
4637
auto &diags = proto->getASTContext ().Diags ;
@@ -4911,7 +4910,7 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
4911
4910
4912
4911
// If we had multiple viable types, diagnose the ambiguity.
4913
4912
if (!viable.empty ()) {
4914
- diagnoseOrDefer (assocType , true ,
4913
+ getASTContext (). addDelayedConformanceDiag (Conformance , true ,
4915
4914
[assocType, viable](NormalProtocolConformance *conformance) {
4916
4915
auto &diags = assocType->getASTContext ().Diags ;
4917
4916
diags.diagnose (assocType, diag::ambiguous_witnesses_type,
@@ -4927,7 +4926,7 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
4927
4926
GlobalMissingWitnesses.insert ({assocType, {}});
4928
4927
4929
4928
// None of the candidates were viable.
4930
- diagnoseOrDefer (assocType , true ,
4929
+ getASTContext (). addDelayedConformanceDiag (Conformance , true ,
4931
4930
[nonViable](NormalProtocolConformance *conformance) {
4932
4931
auto &diags = conformance->getDeclContext ()->getASTContext ().Diags ;
4933
4932
for (auto candidate : nonViable) {
@@ -5112,7 +5111,7 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
5112
5111
if (!Conformance->isInvalid ()) {
5113
5112
if (result.getKind () == CheckRequirementsResult::RequirementFailure) {
5114
5113
auto Loc = this ->Loc ;
5115
- diagnoseOrDefer ( nullptr , /* isError=*/ true ,
5114
+ getASTContext (). addDelayedConformanceDiag (Conformance , /* isError=*/ true ,
5116
5115
[Loc, result, proto, substitutions, module ](NormalProtocolConformance *conformance) {
5117
5116
TypeChecker::diagnoseRequirementFailure (
5118
5117
result.getRequirementFailureInfo (), Loc, Loc,
@@ -5147,7 +5146,7 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
5147
5146
const DeclContext *DC = this ->DC ;
5148
5147
auto requiredAccessScope = getRequiredAccessScope ();
5149
5148
5150
- diagnoseOrDefer (assocType , false ,
5149
+ getASTContext (). addDelayedConformanceDiag (Conformance , false ,
5151
5150
[DC, requiredAccessScope, typeDecl](
5152
5151
NormalProtocolConformance *conformance) {
5153
5152
AccessLevel requiredAccess =
@@ -5170,7 +5169,8 @@ void ConformanceChecker::ensureRequirementsAreSatisfied() {
5170
5169
bool witnessIsUsableFromInline = typeDecl->getFormalAccessScope (
5171
5170
DC, /* usableFromInlineAsPublic*/ true ).isPublic ();
5172
5171
if (!witnessIsUsableFromInline)
5173
- diagnoseOrDefer (assocType, false , DiagnoseUsableFromInline (typeDecl));
5172
+ getASTContext ().addDelayedConformanceDiag (Conformance, false ,
5173
+ DiagnoseUsableFromInline (typeDecl));
5174
5174
}
5175
5175
}
5176
5176
@@ -5707,20 +5707,6 @@ void swift::diagnoseConformanceFailure(Type T,
5707
5707
T, Proto->getDeclaredInterfaceType ());
5708
5708
}
5709
5709
5710
- void ConformanceChecker::diagnoseOrDefer (
5711
- const ValueDecl *requirement, bool isError,
5712
- std::function<void (NormalProtocolConformance *)> fn) {
5713
- if (isError)
5714
- Conformance->setInvalid ();
5715
-
5716
- // Stash this in the ASTContext for later emission.
5717
- auto conformance = Conformance;
5718
-
5719
- getASTContext ().addDelayedConformanceDiag (
5720
- conformance,
5721
- {requirement, [conformance, fn] { fn (conformance); }, isError});
5722
- }
5723
-
5724
5710
void ConformanceChecker::emitDelayedDiags () {
5725
5711
auto diags = getASTContext ().takeDelayedConformanceDiags (Conformance);
5726
5712
@@ -5731,7 +5717,7 @@ void ConformanceChecker::emitDelayedDiags() {
5731
5717
AlreadyComplained = true ;
5732
5718
}
5733
5719
5734
- diag.Callback ();
5720
+ diag.Callback (Conformance );
5735
5721
}
5736
5722
}
5737
5723
0 commit comments