Skip to content

Commit 992caba

Browse files
author
Joe Shajrawi
committed
support stores of non-loadable types under opaque mode
1 parent c724ddb commit 992caba

File tree

4 files changed

+21
-7
lines changed

4 files changed

+21
-7
lines changed

lib/SIL/TypeLowering.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1129,11 +1129,6 @@ namespace {
11291129
llvm_unreachable("store copy");
11301130
}
11311131

1132-
void emitStore(SILBuilder &B, SILLocation loc, SILValue value,
1133-
SILValue addr, StoreOwnershipQualifier qual) const override {
1134-
llvm_unreachable("store");
1135-
}
1136-
11371132
SILValue emitLoad(SILBuilder &B, SILLocation loc, SILValue addr,
11381133
LoadOwnershipQualifier qual) const override {
11391134
llvm_unreachable("store");

lib/SILGen/RValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ class ExplodeTupleValue
9595
// Project the element.
9696
SILValue elt;
9797
if (tuple->getType().isObject()) {
98-
assert(eltTI.isLoadable());
98+
assert(eltTI.isLoadable() || !gen.silConv.useLoweredAddresses());
9999
elt = gen.B.createTupleExtract(loc, tuple, i, eltTy);
100100
} else {
101101
elt = gen.B.createTupleElementAddr(loc, tuple, i, eltTy);

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ class EmitBBArguments : public CanTypeVisitor<EmitBBArguments,
169169
elements.push_back(elt);
170170
}
171171

172-
if (tl.isLoadable()) {
172+
if (tl.isLoadable() || !gen.silConv.useLoweredAddresses()) {
173173
SmallVector<SILValue, 4> elementValues;
174174
if (canBeGuaranteed) {
175175
// If all of the elements were guaranteed, we can form a guaranteed tuple.

test/SILGen/opaque_values_silgen.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,25 @@ func assigninout<T>(_ a: inout T, _ b: T) {
4141
a = b
4242
}
4343

44+
// Test that we no longer use copy_addr or tuple_element_addr when copy by value is possible
45+
// ---
46+
// CHECK-LABEL: sil hidden @_TF20opaque_values_silgen14tupleReturnInturFTSix_Si : $@convention(thin) <T> (Int, @in T) -> Int {
47+
// CHECK: bb0([[ARG0:%.*]] : $Int, [[ARG1:%.*]] : $T):
48+
// CHECK: [[TPL:%.*]] = tuple ([[ARG0]] : $Int, [[ARG1]] : $T)
49+
// CHECK: [[BORROWED_ARG1:%.*]] = begin_borrow [[TPL]] : $(Int, T)
50+
// CHECK: [[CPY:%.*]] = copy_value [[BORROWED_ARG1]] : $(Int, T)
51+
// CHECK: [[INT:%.*]] = tuple_extract [[CPY]] : $(Int, T), 0
52+
// CHECK: [[GEN:%.*]] = tuple_extract [[CPY]] : $(Int, T), 1
53+
// CHECK: destroy_value [[GEN]] : $T
54+
// CHECK: end_borrow [[BORROWED_ARG1]] from [[TPL]] : $(Int, T), $(Int, T)
55+
// CHECK: destroy_value [[TPL]] : $(Int, T)
56+
// CHECK: return [[INT]]
57+
// CHECK: } // end sil function '_TF20opaque_values_silgen14tupleReturnInturFTSix_Si'
58+
func tupleReturnInt<T>(_ x: (Int, T)) -> Int {
59+
let y = x.0
60+
return y
61+
}
62+
4463
// SILGen, prepareArchetypeCallee. Materialize a
4564
// non-class-constrainted self from a class-constrained archetype.
4665
// ---

0 commit comments

Comments
 (0)