Skip to content

Commit f116799

Browse files
committed
[Sema] Factor out ConformanceChecker::resolveValueWitnesses
checkConformance was pretty long. No functionality change.
1 parent 4270bdd commit f116799

File tree

2 files changed

+57
-49
lines changed

2 files changed

+57
-49
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 54 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -3625,60 +3625,14 @@ void ConformanceChecker::ensureRequirementsAreSatisfied(
36253625
}
36263626

36273627
#pragma mark Protocol conformance checking
3628-
void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
3629-
assert(!Conformance->isComplete() && "Conformance is already complete");
3630-
3631-
FrontendStatsTracer statsTracer(TC.Context.Stats, "check-conformance",
3632-
Conformance);
3633-
3634-
llvm::SaveAndRestore<bool> restoreSuppressDiagnostics(SuppressDiagnostics);
3635-
SuppressDiagnostics = false;
3636-
3637-
// FIXME: Caller checks that this type conforms to all of the
3638-
// inherited protocols.
3639-
3640-
// Emit known diags for this conformance.
3641-
emitDelayedDiags();
3642-
3643-
// If delayed diags have already complained, return.
3644-
if (AlreadyComplained) {
3645-
Conformance->setInvalid();
3646-
return;
3647-
}
3648-
3649-
// Resolve all of the type witnesses.
3650-
resolveTypeWitnesses();
3651-
3652-
// Diagnose missing type witnesses for now.
3653-
diagnoseMissingWitnesses(Kind);
3654-
3655-
// Ensure the conforming type is used.
3656-
//
3657-
// FIXME: This feels like the wrong place for this, but if we don't put
3658-
// it here, extensions don't end up depending on the extended type.
3659-
recordConformanceDependency(DC, Adoptee->getAnyNominal(), Conformance, false);
36603628

3661-
// If we complain about any associated types, there is no point in continuing.
3662-
// FIXME: Not really true. We could check witnesses that don't involve the
3663-
// failed associated types.
3664-
if (AlreadyComplained) {
3665-
Conformance->setInvalid();
3666-
return;
3667-
}
3668-
3669-
// Diagnose missing value witnesses later.
3670-
SWIFT_DEFER { diagnoseMissingWitnesses(Kind); };
3671-
3672-
// Ensure the associated type conformances are used.
3673-
addUsedConformances(Conformance);
3674-
3675-
// Check non-type requirements.
3629+
void ConformanceChecker::resolveValueWitnesses() {
36763630
for (auto member : Proto->getMembers()) {
36773631
auto requirement = dyn_cast<ValueDecl>(member);
36783632
if (!requirement)
36793633
continue;
36803634

3681-
// Associated type requirements handled above.
3635+
// Associated type requirements handled elsewhere.
36823636
if (isa<TypeDecl>(requirement))
36833637
continue;
36843638

@@ -3829,7 +3783,7 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
38293783
// If this is an accessor for a storage decl, ignore it.
38303784
if (isa<AccessorDecl>(requirement))
38313785
continue;
3832-
3786+
38333787
// Try to resolve the witness via explicit definitions.
38343788
switch (resolveWitnessViaLookup(requirement)) {
38353789
case ResolveWitnessResult::Success:
@@ -3875,6 +3829,57 @@ void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
38753829
break;
38763830
}
38773831
}
3832+
}
3833+
3834+
void ConformanceChecker::checkConformance(MissingWitnessDiagnosisKind Kind) {
3835+
assert(!Conformance->isComplete() && "Conformance is already complete");
3836+
3837+
FrontendStatsTracer statsTracer(TC.Context.Stats, "check-conformance",
3838+
Conformance);
3839+
3840+
llvm::SaveAndRestore<bool> restoreSuppressDiagnostics(SuppressDiagnostics);
3841+
SuppressDiagnostics = false;
3842+
3843+
// FIXME: Caller checks that this type conforms to all of the
3844+
// inherited protocols.
3845+
3846+
// Emit known diags for this conformance.
3847+
emitDelayedDiags();
3848+
3849+
// If delayed diags have already complained, return.
3850+
if (AlreadyComplained) {
3851+
Conformance->setInvalid();
3852+
return;
3853+
}
3854+
3855+
// Resolve all of the type witnesses.
3856+
resolveTypeWitnesses();
3857+
3858+
// Diagnose missing type witnesses for now.
3859+
diagnoseMissingWitnesses(Kind);
3860+
3861+
// Ensure the conforming type is used.
3862+
//
3863+
// FIXME: This feels like the wrong place for this, but if we don't put
3864+
// it here, extensions don't end up depending on the extended type.
3865+
recordConformanceDependency(DC, Adoptee->getAnyNominal(), Conformance, false);
3866+
3867+
// If we complain about any associated types, there is no point in continuing.
3868+
// FIXME: Not really true. We could check witnesses that don't involve the
3869+
// failed associated types.
3870+
if (AlreadyComplained) {
3871+
Conformance->setInvalid();
3872+
return;
3873+
}
3874+
3875+
// Diagnose missing value witnesses later.
3876+
SWIFT_DEFER { diagnoseMissingWitnesses(Kind); };
3877+
3878+
// Ensure the associated type conformances are used.
3879+
addUsedConformances(Conformance);
3880+
3881+
// Check non-type requirements.
3882+
resolveValueWitnesses();
38783883

38793884
emitDelayedDiags();
38803885

lib/Sema/TypeCheckProtocol.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -675,6 +675,9 @@ class ConformanceChecker : public WitnessChecker {
675675
/// Resolve all of the type witnesses.
676676
void resolveTypeWitnesses();
677677

678+
/// Resolve all of the non-type witnesses.
679+
void resolveValueWitnesses();
680+
678681
/// Resolve the witness for the given non-type requirement as
679682
/// directly as possible, only resolving other witnesses if
680683
/// needed, e.g., to determine type witnesses used within the

0 commit comments

Comments
 (0)