Skip to content

Commit 9c077ec

Browse files
committed
Sema: Consolidate calls to emitDelayedDiags()
1 parent ec7269d commit 9c077ec

File tree

3 files changed

+42
-65
lines changed

3 files changed

+42
-65
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 40 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
18581876
namespace {
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-
53215302
ProtocolConformanceRef
53225303
TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M,
53235304
bool skipConditionalRequirements,

lib/Sema/TypeCheckProtocol.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,6 @@ class ConformanceChecker : public WitnessChecker {
141141
/// this protocol under checking.
142142
unsigned LocalMissingWitnessesStartIndex;
143143

144-
/// Whether we've already complained about problems with this conformance.
145-
bool AlreadyComplained = false;
146-
147144
/// Record a (non-type) witness for the given requirement.
148145
void recordWitness(ValueDecl *requirement, const RequirementMatch &match);
149146

@@ -210,9 +207,6 @@ class ConformanceChecker : public WitnessChecker {
210207
bool diagnoseMissingWitnesses(MissingWitnessDiagnosisKind Kind,
211208
bool Delayed);
212209

213-
/// Emit any diagnostics that have been delayed.
214-
void emitDelayedDiags();
215-
216210
ConformanceChecker(ASTContext &ctx, NormalProtocolConformance *conformance,
217211
llvm::SetVector<ASTContext::MissingWitness> &GlobalMissingWitnesses);
218212

test/Distributed/distributed_actor_system_missing.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ distributed actor DA {
2525
// Test case for: https://github.com/apple/swift/issues/58663
2626
distributed actor Server { // expected-error 2 {{distributed actor 'Server' does not declare ActorSystem it can be used with}}
2727
// expected-note@-1{{you can provide a module-wide default actor system by declaring:}}
28+
// expected-error@-2{{type 'Server' does not conform to protocol 'Encodable'}}
29+
// expected-error@-3{{type 'Server' does not conform to protocol 'Decodable'}}
2830
typealias ActorSystem = DoesNotExistDataSystem
2931
// expected-error@-1{{cannot find type 'DoesNotExistDataSystem' in scope}}
3032
typealias SerializationRequirement = any Codable

0 commit comments

Comments
 (0)