Skip to content

Commit d7be399

Browse files
authored
Merge pull request #67943 from gottesmm/pr-c5eb72c4d397b9ab4e8a1b477187c3b7b059f540
[silgen] Convert even more cases of using trivial and values without ownership to use for*RValueWithoutOwnership APIs.
2 parents 1219459 + ff948f7 commit d7be399

File tree

9 files changed

+49
-43
lines changed

9 files changed

+49
-43
lines changed

lib/SILGen/SILGenBridging.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -681,7 +681,7 @@ static ManagedValue emitNativeToCBridgedNonoptionalValue(SILGenFunction &SGF,
681681
// when they are converted to an object via objc_metatype_to_object.
682682
assert(!v.hasCleanup() &&
683683
"Metatypes are trivial and thus should not have cleanups");
684-
return ManagedValue::forUnmanaged(native);
684+
return ManagedValue::forObjectRValueWithoutOwnership(native);
685685
}
686686
}
687687

lib/SILGen/SILGenBuilder.cpp

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -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,
600600
ManagedValue 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

677679
ManagedValue SILGenBuilder::createManagedFunctionRef(SILLocation loc,
678680
SILFunction *f) {
679-
return ManagedValue::forUnmanaged(createFunctionRefFor(loc, f));
681+
return ManagedValue::forObjectRValueWithoutOwnership(
682+
createFunctionRefFor(loc, f));
680683
}
681684

682685
ManagedValue 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

801804
ManagedValue 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

