Skip to content

Commit 2df98a6

Browse files
committed
[sil-opaque-values] Add support for visitBindOptionalExpr.
1 parent b48b3b0 commit 2df98a6

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3992,7 +3992,7 @@ RValue RValueEmitter::visitBindOptionalExpr(BindOptionalExpr *E, SGFContext C) {
39923992
auto &optTL = SGF.getTypeLowering(E->getSubExpr()->getType());
39933993

39943994
ManagedValue optValue;
3995-
if (optTL.isLoadable()) {
3995+
if (!SGF.silConv.useLoweredAddresses() || optTL.isLoadable()) {
39963996
optValue = SGF.emitRValueAsSingleValue(E->getSubExpr());
39973997
} else {
39983998
auto temp = SGF.emitTemporary(E, optTL);

test/SILGen/opaque_values_silgen.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1050,6 +1050,29 @@ func s490_______loadBorrow() {
10501050
_ = foo.foo(pos: 1)
10511051
}
10521052

1053+
protocol ConvertibleToP {
1054+
func asP() -> P
1055+
}
1056+
1057+
// Test visitBindOptionalExpr
1058+
// ---
1059+
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s500_______getAnyHashAA1P_pSgAA14ConvertibleToP_pSgF : $@convention(thin) (@in Optional<ConvertibleToP>) -> @out Optional<P> {
1060+
// CHECK: bb0(%0 : $Optional<ConvertibleToP>):
1061+
// CHECK: [[BORROW:%.*]] = begin_borrow %0 : $Optional<ConvertibleToP>
1062+
// CHECK: [[COPY:%.*]] = copy_value [[BORROW]] : $Optional<ConvertibleToP>
1063+
// CHECK: [[DATA:%.*]] = unchecked_enum_data [[COPY]] : $Optional<ConvertibleToP>, #Optional.some!enumelt.1
1064+
// CHECK: [[VAL:%.*]] = open_existential_value [[DATA]] : $ConvertibleToP to $@opened("{{.*}}") ConvertibleToP
1065+
// CHECK: [[WT:%.*]] = witness_method $@opened("{{.*}}") ConvertibleToP, #ConvertibleToP.asP!1 : <Self where Self : ConvertibleToP> (Self) -> () -> P, %12 : $@opened("{{.*}}") ConvertibleToP : $@convention(witness_method) <τ_0_0 where τ_0_0 : ConvertibleToP> (@in_guaranteed τ_0_0) -> @out P
1066+
// CHECK: [[AS_P:%.*]] = apply [[WT]]<@opened("{{.*}}") ConvertibleToP>(%12) : $@convention(witness_method) <τ_0_0 where τ_0_0 : ConvertibleToP> (@in_guaranteed τ_0_0) -> @out P
1067+
// CHECK: [[ENUM:%.*]] = enum $Optional<P>, #Optional.some!enumelt.1, [[AS_P]] : $P
1068+
// CHECK: destroy_value [[DATA]] : $ConvertibleToP
1069+
// CHECK: end_borrow [[BORROW]] from %0 : $Optional<ConvertibleToP>, $Optional<ConvertibleToP>
1070+
// CHECK: br bb{{.*}}([[ENUM]] : $Optional<P>)
1071+
// CHECK: // end sil function '_T020opaque_values_silgen21s500_______getAnyHashAA1P_pSgAA14ConvertibleToP_pSgF'
1072+
func s500_______getAnyHash(_ value: ConvertibleToP?) -> P? {
1073+
return value?.asP()
1074+
}
1075+
10531076
// Tests conditional value casts and correspondingly generated reabstraction thunk, with <T> types
10541077
// ---
10551078
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s999_____condTFromAnyyyp_xtlF : $@convention(thin) <T> (@in Any, @in T) -> () {

0 commit comments

Comments
 (0)