Skip to content

Commit 8379601

Browse files
committed
SIL: Don't recursively lower ExistentialType and ParameterizedProtocolType
1 parent 09b061b commit 8379601

File tree

2 files changed

+11
-41
lines changed

2 files changed

+11
-41
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2912,47 +2912,6 @@ TypeConverter::computeLoweredRValueType(TypeExpansionContext forExpansion,
29122912
MetatypeRepresentation::Thick);
29132913
}
29142914

2915-
CanType visitExistentialType(CanExistentialType substExistType) {
2916-
// Try to avoid walking into the constraint type if we can help it
2917-
if (!substExistType->hasTypeParameter() &&
2918-
!substExistType->hasArchetype() &&
2919-
!substExistType->hasOpaqueArchetype()) {
2920-
return substExistType;
2921-
}
2922-
2923-
return CanExistentialType::get(visit(substExistType.getConstraintType()));
2924-
}
2925-
2926-
CanType
2927-
visitParameterizedProtocolType(CanParameterizedProtocolType substPPT) {
2928-
bool changed = false;
2929-
SmallVector<Type, 4> loweredSubstArgs;
2930-
loweredSubstArgs.reserve(substPPT.getArgs().size());
2931-
2932-
auto origConstraint = origType.getExistentialConstraintType();
2933-
auto origPPT = origConstraint.getAs<ParameterizedProtocolType>();
2934-
if (!origPPT)
2935-
return substPPT;
2936-
2937-
for (auto i : indices(substPPT.getArgs())) {
2938-
auto origArgTy = AbstractionPattern(
2939-
origConstraint.getGenericSignatureOrNull(), origPPT.getArgs()[i]);
2940-
auto substArgType = substPPT.getArgs()[i];
2941-
2942-
CanType loweredSubstEltType =
2943-
TC.getLoweredRValueType(forExpansion, origArgTy, substArgType);
2944-
changed = changed || substArgType != loweredSubstEltType;
2945-
2946-
loweredSubstArgs.push_back(loweredSubstEltType);
2947-
}
2948-
2949-
if (!changed)
2950-
return substPPT;
2951-
2952-
return CanParameterizedProtocolType::get(
2953-
TC.Context, substPPT->getBaseType(), loweredSubstArgs);
2954-
}
2955-
29562915
// Lower pack element types.
29572916
CanType visitPackType(CanPackType substPackType) {
29582917
return computeLoweredPackType(TC, forExpansion, origType,

test/SILGen/parameterized_existentials.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,3 +98,14 @@ func upcastResult() {
9898
func force<T, U, V>() -> any P<T, U, V> {
9999
return R(force: { force() }).force()
100100
}
101+
102+
protocol Box<Contents> {
103+
associatedtype Contents
104+
105+
var contents: Contents { get }
106+
}
107+
108+
// CHECK-LABEL: sil hidden [ossa] @$s13parameterized13functionTypes3box5valueq_AA3Box_pq_xc8ContentsRts_XP_xtr0_lF : $@convention(thin) <T, U> (@in_guaranteed any Box<(T) -> U>, @in_guaranteed T) -> @out U {
109+
func functionTypes<T, U>(box: any Box<(T) -> U>, value: T) -> U {
110+
return box.contents(value)
111+
}

0 commit comments

Comments
 (0)