From 118ca59bcce6f667d9e131de2690793a30cacd87 Mon Sep 17 00:00:00 2001 From: Nate Chandler Date: Wed, 22 Mar 2023 14:19:41 -0700 Subject: [PATCH] [SILOptimizer] hop_to_executor may synchronize. If a deinitializer has an external side-effect, it should execute after any other tasks have executed on the same actor with potentially external side effects. rdar://98542036 --- lib/SIL/Utils/MemAccessUtils.cpp | 3 ++- test/SILOptimizer/deinit_barrier.sil | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/lib/SIL/Utils/MemAccessUtils.cpp b/lib/SIL/Utils/MemAccessUtils.cpp index 19ddf784cc171..217c99f63d4d4 100644 --- a/lib/SIL/Utils/MemAccessUtils.cpp +++ b/lib/SIL/Utils/MemAccessUtils.cpp @@ -427,7 +427,8 @@ bool swift::mayLoadWeakOrUnowned(SILInstruction *instruction) { bool swift::maySynchronizeNotConsideringSideEffects(SILInstruction *instruction) { return FullApplySite::isa(instruction) || isa(instruction) - || isa(instruction); + || isa(instruction) + || isa(instruction); } bool swift::mayBeDeinitBarrierNotConsideringSideEffects(SILInstruction *instruction) { diff --git a/test/SILOptimizer/deinit_barrier.sil b/test/SILOptimizer/deinit_barrier.sil index 49a13dac32bca..574a472142b6d 100644 --- a/test/SILOptimizer/deinit_barrier.sil +++ b/test/SILOptimizer/deinit_barrier.sil @@ -85,3 +85,21 @@ entry: return %retval : $() } +actor A {} + +sil @getA : $() -> (@owned A) +sil @borrowA : $@yield_once @convention(thin) () -> @yields @guaranteed A + +// CHECK-LABEL: begin running test 1 of 1 on test_hop_to_executor: is-deinit-barrier +// CHECK: hop_to_executor +// CHECK: true +// CHECK-LABEL: end running test 1 of 1 on test_hop_to_executor: is-deinit-barrier +sil [ossa] @test_hop_to_executor : $@convention(thin) () -> () { + %borrowA = function_ref @borrowA : $@yield_once @convention(thin) () -> @yields @guaranteed A + (%a, %token) = begin_apply %borrowA() : $@yield_once @convention(thin) () -> @yields @guaranteed A + test_specification "is-deinit-barrier @instruction" + hop_to_executor %a : $A + end_apply %token + %retval = tuple () + return %retval : $() +}