Skip to content

Commit 58056a6

Browse files
authored
Merge pull request #5540 from gottesmm/force_specification_of_ownership_semantics_loadstore
[semantic-arc] Eliminate default {Load,Store}OwnershipQualification argument to SILBuilder::create{Load,Store}(...)
2 parents ae157f7 + bffa7ad commit 58056a6

33 files changed

+218
-125
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -457,9 +457,8 @@ class SILBuilder {
457457
getSILDebugLocation(Loc), text.toStringRef(Out), encoding, F));
458458
}
459459

460-
LoadInst *createLoad(
461-
SILLocation Loc, SILValue LV,
462-
LoadOwnershipQualifier Qualifier = LoadOwnershipQualifier::Unqualified) {
460+
LoadInst *createLoad(SILLocation Loc, SILValue LV,
461+
LoadOwnershipQualifier Qualifier) {
463462
assert(LV->getType().isLoadable(F.getModule()));
464463
return insert(new (F.getModule())
465464
LoadInst(getSILDebugLocation(Loc), LV, Qualifier));
@@ -472,8 +471,7 @@ class SILBuilder {
472471
}
473472

474473
StoreInst *createStore(SILLocation Loc, SILValue Src, SILValue DestAddr,
475-
StoreOwnershipQualifier Qualifier =
476-
StoreOwnershipQualifier::Unqualified) {
474+
StoreOwnershipQualifier Qualifier) {
477475
return insert(new (F.getModule()) StoreInst(getSILDebugLocation(Loc), Src,
478476
DestAddr, Qualifier));
479477
}

include/swift/SIL/SILCloner.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -660,9 +660,9 @@ template<typename ImplClass>
660660
void
661661
SILCloner<ImplClass>::visitLoadInst(LoadInst *Inst) {
662662
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
663-
doPostProcess(Inst,
664-
getBuilder().createLoad(getOpLocation(Inst->getLoc()),
665-
getOpValue(Inst->getOperand())));
663+
doPostProcess(Inst, getBuilder().createLoad(getOpLocation(Inst->getLoc()),
664+
getOpValue(Inst->getOperand()),
665+
Inst->getOwnershipQualifier()));
666666
}
667667

668668
template <typename ImplClass>
@@ -676,10 +676,10 @@ void SILCloner<ImplClass>::visitLoadBorrowInst(LoadBorrowInst *Inst) {
676676
template <typename ImplClass>
677677
void SILCloner<ImplClass>::visitStoreInst(StoreInst *Inst) {
678678
getBuilder().setCurrentDebugScope(getOpScope(Inst->getDebugScope()));
679-
doPostProcess(Inst,
680-
getBuilder().createStore(getOpLocation(Inst->getLoc()),
681-
getOpValue(Inst->getSrc()),
682-
getOpValue(Inst->getDest())));
679+
doPostProcess(Inst, getBuilder().createStore(getOpLocation(Inst->getLoc()),
680+
getOpValue(Inst->getSrc()),
681+
getOpValue(Inst->getDest()),
682+
Inst->getOwnershipQualifier()));
683683
}
684684

685685
template <typename ImplClass>

lib/SIL/TypeLowering.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,8 @@ namespace {
494494
public:
495495
void emitDestroyAddress(SILBuilder &B, SILLocation loc,
496496
SILValue addr) const override {
497-
SILValue value = B.createLoad(loc, addr);
497+
SILValue value =
498+
B.createLoad(loc, addr, LoadOwnershipQualifier::Unqualified);
498499
emitDestroyValue(B, loc, value);
499500
}
500501

@@ -519,13 +520,13 @@ namespace {
519520

520521
SILValue emitLoadOfCopy(SILBuilder &B, SILLocation loc, SILValue addr,
521522
IsTake_t isTake) const override {
522-
return B.createLoad(loc, addr);
523+
return B.createLoad(loc, addr, LoadOwnershipQualifier::Unqualified);
523524
}
524525

525526
void emitStoreOfCopy(SILBuilder &B, SILLocation loc,
526527
SILValue value, SILValue addr,
527528
IsInitialization_t isInit) const override {
528-
B.createStore(loc, value, addr);
529+
B.createStore(loc, value, addr, StoreOwnershipQualifier::Unqualified);
529530
}
530531

531532
void emitDestroyAddress(SILBuilder &B, SILLocation loc,
@@ -565,7 +566,8 @@ namespace {
565566

566567
SILValue emitLoadOfCopy(SILBuilder &B, SILLocation loc,
567568
SILValue addr, IsTake_t isTake) const override {
568-
SILValue value = B.createLoad(loc, addr);
569+
SILValue value =
570+
B.createLoad(loc, addr, LoadOwnershipQualifier::Unqualified);
569571
if (!isTake)
570572
emitCopyValue(B, loc, value);
571573
return value;
@@ -575,8 +577,9 @@ namespace {
575577
SILValue newValue, SILValue addr,
576578
IsInitialization_t isInit) const override {
577579
SILValue oldValue;
578-
if (!isInit) oldValue = B.createLoad(loc, addr);
579-
B.createStore(loc, newValue, addr);
580+
if (!isInit)
581+
oldValue = B.createLoad(loc, addr, LoadOwnershipQualifier::Unqualified);
582+
B.createStore(loc, newValue, addr, StoreOwnershipQualifier::Unqualified);
580583
if (!isInit)
581584
emitDestroyValue(B, loc, oldValue);
582585
}

lib/SILGen/ManagedValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void ManagedValue::copyInto(SILGenFunction &gen, SILValue dest, SILLocation L) {
5252
return;
5353
}
5454
lowering.emitCopyValue(gen.B, L, getValue());
55-
gen.B.createStore(L, getValue(), dest);
55+
gen.B.createStore(L, getValue(), dest, StoreOwnershipQualifier::Unqualified);
5656
}
5757

5858
/// This is the same operation as 'copy', but works on +0 values that don't

lib/SILGen/RValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ class ExplodeTupleValue
105105
// loaded. Except it's not really an invariant, because
106106
// argument emission likes to lie sometimes.
107107
if (eltTI.isLoadable()) {
108-
elt = gen.B.createLoad(loc, elt);
108+
elt = gen.B.createLoad(loc, elt, LoadOwnershipQualifier::Unqualified);
109109
}
110110
}
111111

lib/SILGen/SILGenApply.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -719,7 +719,8 @@ static Callee prepareArchetypeCallee(SILGenFunction &gen, SILLocation loc,
719719
// Store the reference into a temporary.
720720
auto temp =
721721
gen.emitTemporaryAllocation(selfLoc, ref.getValue()->getType());
722-
gen.B.createStore(selfLoc, ref.getValue(), temp);
722+
gen.B.createStore(selfLoc, ref.getValue(), temp,
723+
StoreOwnershipQualifier::Unqualified);
723724

724725
// If we had a cleanup, create a cleanup at the new address.
725726
return maybeEnterCleanupForTransformed(gen, ref, temp);
@@ -1997,7 +1998,8 @@ namespace {
19971998

19981999
// If the value isn't address-only, go ahead and load.
19992000
if (!substTL.isAddressOnly()) {
2000-
auto load = gen.B.createLoad(loc, value.forward(gen));
2001+
auto load = gen.B.createLoad(loc, value.forward(gen),
2002+
LoadOwnershipQualifier::Unqualified);
20012003
value = gen.emitManagedRValueWithCleanup(load);
20022004
}
20032005

@@ -2578,7 +2580,8 @@ static ManagedValue emitMaterializeIntoTemporary(SILGenFunction &gen,
25782580
ManagedValue object) {
25792581
auto temporary = gen.emitTemporaryAllocation(loc, object.getType());
25802582
bool hadCleanup = object.hasCleanup();
2581-
gen.B.createStore(loc, object.forward(gen), temporary);
2583+
gen.B.createStore(loc, object.forward(gen), temporary,
2584+
StoreOwnershipQualifier::Unqualified);
25822585

25832586
// The temporary memory is +0 if the value was.
25842587
if (hadCleanup) {
@@ -3894,12 +3897,14 @@ ManagedValue SILGenFunction::emitInjectEnum(SILLocation loc,
38943897
if (payloadMV) {
38953898
// If the payload was indirect, we already evaluated it and
38963899
// have a single value. Store it into the result.
3897-
B.createStore(loc, payloadMV.forward(*this), resultData);
3900+
B.createStore(loc, payloadMV.forward(*this), resultData,
3901+
StoreOwnershipQualifier::Unqualified);
38983902
} else if (payloadTL.isLoadable()) {
38993903
// The payload of this specific enum case might be loadable
39003904
// even if the overall enum is address-only.
39013905
payloadMV = std::move(payload).getAsSingleValue(*this, origFormalType);
3902-
B.createStore(loc, payloadMV.forward(*this), resultData);
3906+
B.createStore(loc, payloadMV.forward(*this), resultData,
3907+
StoreOwnershipQualifier::Unqualified);
39033908
} else {
39043909
// The payload is address-only. Evaluate it directly into
39053910
// the enum.
@@ -5557,7 +5562,7 @@ RValue SILGenFunction::emitDynamicMemberRefExpr(DynamicMemberRefExpr *e,
55575562
// Package up the result.
55585563
auto optResult = optTemp;
55595564
if (optTL.isLoadable())
5560-
optResult = B.createLoad(e, optResult);
5565+
optResult = B.createLoad(e, optResult, LoadOwnershipQualifier::Unqualified);
55615566
return RValue(*this, e, emitManagedRValueWithCleanup(optResult, optTL));
55625567
}
55635568

@@ -5650,6 +5655,6 @@ RValue SILGenFunction::emitDynamicSubscriptExpr(DynamicSubscriptExpr *e,
56505655
// Package up the result.
56515656
auto optResult = optTemp;
56525657
if (optTL.isLoadable())
5653-
optResult = B.createLoad(e, optResult);
5658+
optResult = B.createLoad(e, optResult, LoadOwnershipQualifier::Unqualified);
56545659
return RValue(*this, e, emitManagedRValueWithCleanup(optResult, optTL));
56555660
}

lib/SILGen/SILGenBridging.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ emitBridgeNativeToObjectiveC(SILGenFunction &gen,
121121
if (witnessFnTy.castTo<SILFunctionType>()->getParameters()[0].isIndirect()
122122
&& !swiftValue.getType().isAddress()) {
123123
auto tmp = gen.emitTemporaryAllocation(loc, swiftValue.getType());
124-
gen.B.createStore(loc, swiftValue.getValue(), tmp);
124+
gen.B.createStore(loc, swiftValue.getValue(), tmp,
125+
StoreOwnershipQualifier::Unqualified);
125126
swiftValue = ManagedValue::forUnmanaged(tmp);
126127
}
127128

@@ -449,7 +450,8 @@ ManagedValue SILGenFunction::emitFuncToBlock(SILLocation loc,
449450
// Store the function to the block without claiming it, so that it still
450451
// gets cleaned up in scope. Copying the block will create an independent
451452
// reference.
452-
B.createStore(loc, fn.getValue(), capture);
453+
B.createStore(loc, fn.getValue(), capture,
454+
StoreOwnershipQualifier::Unqualified);
453455
auto invokeFn = B.createFunctionRef(loc, thunk);
454456

455457
auto stackBlock = B.createInitBlockStorageHeader(loc, storage, invokeFn,

lib/SILGen/SILGenBuiltin.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ emitBuiltinCastReference(SILGenFunction &gen,
592592
// a retain. The cast will load the reference from the source temp and
593593
// store it into a dest temp effectively forwarding the cleanup.
594594
fromAddr = gen.emitTemporaryAllocation(loc, srcVal->getType());
595-
gen.B.createStore(loc, srcVal, fromAddr);
595+
gen.B.createStore(loc, srcVal, fromAddr,
596+
StoreOwnershipQualifier::Unqualified);
596597
} else {
597598
// The cast loads directly from the source address.
598599
fromAddr = srcVal;
@@ -606,7 +607,8 @@ emitBuiltinCastReference(SILGenFunction &gen,
606607
return gen.emitManagedBufferWithCleanup(toAddr);
607608

608609
// Load the destination value.
609-
auto result = gen.B.createLoad(loc, toAddr);
610+
auto result =
611+
gen.B.createLoad(loc, toAddr, LoadOwnershipQualifier::Unqualified);
610612
return gen.emitManagedRValueWithCleanup(result);
611613
}
612614

@@ -630,7 +632,8 @@ static ManagedValue emitBuiltinReinterpretCast(SILGenFunction &gen,
630632
// If the from value is loadable, move it to a buffer.
631633
if (fromTL.isLoadable()) {
632634
fromAddr = gen.emitTemporaryAllocation(loc, args[0].getValue()->getType());
633-
gen.B.createStore(loc, args[0].getValue(), fromAddr);
635+
gen.B.createStore(loc, args[0].getValue(), fromAddr,
636+
StoreOwnershipQualifier::Unqualified);
634637
} else {
635638
fromAddr = args[0].getValue();
636639
}
@@ -640,7 +643,8 @@ static ManagedValue emitBuiltinReinterpretCast(SILGenFunction &gen,
640643
// Load and retain the destination value if it's loadable. Leave the cleanup
641644
// on the original value since we don't know anything about it's type.
642645
if (toTL.isLoadable()) {
643-
SILValue val = gen.B.createLoad(loc, toAddr);
646+
SILValue val =
647+
gen.B.createLoad(loc, toAddr, LoadOwnershipQualifier::Unqualified);
644648
return gen.emitManagedRetain(loc, val, toTL);
645649
}
646650
// Leave the cleanup on the original value.

lib/SILGen/SILGenConstructor.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,9 @@ void SILGenFunction::emitValueConstructor(ConstructorDecl *ctor) {
275275

276276
if (!lowering.isAddressOnly()) {
277277
// Otherwise, load and return the final 'self' value.
278-
selfValue = B.createLoad(cleanupLoc, selfLV);
279-
278+
selfValue =
279+
B.createLoad(cleanupLoc, selfLV, LoadOwnershipQualifier::Unqualified);
280+
280281
// Emit a retain of the loaded value, since we return it +1.
281282
lowering.emitCopyValue(B, cleanupLoc, selfValue);
282283

@@ -581,7 +582,8 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
581582
if (NeedsBoxForSelf) {
582583
SILLocation prologueLoc = RegularLocation(ctor);
583584
prologueLoc.markAsPrologue();
584-
B.createStore(prologueLoc, selfArg, VarLocs[selfDecl].value);
585+
B.createStore(prologueLoc, selfArg, VarLocs[selfDecl].value,
586+
StoreOwnershipQualifier::Unqualified);
585587
} else {
586588
selfArg = B.createMarkUninitialized(selfDecl, selfArg, MUKind);
587589
VarLocs[selfDecl] = VarLoc::get(selfArg);
@@ -667,8 +669,9 @@ void SILGenFunction::emitClassConstructorInitializer(ConstructorDecl *ctor) {
667669
// Emit the call to super.init() right before exiting from the initializer.
668670
if (Expr *SI = ctor->getSuperInitCall())
669671
emitRValue(SI);
670-
671-
selfArg = B.createLoad(cleanupLoc, VarLocs[selfDecl].value);
672+
673+
selfArg = B.createLoad(cleanupLoc, VarLocs[selfDecl].value,
674+
LoadOwnershipQualifier::Unqualified);
672675
}
673676

674677
// We have to do a retain because we are returning the pointer +1.

lib/SILGen/SILGenConvert.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,8 @@ ManagedValue SILGenFunction::emitUncheckedGetOptionalValueFrom(SILLocation loc,
249249
someDecl, origPayloadTy);
250250

251251
if (optTL.isLoadable())
252-
payloadVal = B.createLoad(loc, payloadVal);
252+
payloadVal =
253+
B.createLoad(loc, payloadVal, LoadOwnershipQualifier::Unqualified);
253254
}
254255

255256
// Produce a correctly managed value.
@@ -358,7 +359,8 @@ SILGenFunction::emitPointerToPointer(SILLocation loc,
358359
// The generic function currently always requires indirection, but pointers
359360
// are always loadable.
360361
auto origBuf = emitTemporaryAllocation(loc, input.getType());
361-
B.createStore(loc, input.forward(*this), origBuf);
362+
B.createStore(loc, input.forward(*this), origBuf,
363+
StoreOwnershipQualifier::Unqualified);
362364
auto origValue = emitManagedBufferWithCleanup(origBuf);
363365

364366
// Invoke the conversion intrinsic to convert to the destination type.

lib/SILGen/SILGenDecl.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ void TupleInitialization::copyOrInitValueInto(SILGenFunction &SGF,
9191
if (value->getType().isAddress()) {
9292
member = SGF.B.createTupleElementAddr(loc, value, i, fieldTy);
9393
if (!fieldTL.isAddressOnly())
94-
member = SGF.B.createLoad(loc, member);
94+
member =
95+
SGF.B.createLoad(loc, member, LoadOwnershipQualifier::Unqualified);
9596
} else {
9697
member = SGF.B.createTupleExtract(loc, value, i, fieldTy);
9798
}
@@ -712,7 +713,8 @@ emitEnumMatch(ManagedValue value, EnumElementDecl *ElementDecl,
712713
ElementDecl, eltTy);
713714
// Load a loadable data value.
714715
if (eltTL.isLoadable())
715-
eltValue = SGF.B.createLoad(loc, eltValue);
716+
eltValue =
717+
SGF.B.createLoad(loc, eltValue, LoadOwnershipQualifier::Unqualified);
716718
} else {
717719
// Otherwise, we're consuming this as a +1 value.
718720
value.forward(SGF);
@@ -726,7 +728,8 @@ emitEnumMatch(ManagedValue value, EnumElementDecl *ElementDecl,
726728
SILValue boxedValue = SGF.B.createProjectBox(loc, eltMV.getValue(), 0);
727729
auto &boxedTL = SGF.getTypeLowering(boxedValue->getType());
728730
if (boxedTL.isLoadable())
729-
boxedValue = SGF.B.createLoad(loc, boxedValue);
731+
boxedValue = SGF.B.createLoad(loc, boxedValue,
732+
LoadOwnershipQualifier::Unqualified);
730733

731734
// We must treat the boxed value as +0 since it may be shared. Copy it if
732735
// nontrivial.

lib/SILGen/SILGenDynamicCast.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ namespace {
140140
//emission.
141141
scalarOperandValue = operand.forward(SGF);
142142
if (scalarOperandValue->getType().isAddress()) {
143-
scalarOperandValue = SGF.B.createLoad(Loc, scalarOperandValue);
143+
scalarOperandValue = SGF.B.createLoad(
144+
Loc, scalarOperandValue, LoadOwnershipQualifier::Unqualified);
144145
}
145146
SGF.B.createCheckedCastBranch(Loc, /*exact*/ false, scalarOperandValue,
146147
origTargetTL.getLoweredType(),
@@ -363,7 +364,8 @@ adjustForConditionalCheckedCastOperand(SILLocation loc, ManagedValue src,
363364
// Okay, if all we need to do is drop the value in an address,
364365
// this is easy.
365366
if (!hasAbstraction) {
366-
SGF.B.createStore(loc, src.forward(SGF), init->getAddress());
367+
SGF.B.createStore(loc, src.forward(SGF), init->getAddress(),
368+
StoreOwnershipQualifier::Unqualified);
367369
init->finishInitialization(SGF);
368370
return init->getManagedAddress();
369371
}

lib/SILGen/SILGenExpr.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3243,7 +3243,8 @@ class AutoreleasingWritebackComponent : public LogicalPathComponent {
32433243
RValue get(SILGenFunction &gen, SILLocation loc,
32443244
ManagedValue base, SGFContext c) && override {
32453245
// Load the value at +0.
3246-
SILValue owned = gen.B.createLoad(loc, base.getUnmanagedValue());
3246+
SILValue owned = gen.B.createLoad(loc, base.getUnmanagedValue(),
3247+
LoadOwnershipQualifier::Unqualified);
32473248
// Convert it to unowned.
32483249
auto refType = owned->getType().getSwiftRValueType();
32493250
auto unownedType = SILType::getPrimitiveObjectType(

lib/SILGen/SILGenForeignError.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,8 @@ void SILGenFunction::emitForeignErrorBlock(SILLocation loc,
268268
// conditionally claiming the value. In practice, claiming it
269269
// unconditionally is fine because we want to assume it's nil in the
270270
// other path.
271-
SILValue errorV = B.createLoad(loc, errorSlot.forward(*this));
271+
SILValue errorV = B.createLoad(loc, errorSlot.forward(*this),
272+
LoadOwnershipQualifier::Unqualified);
272273
ManagedValue error = emitManagedRValueWithCleanup(errorV);
273274

274275
// Turn the error into an Error value.
@@ -384,7 +385,8 @@ emitErrorIsNonNilErrorCheck(SILGenFunction &gen, SILLocation loc,
384385
// If we're suppressing the check, just don't check.
385386
if (suppressErrorCheck) return;
386387

387-
SILValue optionalError = gen.B.createLoad(loc, errorSlot.getValue());
388+
SILValue optionalError = gen.B.createLoad(
389+
loc, errorSlot.getValue(), LoadOwnershipQualifier::Unqualified);
388390

389391
ASTContext &ctx = gen.getASTContext();
390392

0 commit comments

Comments
 (0)