@@ -1855,6 +1855,24 @@ static ValueDecl *getObjCRequirementSibling(
18551855 return nullptr ;
18561856}
18571857
1858+ static void emitDelayedDiags (NormalProtocolConformance *conformance) {
1859+ auto *dc = conformance->getDeclContext ();
1860+ auto diags = dc->getASTContext ().takeDelayedConformanceDiags (conformance);
1861+ bool alreadyComplained = false ;
1862+ for (const auto &diag: diags) {
1863+ // Complain that the type does not conform, once.
1864+ if (diag.IsError && !alreadyComplained) {
1865+ diagnoseConformanceFailure (dc->getSelfInterfaceType (),
1866+ conformance->getProtocol (),
1867+ dc,
1868+ conformance->getLoc ());
1869+ alreadyComplained = true ;
1870+ }
1871+
1872+ diag.Callback (conformance);
1873+ }
1874+ }
1875+
18581876namespace {
18591877
18601878// / This is a wrapper of multiple instances of ConformanceChecker to allow us
@@ -1881,12 +1899,9 @@ class MultiConformanceChecker {
18811899 MultiConformanceChecker (ASTContext &ctx) : Context(ctx) {}
18821900
18831901 ~MultiConformanceChecker () {
1884- // force-flush diagnostics in checkers that have not already complained
1902+ // Emit diagnostics at the very end.
18851903 for (auto &checker : AllUsedCheckers) {
1886- if (checker.AlreadyComplained )
1887- continue ;
1888-
1889- checker.emitDelayedDiags ();
1904+ emitDelayedDiags (checker.Conformance );
18901905 }
18911906 }
18921907
@@ -3815,26 +3830,29 @@ diagnoseMissingWitnesses(MissingWitnessDiagnosisKind Kind, bool Delayed) {
38153830 return true ;
38163831 }
38173832
3818- // Diagnose the missing witnesses.
3819- for (auto &Missing : LocalMissing) {
3820- auto requirement = Missing.requirement ;
3821- auto matches = Missing.matches ;
3822- auto nominal = DC->getSelfNominalTypeDecl ();
3833+ if (Kind != MissingWitnessDiagnosisKind::FixItOnly) {
3834+ // Diagnose the missing witnesses.
3835+ for (auto &Missing : LocalMissing) {
3836+ auto requirement = Missing.requirement ;
3837+ auto matches = Missing.matches ;
3838+ auto nominal = DC->getSelfNominalTypeDecl ();
38233839
3824- getASTContext ().addDelayedConformanceDiag (Conformance, true ,
3825- [requirement, matches, nominal](NormalProtocolConformance *conformance) {
3826- auto dc = conformance->getDeclContext ();
3827- auto *protocol = conformance->getProtocol ();
3828- // Possibly diagnose reason for automatic derivation failure
3829- DerivedConformance::tryDiagnoseFailedDerivation (dc, nominal, protocol);
3830- // Diagnose each of the matches.
3831- for (const auto &match : matches) {
3832- diagnoseMatch (dc->getParentModule (), conformance, requirement, match);
3833- }
3834- });
3840+ getASTContext ().addDelayedConformanceDiag (Conformance, true ,
3841+ [requirement, matches, nominal](NormalProtocolConformance *conformance) {
3842+ auto dc = conformance->getDeclContext ();
3843+ auto *protocol = conformance->getProtocol ();
3844+ // Possibly diagnose reason for automatic derivation failure
3845+ DerivedConformance::tryDiagnoseFailedDerivation (dc, nominal, protocol);
3846+ // Diagnose each of the matches.
3847+ for (const auto &match : matches) {
3848+ diagnoseMatch (dc->getParentModule (), conformance, requirement, match);
3849+ }
3850+ });
3851+ }
38353852 }
38363853
38373854 switch (Kind) {
3855+ case MissingWitnessDiagnosisKind::FixItOnly:
38383856 case MissingWitnessDiagnosisKind::ErrorFixIt: {
38393857 const auto MissingWitnesses = filterProtocolRequirements (
38403858 GlobalMissingWitnesses.getArrayRef (), Adoptee);
@@ -3845,16 +3863,7 @@ diagnoseMissingWitnesses(MissingWitnessDiagnosisKind Kind, bool Delayed) {
38453863 clearGlobalMissingWitnesses ();
38463864 return true ;
38473865 }
3848- case MissingWitnessDiagnosisKind::ErrorOnly: {
3849- getASTContext ().addDelayedConformanceDiag (Conformance, true ,
3850- [](NormalProtocolConformance *) {});
3851- return true ;
3852- }
3853- case MissingWitnessDiagnosisKind::FixItOnly:
3854- diagnoseProtocolStubFixit (Conformance,
3855- filterProtocolRequirements (GlobalMissingWitnesses.getArrayRef (),
3856- Adoptee));
3857- clearGlobalMissingWitnesses ();
3866+ case MissingWitnessDiagnosisKind::ErrorOnly:
38583867 return true ;
38593868 }
38603869}
@@ -5115,18 +5124,6 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
51155124 FrontendStatsTracer statsTracer (getASTContext ().Stats ,
51165125 " check-conformance" , Conformance);
51175126
5118- // FIXME: Caller checks that this type conforms to all of the
5119- // inherited protocols.
5120-
5121- // Emit known diags for this conformance.
5122- emitDelayedDiags ();
5123-
5124- // If delayed diags have already complained, return.
5125- if (AlreadyComplained) {
5126- Conformance->setInvalid ();
5127- return ;
5128- }
5129-
51305127 // Resolve all of the type witnesses.
51315128 resolveTypeWitnesses ();
51325129
@@ -5139,8 +5136,6 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
51395136 // Diagnose any missing witnesses.
51405137 diagnoseMissingWitnesses (Kind, /* Delayed=*/ false );
51415138
5142- emitDelayedDiags ();
5143-
51445139 // Except in specific hardcoded cases for Foundation/Swift
51455140 // standard library compatibility, an _ObjectiveCBridgeable
51465141 // conformance must appear in the same module as the definition of
@@ -5304,20 +5299,6 @@ void swift::diagnoseConformanceFailure(Type T,
53045299 T, Proto->getDeclaredInterfaceType ());
53055300}
53065301
5307- void ConformanceChecker::emitDelayedDiags () {
5308- auto diags = getASTContext ().takeDelayedConformanceDiags (Conformance);
5309-
5310- for (const auto &diag: diags) {
5311- // Complain that the type does not conform, once.
5312- if (diag.IsError && !AlreadyComplained) {
5313- diagnoseConformanceFailure (Adoptee, Proto, DC, Loc);
5314- AlreadyComplained = true ;
5315- }
5316-
5317- diag.Callback (Conformance);
5318- }
5319- }
5320-
53215302ProtocolConformanceRef
53225303TypeChecker::containsProtocol (Type T, ProtocolDecl *Proto, ModuleDecl *M,
53235304 bool skipConditionalRequirements,
0 commit comments