Skip to content

Commit dd7f5ec

Browse files
committed
[region-isolation] Handle ref_to_bridge_object especially.
I was correct that it is lookthrough, but it has multiple parameters, so the normal "baked" implementation cannot be used since the "baked" implementation assumes that any insts it handles has a single operand.
1 parent d4f727a commit dd7f5ec

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

lib/SILOptimizer/Analysis/RegionAnalysis.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,6 @@ CONSTANT_TRANSLATION(TupleInst, Assign)
23042304
CONSTANT_TRANSLATION(BeginAccessInst, LookThrough)
23052305
CONSTANT_TRANSLATION(BeginBorrowInst, LookThrough)
23062306
CONSTANT_TRANSLATION(BeginDeallocRefInst, LookThrough)
2307-
CONSTANT_TRANSLATION(RefToBridgeObjectInst, LookThrough)
23082307
CONSTANT_TRANSLATION(BridgeObjectToRefInst, LookThrough)
23092308
CONSTANT_TRANSLATION(CopyValueInst, LookThrough)
23102309
CONSTANT_TRANSLATION(ExplicitCopyValueInst, LookThrough)
@@ -2614,6 +2613,13 @@ CAST_WITH_MAYBE_SENDABLE_NONSENDABLE_OP_AND_RESULT(UncheckedValueCastInst)
26142613
// Custom Handling
26152614
//
26162615

2616+
TranslationSemantics
2617+
PartitionOpTranslator::visitRefToBridgeObjectInst(RefToBridgeObjectInst *r) {
2618+
translateSILLookThrough(
2619+
SILValue(r), r->getOperand(RefToBridgeObjectInst::ConvertedOperand));
2620+
return TranslationSemantics::Special;
2621+
}
2622+
26172623
TranslationSemantics
26182624
PartitionOpTranslator::visitPackElementGetInst(PackElementGetInst *r) {
26192625
if (!isNonSendableType(r->getType()))

test/Concurrency/transfernonsendable_instruction_matching.sil

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1627,3 +1627,23 @@ bb0:
16271627
%9999 = tuple ()
16281628
return %9999 : $()
16291629
}
1630+
1631+
sil @use_bridge_object : $@convention(thin) (@guaranteed Builtin.BridgeObject) -> ()
1632+
1633+
// ref_to_bridge_object is lookthrough in its first parameter. So we should
1634+
// error on the use, not that instruction.
1635+
sil [ossa] @ref_to_bridge_object_test : $@convention(thin) @async (Builtin.Word) -> () {
1636+
bb0(%arg : $Builtin.Word):
1637+
%constructFn = function_ref @constructNonSendableKlass : $@convention(thin) () -> @owned NonSendableKlass
1638+
%value = apply %constructFn() : $@convention(thin) () -> @owned NonSendableKlass
1639+
1640+
%transferNonSendableKlass = function_ref @transferNonSendableKlass : $@convention(thin) @async (@guaranteed NonSendableKlass) -> ()
1641+
apply [caller_isolation=nonisolated] [callee_isolation=global_actor] %transferNonSendableKlass(%value) : $@convention(thin) @async (@guaranteed NonSendableKlass) -> () // expected-warning {{transferring value of non-Sendable type 'NonSendableKlass' from nonisolated context to global actor '<null>'-isolated context; later accesses could race}}
1642+
1643+
%b = ref_to_bridge_object %value : $NonSendableKlass, %arg : $Builtin.Word
1644+
%bridgeUse = function_ref @use_bridge_object : $@convention(thin) (@guaranteed Builtin.BridgeObject) -> ()
1645+
apply %bridgeUse(%b) : $@convention(thin) (@guaranteed Builtin.BridgeObject) -> () // expected-note {{access here could race}}
1646+
destroy_value %b : $Builtin.BridgeObject
1647+
%9999 = tuple ()
1648+
return %9999 : $()
1649+
}

0 commit comments

Comments
 (0)