Skip to content

Commit 8421251

Browse files
committed
AST: getOpenedElementSignature() uses LocalArchetypeRequirementCollector
1 parent 4128bef commit 8421251

File tree

1 file changed

+4
-92
lines changed

1 file changed

+4
-92
lines changed

lib/AST/ASTContext.cpp

Lines changed: 4 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -5928,100 +5928,12 @@ ASTContext::getOpenedElementSignature(CanGenericSignature baseGenericSig,
59285928
if (found != sigs.end())
59295929
return found->second;
59305930

5931-
// This operation doesn't make sense if the input signature does not contain`
5932-
// any pack generic parameters.
5933-
#ifndef NDEBUG
5934-
{
5935-
auto found = std::find_if(baseGenericSig.getGenericParams().begin(),
5936-
baseGenericSig.getGenericParams().end(),
5937-
[](GenericTypeParamType *paramType) {
5938-
return paramType->isParameterPack();
5939-
});
5940-
assert(found != baseGenericSig.getGenericParams().end());
5941-
}
5942-
#endif
5943-
5944-
// The pack element signature includes all type parameters and requirements
5945-
// from the outer context, plus a new set of type parameters representing
5946-
// open pack elements and their corresponding element requirements.
5947-
5948-
llvm::SmallMapVector<GenericTypeParamType *,
5949-
GenericTypeParamType *, 2> packElementParams;
5950-
SmallVector<GenericTypeParamType *, 2> genericParams(
5951-
baseGenericSig.getGenericParams().begin(), baseGenericSig.getGenericParams().end());
5952-
SmallVector<Requirement, 2> requirements;
5953-
5954-
auto packElementDepth =
5955-
baseGenericSig.getInnermostGenericParams().front()->getDepth() + 1;
5956-
5957-
for (auto paramType : baseGenericSig.getGenericParams()) {
5958-
if (!paramType->isParameterPack())
5959-
continue;
5960-
5961-
// Only include opened element parameters for packs in the given
5962-
// shape equivalence class.
5963-
if (!baseGenericSig->haveSameShape(paramType, shapeClass))
5964-
continue;
5965-
5966-
auto *elementParam = GenericTypeParamType::get(/*isParameterPack*/false,
5967-
packElementDepth,
5968-
packElementParams.size(),
5969-
*this);
5970-
genericParams.push_back(elementParam);
5971-
packElementParams[paramType] = elementParam;
5972-
}
5973-
5974-
auto eraseParameterPackRec = [&](Type type) -> Type {
5975-
return type.transformTypeParameterPacks(
5976-
[&](SubstitutableType *t) -> std::optional<Type> {
5977-
if (auto *paramType = dyn_cast<GenericTypeParamType>(t)) {
5978-
if (packElementParams.find(paramType) != packElementParams.end()) {
5979-
return Type(packElementParams[paramType]);
5980-
}
5981-
5982-
return Type(t);
5983-
}
5984-
return std::nullopt;
5985-
});
5986-
};
5987-
5988-
for (auto requirement : baseGenericSig.getRequirements()) {
5989-
requirements.push_back(requirement);
5990-
5991-
// If this requirement contains parameter packs, create a new requirement
5992-
// for the corresponding pack element.
5993-
switch (requirement.getKind()) {
5994-
case RequirementKind::SameShape:
5995-
// Drop same-shape requirements from the element signature.
5996-
break;
5997-
case RequirementKind::Conformance:
5998-
case RequirementKind::Superclass:
5999-
case RequirementKind::SameType: {
6000-
auto firstType = eraseParameterPackRec(requirement.getFirstType());
6001-
auto secondType = eraseParameterPackRec(requirement.getSecondType());
6002-
if (firstType->isEqual(requirement.getFirstType()) &&
6003-
secondType->isEqual(requirement.getSecondType()))
6004-
break;
6005-
6006-
requirements.emplace_back(requirement.getKind(),
6007-
firstType, secondType);
6008-
break;
6009-
}
6010-
case RequirementKind::Layout: {
6011-
auto firstType = eraseParameterPackRec(requirement.getFirstType());
6012-
if (firstType->isEqual(requirement.getFirstType()))
6013-
break;
6014-
6015-
requirements.emplace_back(requirement.getKind(), firstType,
6016-
requirement.getLayoutConstraint());
6017-
break;
6018-
}
6019-
}
6020-
}
6021-
5931+
LocalArchetypeRequirementCollector collector(*this, baseGenericSig);
5932+
collector.addOpenedElement(shapeClass);
60225933
auto elementSig = buildGenericSignature(
6023-
*this, GenericSignature(), genericParams, requirements,
5934+
*this, collector.OuterSig, collector.Params, collector.Requirements,
60245935
/*allowInverses=*/false).getCanonicalSignature();
5936+
60255937
sigs[key] = elementSig;
60265938
return elementSig;
60275939
}

0 commit comments

Comments
 (0)