Skip to content

Commit e134ad7

Browse files
Merge pull request #41551 from nate-chandler/lexical_lifetimes/abort_apply-may-synchronize
[SIL] abort_apply insts maySynchronize.
2 parents 6b44cd8 + a19ad91 commit e134ad7

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
// =============================================================================
@@ -891,7 +892,7 @@ exit:
891892

892893
// Don't hoist over end_apply. These are lowered to calls to continuations
893894
// which can have the same sorts of side-effects as function calls.
894-
895+
//
895896
// CHECK-LABEL: sil [ossa] @dont_hoist_over_end_apply : {{.*}} {
896897
// CHECK: end_apply
897898
// CHECK: end_borrow
@@ -909,6 +910,40 @@ entry(%instance : @owned $C, %input : $S):
909910
return %retval : $()
910911
}
911912

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

0 commit comments

Comments
 (0)