Skip to content

Commit

Permalink
Merge pull request #14187 from shajrawi/fix_part_apply
Browse files Browse the repository at this point in the history
IRGen: fix a corner-case wherein a partial_apply was not converted in LoadableByAddress
  • Loading branch information
Joe Shajrawi committed Jan 26, 2018
2 parents ef4624b + 350e921 commit 02fcdf1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
24 changes: 10 additions & 14 deletions lib/IRGen/LoadableByAddress.cpp
Expand Up @@ -79,24 +79,16 @@ static bool shouldTransformFunctionType(GenericEnvironment *env,
CanSILFunctionType fnType,
irgen::IRGenModule &IGM);

static SILParameterInfo getNewParameter(GenericEnvironment *env,
SILParameterInfo param,
irgen::IRGenModule &IGM);

static bool shouldTransformParameter(GenericEnvironment *env,
SILParameterInfo param,
irgen::IRGenModule &IGM) {
SILType storageType = param.getSILStorageType();

// FIXME: only function types and not recursively-transformable types?
if (auto fnType = storageType.getAs<SILFunctionType>())
return shouldTransformFunctionType(env, fnType, IGM);

switch (param.getConvention()) {
case ParameterConvention::Indirect_In_Guaranteed:
case ParameterConvention::Indirect_Inout:
case ParameterConvention::Indirect_InoutAliasable:
case ParameterConvention::Indirect_In:
return false;
default:
return isLargeLoadableType(env, storageType, IGM);
}
auto newParam = getNewParameter(env, param, IGM);
return (param != newParam);
}

static bool shouldTransformFunctionType(GenericEnvironment *env,
Expand Down Expand Up @@ -2558,6 +2550,10 @@ void LoadableByAddress::run() {
if (isa<ProjectBlockStorageInst>(dest)) {
storeToBlockStorageInstrs.insert(SI);
}
} else if (auto *PAI = dyn_cast<PartialApplyInst>(&I)) {
if (modApplies.count(PAI) == 0) {
modApplies.insert(PAI);
}
}
}
}
Expand Down
14 changes: 14 additions & 0 deletions test/IRGen/big_types_corner_cases.swift
Expand Up @@ -205,3 +205,17 @@ func bigStructGet() -> BigStruct {
public func testGetFunc() {
let testGetPtr: @convention(thin) () -> BigStruct = bigStructGet
}

// CHECK-LABEL: define{{( protected)?}} hidden swiftcc void @"$S22big_types_corner_cases7TestBigC4testyyF"(%T22big_types_corner_cases7TestBigC* swiftself)
// CHECK: [[CALL1:%.*]] = call %swift.type* @"$SSayy22big_types_corner_cases9BigStructVcSgGMa"
// CHECK: [[CALL2:%.*]] = call i8** @"$SSayy22big_types_corner_cases9BigStructVcSgGSayxGs10CollectionsWl
// 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
// CHECK: ret void
class TestBig {
typealias Handler = (BigStruct) -> Void

func test() {
let arr = [Handler?]()
let d = arr.index(where: { _ in true })
}
}

0 comments on commit 02fcdf1

Please sign in to comment.