@@ -1068,8 +1068,6 @@ RequirementEnvironment::RequirementEnvironment(
1068
1068
auto selfType = cast<GenericTypeParamType>(
1069
1069
proto->getSelfInterfaceType ()->getCanonicalType ());
1070
1070
1071
- SmallVector<GenericTypeParamType*, 4 > allGenericParams;
1072
-
1073
1071
// Add the generic signature of the context of the conformance. This includes
1074
1072
// the generic parameters from the conforming type as well as any additional
1075
1073
// constraints that might occur on the extension that declares the
@@ -1079,9 +1077,7 @@ RequirementEnvironment::RequirementEnvironment(
1079
1077
if ((conformanceSig = conformanceDC->getGenericSignatureOfContext ())) {
1080
1078
// Use the canonical signature here.
1081
1079
conformanceSig = conformanceSig->getCanonicalSignature ();
1082
- allGenericParams.append (conformanceSig->getGenericParams ().begin (),
1083
- conformanceSig->getGenericParams ().end ());
1084
- depth = allGenericParams.back ()->getDepth () + 1 ;
1080
+ depth = conformanceSig->getGenericParams ().back ()->getDepth () + 1 ;
1085
1081
}
1086
1082
1087
1083
// Add the generic signature of the requirement, substituting our concrete
@@ -1121,39 +1117,46 @@ RequirementEnvironment::RequirementEnvironment(
1121
1117
return ProtocolConformanceRef (proto);
1122
1118
});
1123
1119
1124
- // First, add the generic parameters from the requirement.
1125
- for (auto genericParam : reqSig->getGenericParams ().slice (1 )) {
1126
- // The only depth that makes sense is depth == 1, the generic parameters
1127
- // of the requirement itself. Anything else is from invalid code.
1128
- if (genericParam->getDepth () != 1 ) {
1129
- return ;
1120
+ // If the requirement itself is non-generic, the synthetic signature
1121
+ // is that of the conformance context.
1122
+ if (reqSig->getGenericParams ().size () == 1 &&
1123
+ reqSig->getRequirements ().size () == 1 ) {
1124
+ syntheticSignature = conformanceDC->getGenericSignatureOfContext ();
1125
+ if (syntheticSignature) {
1126
+ syntheticSignature = syntheticSignature->getCanonicalSignature ();
1127
+ syntheticEnvironment =
1128
+ syntheticSignature->createGenericEnvironment (
1129
+ *conformanceDC->getParentModule ());
1130
1130
}
1131
1131
1132
- // Create an equivalent generic parameter at the next depth.
1133
- auto substGenericParam =
1134
- GenericTypeParamType::get (depth, genericParam->getIndex (), ctx);
1135
-
1136
- allGenericParams.push_back (substGenericParam);
1132
+ return ;
1137
1133
}
1138
1134
1139
- // If there were no generic parameters, we're done.
1140
- if (allGenericParams.empty ()) return ;
1141
-
1142
1135
// Construct a generic signature builder by collecting the constraints
1143
1136
// from the requirement and the context of the conformance together,
1144
1137
// because both define the capabilities of the requirement.
1145
1138
GenericSignatureBuilder builder (
1146
1139
ctx,
1147
1140
TypeChecker::LookUpConformance (tc, conformanceDC));
1148
1141
1149
- unsigned firstGenericParamToAdd = 0 ;
1150
1142
if (conformanceSig) {
1151
1143
builder.addGenericSignature (conformanceSig);
1152
- firstGenericParamToAdd = conformanceSig->getGenericParams ().size ();
1153
1144
}
1154
1145
1155
- for (unsigned gp : range (firstGenericParamToAdd, allGenericParams.size ()))
1156
- builder.addGenericParameter (allGenericParams[gp]);
1146
+ // First, add the generic parameters from the requirement.
1147
+ for (auto genericParam : reqSig->getGenericParams ().slice (1 )) {
1148
+ // The only depth that makes sense is depth == 1, the generic parameters
1149
+ // of the requirement itself. Anything else is from invalid code.
1150
+ if (genericParam->getDepth () != 1 ) {
1151
+ return ;
1152
+ }
1153
+
1154
+ // Create an equivalent generic parameter at the next depth.
1155
+ auto substGenericParam =
1156
+ GenericTypeParamType::get (depth, genericParam->getIndex (), ctx);
1157
+
1158
+ builder.addGenericParameter (substGenericParam);
1159
+ }
1157
1160
1158
1161
++NumRequirementEnvironments;
1159
1162
0 commit comments