SIL: Stub out type lowering of function types containing pack expansions

This commit is contained in:
Slava Pestov
2022-12-05 14:09:32 -05:00
parent 5b9aef91f8
commit f9141e1aa1
3 changed files with 49 additions and 4 deletions

View File

@@ -934,6 +934,20 @@ public:
}
}
bool isTypeParameterPack() const {
switch (getKind()) {
case Kind::Opaque:
return false;
case Kind::Type:
case Kind::ClangType:
case Kind::Discard: {
return getType()->isParameterPack();
}
default:
return false;
}
}
/// Is this an interface type that is subject to a concrete
/// same-type constraint?
bool isConcreteType() const;

View File

@@ -1584,7 +1584,15 @@ public:
// If so, let's put a fresh generic parameter in the substituted signature
// here.
unsigned paramIndex = substGenericParams.size();
auto gp = GenericTypeParamType::get(false, 0, paramIndex, TC.Context);
bool isParameterPack = false;
if (substTy->isParameterPack() || substTy->is<PackArchetypeType>())
isParameterPack = true;
else if (pattern.isTypeParameterPack())
isParameterPack = true;
auto gp = GenericTypeParamType::get(isParameterPack, 0, paramIndex,
TC.Context);
substGenericParams.push_back(gp);
substReplacementTypes.push_back(substTy);
@@ -1881,11 +1889,30 @@ public:
}
CanType visitPackType(PackType *pack, AbstractionPattern pattern) {
llvm_unreachable("Unimplemented!");
if (auto gp = handleTypeParameterInAbstractionPattern(pattern, pack))
return gp;
// Break down the pack.
SmallVector<Type, 4> packElts;
for (unsigned i = 0; i < pack->getNumElements(); ++i) {
packElts.push_back(visit(pack->getElementType(i),
pattern.getPackElementType(i)));
}
return CanType(PackType::get(TC.Context, packElts));
}
CanType visitPackExpansionType(PackExpansionType *pack, AbstractionPattern pattern) {
llvm_unreachable("Unimplemented!");
CanType visitPackExpansionType(PackExpansionType *pack,
AbstractionPattern pattern) {
// Avoid walking into the pattern and count type if we can help it.
if (!pack->hasTypeParameter() && !pack->hasArchetype() &&
!pack->hasOpaqueArchetype()) {
return CanType(pack);
}
return CanType(PackExpansionType::get(
visit(pack->getPatternType(), pattern.getPackExpansionPatternType()),
visit(pack->getCountType(), pattern.getPackExpansionCountType())));
}
CanType visitExistentialType(ExistentialType *exist,

View File

@@ -11,4 +11,8 @@ public struct VariadicType<T...> {
// CHECK-LABEL: sil [ossa] @$s19pack_expansion_type12VariadicTypeV14variadicMethod1t1ux_qd__txQp_txxQp_qd__qd__Qptqd__RhzlF : $@convention(method) <T...><U... where ((T, U)...) : Any> (@in_guaranteed T..., @in_guaranteed U..., VariadicType<T...>) -> @out (T, U)... {
// CHECK: bb0(%0 : $*(T, U)..., %1 : $*T..., %2 : $*U..., %3 : $VariadicType<T...>):
public func variadicMethod<U...>(t: T..., u: U...) -> ((T, U)...) {}
// CHECK-LABEL: sil [ossa] @$s19pack_expansion_type12VariadicTypeV13takesFunction1tyqd__qd__Qp_txxQpXE_tlF : $@convention(method) <T...><U...> (@noescape @callee_guaranteed @substituted <τ_0_0..., τ_0_1..., τ_0_2..., τ_0_3...> (@in_guaranteed τ_0_0...) -> @out τ_0_2... for <T, T, U, U>, VariadicType<T...>) -> () {
// CHECK: bb0(%0 : $@noescape @callee_guaranteed @substituted <τ_0_0..., τ_0_1..., τ_0_2..., τ_0_3...> (@in_guaranteed τ_0_0...) -> @out τ_0_2... for <T, T, U, U>, %1 : $VariadicType<T...>):
public func takesFunction<U...>(t: (T...) -> (U...)) {}
}