Skip to content

Commit 626e708

Browse files
committed
[OpaqueValues] Fix @in_guaranteed loadable yields.
When opaque values are enabled, when yielding a value with an indirect convention, a value whose type's category is "object" must be yielded. Previously, if a value's type was loadable, an attempt was made to yield a value whose type's category was "address". Here, that's fixed. Additionally, handling for trivial types yielded via @in_guaranteed is added.
1 parent 0d666e2 commit 626e708

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

lib/SILGen/SILGenPoly.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1736,10 +1736,13 @@ static ManagedValue manageYield(SILGenFunction &SGF, SILValue value,
17361736
return ManagedValue::forUnmanaged(value);
17371737
return ManagedValue::forBorrowedObjectRValue(value);
17381738
case ParameterConvention::Indirect_In_Guaranteed: {
1739-
bool isOpaque = SGF.getTypeLowering(value->getType()).isAddressOnly() &&
1740-
!SGF.silConv.useLoweredAddresses();
1741-
return isOpaque ? ManagedValue::forBorrowedObjectRValue(value)
1742-
: ManagedValue::forBorrowedAddressRValue(value);
1739+
if (SGF.silConv.useLoweredAddresses()) {
1740+
return ManagedValue::forBorrowedAddressRValue(value);
1741+
}
1742+
if (value->getType().isTrivial(SGF.F)) {
1743+
return ManagedValue::forTrivialObjectRValue(value);
1744+
}
1745+
return ManagedValue::forBorrowedObjectRValue(value);
17431746
}
17441747
}
17451748
llvm_unreachable("bad kind");

test/SILGen/opaque_values_silgen_resilient.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,40 @@ public indirect enum OneOfThese : Hashable {
2828
}
2929

3030

31+
public protocol ProtocolWithAYield {
32+
associatedtype Assoc
33+
@_borrowed
34+
subscript() -> Assoc { get }
35+
}
36+
37+
public struct ResilientTrivialStruct {}
38+
39+
public struct StructYieldingAResilientTrivialValue : ProtocolWithAYield {
40+
var i: ResilientTrivialStruct
41+
public typealias Assoc = ResilientTrivialStruct
42+
// CHECK-LABEL: sil {{.*}}@$s30opaque_values_silgen_resilient36StructYieldingAResilientTrivialValueVAA18ProtocolWithAYieldA2aDP5AssocQzycirTW {{.*}} {
43+
// CHECK: yield {{%[^,]+}} : $ResilientTrivialStruct
44+
// CHECK-LABEL: } // end sil function '$s30opaque_values_silgen_resilient36StructYieldingAResilientTrivialValueVAA18ProtocolWithAYieldA2aDP5AssocQzycirTW'
45+
public subscript() -> ResilientTrivialStruct {
46+
_read {
47+
yield i
48+
}
49+
}
50+
}
51+
52+
public struct ResilientNontrivialStruct {
53+
var s: String
54+
}
55+
56+
public struct StructYieldingAResilientNonetrivialValue : ProtocolWithAYield {
57+
var i: ResilientNontrivialStruct
58+
public typealias Assoc = ResilientNontrivialStruct
59+
// CHECK-LABEL: sil {{.*}}@$s30opaque_values_silgen_resilient40StructYieldingAResilientNonetrivialValueVAA18ProtocolWithAYieldA2aDP5AssocQzycirTW {{.*}} {
60+
// CHECK: yield {{%[^,]+}} : $ResilientNontrivialStruct
61+
// CHECK-LABEL: } // end sil function '$s30opaque_values_silgen_resilient40StructYieldingAResilientNonetrivialValueVAA18ProtocolWithAYieldA2aDP5AssocQzycirTW'
62+
public subscript() -> ResilientNontrivialStruct {
63+
_read {
64+
yield i
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)