Skip to content

Commit 7cdc55d

Browse files
author
Joe Shajrawi
committed
Support opaque values inside open existential boxes
1 parent 48c10aa commit 7cdc55d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/SIL/SILVerifier.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2210,7 +2210,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
22102210

22112211
CanType resultInstanceTy = OEI->getType().getSwiftRValueType();
22122212

2213-
require(OEI->getType().isAddress(),
2213+
require(OEI->getType().isAddress() || !fnConv.useLoweredAddresses(),
22142214
"open_existential_box result must be an address");
22152215

22162216
auto archetype = getOpenedArchetypeOf(resultInstanceTy);

test/SILGen/opaque_values_silgen.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,3 +325,18 @@ func s200______use_foo_var() {
325325
func s210______compErasure(_ x: Foo & Error) -> Error {
326326
return x
327327
}
328+
329+
// Tests that existential boxes can contain opaque types
330+
// ---
331+
// CHECK-LABEL: sil hidden @_T020opaque_values_silgen21s220_____openExistBoxSSs5Error_pF : $@convention(thin) (@owned Error) -> @owned String {
332+
// CHECK: bb0([[ARG:%.*]] : $Error):
333+
// CHECK: [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
334+
// CHECK: [[OPAQUE_ARG:%.*]] = open_existential_box [[BORROWED_ARG]] : $Error to $@opened({{.*}}) Error
335+
// CHECK: [[RET_STRING:%.*]] = apply{{.*}}<@opened({{.*}}) Error>([[OPAQUE_ARG]]) : $@convention(witness_method) <τ_0_0 where τ_0_0 : Error> (@in_guaranteed τ_0_0) -> @owned String
336+
// CHECK: end_borrow [[BORROWED_ARG]] from [[ARG]]
337+
// CHECK: destroy_value [[ARG]] : $Error
338+
// CHECK: return [[RET_STRING]] : $String
339+
// CHECK-LABEL: } // end sil function '_T020opaque_values_silgen21s220_____openExistBoxSSs5Error_pF'
340+
func s220_____openExistBox(_ x: Error) -> String {
341+
return x._domain
342+
}

0 commit comments

Comments
 (0)