Skip to content

Commit 8371f14

Browse files
authored
Merge pull request #12915 from slavapestov/reabstract-bridged-value-4.1
SILGen: Fix bridging of optional function types to AnyObject [4.1]
2 parents 1cc577e + 1e61cd6 commit 8371f14

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,16 @@ emitBridgeNativeToObjectiveC(SILGenFunction &SGF,
127127
// Substitute into the witness function type.
128128
witnessFnTy = witnessFnTy.substGenericArgs(SGF.SGM.M, typeSubMap);
129129

130+
// We might have to re-abstract the 'self' value if it is an
131+
// Optional.
132+
AbstractionPattern origSelfType(witness->getInterfaceType());
133+
origSelfType = origSelfType.getFunctionInputType();
134+
135+
swiftValue = SGF.emitSubstToOrigValue(loc, swiftValue,
136+
origSelfType,
137+
swiftValueType,
138+
SGFContext());
139+
130140
// The witness may be more abstract than the concrete value we're bridging,
131141
// for instance, if the value is a concrete instantiation of a generic type.
132142
//

test/SILGen/objc_bridging_any.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -736,6 +736,16 @@ class AnyHashableClass : NSObject {
736736
}
737737
}
738738

739+
// CHECK-LABEL: sil hidden @_T017objc_bridging_any33bridgeOptionalFunctionToAnyObjectyXlyycSg2fn_tF : $@convention(thin) (@owned Optional<@callee_owned () -> ()>) -> @owned AnyObject
740+
// CHECK: [[BRIDGE:%.*]] = function_ref @_T0Sq19_bridgeToObjectiveCyXlyF
741+
// CHECK: [[FN:%.*]] = function_ref @_T0Iex_ytytIexir_TR
742+
// CHECK: partial_apply [[FN]]
743+
// CHECK: [[SELF:%.*]] = alloc_stack $Optional<@callee_owned (@in ()) -> @out ()>
744+
// CHECK: apply [[BRIDGE]]<() -> ()>([[SELF]])
745+
func bridgeOptionalFunctionToAnyObject(fn: (() -> ())?) -> AnyObject {
746+
return fn as AnyObject
747+
}
748+
739749
// CHECK-LABEL: sil_witness_table shared [serialized] GenericOption: Hashable module objc_generics {
740750
// CHECK-NEXT: base_protocol Equatable: GenericOption: Equatable module objc_generics
741751
// CHECK-NEXT: method #Hashable.hashValue!getter.1: {{.*}} : @_T0SC13GenericOptionVs8Hashable13objc_genericssACP9hashValueSivgTW

0 commit comments

Comments
 (0)