Skip to content

Commit 350e921

Browse files
author
Joe Shajrawi
committed
IRGen: fix a corner-case wherein a partial_apply was not converted in LoadableByAddress
It cleans up shouldTransformParameter, fixing a corner-case for optional function parameter, and re-creates *all* partial applies that only contain function/optional function parameters
1 parent 9c37cb8 commit 350e921

File tree

2 files changed

+24
-14
lines changed

2 files changed

+24
-14
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,24 +79,16 @@ static bool shouldTransformFunctionType(GenericEnvironment *env,
7979
CanSILFunctionType fnType,
8080
irgen::IRGenModule &IGM);
8181

82+
static SILParameterInfo getNewParameter(GenericEnvironment *env,
83+
SILParameterInfo param,
84+
irgen::IRGenModule &IGM);
85+
8286
static bool shouldTransformParameter(GenericEnvironment *env,
8387
SILParameterInfo param,
8488
irgen::IRGenModule &IGM) {
85-
SILType storageType = param.getSILStorageType();
86-
87-
// FIXME: only function types and not recursively-transformable types?
88-
if (auto fnType = storageType.getAs<SILFunctionType>())
89-
return shouldTransformFunctionType(env, fnType, IGM);
9089

91-
switch (param.getConvention()) {
92-
case ParameterConvention::Indirect_In_Guaranteed:
93-
case ParameterConvention::Indirect_Inout:
94-
case ParameterConvention::Indirect_InoutAliasable:
95-
case ParameterConvention::Indirect_In:
96-
return false;
97-
default:
98-
return isLargeLoadableType(env, storageType, IGM);
99-
}
90+
auto newParam = getNewParameter(env, param, IGM);
91+
return (param != newParam);
10092
}
10193

10294
static bool shouldTransformFunctionType(GenericEnvironment *env,
@@ -2558,6 +2550,10 @@ void LoadableByAddress::run() {
25582550
if (isa<ProjectBlockStorageInst>(dest)) {
25592551
storeToBlockStorageInstrs.insert(SI);
25602552
}
2553+
} else if (auto *PAI = dyn_cast<PartialApplyInst>(&I)) {
2554+
if (modApplies.count(PAI) == 0) {
2555+
modApplies.insert(PAI);
2556+
}
25612557
}
25622558
}
25632559
}

test/IRGen/big_types_corner_cases.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,17 @@ func bigStructGet() -> BigStruct {
205205
public func testGetFunc() {
206206
let testGetPtr: @convention(thin) () -> BigStruct = bigStructGet
207207
}
208+
209+
// CHECK-LABEL: define{{( protected)?}} hidden swiftcc void @"$S22big_types_corner_cases7TestBigC4testyyF"(%T22big_types_corner_cases7TestBigC* swiftself)
210+
// CHECK: [[CALL1:%.*]] = call %swift.type* @"$SSayy22big_types_corner_cases9BigStructVcSgGMa"
211+
// CHECK: [[CALL2:%.*]] = call i8** @"$SSayy22big_types_corner_cases9BigStructVcSgGSayxGs10CollectionsWl
212+
// CHECK: call swiftcc void @"$Ss10CollectionPsE5index5where5IndexQzSgSb7ElementQzKc_tKF"(%TSq.0* noalias nocapture sret {{.*}}, i8* bitcast (i1 (%T22big_types_corner_cases9BigStructVytIegir_Sg*, %swift.refcounted*, %swift.error**)* @"$S22big_types_corner_cases9BigStructVIegy_SgSbs5Error_pIgxdzo_ACytIegir_SgSbsAE_pIgidzo_TRTA" to i8*), %swift.refcounted* {{.*}}, %swift.type* [[CALL1]], i8** [[CALL2]], %swift.opaque* noalias nocapture swiftself
213+
// CHECK: ret void
214+
class TestBig {
215+
typealias Handler = (BigStruct) -> Void
216+
217+
func test() {
218+
let arr = [Handler?]()
219+
let d = arr.index(where: { _ in true })
220+
}
221+
}

0 commit comments

Comments
 (0)