Skip to content

Commit 2545af6

Browse files
authored
Merge pull request #12203 from DougGregor/requirement-environment-fewer-gsbs
2 parents cd18c38 + 27e4333 commit 2545af6

File tree

1 file changed

+24
-11
lines changed

1 file changed

+24
-11
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,16 @@
4141
#include "swift/Serialization/SerializedModuleLoader.h"
4242
#include "llvm/ADT/ScopedHashTable.h"
4343
#include "llvm/ADT/SmallString.h"
44+
#include "llvm/ADT/Statistic.h"
4445
#include "llvm/Support/Compiler.h"
4546
#include "llvm/Support/ErrorHandling.h"
4647
#include "llvm/Support/SaveAndRestore.h"
4748

48-
#define DEBUG_TYPE "protocol-conformance-checking"
49+
#define DEBUG_TYPE "Protocol conformance checking"
4950
#include "llvm/Support/Debug.h"
5051

52+
STATISTIC(NumRequirementEnvironments, "# of requirement environments");
53+
5154
using namespace swift;
5255

5356
namespace {
@@ -1065,26 +1068,19 @@ RequirementEnvironment::RequirementEnvironment(
10651068
auto selfType = cast<GenericTypeParamType>(
10661069
proto->getSelfInterfaceType()->getCanonicalType());
10671070

1068-
// Construct a generic signature builder by collecting the constraints
1069-
// from the requirement and the context of the conformance together,
1070-
// because both define the capabilities of the requirement.
1071-
GenericSignatureBuilder builder(
1072-
ctx,
1073-
TypeChecker::LookUpConformance(tc, conformanceDC));
1074-
10751071
SmallVector<GenericTypeParamType*, 4> allGenericParams;
10761072

10771073
// Add the generic signature of the context of the conformance. This includes
10781074
// the generic parameters from the conforming type as well as any additional
10791075
// constraints that might occur on the extension that declares the
10801076
// conformance (i.e., if the conformance is conditional).
1077+
GenericSignature *conformanceSig;
10811078
unsigned depth = 0;
1082-
if (auto *conformanceSig = conformanceDC->getGenericSignatureOfContext()) {
1079+
if ((conformanceSig = conformanceDC->getGenericSignatureOfContext())) {
10831080
// Use the canonical signature here.
10841081
conformanceSig = conformanceSig->getCanonicalSignature();
10851082
allGenericParams.append(conformanceSig->getGenericParams().begin(),
10861083
conformanceSig->getGenericParams().end());
1087-
builder.addGenericSignature(conformanceSig);
10881084
depth = allGenericParams.back()->getDepth() + 1;
10891085
}
10901086

@@ -1138,12 +1134,29 @@ RequirementEnvironment::RequirementEnvironment(
11381134
GenericTypeParamType::get(depth, genericParam->getIndex(), ctx);
11391135

11401136
allGenericParams.push_back(substGenericParam);
1141-
builder.addGenericParameter(substGenericParam);
11421137
}
11431138

11441139
// If there were no generic parameters, we're done.
11451140
if (allGenericParams.empty()) return;
11461141

1142+
// Construct a generic signature builder by collecting the constraints
1143+
// from the requirement and the context of the conformance together,
1144+
// because both define the capabilities of the requirement.
1145+
GenericSignatureBuilder builder(
1146+
ctx,
1147+
TypeChecker::LookUpConformance(tc, conformanceDC));
1148+
1149+
unsigned firstGenericParamToAdd = 0;
1150+
if (conformanceSig) {
1151+
builder.addGenericSignature(conformanceSig);
1152+
firstGenericParamToAdd = conformanceSig->getGenericParams().size();
1153+
}
1154+
1155+
for (unsigned gp : range(firstGenericParamToAdd, allGenericParams.size()))
1156+
builder.addGenericParameter(allGenericParams[gp]);
1157+
1158+
++NumRequirementEnvironments;
1159+
11471160
// Next, add each of the requirements (mapped from the requirement's
11481161
// interface types into the abstract type parameters).
11491162
auto source =

0 commit comments

Comments
 (0)