Skip to content

Commit eb898b2

Browse files
authored
Merge pull request #7718 from DougGregor/make-all-dependent-types-truth
2 parents 49011a3 + 5f4b2cf commit eb898b2

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

lib/AST/GenericEnvironment.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -412,9 +412,7 @@ getSubstitutionMap(SubstitutionList subs) const {
412412
continue;
413413
}
414414

415-
// FIXME: getAllDependentTypes() includes generic type parameters that
416-
// have been made concrete.
417-
assert(contextTy->hasError() || depTy->is<GenericTypeParamType>());
415+
assert(contextTy->hasError());
418416
}
419417

420418
assert(subs.empty() && "did not use all substitutions?!");

lib/AST/GenericSignature.cpp

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)