@@ -239,6 +239,19 @@ bool GenericSignature::enumeratePairedRequirements(
239239 ArrayRef<GenericTypeParamType *> genericParams = getGenericParams ();
240240 unsigned curGenericParamIdx = 0 , numGenericParams = genericParams.size ();
241241
242+ // Figure out which generic parameters are complete.
243+ SmallVector<bool , 4 > genericParamsAreConcrete (genericParams.size (), false );
244+ for (auto req : reqs) {
245+ if (req.getKind () != RequirementKind::SameType) continue ;
246+ if (req.getSecondType ()->isTypeParameter ()) continue ;
247+
248+ auto gp = req.getFirstType ()->getAs <GenericTypeParamType>();
249+ if (!gp) continue ;
250+
251+ unsigned index = GenericParamKey (gp).findIndexIn (genericParams);
252+ genericParamsAreConcrete[index] = true ;
253+ }
254+
242255 // / Local function to 'catch up' to the next dependent type we're going to
243256 // / visit, calling the function for each of the generic parameters in the
244257 // / generic parameter list prior to this parameter.
@@ -263,7 +276,10 @@ bool GenericSignature::enumeratePairedRequirements(
263276 if (curGenericParam->getDepth () < stopDepth ||
264277 (curGenericParam->getDepth () == stopDepth &&
265278 curGenericParam->getIndex () < stopIndex)) {
266- if (fn (curGenericParam, { })) return true ;
279+ if (!genericParamsAreConcrete[curGenericParamIdx] &&
280+ fn (curGenericParam, { }))
281+ return true ;
282+
267283 ++curGenericParamIdx;
268284 continue ;
269285 }
@@ -291,16 +307,10 @@ bool GenericSignature::enumeratePairedRequirements(
291307
292308 // Utility to skip over non-conformance constraints that apply to this
293309 // type.
294- bool sawSameTypeToConcreteConstraint = false ;
295310 auto skipNonConformanceConstraints = [&] {
296311 while (curReqIdx != numReqs &&
297312 reqs[curReqIdx].getKind () != RequirementKind::Conformance &&
298313 reqs[curReqIdx].getFirstType ()->getCanonicalType () == depTy) {
299- // Record whether we saw a same-type constraint mentioning this type.
300- if (reqs[curReqIdx].getKind () == RequirementKind::SameType &&
301- !reqs[curReqIdx].getSecondType ()->isTypeParameter ())
302- sawSameTypeToConcreteConstraint = true ;
303-
304314 ++curReqIdx;
305315 }
306316 };
@@ -324,7 +334,10 @@ bool GenericSignature::enumeratePairedRequirements(
324334 // If there were any conformance constraints, or we have a generic
325335 // parameter we can't skip, invoke the callback.
326336 if ((startIdx != endIdx ||
327- (isa<GenericTypeParamType>(depTy) && !sawSameTypeToConcreteConstraint)) &&
337+ (isa<GenericTypeParamType>(depTy) &&
338+ !genericParamsAreConcrete[
339+ GenericParamKey (cast<GenericTypeParamType>(depTy))
340+ .findIndexIn (genericParams)])) &&
328341 fn (depTy, reqs.slice (startIdx, endIdx-startIdx)))
329342 return true ;
330343 }
0 commit comments