809812
ManagedValue SILGenBuilder::
810813
createValueMetatype(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

816819
ManagedValue 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

948951
void SILGenBuilder::emitDestructureValueOperation(

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,7 +1475,8 @@ static ManagedValue emitBuiltinEndAsyncLet(
14751475
static ManagedValue emitBuiltinGetCurrentExecutor(
14761476
SILGenFunction &SGF, SILLocation loc, SubstitutionMap subs,
14771477
PreparedArguments &&preparedArgs, SGFContext C) {
1478-
return ManagedValue::forUnmanaged(SGF.emitGetCurrentExecutor(loc));
1478+
return ManagedValue::forObjectRValueWithoutOwnership(
1479+
SGF.emitGetCurrentExecutor(loc));
14791480
}
14801481

14811482
// Emit SIL for sizeof/strideof/alignof.
@@ -1766,7 +1767,7 @@ static ManagedValue emitBuildExecutorRef(SILGenFunction &SGF, SILLocation loc,
17661767
auto builtinApply = SGF.B.createBuiltin(loc, builtinID,
17671768
SILType::getPrimitiveObjectType(ctx.TheExecutorType),
17681769
subs, argValues);
1769-
return ManagedValue::forUnmanaged(builtinApply);
1770+
return ManagedValue::forObjectRValueWithoutOwnership(builtinApply);
17701771
}
17711772
static ManagedValue emitBuiltinBuildOrdinarySerialExecutorRef(
17721773
SILGenFunction &SGF, SILLocation loc, SubstitutionMap subs,

lib/SILGen/SILGenConvert.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,23 @@ auto SILGenFunction::emitSourceLocationArgs(SourceLoc sourceLoc,
164164
SourceLocArgs result;
165165
SILValue literal = B.createStringLiteral(emitLoc, StringRef(filename),
166166
StringLiteralInst::Encoding::UTF8);
167-
result.filenameStartPointer = ManagedValue::forUnmanaged(literal);
167+
result.filenameStartPointer =
168+
ManagedValue::forObjectRValueWithoutOwnership(literal);
168169
// File length
169170
literal = B.createIntegerLiteral(emitLoc, wordTy, filename.size());
170-
result.filenameLength = ManagedValue::forUnmanaged(literal);
171+
result.filenameLength =
172+
ManagedValue::forObjectRValueWithoutOwnership(literal);
171173
// File is ascii
172174
literal = B.createIntegerLiteral(emitLoc, i1Ty, isASCII);
173-
result.filenameIsAscii = ManagedValue::forUnmanaged(literal);
175+
result.filenameIsAscii =
176+
ManagedValue::forObjectRValueWithoutOwnership(literal);
174177
// Line
175178
literal = B.createIntegerLiteral(emitLoc, wordTy, line);
176-
result.line = ManagedValue::forUnmanaged(literal);
179+
result.line = ManagedValue::forObjectRValueWithoutOwnership(literal);
177180
// Column
178181
literal = B.createIntegerLiteral(emitLoc, wordTy, column);
179-
result.column = ManagedValue::forUnmanaged(literal);
180-
182+
result.column = ManagedValue::forObjectRValueWithoutOwnership(literal);
183+
181184
return result;
182185
}
183186

@@ -225,8 +228,8 @@ SILGenFunction::emitPreconditionOptionalHasValue(SILLocation loc,
225228
auto isImplicitUnwrapLiteral =
226229
B.createIntegerLiteral(loc, i1Ty, isImplicitUnwrap);
227230
auto isImplicitUnwrapValue =
228-
ManagedValue::forUnmanaged(isImplicitUnwrapLiteral);
229-
231+
ManagedValue::forObjectRValueWithoutOwnership(isImplicitUnwrapLiteral);
232+
230233
emitApplyOfLibraryIntrinsic(loc, diagnoseFailure, SubstitutionMap(),
231234
{
232235
args.filenameStartPointer,
@@ -783,7 +786,7 @@ ManagedValue SILGenFunction::emitExistentialErasure(
783786
B.createInitExistentialMetatype(loc, metatype,
784787
existentialTL.getLoweredType(),
785788
conformances);
786-
return ManagedValue::forUnmanaged(upcast);
789+
return ManagedValue::forObjectRValueWithoutOwnership(upcast);
787790
}
788791
case ExistentialRepresentation::Class: {
789792
assert(existentialTL.isLoadable());

lib/SILGen/SILGenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2087,7 +2087,7 @@ SILGenFunction::emitFormalAccessManagedRValueWithCleanup(SILLocation loc,
20872087
assert(isInFormalEvaluationScope() && "Must be in formal evaluation scope");
20882088
auto &lowering = getTypeLowering(value->getType());
20892089
if (lowering.isTrivial())
2090-
return ManagedValue::forUnmanaged(value);
2090+
return ManagedValue::forObjectRValueWithoutOwnership(value);
20912091

20922092
auto &cleanup = Cleanups.pushCleanup<FormalAccessReleaseValueCleanup>();
20932093
CleanupHandle handle = Cleanups.getTopCleanup();

lib/SILGen/SILGenExpr.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ ManagedValue SILGenFunction::emitManagedRetain(SILLocation loc,
7171
const TypeLowering &lowering) {
7272
assert(lowering.getLoweredType() == v->getType());
7373
if (lowering.isTrivial())
74-
return ManagedValue::forUnmanaged(v);
74+
return ManagedValue::forRValueWithoutOwnership(v);
7575
if (v->getType().isObject() && v->getOwnershipKind() == OwnershipKind::None)
76-
return ManagedValue::forUnmanaged(v);
76+
return ManagedValue::forObjectRValueWithoutOwnership(v);
7777
assert((!lowering.isAddressOnly() || !silConv.useLoweredAddresses()) &&
7878
"cannot retain an unloadable type");
7979

@@ -91,9 +91,9 @@ ManagedValue SILGenFunction::emitManagedLoadCopy(SILLocation loc, SILValue v,
9191
assert(lowering.getLoweredType().getAddressType() == v->getType());
9292
v = lowering.emitLoadOfCopy(B, loc, v, IsNotTake);
9393
if (lowering.isTrivial())
94-
return ManagedValue::forUnmanaged(v);
94+
return ManagedValue::forRValueWithoutOwnership(v);
9595
if (v->getOwnershipKind() == OwnershipKind::None)
96-
return ManagedValue::forUnmanaged(v);
96+
return ManagedValue::forObjectRValueWithoutOwnership(v);
9797
assert((!lowering.isAddressOnly() || !silConv.useLoweredAddresses()) &&
9898
"cannot retain an unloadable type");
9999
return emitManagedRValueWithCleanup(v, lowering);
@@ -111,7 +111,7 @@ SILGenFunction::emitManagedLoadBorrow(SILLocation loc, SILValue v,
111111
assert(lowering.getLoweredType().getAddressType() == v->getType());
112112
if (lowering.isTrivial()) {
113113
v = lowering.emitLoadOfCopy(B, loc, v, IsNotTake);
114-
return ManagedValue::forUnmanaged(v);
114+
return ManagedValue::forObjectRValueWithoutOwnership(v);
115115
}
116116

117117
assert((!lowering.isAddressOnly() || !silConv.useLoweredAddresses()) &&
@@ -312,11 +312,11 @@ ManagedValue SILGenFunction::emitManagedBorrowedRValueWithCleanup(
312312
assert(lowering.getLoweredType().getObjectType() ==
313313
borrowed->getType().getObjectType());
314314
if (lowering.isTrivial())
315-
return ManagedValue::forUnmanaged(borrowed);
315+
return ManagedValue::forRValueWithoutOwnership(borrowed);
316316

317317
if (borrowed->getType().isObject() &&
318318
borrowed->getOwnershipKind() == OwnershipKind::None)
319-
return ManagedValue::forUnmanaged(borrowed);
319+
return ManagedValue::forObjectRValueWithoutOwnership(borrowed);
320320

321321
if (borrowed->getType().isObject()) {
322322
Cleanups.pushCleanup<EndBorrowCleanup>(borrowed);
@@ -330,11 +330,11 @@ ManagedValue SILGenFunction::emitManagedBorrowedRValueWithCleanup(
330330
assert(lowering.getLoweredType().getObjectType() ==
331331
original->getType().getObjectType());
332332
if (lowering.isTrivial())
333-
return ManagedValue::forUnmanaged(borrowed);
333+
return ManagedValue::forRValueWithoutOwnership(borrowed);
334334

335335
if (original->getType().isObject() &&
336336
original->getOwnershipKind() == OwnershipKind::None)
337-
return ManagedValue::forUnmanaged(borrowed);
337+
return ManagedValue::forObjectRValueWithoutOwnership(borrowed);
338338

339339
Cleanups.pushCleanup<EndBorrowCleanup>(borrowed);
340340
return ManagedValue(borrowed, CleanupHandle::invalid());
@@ -350,9 +350,9 @@ ManagedValue SILGenFunction::emitManagedRValueWithCleanup(SILValue v,
350350
assert(lowering.getLoweredType().getObjectType() ==
351351
v->getType().getObjectType());
352352
if (lowering.isTrivial())
353-
return ManagedValue::forUnmanaged(v);
353+
return ManagedValue::forRValueWithoutOwnership(v);
354354
if (v->getType().isObject() && v->getOwnershipKind() == OwnershipKind::None) {
355-
return ManagedValue::forUnmanaged(v);
355+
return ManagedValue::forRValueWithoutOwnership(v);
356356
}
357357
return ManagedValue(v, enterDestroyCleanup(v));
358358
}

lib/SILGen/SILGenFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1184,7 +1184,7 @@ void SILGenFunction::emitArtificialTopLevel(Decl *mainDecl) {
11841184
unwrappedTy = SILType::getPrimitiveObjectType(canInnerTy);
11851185
}
11861186

1187-
auto managedArgv = ManagedValue::forUnmanaged(argv);
1187+
auto managedArgv = ManagedValue::forObjectRValueWithoutOwnership(argv);
11881188

11891189
if (unwrappedTy != argv->getType()) {
11901190
auto converted =

lib/SILGen/SILGenLValue.cpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,10 +1038,9 @@ namespace {
10381038
if (refType.is<ExistentialMetatypeType>()) {
10391039
assert(refType.getPreferredExistentialRepresentation()
10401040
== ExistentialRepresentation::Metatype);
1041-
ref = ManagedValue::forUnmanaged(
1042-
SGF.B.createOpenExistentialMetatype(loc,
1043-
result.getUnmanagedValue(),
1044-
getTypeOfRValue()));
1041+
ref = ManagedValue::forObjectRValueWithoutOwnership(
1042+
SGF.B.createOpenExistentialMetatype(loc, result.getUnmanagedValue(),
1043+
getTypeOfRValue()));
10451044
} else {
10461045
assert(refType.getPreferredExistentialRepresentation()
10471046
== ExistentialRepresentation::Class);

lib/SILGen/SILGenPattern.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2918,7 +2918,7 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
29182918

29192919
if (auto *singleEnumDecl = canSubjectTy->getEnumOrBoundGenericEnum()) {
29202920
if (singleEnumDecl->isObjC()) {
2921-
auto metatype = ManagedValue::forUnmanaged(
2921+
auto metatype = ManagedValue::forObjectRValueWithoutOwnership(
29222922
B.createMetatype(loc, loweredMetatypeType));
29232923

29242924
// Bitcast the enum value to its raw type. (This is only safe for @objc

0 commit comments

Comments
 (0)