Skip to content

[NFC] Fold Switch-Nest in Obligation Verification #33411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 32 additions & 53 deletions lib/Frontend/DependencyVerifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,71 +481,50 @@ bool DependencyVerifier::verifyObligations(
auto &diags = SF->getASTContext().Diags;
for (auto &expectation : ExpectedDependencies) {
const bool wantsCascade = expectation.isCascading();
switch (expectation.Info.Kind) {
case Expectation::Kind::Negative:
if (expectation.Info.Kind == Expectation::Kind::Negative) {
// We'll verify negative expectations separately.
NegativeExpectations.insert({expectation.MessageRange, expectation});
break;
case Expectation::Kind::Member:
matchExpectationOrFail(
OM, expectation,
[&](Obligation &p) {
const auto haveCascade = p.getCascades();
continue;
}

matchExpectationOrFail(
OM, expectation,
[&](Obligation &O) {
const auto haveCascade = O.getCascades();
switch (expectation.Info.Kind) {
case Expectation::Kind::Negative:
llvm_unreachable("Should have been handled above!");
case Expectation::Kind::Member:
if (haveCascade != wantsCascade) {
diagnose(diags, expectation.MessageRange.begin(),
diag::dependency_cascading_mismatch, wantsCascade,
haveCascade);
return p.fail();
return O.fail();
} else {
return O.fullfill();
}

return p.fullfill();
},
[&](const Expectation &e) {
diagnose(
diags, e.MessageRange.begin(), diag::missing_member_dependency,
static_cast<uint8_t>(expectation.Info.Kind), e.MessageRange);
});
break;
case Expectation::Kind::PotentialMember:
matchExpectationOrFail(
OM, expectation,
[&](Obligation &p) {
assert(p.getName().empty());
const auto haveCascade = p.getCascades();
case Expectation::Kind::PotentialMember:
assert(O.getName().empty());
if (haveCascade != wantsCascade) {
diagnose(diags, expectation.MessageRange.begin(),
diag::potential_dependency_cascading_mismatch,
wantsCascade, haveCascade);
return p.fail();
return O.fail();
} else {
return O.fullfill();
}

return p.fullfill();
},
[&](const Expectation &e) {
diagnose(
diags, e.MessageRange.begin(), diag::missing_member_dependency,
static_cast<uint8_t>(expectation.Info.Kind), e.MessageRange);
});
break;
case Expectation::Kind::Provides:
matchExpectationOrFail(
OM, expectation, [](Obligation &O) { return O.fullfill(); },
[&](const Expectation &e) {
diagnose(
diags, e.MessageRange.begin(), diag::missing_member_dependency,
static_cast<uint8_t>(expectation.Info.Kind), e.MessageRange);
});
break;
case Expectation::Kind::DynamicMember:
matchExpectationOrFail(
OM, expectation, [](Obligation &O) { return O.fullfill(); },
[&](const Expectation &e) {
diagnose(
diags, e.MessageRange.begin(), diag::missing_member_dependency,
static_cast<uint8_t>(expectation.Info.Kind), e.MessageRange);
});
break;
}
case Expectation::Kind::Provides:
case Expectation::Kind::DynamicMember:
return O.fullfill();
}

llvm_unreachable("Unhandled expectation kind!");
},
[&](const Expectation &e) {
diagnose(diags, e.MessageRange.begin(),
diag::missing_member_dependency,
static_cast<uint8_t>(expectation.Info.Kind), e.MessageRange);
});
}

return false;
Expand Down