Skip to content

Commit f529072

Browse files
committed
Remove side-effects semantics from unchecked_ownership_converison.
I can't reason about whether this is correct to do, because SIL both uses the side-effects semantics to model arbitrary implicit dependencies and simultaneously considers them to be memory writes. What's more, the SIL instruction definitions almost *never* specify the actual constraints that we're attempting to approximate with the model. Be that as it may, we can't verify SIL if we "conservatively" consider instructions that don't write to memory to be writes. So I'll attempt to fix the undocumented model and find out what breaks. Fixes rdar://70737095 Unknown instruction: unchecked_ownership_conversion
1 parent 5329d92 commit f529072

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

include/swift/SIL/SILNodes.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ ABSTRACT_VALUE_AND_INST(SingleValueInstruction, ValueBase, SILInstruction)
575575
SingleValueInstruction, MayHaveSideEffects, DoesNotRelease)
576576
#include "swift/AST/ReferenceStorage.def"
577577
SINGLE_VALUE_INST(UncheckedOwnershipConversionInst, unchecked_ownership_conversion,
578-
SingleValueInstruction, MayHaveSideEffects, MayRelease)
578+
SingleValueInstruction, None, MayRelease)
579579

580580
// IsUnique does not actually write to memory but should be modeled
581581
// as such. Its operand is a pointer to an object reference. The

test/SILOptimizer/load_borrow_verify.sil

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,24 @@ bb0(%0 : @owned $AnyObject):
7676
dealloc_stack %1 : $*Optional<AnyObject>
7777
%99 = tuple ()
7878
return %99 : $()
79-
}
79+
}
80+
81+
// unchecked_ownership_conversion should not be considered a write to memory.
82+
class ObjectWrapper {
83+
var object: AnyObject
84+
}
85+
86+
// CHECK-LABEL: sil [ossa] @unchecked_ownership_conversion_test : $@convention(thin) (@guaranteed ObjectWrapper) -> @owned ObjectWrapper {
87+
// CHECK: bb0(%0 : @guaranteed $ObjectWrapper):
88+
// CHECK: load_borrow
89+
// CHECK: unchecked_ownership_conversion %0 : $ObjectWrapper, @guaranteed to @owned
90+
// CHECK: end_borrow
91+
// CHECK-LABEL: } // end sil function 'unchecked_ownership_conversion_test'
92+
sil [ossa] @unchecked_ownership_conversion_test : $@convention(thin) (@guaranteed ObjectWrapper) -> @owned ObjectWrapper {
93+
bb0(%0 : @guaranteed $ObjectWrapper):
94+
%1 = ref_element_addr %0 : $ObjectWrapper, #ObjectWrapper.object
95+
%2 = load_borrow %1 : $*AnyObject
96+
%3 = unchecked_ownership_conversion %0 : $ObjectWrapper, @guaranteed to @owned
97+
end_borrow %2 : $AnyObject
98+
return %3 : $ObjectWrapper
99+
}

0 commit comments

Comments
 (0)