Skip to content

Commit 62c6ed2

Browse files
committed
[region-isolation] Add support for open_existential_value.
1 parent 4bba194 commit 62c6ed2

File tree

3 files changed

+29
-2
lines changed

3 files changed

+29
-2
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ static bool isStaticallyLookThroughInst(SILInstruction *inst) {
212212
case SILInstructionKind::MoveOnlyWrapperToCopyableValueInst:
213213
case SILInstructionKind::MoveValueInst:
214214
case SILInstructionKind::OpenExistentialAddrInst:
215+
case SILInstructionKind::OpenExistentialValueInst:
215216
case SILInstructionKind::ProjectBlockStorageInst:
216217
case SILInstructionKind::ProjectBoxInst:
217218
case SILInstructionKind::RefToBridgeObjectInst:
@@ -2336,6 +2337,7 @@ CONSTANT_TRANSLATION(UnownedCopyValueInst, LookThrough)
23362337
CONSTANT_TRANSLATION(DropDeinitInst, LookThrough)
23372338
CONSTANT_TRANSLATION(ValueToBridgeObjectInst, LookThrough)
23382339
CONSTANT_TRANSLATION(BeginCOWMutationInst, LookThrough)
2340+
CONSTANT_TRANSLATION(OpenExistentialValueInst, LookThrough)
23392341

23402342
//===---
23412343
// Store
@@ -2466,7 +2468,6 @@ CONSTANT_TRANSLATION(ExistentialMetatypeInst, Unhandled)
24662468
CONSTANT_TRANSLATION(InitExistentialValueInst, Unhandled)
24672469
CONSTANT_TRANSLATION(InitExistentialMetatypeInst, Unhandled)
24682470
CONSTANT_TRANSLATION(OpenExistentialMetatypeInst, Unhandled)
2469-
CONSTANT_TRANSLATION(OpenExistentialValueInst, Unhandled)
24702471

24712472
//===---
24722473
// Differentiable

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1586,4 +1586,4 @@ bb0:
15861586

15871587
%9999 = tuple ()
15881588
return %9999 : $()
1589-
}
1589+
}

test/Concurrency/transfernonsendable_instruction_matching_opaquevalues.sil

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ case none
5252
case some(T)
5353
}
5454

55+
protocol P {
56+
func doSomething()
57+
}
58+
5559
/////////////////
5660
// MARK: Tests //
5761
/////////////////
@@ -92,3 +96,25 @@ bb0:
9296
%9999 = tuple ()
9397
return %9999 : $()
9498
}
99+
100+
sil @initP : $@convention(thin) () -> @owned P
101+
sil @transferP : $@async @convention(thin) (@guaranteed P) -> ()
102+
103+
sil [ossa] @open_existential_value_test : $@async @convention(thin) () -> () {
104+
bb0:
105+
%f = function_ref @initP : $@convention(thin) () -> @owned P
106+
%p = apply %f() : $@convention(thin) () -> @owned P
107+
108+
%transferP = function_ref @transferP : $@async @convention(thin) (@guaranteed P) -> ()
109+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferP(%p) : $@async @convention(thin) (@guaranteed P) -> () // expected-warning {{transferring value of non-Sendable type 'any P' from nonisolated context to global actor '<null>'-isolated context}}
110+
111+
%b = begin_borrow %p : $P
112+
%v = open_existential_value %b : $P to $@opened("EF755EF2-B636-11E7-B7B4-A45E60ECC541", P) Self
113+
%w = witness_method $@opened("EF755EF2-B636-11E7-B7B4-A45E60ECC541", P) Self, #P.doSomething, %v : $@opened("EF755EF2-B636-11E7-B7B4-A45E60ECC541", P) Self : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> ()
114+
apply %w<@opened("EF755EF2-B636-11E7-B7B4-A45E60ECC541", P) Self>(%v) : $@convention(witness_method: P) <τ_0_0 where τ_0_0 : P> (@in_guaranteed τ_0_0) -> () // expected-note {{access here could race}}
115+
end_borrow %b : $P
116+
destroy_value %p : $P
117+
118+
%9999 = tuple ()
119+
return %9999 : $()
120+
}

0 commit comments

Comments
 (0)