Skip to content

Commit a19ad91

Browse files
committed
[SIL] abort_apply insts maySynchronize.
Just as a full apply may have side-effects including synchronization, so may an abort_apply, which is lowered to the apply of a continuation.
1 parent ac70bf7 commit a19ad91

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

lib/SIL/IR/SILInstruction.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1378,7 +1378,8 @@ bool SILInstruction::mayTrap() const {
13781378
bool SILInstruction::maySynchronize() const {
13791379
// TODO: We need side-effect analysis and library annotation for this to be
13801380
// a reasonable API. For now, this is just a placeholder.
1381-
return isa<FullApplySite>(this) || isa<EndApplyInst>(this);
1381+
return isa<FullApplySite>(this) || isa<EndApplyInst>(this) ||
1382+
isa<AbortApplyInst>(this);
13821383
}
13831384

13841385
bool SILInstruction::isMetaInstruction() const {

test/SILOptimizer/shrink_borrow_scope.sil

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ sil [ossa] @callee_optional_d_guaranteed: $@convention(thin) (@guaranteed Option
3636
sil [ossa] @synchronization_point : $@convention(thin) () -> ()
3737
sil [ossa] @modify_s : $@yield_once @convention(thin) () -> @yields @inout S
3838
sil [ossa] @barrier : $@convention(thin) () -> ()
39+
sil [ossa] @failable : $@convention(thin) () -> @error Error
3940

4041

4142
// =============================================================================
@@ -888,7 +889,7 @@ exit:
888889

889890
// Don't hoist over end_apply. These are lowered to calls to continuations
890891
// which can have the same sorts of side-effects as function calls.
891-
892+
//
892893
// CHECK-LABEL: sil [ossa] @dont_hoist_over_end_apply : {{.*}} {
893894
// CHECK: end_apply
894895
// CHECK: end_borrow
@@ -906,6 +907,40 @@ entry(%instance : @owned $C, %input : $S):
906907
return %retval : $()
907908
}
908909

910+
// Don't hoist over abort_apply. These are lowered to calls to continuations
911+
// which can have the same sorts of side-effects as function calls.
912+
//
913+
// CHECK-LABEL: sil [ossa] @dont_hoist_over_abort_apply : {{.*}} {
914+
// CHECK: {{bb[0-9]+}}([[REGISTER_1:%[^,]+]] : $Error):
915+
// CHECK: abort_apply
916+
// CHECK: end_borrow
917+
// CHECK: destroy_value
918+
// CHECK: tuple
919+
// CHECK: throw
920+
// CHECK-LABEL: } // end sil function 'dont_hoist_over_abort_apply'
921+
sil [ossa] @dont_hoist_over_abort_apply : $@convention(thin) (@owned C, S) -> @error Error {
922+
entry(%instance : @owned $C, %input : $S):
923+
%lifetime = begin_borrow [lexical] %instance : $C
924+
%callee_guaranteed = function_ref @callee_guaranteed : $@convention(thin) (@guaranteed C) -> ()
925+
apply %callee_guaranteed(%lifetime) : $@convention(thin) (@guaranteed C) -> ()
926+
%modify_s = function_ref @modify_s : $@yield_once @convention(thin) () -> @yields @inout S
927+
(%addr, %continuation) = begin_apply %modify_s() : $@yield_once @convention(thin) () -> @yields @inout S
928+
%failable = function_ref @failable : $@convention(thin) () -> @error Error
929+
try_apply %failable() : $@convention(thin) () -> @error Error, normal success, error failure
930+
success(%retval : $()):
931+
store %input to [trivial] %addr : $*S
932+
end_apply %continuation
933+
end_borrow %lifetime : $C
934+
destroy_value %instance : $C
935+
return %retval : $()
936+
failure(%error : $Error):
937+
abort_apply %continuation
938+
%blah = tuple ()
939+
end_borrow %lifetime : $C
940+
destroy_value %instance : $C
941+
throw %error : $Error
942+
}
943+
909944
// Don't hoist out of a block when one of its predecessors has a terminator that
910945
// is a use of the end_borrow.
911946
//

0 commit comments

Comments
 (0)