Skip to content

Commit 25ac1f5

Browse files
committed
AST: Refactor verifyGenericSignature() to use AbstractGenericSignatureRequest
1 parent ee5a3fe commit 25ac1f5

File tree

1 file changed

+29
-32
lines changed

1 file changed

+29
-32
lines changed

lib/AST/GenericSignatureBuilder.cpp

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -8453,34 +8453,32 @@ void GenericSignatureBuilder::verifyGenericSignature(ASTContext &context,
84538453
llvm::errs() << "\n";
84548454

84558455
// Try building a new signature having the same requirements.
8456-
auto genericParams = sig.getGenericParams();
8457-
auto requirements = sig.getRequirements();
8456+
SmallVector<GenericTypeParamType *, 2> genericParams;
8457+
for (auto *genericParam : sig.getGenericParams())
8458+
genericParams.push_back(genericParam);
8459+
8460+
SmallVector<Requirement, 2> requirements;
8461+
for (auto requirement : sig.getRequirements())
8462+
requirements.push_back(requirement);
84588463

84598464
{
84608465
PrettyStackTraceGenericSignature debugStack("verifying", sig);
84618466

8462-
// Form a new generic signature builder.
8463-
GenericSignatureBuilder builder(context);
8464-
8465-
// Add the generic parameters.
8466-
for (auto gp : genericParams)
8467-
builder.addGenericParameter(gp);
8468-
8469-
// Add the requirements.
8470-
auto source = FloatingRequirementSource::forAbstract();
8471-
for (auto req : requirements)
8472-
builder.addRequirement(req, source, nullptr);
8467+
auto newSigWithError = evaluateOrDefault(
8468+
context.evaluator,
8469+
AbstractGenericSignatureRequest{
8470+
nullptr,
8471+
genericParams,
8472+
requirements},
8473+
GenericSignatureWithError());
84738474

84748475
// If there were any errors, the signature was invalid.
8475-
if (builder.Impl->HadAnyError) {
8476+
if (newSigWithError.getInt()) {
84768477
context.Diags.diagnose(SourceLoc(), diag::generic_signature_not_valid,
84778478
sig->getAsString());
84788479
}
84798480

8480-
// Form a generic signature from the result.
8481-
auto newSig =
8482-
std::move(builder).computeGenericSignature(
8483-
/*allowConcreteGenericParams=*/true);
8481+
auto newSig = newSigWithError.getPointer();
84848482

84858483
// The new signature should be equal.
84868484
if (!newSig->isEqual(sig)) {
@@ -8493,28 +8491,27 @@ void GenericSignatureBuilder::verifyGenericSignature(ASTContext &context,
84938491
for (unsigned victimIndex : indices(requirements)) {
84948492
PrettyStackTraceGenericSignature debugStack("verifying", sig, victimIndex);
84958493

8496-
// Form a new generic signature builder.
8497-
GenericSignatureBuilder builder(context);
8498-
8499-
// Add the generic parameters.
8500-
for (auto gp : genericParams)
8501-
builder.addGenericParameter(gp);
8502-
85038494
// Add the requirements *except* the victim.
8504-
auto source = FloatingRequirementSource::forAbstract();
8495+
SmallVector<Requirement, 2> newRequirements;
85058496
for (unsigned i : indices(requirements)) {
85068497
if (i != victimIndex)
8507-
builder.addRequirement(requirements[i], source, nullptr);
8498+
newRequirements.push_back(requirements[i]);
85088499
}
85098500

8501+
auto newSigWithError = evaluateOrDefault(
8502+
context.evaluator,
8503+
AbstractGenericSignatureRequest{
8504+
nullptr,
8505+
genericParams,
8506+
newRequirements},
8507+
GenericSignatureWithError());
8508+
85108509
// If there were any errors, we formed an invalid signature, so
85118510
// just continue.
8512-
if (builder.Impl->HadAnyError) continue;
8511+
if (newSigWithError.getInt())
8512+
continue;
85138513

8514-
// Form a generic signature from the result.
8515-
auto newSig =
8516-
std::move(builder).computeGenericSignature(
8517-
/*allowConcreteGenericParams=*/true);
8514+
auto newSig = newSigWithError.getPointer();
85188515

85198516
// If the new signature once again contains the removed requirement, it's
85208517
// not redundant.

0 commit comments

Comments
 (0)