@@ -7433,9 +7433,46 @@ void GenericSignatureBuilder::verifyGenericSignature(ASTContext &context,
7433
7433
sig->print (llvm::errs ());
7434
7434
llvm::errs () << " \n " ;
7435
7435
7436
- // Try removing each requirement in turn .
7436
+ // Try building a new signature having the same requirements .
7437
7437
auto genericParams = sig->getGenericParams ();
7438
7438
auto requirements = sig->getRequirements ();
7439
+
7440
+ {
7441
+ PrettyStackTraceGenericSignature debugStack (" verifying" , sig);
7442
+
7443
+ // Form a new generic signature builder.
7444
+ GenericSignatureBuilder builder (context);
7445
+
7446
+ // Add the generic parameters.
7447
+ for (auto gp : genericParams)
7448
+ builder.addGenericParameter (gp);
7449
+
7450
+ // Add the requirements.
7451
+ auto source = FloatingRequirementSource::forAbstract ();
7452
+ for (auto req : requirements)
7453
+ builder.addRequirement (req, source, nullptr );
7454
+
7455
+ // If there were any errors, the signature was invalid.
7456
+ if (builder.Impl ->HadAnyError ) {
7457
+ context.Diags .diagnose (SourceLoc (), diag::generic_signature_not_valid,
7458
+ sig->getAsString ());
7459
+ }
7460
+
7461
+ // Form a generic signature from the result.
7462
+ auto newSig =
7463
+ std::move (builder).computeGenericSignature (
7464
+ SourceLoc (),
7465
+ /* allowConcreteGenericParams=*/ true ,
7466
+ /* allowBuilderToMove=*/ true );
7467
+
7468
+ // The new signature should be equal.
7469
+ if (newSig->getCanonicalSignature () != sig->getCanonicalSignature ()) {
7470
+ context.Diags .diagnose (SourceLoc (), diag::generic_signature_not_equal,
7471
+ sig->getAsString (), newSig->getAsString ());
7472
+ }
7473
+ }
7474
+
7475
+ // Try removing each requirement in turn.
7439
7476
for (unsigned victimIndex : indices (requirements)) {
7440
7477
PrettyStackTraceGenericSignature debugStack (" verifying" , sig, victimIndex);
7441
7478
@@ -7453,8 +7490,8 @@ void GenericSignatureBuilder::verifyGenericSignature(ASTContext &context,
7453
7490
builder.addRequirement (requirements[i], source, nullptr );
7454
7491
}
7455
7492
7456
- // Finalize the generic signature. If there were any errors, we formed
7457
- // an invalid signature, so just continue.
7493
+ // If there were any errors, we formed an invalid signature, so
7494
+ // just continue.
7458
7495
if (builder.Impl ->HadAnyError ) continue ;
7459
7496
7460
7497
// Form a generic signature from the result.
0 commit comments