mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[ConstraintSystem] Implement pack expansion type opening
Models `PackExpansionType` as a type variable that can only bind to `PackExpansionType` and `expansion of` constraint that connects expansion variable to its pattern, shape types.
This commit is contained in:
committed by
Pavel Yaskevich
parent
6437531dd7
commit
39c2bbb1ea
@@ -984,6 +984,32 @@ Type ConstraintSystem::openType(Type type, OpenedTypeMap &replacements) {
|
||||
});
|
||||
}
|
||||
|
||||
Type ConstraintSystem::openPackExpansionType(PackExpansionType *expansion,
|
||||
OpenedTypeMap &replacements) {
|
||||
auto patternType = openType(expansion->getPatternType(), replacements);
|
||||
auto shapeType = openType(expansion->getCountType(), replacements);
|
||||
|
||||
auto openedPackExpansion = PackExpansionType::get(patternType, shapeType);
|
||||
|
||||
auto known = OpenedPackExpansionTypes.find(openedPackExpansion);
|
||||
if (known != OpenedPackExpansionTypes.end())
|
||||
return known->second;
|
||||
|
||||
auto *expansionVar = createTypeVariable(
|
||||
getConstraintLocator({}, ConstraintLocator::PackExpansionType),
|
||||
TVO_PackExpansion);
|
||||
|
||||
// This constraint is important to make sure that pack expansion always
|
||||
// has a binding and connect pack expansion var to any type variables
|
||||
// that appear in pattern and shape types.
|
||||
addUnsolvedConstraint(Constraint::create(
|
||||
*this, ConstraintKind::Defaultable, expansionVar, openedPackExpansion,
|
||||
getConstraintLocator({}, ConstraintLocator::PackExpansionType)));
|
||||
|
||||
OpenedPackExpansionTypes[openedPackExpansion] = expansionVar;
|
||||
return expansionVar;
|
||||
}
|
||||
|
||||
Type ConstraintSystem::openOpaqueType(OpaqueTypeArchetypeType *opaque,
|
||||
ConstraintLocatorBuilder locator) {
|
||||
auto opaqueDecl = opaque->getDecl();
|
||||
|
||||
Reference in New Issue
Block a user