Skip to content

Commit 162cbc3

Browse files
committed
AST: getOpenedElementSignature() uses LocalArchetypeRequirementCollector
1 parent 256589f commit 162cbc3

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
@@ -5931,100 +5931,12 @@ ASTContext::getOpenedElementSignature(CanGenericSignature baseGenericSig,
59315931
if (found != sigs.end())
59325932
return found->second;
59335933

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

0 commit comments

Comments
 (0)