@@ -330,7 +330,7 @@ ManagedValue SILGenBuilder::createFormalAccessLoadTake(SILLocation loc,
330330 ManagedValue base) {
331331 if (SGF.getTypeLowering (base.getType ()).isTrivial ()) {
332332 auto *i = createLoad (loc, base.getValue (), LoadOwnershipQualifier::Trivial);
333- return ManagedValue::forUnmanaged (i);
333+ return ManagedValue::forObjectRValueWithoutOwnership (i);
334334 }
335335
336336 SILValue baseValue = base.getValue ();
@@ -342,7 +342,7 @@ ManagedValue SILGenBuilder::createFormalAccessLoadCopy(SILLocation loc,
342342 ManagedValue base) {
343343 if (SGF.getTypeLowering (base.getType ()).isTrivial ()) {
344344 auto *i = createLoad (loc, base.getValue (), LoadOwnershipQualifier::Trivial);
345- return ManagedValue::forUnmanaged (i);
345+ return ManagedValue::forObjectRValueWithoutOwnership (i);
346346 }
347347
348348 SILValue baseValue = base.getValue ();
@@ -590,7 +590,7 @@ SILGenBuilder::createMarkUninitialized(ValueDecl *decl, ManagedValue operand,
590590
591591 // If we have a trivial value, just return without a cleanup.
592592 if (operand.getOwnershipKind () != OwnershipKind::Owned) {
593- return ManagedValue::forUnmanaged (value);
593+ return ManagedValue::forObjectRValueWithoutOwnership (value);
594594 }
595595
596596 // Otherwise, recreate the cleanup.
@@ -600,8 +600,10 @@ SILGenBuilder::createMarkUninitialized(ValueDecl *decl, ManagedValue operand,
600600ManagedValue SILGenBuilder::createEnum (SILLocation loc, ManagedValue payload,
601601 EnumElementDecl *decl, SILType type) {
602602 SILValue result = createEnum (loc, payload.forward (SGF), decl, type);
603- if (result->getOwnershipKind () != OwnershipKind::Owned)
604- return ManagedValue::forUnmanaged (result);
603+ if (result->getOwnershipKind () == OwnershipKind::None)
604+ return ManagedValue::forObjectRValueWithoutOwnership (result);
605+ if (result->getOwnershipKind () == OwnershipKind::Guaranteed)
606+ return ManagedValue::forBorrowedObjectRValue (result);
605607 return SGF.emitManagedRValueWithCleanup (result);
606608}
607609
@@ -671,12 +673,13 @@ ManagedValue SILGenBuilder::createManagedOptionalNone(SILLocation loc,
671673 SILValue tempResult = SGF.emitTemporaryAllocation (loc, type);
672674 SGF.emitInjectOptionalNothingInto (loc, tempResult,
673675 SGF.getTypeLowering (type));
674- return ManagedValue::forUnmanaged (tempResult);
676+ return ManagedValue::forBorrowedAddressRValue (tempResult);
675677}
676678
677679ManagedValue SILGenBuilder::createManagedFunctionRef (SILLocation loc,
678680 SILFunction *f) {
679- return ManagedValue::forUnmanaged (createFunctionRefFor (loc, f));
681+ return ManagedValue::forObjectRValueWithoutOwnership (
682+ createFunctionRefFor (loc, f));
680683}
681684
682685ManagedValue SILGenBuilder::createTupleElementAddr (SILLocation Loc,
@@ -795,22 +798,22 @@ ManagedValue SILGenBuilder::createSuperMethod(SILLocation loc,
795798 SILDeclRef member,
796799 SILType methodTy) {
797800 SILValue v = createSuperMethod (loc, operand.getValue (), member, methodTy);
798- return ManagedValue::forUnmanaged (v);
801+ return ManagedValue::forObjectRValueWithoutOwnership (v);
799802}
800803
801804ManagedValue SILGenBuilder::createObjCSuperMethod (SILLocation loc,
802805 ManagedValue operand,
803806 SILDeclRef member,
804807 SILType methodTy) {
805808 SILValue v = createObjCSuperMethod (loc, operand.getValue (), member, methodTy);
806- return ManagedValue::forUnmanaged (v);
809+ return ManagedValue::forObjectRValueWithoutOwnership (v);
807810}
808811
809812ManagedValue SILGenBuilder::
810813createValueMetatype (SILLocation loc, SILType metatype,
811814 ManagedValue base) {
812815 SILValue v = createValueMetatype (loc, metatype, base.getValue ());
813- return ManagedValue::forUnmanaged (v);
816+ return ManagedValue::forObjectRValueWithoutOwnership (v);
814817}
815818
816819ManagedValue SILGenBuilder::createStoreBorrow (SILLocation loc,
@@ -897,7 +900,7 @@ ManagedValue SILGenBuilder::createTuple(SILLocation loc, SILType type,
897900 // Handle the empty tuple case.
898901 if (elements.empty ()) {
899902 SILValue result = createTuple (loc, type, ArrayRef<SILValue>());
900- return ManagedValue::forUnmanaged (result);
903+ return ManagedValue::forObjectRValueWithoutOwnership (result);
901904 }
902905
903906 // We need to look for the first value without .none ownership and use that as
@@ -916,7 +919,7 @@ ManagedValue SILGenBuilder::createTuple(SILLocation loc, SILType type,
916919 return mv.forward (getSILGenFunction ());
917920 });
918921 SILValue result = createTuple (loc, type, forwardedValues);
919- return ManagedValue::forUnmanaged (result);
922+ return ManagedValue::forObjectRValueWithoutOwnership (result);
920923 }
921924
922925 // Otherwise, we use that values cloner. This is taking advantage of
@@ -942,7 +945,7 @@ ManagedValue SILGenBuilder::createUncheckedTrivialBitCast(SILLocation loc,
942945 SILType type) {
943946 SILValue result =
944947 SGF.B .createUncheckedTrivialBitCast (loc, original.getValue (), type);
945- return ManagedValue::forUnmanaged (result);
948+ return ManagedValue::forObjectRValueWithoutOwnership (result);
946949}
947950
948951void SILGenBuilder::emitDestructureValueOperation (
0 commit comments