Skip to content

Commit dade867

Browse files
committed
[OpaqueValues] Types with packs remain indirect.
For now, always use indirect convention for types with packs. This is motivated by the fact that getting from/setting to a pack currently requires addresses which aren't materialized for tuples. In the fullness of time, these values should be direct in opaque values mode, but for now it can be postponed.
1 parent 9f66d03 commit dade867

File tree

6 files changed

+46
-17
lines changed

6 files changed

+46
-17
lines changed

include/swift/SIL/SILFunctionConventions.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,10 @@ class SILModuleConventions {
5050
friend SILResultInfo;
5151
friend SILFunctionConventions;
5252

53+
static inline bool
54+
isTypeIndirectForIndirectParamConvention(CanType paramTy,
55+
bool loweredAddresses);
56+
5357
static bool isIndirectSILParam(SILParameterInfo param,
5458
bool loweredAddresses);
5559

@@ -97,6 +101,10 @@ class SILModuleConventions {
97101

98102
bool useLoweredAddresses() const { return loweredAddresses; }
99103

104+
bool isTypeIndirectForIndirectParamConvention(CanType paramTy) {
105+
return isTypeIndirectForIndirectParamConvention(paramTy, loweredAddresses);
106+
}
107+
100108
bool isSILIndirect(SILParameterInfo param) const {
101109
return isIndirectSILParam(param, loweredAddresses);
102110
}
@@ -522,6 +530,12 @@ SILModuleConventions::getFunctionConventions(CanSILFunctionType funcTy) {
522530
return SILFunctionConventions(funcTy, *this);
523531
}
524532

533+
inline bool SILModuleConventions::isTypeIndirectForIndirectParamConvention(
534+
CanType paramTy, bool loweredAddresses) {
535+
return (loweredAddresses || paramTy->isOpenedExistentialWithError() ||
536+
paramTy->hasAnyPack());
537+
}
538+
525539
inline bool SILModuleConventions::isIndirectSILParam(SILParameterInfo param,
526540
bool loweredAddresses) {
527541
switch (param.getConvention()) {
@@ -537,8 +551,8 @@ inline bool SILModuleConventions::isIndirectSILParam(SILParameterInfo param,
537551

538552
case ParameterConvention::Indirect_In:
539553
case ParameterConvention::Indirect_In_Guaranteed:
540-
return (loweredAddresses ||
541-
param.getInterfaceType()->isOpenedExistentialWithError());
554+
return isTypeIndirectForIndirectParamConvention(param.getInterfaceType(),
555+
loweredAddresses);
542556
case ParameterConvention::Indirect_Inout:
543557
case ParameterConvention::Indirect_InoutAliasable:
544558
return true;

lib/SIL/IR/SILValue.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -287,13 +287,17 @@ ValueOwnershipKind::ValueOwnershipKind(const SILFunction &F, SILType Type,
287287
}
288288

289289
switch (Convention) {
290-
case SILArgumentConvention::Indirect_In:
291-
value = moduleConventions.useLoweredAddresses() ? OwnershipKind::None
292-
: OwnershipKind::Owned;
293-
break;
294290
case SILArgumentConvention::Indirect_In_Guaranteed:
295-
value = moduleConventions.useLoweredAddresses() ? OwnershipKind::None
296-
: OwnershipKind::Guaranteed;
291+
value = moduleConventions.isTypeIndirectForIndirectParamConvention(
292+
Type.getASTType())
293+
? OwnershipKind::None
294+
: OwnershipKind::Guaranteed;
295+
break;
296+
case SILArgumentConvention::Indirect_In:
297+
value = moduleConventions.isTypeIndirectForIndirectParamConvention(
298+
Type.getASTType())
299+
? OwnershipKind::None
300+
: OwnershipKind::Owned;
297301
break;
298302
case SILArgumentConvention::Indirect_Inout:
299303
case SILArgumentConvention::Indirect_InoutAliasable:

test/SIL/Parser/opaque_values_parse.sil

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,17 +118,20 @@ bb0(%instance : @guaranteed $WeakBox<T>):
118118
// Test tuple_pack_extract parsing.
119119

120120
// CHECK-LABEL: sil [ossa] @test_tuple_pack_extract : {{.*}} {
121-
// CHECK: bb0([[TUPLE:%[^,]+]] :
121+
// CHECK: bb0([[TUPLE_ADDR:%[^,]+]] :
122+
// CHECK: [[TUPLE:%[^,]+]] = load_borrow [[TUPLE_ADDR]]
122123
// CHECK: [[ZERO:%[^,]+]] = integer_literal
123124
// CHECK: [[INDEX:%[^,]+]] = dynamic_pack_index [[ZERO]]
124125
// CHECK: [[ELT:%[^,]+]] = tuple_pack_extract [[INDEX]] of [[TUPLE]]
125126
// CHECK-LABEL: } // end sil function 'test_tuple_pack_extract'
126127
sil [ossa] @test_tuple_pack_extract : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> () {
127-
entry(%tuple : @guaranteed $(repeat each T)):
128+
entry(%tuple_addr : $*(repeat each T)):
129+
%tuple = load_borrow %tuple_addr : $*(repeat each T)
128130
%zero = integer_literal $Builtin.Word, 0
129131
%index = dynamic_pack_index %zero of $Pack{repeat each T}
130132
%opened = open_pack_element %index of <each U_1> at <Pack{repeat each T}>, shape $U_1, uuid "00000000-0000-0000-0000-000000000000"
131133
%elt = tuple_pack_extract %index of %tuple : $(repeat each T) as $@pack_element("00000000-0000-0000-0000-000000000000") U_1
134+
end_borrow %tuple : $(repeat each T)
132135
%retval = tuple ()
133136
return %retval : $()
134137
}

test/SIL/Serialization/opaque_values_serialize.sil

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,17 +102,20 @@ bb0(%instance : @guaranteed $WeakBox<T>):
102102
// Test tuple_pack_extract parsing.
103103

104104
// CHECK-LABEL: sil [ossa] @test_tuple_pack_extract : {{.*}} {
105-
// CHECK: bb0([[TUPLE:%[^,]+]] :
105+
// CHECK: bb0([[TUPLE_ADDR:%[^,]+]] :
106+
// CHECK: [[TUPLE:%[^,]+]] = load_borrow [[TUPLE_ADDR]]
106107
// CHECK: [[ZERO:%[^,]+]] = integer_literal
107108
// CHECK: [[INDEX:%[^,]+]] = dynamic_pack_index [[ZERO]]
108109
// CHECK: [[ELT:%[^,]+]] = tuple_pack_extract [[INDEX]] of [[TUPLE]]
109110
// CHECK-LABEL: } // end sil function 'test_tuple_pack_extract'
110111
sil [ossa] @test_tuple_pack_extract : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> () {
111-
entry(%tuple : @guaranteed $(repeat each T)):
112+
entry(%tuple_addr : $*(repeat each T)):
113+
%tuple = load_borrow %tuple_addr : $*(repeat each T)
112114
%zero = integer_literal $Builtin.Word, 0
113115
%index = dynamic_pack_index %zero of $Pack{repeat each T}
114116
%opened = open_pack_element %index of <each U_1> at <Pack{repeat each T}>, shape $U_1, uuid "00000000-0000-0000-0000-000000000000"
115117
%elt = tuple_pack_extract %index of %tuple : $(repeat each T) as $@pack_element("00000000-0000-0000-0000-000000000000") U_1
118+
end_borrow %tuple : $(repeat each T)
116119
%retval = tuple ()
117120
return %retval : $()
118121
}

test/SIL/cloning_opaque_values.sil

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,28 @@ bb0(%instance : @guaranteed $WeakBox<T>):
3030
}
3131

3232
// CHECK-LABEL: sil [ossa] @tuple_pack_extract_caller : {{.*}} {
33-
// CHECK: bb0([[TUPLE:%[^,]+]] :
33+
// CHECK: bb0([[TUPLE_ADDR:%[^,]+]] :
34+
// CHECK: [[TUPLE:%[^,]+]] = load_borrow [[TUPLE_ADDR]]
3435
// CHECK: [[ZERO:%[^,]+]] = integer_literal
3536
// CHECK: [[INDEX:%[^,]+]] = dynamic_pack_index [[ZERO]]
3637
// CHECK: open_pack_element [[INDEX]] of <each U_1> at <Pack{repeat each T}>, shape $each U_1, uuid [[UUID:"[A-F0-9\-]+"]]
3738
// CHECK: tuple_pack_extract [[INDEX]] of [[TUPLE]] : $(repeat each T) as $@pack_element([[UUID]]) each U_1
3839
// CHECK-LABEL: } // end sil function 'tuple_pack_extract_caller'
3940
sil [ossa] @tuple_pack_extract_caller : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> () {
40-
entry(%tuple : @guaranteed $(repeat each T)):
41+
entry(%tuple_addr : $*(repeat each T)):
4142
%callee = function_ref @tuple_pack_extract : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> ()
42-
%retval = apply %callee<Pack{repeat each T}>(%tuple) : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> ()
43+
%retval = apply %callee<Pack{repeat each T}>(%tuple_addr) : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> ()
4344
return %retval : $()
4445
}
4546

4647
sil [always_inline] [ossa] @tuple_pack_extract : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> () {
47-
entry(%tuple : @guaranteed $(repeat each T)):
48+
entry(%tuple_addr : $*(repeat each T)):
49+
%tuple = load_borrow %tuple_addr : $*(repeat each T)
4850
%zero = integer_literal $Builtin.Word, 0
4951
%index = dynamic_pack_index %zero of $Pack{repeat each T}
5052
%opened = open_pack_element %index of <each U_1> at <Pack{repeat each T}>, shape $U_1, uuid "00000000-0000-0000-0000-000000000000"
5153
%elt = tuple_pack_extract %index of %tuple : $(repeat each T) as $@pack_element("00000000-0000-0000-0000-000000000000") U_1
54+
end_borrow %tuple : $(repeat each T)
5255
%retval = tuple ()
5356
return %retval : $()
5457
}

test/SILOptimizer/address_lowering.sil

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2697,13 +2697,15 @@ entry:
26972697
// CHECK: apply [[BORROW]]<@pack_element([[UUID]]) each U_1>([[ELEMENT_ADDR]])
26982698
// CHECK-LABEL: } // end sil function 'test_tuple_pack_extract'
26992699
sil [ossa] @test_tuple_pack_extract : $@convention(thin) <each T> (@in_guaranteed (repeat each T)) -> () {
2700-
entry(%tuple : @guaranteed $(repeat each T)):
2700+
entry(%tuple_addr : $*(repeat each T)):
2701+
%tuple = load_borrow %tuple_addr : $*(repeat each T)
27012702
%zero = integer_literal $Builtin.Word, 0
27022703
%index = dynamic_pack_index %zero of $Pack{repeat each T}
27032704
%opened = open_pack_element %index of <each U_1> at <Pack{repeat each T}>, shape $U_1, uuid "00000000-0000-0000-0000-000000000002"
27042705
%elt = tuple_pack_extract %index of %tuple : $(repeat each T) as $@pack_element("00000000-0000-0000-0000-000000000002") U_1
27052706
%borrow = function_ref @borrowT : $@convention(thin) <T> (@in_guaranteed T) -> ()
27062707
apply %borrow<@pack_element("00000000-0000-0000-0000-000000000002") U_1>(%elt) : $@convention(thin) <T> (@in_guaranteed T) -> ()
2708+
end_borrow %tuple : $(repeat each T)
27072709
%retval = tuple ()
27082710
return %retval : $()
27092711
}

0 commit comments

Comments
 (0)