Skip to content

Commit a7c7e96

Browse files
authored
Merge pull request #5443 from gottesmm/rename_typelowering_apis_from_retainrelease_to_copydestroy
2 parents db7a047 + 8b41745 commit a7c7e96

15 files changed

+76
-83
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1489,15 +1489,15 @@ class SILBuilder {
14891489
void emitRetainValueOperation(SILLocation Loc, SILValue v) {
14901490
assert(!v->getType().isAddress());
14911491
auto &lowering = getTypeLowering(v->getType());
1492-
return lowering.emitRetainValue(*this, Loc, v);
1492+
lowering.emitCopyValue(*this, Loc, v);
14931493
}
14941494

14951495
/// Convenience function for calling TypeLowering.emitRelease on the type
14961496
/// lowering for the non-address value.
14971497
void emitReleaseValueOperation(SILLocation Loc, SILValue v) {
14981498
assert(!v->getType().isAddress());
14991499
auto &lowering = getTypeLowering(v->getType());
1500-
lowering.emitReleaseValue(*this, Loc, v);
1500+
lowering.emitDestroyValue(*this, Loc, v);
15011501
}
15021502

15031503
SILValue emitTupleExtract(SILLocation Loc, SILValue Operand, unsigned FieldNo,

include/swift/SIL/TypeLowering.h

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -238,32 +238,32 @@ class TypeLowering {
238238
/// Emit a lowered 'release_value' operation.
239239
///
240240
/// This type must be loadable.
241-
virtual void emitLoweredReleaseValue(SILBuilder &B, SILLocation loc,
241+
virtual void emitLoweredDestroyValue(SILBuilder &B, SILLocation loc,
242242
SILValue value,
243243
LoweringStyle loweringStyle) const = 0;
244244

245245
void emitLoweredDestroyChildValue(SILBuilder &B, SILLocation loc,
246246
SILValue value,
247247
LoweringStyle loweringStyle) const {
248248
if (loweringStyle != LoweringStyle::Shallow)
249-
return emitLoweredReleaseValue(B, loc, value, loweringStyle);
250-
return emitReleaseValue(B, loc, value);
249+
return emitLoweredDestroyValue(B, loc, value, loweringStyle);
250+
return emitDestroyValue(B, loc, value);
251251
}
252252

253253
/// Emit a lowered 'release_value' operation.
254254
///
255255
/// This type must be loadable.
256-
void emitLoweredReleaseValueShallow(SILBuilder &B, SILLocation loc,
256+
void emitLoweredDestroyValueShallow(SILBuilder &B, SILLocation loc,
257257
SILValue value) const {
258-
emitLoweredReleaseValue(B, loc, value, LoweringStyle::Shallow);
258+
emitLoweredDestroyValue(B, loc, value, LoweringStyle::Shallow);
259259
}
260260

261261
/// Emit a lowered 'release_value' operation.
262262
///
263263
/// This type must be loadable.
264-
void emitLoweredReleaseValueDeepNoEnum(SILBuilder &B, SILLocation loc,
264+
void emitLoweredDestroyValueDeepNoEnum(SILBuilder &B, SILLocation loc,
265265
SILValue value) const {
266-
emitLoweredReleaseValue(B, loc, value, LoweringStyle::DeepNoEnum);
266+
emitLoweredDestroyValue(B, loc, value, LoweringStyle::DeepNoEnum);
267267
}
268268

269269
/// Given a primitively loaded value of this type (which must be
@@ -274,30 +274,30 @@ class TypeLowering {
274274
/// example, it performs an unowned_release on a value of [unknown]
275275
/// type. It is therefore not necessarily the right thing to do on
276276
/// a semantic load.
277-
virtual void emitReleaseValue(SILBuilder &B, SILLocation loc,
277+
virtual void emitDestroyValue(SILBuilder &B, SILLocation loc,
278278
SILValue value) const = 0;
279279

280280
/// Emit a lowered 'retain_value' operation.
281281
///
282282
/// This type must be loadable.
283-
virtual void emitLoweredRetainValue(SILBuilder &B, SILLocation loc,
283+
virtual void emitLoweredCopyValue(SILBuilder &B, SILLocation loc,
284284
SILValue value,
285285
LoweringStyle style) const = 0;
286286

287287
/// Emit a lowered 'retain_value' operation.
288288
///
289289
/// This type must be loadable.
290-
void emitLoweredRetainValueShallow(SILBuilder &B, SILLocation loc,
290+
void emitLoweredCopyValueShallow(SILBuilder &B, SILLocation loc,
291291
SILValue value) const {
292-
emitLoweredRetainValue(B, loc, value, LoweringStyle::Shallow);
292+
emitLoweredCopyValue(B, loc, value, LoweringStyle::Shallow);
293293
}
294294

295295
/// Emit a lowered 'retain_value' operation.
296296
///
297297
/// This type must be loadable.
298298
void emitLoweredRetainValueDeepNoEnum(SILBuilder &B, SILLocation loc,
299-
SILValue value) const {
300-
emitLoweredRetainValue(B, loc, value, LoweringStyle::DeepNoEnum);
299+
SILValue value) const {
300+
emitLoweredCopyValue(B, loc, value, LoweringStyle::DeepNoEnum);
301301
}
302302

303303
/// Given a primitively loaded value of this type (which must be
@@ -307,16 +307,16 @@ class TypeLowering {
307307
/// with exactly the same semantics. For example, it performs an
308308
/// unowned_retain on a value of [unknown] type. It is therefore
309309
/// not necessarily the right thing to do on a semantic load.
310-
virtual void emitRetainValue(SILBuilder &B, SILLocation loc,
310+
virtual void emitCopyValue(SILBuilder &B, SILLocation loc,
311311
SILValue value) const = 0;
312312

313313
void emitLoweredCopyChildValue(SILBuilder &B, SILLocation loc,
314314
SILValue value,
315315
LoweringStyle style) const {
316316
if (style != LoweringStyle::Shallow) {
317-
emitLoweredRetainValue(B, loc, value, style);
317+
emitLoweredCopyValue(B, loc, value, style);
318318
} else {
319-
emitRetainValue(B, loc, value);
319+
emitCopyValue(B, loc, value);
320320
}
321321
}
322322

lib/SIL/DynamicCasts.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ namespace {
781781
SILValue getOwnedScalar(Source source, const TypeLowering &srcTL) {
782782
assert(!source.isAddress());
783783
if (!source.shouldTake())
784-
srcTL.emitRetainValue(B, Loc, source.Value);
784+
srcTL.emitCopyValue(B, Loc, source.Value);
785785
return source.Value;
786786
}
787787

@@ -1217,15 +1217,15 @@ emitIndirectConditionalCastWithScalar(SILBuilder &B, Module *M,
12171217
SILValue succValue =
12181218
new (B.getModule()) SILArgument(scalarSuccBB, targetValueType);
12191219
if (!shouldTakeOnSuccess(consumption))
1220-
targetTL.emitRetainValue(B, loc, succValue);
1220+
targetTL.emitCopyValue(B, loc, succValue);
12211221
targetTL.emitStoreOfCopy(B, loc, succValue, dest, IsInitialization);
12221222
B.createBranch(loc, indirectSuccBB);
12231223
}
12241224

12251225
// Emit the failure block.
12261226
if (shouldDestroyOnFailure(consumption)) {
12271227
B.setInsertionPoint(scalarFailBB);
1228-
srcTL.emitReleaseValue(B, loc, srcValue);
1228+
srcTL.emitDestroyValue(B, loc, srcValue);
12291229
B.createBranch(loc, indirectFailBB);
12301230
}
12311231
}

lib/SIL/TypeLowering.cpp

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -495,12 +495,12 @@ namespace {
495495
void emitDestroyAddress(SILBuilder &B, SILLocation loc,
496496
SILValue addr) const override {
497497
SILValue value = B.createLoad(loc, addr);
498-
emitReleaseValue(B, loc, value);
498+
emitDestroyValue(B, loc, value);
499499
}
500500

501501
void emitDestroyRValue(SILBuilder &B, SILLocation loc,
502502
SILValue value) const override {
503-
emitReleaseValue(B, loc, value);
503+
emitDestroyValue(B, loc, value);
504504
}
505505

506506
void emitCopyInto(SILBuilder &B, SILLocation loc,
@@ -533,24 +533,22 @@ namespace {
533533
// Trivial
534534
}
535535

536-
void emitLoweredReleaseValue(SILBuilder &B, SILLocation loc,
537-
SILValue value,
536+
void emitLoweredDestroyValue(SILBuilder &B, SILLocation loc, SILValue value,
538537
LoweringStyle loweringStyle) const override {
539538
// Trivial
540539
}
541540

542-
void emitLoweredRetainValue(SILBuilder &B, SILLocation loc,
543-
SILValue value,
541+
void emitLoweredCopyValue(SILBuilder &B, SILLocation loc, SILValue value,
544542
LoweringStyle style) const override {
545543
// Trivial
546544
}
547545

548-
void emitRetainValue(SILBuilder &B, SILLocation loc,
546+
void emitCopyValue(SILBuilder &B, SILLocation loc,
549547
SILValue value) const override {
550548
// Trivial
551549
}
552550

553-
void emitReleaseValue(SILBuilder &B, SILLocation loc,
551+
void emitDestroyValue(SILBuilder &B, SILLocation loc,
554552
SILValue value) const override {
555553
// Trivial
556554
}
@@ -565,7 +563,8 @@ namespace {
565563
SILValue emitLoadOfCopy(SILBuilder &B, SILLocation loc,
566564
SILValue addr, IsTake_t isTake) const override {
567565
SILValue value = B.createLoad(loc, addr);
568-
if (!isTake) emitRetainValue(B, loc, value);
566+
if (!isTake)
567+
emitCopyValue(B, loc, value);
569568
return value;
570569
}
571570

@@ -575,7 +574,8 @@ namespace {
575574
SILValue oldValue;
576575
if (!isInit) oldValue = B.createLoad(loc, addr);
577576
B.createStore(loc, newValue, addr);
578-
if (!isInit) emitReleaseValue(B, loc, oldValue);
577+
if (!isInit)
578+
emitDestroyValue(B, loc, oldValue);
579579
}
580580
};
581581

@@ -657,13 +657,12 @@ namespace {
657657
});
658658
}
659659

660-
void emitRetainValue(SILBuilder &B, SILLocation loc,
660+
void emitCopyValue(SILBuilder &B, SILLocation loc,
661661
SILValue aggValue) const override {
662662
B.createRetainValue(loc, aggValue, Atomicity::Atomic);
663663
}
664664

665-
void emitLoweredRetainValue(SILBuilder &B, SILLocation loc,
666-
SILValue aggValue,
665+
void emitLoweredCopyValue(SILBuilder &B, SILLocation loc, SILValue aggValue,
667666
LoweringStyle style) const override {
668667
for (auto &child : getChildren(B.getModule())) {
669668
auto &childLowering = child.getLowering();
@@ -676,22 +675,22 @@ namespace {
676675
}
677676
}
678677

679-
void emitReleaseValue(SILBuilder &B, SILLocation loc,
678+
void emitDestroyValue(SILBuilder &B, SILLocation loc,
680679
SILValue aggValue) const override {
681680
B.emitReleaseValueAndFold(loc, aggValue);
682681
}
683682

684-
void emitLoweredReleaseValue(SILBuilder &B, SILLocation loc,
683+
void emitLoweredDestroyValue(SILBuilder &B, SILLocation loc,
685684
SILValue aggValue,
686685
LoweringStyle loweringStyle) const override {
687686
SimpleOperationTy Fn;
688687

689688
switch(loweringStyle) {
690689
case LoweringStyle::Shallow:
691-
Fn = &TypeLowering::emitReleaseValue;
690+
Fn = &TypeLowering::emitDestroyValue;
692691
break;
693692
case LoweringStyle::DeepNoEnum:
694-
Fn = &TypeLowering::emitLoweredReleaseValueDeepNoEnum;
693+
Fn = &TypeLowering::emitLoweredDestroyValueDeepNoEnum;
695694
break;
696695
}
697696

@@ -774,24 +773,22 @@ namespace {
774773
: NonTrivialLoadableTypeLowering(SILType::getPrimitiveObjectType(type),
775774
IsNotReferenceCounted) {}
776775

777-
void emitRetainValue(SILBuilder &B, SILLocation loc,
776+
void emitCopyValue(SILBuilder &B, SILLocation loc,
778777
SILValue value) const override {
779778
B.createRetainValue(loc, value, Atomicity::Atomic);
780779
}
781780

782-
void emitLoweredRetainValue(SILBuilder &B, SILLocation loc,
783-
SILValue value,
781+
void emitLoweredCopyValue(SILBuilder &B, SILLocation loc, SILValue value,
784782
LoweringStyle style) const override {
785783
B.createRetainValue(loc, value, Atomicity::Atomic);
786784
}
787-
788-
void emitReleaseValue(SILBuilder &B, SILLocation loc,
785+
786+
void emitDestroyValue(SILBuilder &B, SILLocation loc,
789787
SILValue value) const override {
790788
B.emitReleaseValueAndFold(loc, value);
791789
}
792790

793-
void emitLoweredReleaseValue(SILBuilder &B, SILLocation loc,
794-
SILValue value,
791+
void emitLoweredDestroyValue(SILBuilder &B, SILLocation loc, SILValue value,
795792
LoweringStyle style) const override {
796793
assert(style != LoweringStyle::Shallow &&
797794
"This method should never be called when performing a shallow "
@@ -805,16 +802,14 @@ namespace {
805802
LeafLoadableTypeLowering(SILType type, IsReferenceCounted_t isRefCounted)
806803
: NonTrivialLoadableTypeLowering(type, isRefCounted) {}
807804

808-
void emitLoweredRetainValue(SILBuilder &B, SILLocation loc,
809-
SILValue value,
805+
void emitLoweredCopyValue(SILBuilder &B, SILLocation loc, SILValue value,
810806
LoweringStyle style) const override {
811-
emitRetainValue(B, loc, value);
807+
emitCopyValue(B, loc, value);
812808
}
813809

814-
void emitLoweredReleaseValue(SILBuilder &B, SILLocation loc,
815-
SILValue value,
810+
void emitLoweredDestroyValue(SILBuilder &B, SILLocation loc, SILValue value,
816811
LoweringStyle style) const override {
817-
emitReleaseValue(B, loc, value);
812+
emitDestroyValue(B, loc, value);
818813
}
819814
};
820815

@@ -825,13 +820,13 @@ namespace {
825820
ReferenceTypeLowering(SILType type)
826821
: LeafLoadableTypeLowering(type, IsReferenceCounted) {}
827822

828-
void emitRetainValue(SILBuilder &B, SILLocation loc,
823+
void emitCopyValue(SILBuilder &B, SILLocation loc,
829824
SILValue value) const override {
830825
if (!isa<FunctionRefInst>(value))
831826
B.createStrongRetain(loc, value, Atomicity::Atomic);
832827
}
833828

834-
void emitReleaseValue(SILBuilder &B, SILLocation loc,
829+
void emitDestroyValue(SILBuilder &B, SILLocation loc,
835830
SILValue value) const override {
836831
B.emitStrongReleaseAndFold(loc, value);
837832
}
@@ -843,12 +838,12 @@ namespace {
843838
LoadableUnownedTypeLowering(SILType type)
844839
: LeafLoadableTypeLowering(type, IsReferenceCounted) {}
845840

846-
void emitRetainValue(SILBuilder &B, SILLocation loc,
841+
void emitCopyValue(SILBuilder &B, SILLocation loc,
847842
SILValue value) const override {
848843
B.createUnownedRetain(loc, value, Atomicity::Atomic);
849844
}
850845

851-
void emitReleaseValue(SILBuilder &B, SILLocation loc,
846+
void emitDestroyValue(SILBuilder &B, SILLocation loc,
852847
SILValue value) const override {
853848
B.createUnownedRelease(loc, value, Atomicity::Atomic);
854849
}
@@ -888,24 +883,22 @@ namespace {
888883
B.emitDestroyAddrAndFold(loc, value);
889884
}
890885

891-
void emitRetainValue(SILBuilder &B, SILLocation loc,
886+
void emitCopyValue(SILBuilder &B, SILLocation loc,
892887
SILValue value) const override {
893888
llvm_unreachable("type is not loadable!");
894889
}
895890

896-
void emitLoweredRetainValue(SILBuilder &B, SILLocation loc,
897-
SILValue value,
891+
void emitLoweredCopyValue(SILBuilder &B, SILLocation loc, SILValue value,
898892
LoweringStyle style) const override {
899893
llvm_unreachable("type is not loadable!");
900894
}
901895

902-
void emitReleaseValue(SILBuilder &B, SILLocation loc,
896+
void emitDestroyValue(SILBuilder &B, SILLocation loc,
903897
SILValue value) const override {
904898
llvm_unreachable("type is not loadable!");
905899
}
906900

907-
void emitLoweredReleaseValue(SILBuilder &B, SILLocation loc,
908-
SILValue value,
901+
void emitLoweredDestroyValue(SILBuilder &B, SILLocation loc, SILValue value,
909902
LoweringStyle style) const override {
910903
llvm_unreachable("type is not loadable!");
911904
}

lib/SILGen/ManagedValue.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ ManagedValue ManagedValue::copy(SILGenFunction &gen, SILLocation l) {
3333
assert(!lowering.isTrivial() && "trivial value has cleanup?");
3434

3535
if (!lowering.isAddressOnly()) {
36-
lowering.emitRetainValue(gen.B, l, getValue());
36+
lowering.emitCopyValue(gen.B, l, getValue());
3737
return gen.emitManagedRValueWithCleanup(getValue(), lowering);
3838
}
3939

@@ -51,7 +51,7 @@ void ManagedValue::copyInto(SILGenFunction &gen, SILValue dest, SILLocation L) {
5151
IsNotTake, IsInitialization);
5252
return;
5353
}
54-
lowering.emitRetainValue(gen.B, L, getValue());
54+
lowering.emitCopyValue(gen.B, L, getValue());
5555
gen.B.createStore(L, getValue(), dest);
5656
}
5757

@@ -65,7 +65,7 @@ ManagedValue ManagedValue::copyUnmanaged(SILGenFunction &gen, SILLocation loc) {
6565

6666
SILValue result;
6767
if (!lowering.isAddressOnly()) {
68-
lowering.emitRetainValue(gen.B, loc, getValue());
68+
lowering.emitCopyValue(gen.B, loc, getValue());
6969
result = getValue();
7070
} else {
7171
result = gen.emitTemporaryAllocation(loc, getType());

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2422,7 +2422,7 @@ RValue SILGenFunction::emitApply(
24222422

24232423
case ResultConvention::Unowned:
24242424
// Unretained. Retain the value.
2425-
resultTL.emitRetainValue(B, loc, result);
2425+
resultTL.emitCopyValue(B, loc, result);
24262426
break;
24272427
}
24282428

0 commit comments

Comments
 (0)