Repository: apple/swift
File: lib/SILGen/SILGenApply.cpp (C++)

Code before:
      selfArgMV.getValue()->getType().isObject()) {
    uncurriedArgs.back() = ManagedValue::forBorrowedObjectRValue(
        lookThroughMoveOnlyCheckerPattern(selfArgMV.getValue()));
  }

  if (fnValue.getFunction()->getConventions().hasGuaranteedResult()) {
    if (isa<LoadBorrowInst>(selfArgMV)) {
      // unchecked_ownership is used to silence the ownership verifier for
      // returning a value produced within a load_borrow scope. SILGenCleanup
      // eliminates it and introduces return_borrow appropriately.
      uncurriedArgs.back() =
          ManagedValue::forForwardedRValue(
              SGF, SGF.B.createUncheckedOwnership(uncurriedLoc.value(),
                                                  selfArgMV.getValue()));
    }
  }

  auto value = SGF.applyBorrowMutateAccessor(
      uncurriedLoc.value(), fnValue, canUnwind, callee.getSubstitutions(),
      uncurriedArgs, calleeTypeInfo.substFnType, options);

  return value;
}

ManagedValue SILGenFunction::applyBorrowMutateAccessor(
    SILLocation loc, ManagedValue fn, bool canUnwind, SubstitutionMap subs,
    ArrayRef<ManagedValue> args, CanSILFunctionType substFnType,
    ApplyOptions options) {
  // Emit the call.
  SmallVector<SILValue, 4> rawResults;

  emitRawApply(*this, loc, fn, subs, args, substFnType, options,
               /*indirect results*/ {}, /*indirect errors*/ {}, rawResults,
               ExecutorBreadcrumb());
  assert(rawResults.size() == 1);
  auto rawResult = rawResults[0];

  if (rawResult->getType().isMoveOnly()) {
    if (rawResult->getType().isAddress()) {
      SILFunctionConventions substFnConv(substFnType, SGM.M);
      auto result = B.createMarkUnresolvedNonCopyableValueInst(
          loc, rawResult,
          substFnConv.hasInoutResult()
              ? MarkUnresolvedNonCopyableValueInst::CheckKind::
                    AssignableButNotConsumable
              : MarkUnresolvedNonCopyableValueInst::CheckKind::
                    NoConsumeOrAssign);
      return ManagedValue::forRValueWithoutOwnership(result);
    }
    auto result = emitManagedCopy(loc, rawResult);
    result = B.createMarkUnresolvedNonCopyableValueInst(

Review comment (suggestion):
@meg-gupta I removed this argument since "unwind" behavior isn't relevant for non-yielding borrow/mutate.  The argument was unused, as expected.

Code after:
      selfArgMV.getValue()->getType().isObject()) {
    uncurriedArgs.back() = ManagedValue::forBorrowedObjectRValue(
        lookThroughMoveOnlyCheckerPattern(selfArgMV.getValue()));
  }

  if (fnValue.getFunction()->getConventions().hasGuaranteedResult()) {
    if (isa<LoadBorrowInst>(selfArgMV)) {
      // unchecked_ownership is used to silence the ownership verifier for
      // returning a value produced within a load_borrow scope. SILGenCleanup
      // eliminates it and introduces return_borrow appropriately.
      uncurriedArgs.back() =
          ManagedValue::forForwardedRValue(
              SGF, SGF.B.createUncheckedOwnership(uncurriedLoc.value(),
                                                  selfArgMV.getValue()));
    }
  }

  auto value = SGF.applyBorrowMutateAccessor(
      uncurriedLoc.value(), fnValue, callee.getSubstitutions(),
      uncurriedArgs, calleeTypeInfo.substFnType, options);

  return value;
}

ManagedValue SILGenFunction::applyBorrowMutateAccessor(
    SILLocation loc, ManagedValue fn, SubstitutionMap subs,
    ArrayRef<ManagedValue> args, CanSILFunctionType substFnType,
    ApplyOptions options) {
  // Emit the call.
  SmallVector<SILValue, 4> rawResults;

  emitRawApply(*this, loc, fn, subs, args, substFnType, options,
               /*indirect results*/ {}, /*indirect errors*/ {}, rawResults,
               ExecutorBreadcrumb());
  assert(rawResults.size() == 1);
  auto rawResult = rawResults[0];

  if (rawResult->getType().isMoveOnly()) {
    if (rawResult->getType().isAddress()) {
      SILFunctionConventions substFnConv(substFnType, SGM.M);
      auto result = B.createMarkUnresolvedNonCopyableValueInst(
          loc, rawResult,
          substFnConv.hasInoutResult()
              ? MarkUnresolvedNonCopyableValueInst::CheckKind::
                    AssignableButNotConsumable
              : MarkUnresolvedNonCopyableValueInst::CheckKind::
                    NoConsumeOrAssign);
      return ManagedValue::forRValueWithoutOwnership(result);
    }
    auto result = emitManagedCopy(loc, rawResult);
    result = B.createMarkUnresolvedNonCopyableValueInst(