Skip to content

Commit ada87f4

Browse files
committed
Fix mark_unresolved_noncopyable_value instruction introduced for mutate accessor result
1 parent 15f241f commit ada87f4

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

include/swift/SIL/SILFunctionConventions.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,14 @@ class SILFunctionConventions {
352352
return resultConvention == ResultConvention::GuaranteedAddress;
353353
}
354354

355+
bool hasInoutResult() const {
356+
if (funcTy->getNumResults() != 1) {
357+
return false;
358+
}
359+
auto resultConvention = funcTy->getResults()[0].getConvention();
360+
return resultConvention == ResultConvention::Inout;
361+
}
362+
355363
struct SILResultTypeFunc;
356364

357365
// Gratuitous template parameter is to delay instantiating `mapped_iterator`

lib/SILGen/SILGenApply.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5491,9 +5491,14 @@ ManagedValue SILGenFunction::applyBorrowMutateAccessor(
54915491

54925492
if (rawResult->getType().isMoveOnly()) {
54935493
if (rawResult->getType().isAddress()) {
5494+
SILFunctionConventions substFnConv(substFnType, SGM.M);
54945495
auto result = B.createMarkUnresolvedNonCopyableValueInst(
54955496
loc, rawResult,
5496-
MarkUnresolvedNonCopyableValueInst::CheckKind::NoConsumeOrAssign);
5497+
substFnConv.hasInoutResult()
5498+
? MarkUnresolvedNonCopyableValueInst::CheckKind::
5499+
AssignableButNotConsumable
5500+
: MarkUnresolvedNonCopyableValueInst::CheckKind::
5501+
NoConsumeOrAssign);
54975502
return ManagedValue::forRValueWithoutOwnership(result);
54985503
}
54995504
auto result = emitManagedCopy(loc, rawResult);

test/SILGen/borrow_accessor.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ public struct GenNCWrapper<T : ~Copyable> : ~Copyable {
699699
// CHECK: [[REG3:%.*]] = struct_element_addr [[REG2]], #GenNCWrapper._w
700700
// CHECK: [[REG4:%.*]] = function_ref @$s15borrow_accessor15SimpleNCWrapperVAARi_zrlE4propxvz : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (@inout SimpleNCWrapper<τ_0_0>) -> @inout τ_0_0
701701
// CHECK: [[REG5:%.*]] = apply [[REG4]]<T>([[REG3]]) : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (@inout SimpleNCWrapper<τ_0_0>) -> @inout τ_0_0
702-
// CHECK: [[REG6:%.*]] = mark_unresolved_non_copyable_value [no_consume_or_assign] [[REG5]]
702+
// CHECK: [[REG6:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[REG5]]
703703
// CHECK: return [[REG6]]
704704
// CHECK: }
705705

@@ -719,7 +719,7 @@ public struct GenNCWrapper<T : ~Copyable> : ~Copyable {
719719
// CHECK: [[REG2:%.*]] = mark_unresolved_non_copyable_value [consumable_and_assignable] [[REG0]]
720720
// CHECK: [[REG3:%.*]] = function_ref @$s15borrow_accessor12GenNCWrapperVAARi_zrlE4propxvz : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (@inout GenNCWrapper<τ_0_0>) -> @inout τ_0_0
721721
// CHECK: [[REG4:%.*]] = apply [[REG3]]<T>([[REG2]]) : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (@inout GenNCWrapper<τ_0_0>) -> @inout τ_0_0
722-
// CHECK: [[REG5:%.*]] = mark_unresolved_non_copyable_value [no_consume_or_assign] [[REG4]]
722+
// CHECK: [[REG5:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[REG4]]
723723
// CHECK: return [[REG5]]
724724
// CHECK: }
725725

@@ -748,7 +748,7 @@ public struct GenNCWrapper<T : ~Copyable> : ~Copyable {
748748
// CHECK: [[REG3:%.*]] = struct_element_addr [[REG2]], #GenNCWrapper._ncw
749749
// CHECK: [[REG4:%.*]] = function_ref @$s15borrow_accessor9NCWrapperV2ncAA2NCVvz : $@convention(method) (@inout NCWrapper) -> @inout NC
750750
// CHECK: [[REG5:%.*]] = apply [[REG4]]([[REG3]]) : $@convention(method) (@inout NCWrapper) -> @inout NC
751-
// CHECK: [[REG6:%.*]] = mark_unresolved_non_copyable_value [no_consume_or_assign] [[REG5]]
751+
// CHECK: [[REG6:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[REG5]]
752752
// CHECK: return [[REG6]]
753753
// CHECK: }
754754

@@ -779,10 +779,10 @@ public struct GenNCWrapper<T : ~Copyable> : ~Copyable {
779779
// CHECK: [[REG2:%.*]] = mark_unresolved_non_copyable_value [consumable_and_assignable] [[REG0]]
780780
// CHECK: [[REG3:%.*]] = function_ref @$s15borrow_accessor12GenNCWrapperVAARi_zrlE3ncwAA0D0Vvz : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (@inout GenNCWrapper<τ_0_0>) -> @inout NCWrapper
781781
// CHECK: [[REG4:%.*]] = apply [[REG3]]<T>([[REG2]]) : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (@inout GenNCWrapper<τ_0_0>) -> @inout NCWrapper
782-
// CHECK: [[REG5:%.*]] = mark_unresolved_non_copyable_value [no_consume_or_assign] [[REG4]]
782+
// CHECK: [[REG5:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[REG4]]
783783
// CHECK: [[REG6:%.*]] = function_ref @$s15borrow_accessor9NCWrapperV2ncAA2NCVvz : $@convention(method) (@inout NCWrapper) -> @inout NC
784784
// CHECK: [[REG7:%.*]] = apply [[REG6]]([[REG5]]) : $@convention(method) (@inout NCWrapper) -> @inout NC
785-
// CHECK: [[REG8:%.*]] = mark_unresolved_non_copyable_value [no_consume_or_assign] [[REG7]]
785+
// CHECK: [[REG8:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[REG7]]
786786
// CHECK: return [[REG8]]
787787
// CHECK: }
788788

@@ -828,7 +828,7 @@ public struct GenNCWrapper<T : ~Copyable> : ~Copyable {
828828
// CHECK: [[REG6:%.*]] = apply [[REG5]]([[REG3]], [[REG4]]) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int
829829
// CHECK: [[REG7:%.*]] = function_ref @$s15borrow_accessor12GenNCWrapperVAARi_zrlEyxSiciz : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (Int, @inout GenNCWrapper<τ_0_0>) -> @inout τ_0_0
830830
// CHECK: [[REG8:%.*]] = apply [[REG7]]<T>([[REG6]], [[REG2]]) : $@convention(method) <τ_0_0 where τ_0_0 : ~Copyable> (Int, @inout GenNCWrapper<τ_0_0>) -> @inout τ_0_0
831-
// CHECK: [[REG9:%.*]] = mark_unresolved_non_copyable_value [no_consume_or_assign] [[REG8]]
831+
// CHECK: [[REG9:%.*]] = mark_unresolved_non_copyable_value [assignable_but_not_consumable] [[REG8]]
832832
// CHECK: return [[REG9]]
833833
// CHECK: }
834834

0 commit comments

Comments
 (0)