Skip to content

Commit 7cb3733

Browse files
committed
Rename OwnershipForwardingMixin -> ForwardingInstruction
1 parent 2b8a397 commit 7cb3733

16 files changed

+72
-75
lines changed

include/swift/SIL/OwnershipUseVisitor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ bool OwnershipUseVisitor<Impl>::visitInnerBorrowScopeEnd(Operand *borrowEnd) {
296296
// TODO: When we have ForwardingInstruction abstraction, walk the use-def
297297
// chain to ensure we have a partial_apply [on_stack] def.
298298
assert(pai && pai->isOnStack() ||
299-
OwnershipForwardingMixin::get(
299+
ForwardingInstruction::get(
300300
cast<SingleValueInstruction>(borrowEnd->get())));
301301
return handleUsePoint(borrowEnd, UseLifetimeConstraint::NonLifetimeEnding);
302302
}

include/swift/SIL/OwnershipUtils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ class ForwardingOperand {
219219
}
220220

221221
bool preservesOwnership() const {
222-
auto &mixin = *OwnershipForwardingMixin::get(use->getUser());
222+
auto &mixin = *ForwardingInstruction::get(use->getUser());
223223
return mixin.preservesOwnership();
224224
}
225225

include/swift/SIL/SILInstruction.h

Lines changed: 29 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,14 +1191,14 @@ class CopyLikeInstruction {
11911191
///
11921192
/// NOTE: We assume that the constructor for the instruction subclass that
11931193
/// initializes the kind field on our object is run before our constructor runs.
1194-
class OwnershipForwardingMixin {
1194+
class ForwardingInstruction {
11951195
ValueOwnershipKind ownershipKind;
11961196
bool preservesOwnershipFlag;
11971197

11981198
protected:
1199-
OwnershipForwardingMixin(SILInstructionKind kind,
1200-
ValueOwnershipKind ownershipKind,
1201-
bool preservesOwnership = true)
1199+
ForwardingInstruction(SILInstructionKind kind,
1200+
ValueOwnershipKind ownershipKind,
1201+
bool preservesOwnership = true)
12021202
: ownershipKind(ownershipKind),
12031203
preservesOwnershipFlag(preservesOwnership) {
12041204
assert(isa(kind) && "Invalid subclass?!");
@@ -1240,7 +1240,7 @@ class OwnershipForwardingMixin {
12401240
}
12411241

12421242
/// Defined inline below due to forward declaration issues.
1243-
static OwnershipForwardingMixin *get(SILInstruction *inst);
1243+
static ForwardingInstruction *get(SILInstruction *inst);
12441244
/// Defined inline below due to forward declaration issues.
12451245
static bool isa(SILInstructionKind kind);
12461246
static bool isa(const SILInstruction *inst) { return isa(inst->getKind()); }
@@ -1253,13 +1253,13 @@ class OwnershipForwardingMixin {
12531253
/// Return true if the forwarded value has the same representation. If true,
12541254
/// then the result can be mapped to the same storage without a move or copy.
12551255
///
1256-
/// \p inst is an OwnershipForwardingMixin
1256+
/// \p inst is an ForwardingInstruction
12571257
static bool hasSameRepresentation(SILInstruction *inst);
12581258

12591259
/// Return true if the forwarded value is address-only either before or after
12601260
/// forwarding.
12611261
///
1262-
/// \p inst is an OwnershipForwardingMixin
1262+
/// \p inst is an ForwardingInstruction
12631263
static bool isAddressOnly(SILInstruction *inst);
12641264
};
12651265

@@ -1272,14 +1272,14 @@ class OwnershipForwardingMixin {
12721272
/// operation that has no operand at all, like `enum .None`.
12731273
class FirstArgOwnershipForwardingSingleValueInst
12741274
: public SingleValueInstruction,
1275-
public OwnershipForwardingMixin {
1275+
public ForwardingInstruction {
12761276
protected:
12771277
FirstArgOwnershipForwardingSingleValueInst(SILInstructionKind kind,
12781278
SILDebugLocation debugLoc,
12791279
SILType ty,
12801280
ValueOwnershipKind ownershipKind)
12811281
: SingleValueInstruction(kind, debugLoc, ty),
1282-
OwnershipForwardingMixin(kind, ownershipKind) {
1282+
ForwardingInstruction(kind, ownershipKind) {
12831283
assert(classof(kind) && "classof missing new subclass?!");
12841284
}
12851285

@@ -1404,16 +1404,15 @@ FirstArgOwnershipForwardingSingleValueInst::classof(SILInstructionKind kind) {
14041404
}
14051405
}
14061406

1407-
class AllArgOwnershipForwardingSingleValueInst
1408-
: public SingleValueInstruction,
1409-
public OwnershipForwardingMixin {
1407+
class AllArgOwnershipForwardingSingleValueInst : public SingleValueInstruction,
1408+
public ForwardingInstruction {
14101409
protected:
14111410
AllArgOwnershipForwardingSingleValueInst(SILInstructionKind kind,
14121411
SILDebugLocation debugLoc,
14131412
SILType ty,
14141413
ValueOwnershipKind ownershipKind)
14151414
: SingleValueInstruction(kind, debugLoc, ty),
1416-
OwnershipForwardingMixin(kind, ownershipKind) {
1415+
ForwardingInstruction(kind, ownershipKind) {
14171416
assert(classof(kind) && "classof missing new subclass?!");
14181417
}
14191418

@@ -5549,13 +5548,13 @@ class ConversionInst : public SingleValueInstruction {
55495548
///
55505549
/// The first operand is the ownership equivalent source.
55515550
class OwnershipForwardingConversionInst : public ConversionInst,
5552-
public OwnershipForwardingMixin {
5551+
public ForwardingInstruction {
55535552
protected:
55545553
OwnershipForwardingConversionInst(SILInstructionKind kind,
55555554
SILDebugLocation debugLoc, SILType ty,
55565555
ValueOwnershipKind ownershipKind)
55575556
: ConversionInst(kind, debugLoc, ty),
5558-
OwnershipForwardingMixin(kind, ownershipKind) {
5557+
ForwardingInstruction(kind, ownershipKind) {
55595558
assert(classof(kind) && "classof missing subclass?!");
55605559
}
55615560

@@ -6784,15 +6783,15 @@ class SelectEnumInstBase
67846783

67856784
/// A select enum inst that produces a static OwnershipKind.
67866785
class OwnershipForwardingSelectEnumInstBase : public SelectEnumInstBase,
6787-
public OwnershipForwardingMixin {
6786+
public ForwardingInstruction {
67886787
protected:
67896788
OwnershipForwardingSelectEnumInstBase(
67906789
SILInstructionKind kind, SILDebugLocation debugLoc, SILType type,
67916790
bool defaultValue, Optional<ArrayRef<ProfileCounter>> caseCounts,
67926791
ProfileCounter defaultCount, ValueOwnershipKind ownershipKind)
67936792
: SelectEnumInstBase(kind, debugLoc, type, defaultValue, caseCounts,
67946793
defaultCount),
6795-
OwnershipForwardingMixin(kind, ownershipKind) {
6794+
ForwardingInstruction(kind, ownershipKind) {
67966795
assert(classof(kind) && "classof missing subclass");
67976796
}
67986797

@@ -8413,7 +8412,7 @@ class MarkUnresolvedMoveAddrInst
84138412
class MarkMustCheckInst
84148413
: public UnaryInstructionBase<SILInstructionKind::MarkMustCheckInst,
84158414
SingleValueInstruction>,
8416-
public OwnershipForwardingMixin {
8415+
public ForwardingInstruction {
84178416
friend class SILBuilder;
84188417

84198418
public:
@@ -8453,8 +8452,8 @@ class MarkMustCheckInst
84538452
MarkMustCheckInst(SILDebugLocation DebugLoc, SILValue operand,
84548453
CheckKind checkKind)
84558454
: UnaryInstructionBase(DebugLoc, operand, operand->getType()),
8456-
OwnershipForwardingMixin(SILInstructionKind::MarkMustCheckInst,
8457-
operand->getOwnershipKind()),
8455+
ForwardingInstruction(SILInstructionKind::MarkMustCheckInst,
8456+
operand->getOwnershipKind()),
84588457
kind(checkKind) {
84598458
assert(operand->getType().isMoveOnly() &&
84608459
"mark_must_check can only take a move only typed value");
@@ -8484,7 +8483,7 @@ class MarkUnresolvedReferenceBindingInst
84848483
: public UnaryInstructionBase<
84858484
SILInstructionKind::MarkUnresolvedReferenceBindingInst,
84868485
SingleValueInstruction>,
8487-
public OwnershipForwardingMixin {
8486+
public ForwardingInstruction {
84888487
friend class SILBuilder;
84898488

84908489
public:
@@ -8500,7 +8499,7 @@ class MarkUnresolvedReferenceBindingInst
85008499
MarkUnresolvedReferenceBindingInst(SILDebugLocation debugLoc,
85018500
SILValue operand, Kind kind)
85028501
: UnaryInstructionBase(debugLoc, operand, operand->getType()),
8503-
OwnershipForwardingMixin(
8502+
ForwardingInstruction(
85048503
SILInstructionKind::MarkUnresolvedReferenceBindingInst,
85058504
operand->getOwnershipKind()),
85068505
kind(kind) {}
@@ -9271,14 +9270,14 @@ class TermInst : public NonValueInstruction {
92719270

92729271
// Forwards the first operand to a result in each successor block.
92739272
class OwnershipForwardingTermInst : public TermInst,
9274-
public OwnershipForwardingMixin {
9273+
public ForwardingInstruction {
92759274
protected:
92769275
OwnershipForwardingTermInst(SILInstructionKind kind,
92779276
SILDebugLocation debugLoc,
92789277
ValueOwnershipKind ownershipKind,
92799278
bool preservesOwnership = true)
92809279
: TermInst(kind, debugLoc),
9281-
OwnershipForwardingMixin(kind, ownershipKind, preservesOwnership) {
9280+
ForwardingInstruction(kind, ownershipKind, preservesOwnership) {
92829281
assert(classof(kind));
92839282
}
92849283

@@ -10791,13 +10790,13 @@ SILFunction *ApplyInstBase<Impl, Base, false>::getCalleeFunction() const {
1079110790
/// The first operand is the ownership equivalent source.
1079210791
class OwnershipForwardingMultipleValueInstruction
1079310792
: public MultipleValueInstruction,
10794-
public OwnershipForwardingMixin {
10793+
public ForwardingInstruction {
1079510794
public:
1079610795
OwnershipForwardingMultipleValueInstruction(SILInstructionKind kind,
1079710796
SILDebugLocation loc,
1079810797
ValueOwnershipKind ownershipKind)
1079910798
: MultipleValueInstruction(kind, loc),
10800-
OwnershipForwardingMixin(kind, ownershipKind) {
10799+
ForwardingInstruction(kind, ownershipKind) {
1080110800
assert(classof(kind) && "Missing subclass from classof?!");
1080210801
}
1080310802

@@ -10941,7 +10940,7 @@ inline bool Operand::isTypeDependent() const {
1094110940
return getUser()->isTypeDependentOperand(*this);
1094210941
}
1094310942

10944-
inline bool OwnershipForwardingMixin::isa(SILInstructionKind kind) {
10943+
inline bool ForwardingInstruction::isa(SILInstructionKind kind) {
1094510944
return FirstArgOwnershipForwardingSingleValueInst::classof(kind) ||
1094610945
AllArgOwnershipForwardingSingleValueInst::classof(kind) ||
1094710946
OwnershipForwardingTermInst::classof(kind) ||
@@ -10952,12 +10951,11 @@ inline bool OwnershipForwardingMixin::isa(SILInstructionKind kind) {
1095210951
kind == SILInstructionKind::MarkUnresolvedReferenceBindingInst;
1095310952
}
1095410953

10955-
inline OwnershipForwardingMixin *
10956-
OwnershipForwardingMixin::get(SILInstruction *inst) {
10954+
inline ForwardingInstruction *ForwardingInstruction::get(SILInstruction *inst) {
1095710955
// I am purposely performing this cast in this manner rather than reinterpret
10958-
// casting to OwnershipForwardingMixin to ensure that we offset to the
10956+
// casting to ForwardingInstruction to ensure that we offset to the
1095910957
// appropriate offset inside of inst instead of converting inst's current
10960-
// location to an OwnershipForwardingMixin which would be incorrect.
10958+
// location to an ForwardingInstruction which would be incorrect.
1096110959
if (auto *result = dyn_cast<FirstArgOwnershipForwardingSingleValueInst>(inst))
1096210960
return result;
1096310961
if (auto *result = dyn_cast<AllArgOwnershipForwardingSingleValueInst>(inst))

lib/SIL/IR/SILInstructions.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,15 +3200,15 @@ ReturnInst::ReturnInst(SILFunction &func, SILDebugLocation debugLoc,
32003200
"result info?!");
32013201
}
32023202

3203-
bool OwnershipForwardingMixin::hasSameRepresentation(SILInstruction *inst) {
3203+
bool ForwardingInstruction::hasSameRepresentation(SILInstruction *inst) {
32043204
switch (inst->getKind()) {
32053205
// Explicitly list instructions which definitely involve a representation
32063206
// change.
32073207
case SILInstructionKind::SwitchEnumInst:
32083208
default:
32093209
// Conservatively assume that a conversion changes representation.
32103210
// Operations can be added as needed to participate in SIL opaque values.
3211-
assert(OwnershipForwardingMixin::isa(inst));
3211+
assert(ForwardingInstruction::isa(inst));
32123212
return false;
32133213

32143214
case SILInstructionKind::ConvertFunctionInst:
@@ -3228,14 +3228,14 @@ bool OwnershipForwardingMixin::hasSameRepresentation(SILInstruction *inst) {
32283228
}
32293229
}
32303230

3231-
bool OwnershipForwardingMixin::isAddressOnly(SILInstruction *inst) {
3231+
bool ForwardingInstruction::isAddressOnly(SILInstruction *inst) {
32323232
if (auto *aggregate =
3233-
dyn_cast<AllArgOwnershipForwardingSingleValueInst>(inst)) {
3233+
dyn_cast<AllArgOwnershipForwardingSingleValueInst>(inst)) {
32343234
// If any of the operands are address-only, then the aggregate must be.
32353235
return aggregate->getType().isAddressOnly(*inst->getFunction());
32363236
}
32373237
// All other forwarding instructions must forward their first operand.
3238-
assert(OwnershipForwardingMixin::isa(inst));
3238+
assert(ForwardingInstruction::isa(inst));
32393239
return inst->getOperand(0)->getType().isAddressOnly(*inst->getFunction());
32403240
}
32413241

lib/SIL/IR/SILPrinter.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1725,8 +1725,7 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17251725
}
17261726
}
17271727

1728-
void printForwardingOwnershipKind(OwnershipForwardingMixin *inst,
1729-
SILValue op) {
1728+
void printForwardingOwnershipKind(ForwardingInstruction *inst, SILValue op) {
17301729
if (!op)
17311730
return;
17321731

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4273,7 +4273,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
42734273
return true;
42744274

42754275
ValueOwnershipKind forwardingOwnership = Val->getOwnershipKind();
4276-
if (OwnershipForwardingMixin::isa(Opcode)) {
4276+
if (ForwardingInstruction::isa(Opcode)) {
42774277
if (parseForwardingOwnershipKind(forwardingOwnership))
42784278
return true;
42794279
}

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,10 +899,10 @@ SILValue swift::findOwnershipReferenceAggregate(SILValue ref) {
899899
if (!root)
900900
return root;
901901

902-
if (isa<FirstArgOwnershipForwardingSingleValueInst>(root)
903-
|| isa<OwnershipForwardingConversionInst>(root)
904-
|| isa<OwnershipForwardingSelectEnumInstBase>(root)
905-
|| isa<OwnershipForwardingMultipleValueInstruction>(root)) {
902+
if (isa<FirstArgOwnershipForwardingSingleValueInst>(root) ||
903+
isa<OwnershipForwardingConversionInst>(root) ||
904+
isa<OwnershipForwardingSelectEnumInstBase>(root) ||
905+
isa<OwnershipForwardingMultipleValueInstruction>(root)) {
906906
SILInstruction *inst = root->getDefiningInstruction();
907907

908908
// The `enum` instruction can have no operand.

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -112,26 +112,26 @@ bool swift::canOpcodeForwardInnerGuaranteedValues(SILValue value) {
112112
if (auto *arg = dyn_cast<SILArgument>(value))
113113
if (auto *ti = arg->getSingleTerminator())
114114
if (ti->mayHaveTerminatorResult())
115-
return OwnershipForwardingMixin::get(ti)->preservesOwnership();
115+
return ForwardingInstruction::get(ti)->preservesOwnership();
116116

117117
if (auto *inst = value->getDefiningInstruction())
118-
if (auto *mixin = OwnershipForwardingMixin::get(inst))
118+
if (auto *mixin = ForwardingInstruction::get(inst))
119119
return mixin->preservesOwnership() &&
120120
!isa<OwnedFirstArgForwardingSingleValueInst>(inst);
121121

122122
return false;
123123
}
124124

125125
bool swift::canOpcodeForwardInnerGuaranteedValues(Operand *use) {
126-
if (auto *mixin = OwnershipForwardingMixin::get(use->getUser()))
126+
if (auto *mixin = ForwardingInstruction::get(use->getUser()))
127127
return mixin->preservesOwnership() &&
128128
!isa<OwnedFirstArgForwardingSingleValueInst>(use->getUser());
129129
return false;
130130
}
131131

132132
bool swift::canOpcodeForwardOwnedValues(SILValue value) {
133133
if (auto *inst = value->getDefiningInstructionOrTerminator()) {
134-
if (auto *mixin = OwnershipForwardingMixin::get(inst)) {
134+
if (auto *mixin = ForwardingInstruction::get(inst)) {
135135
return mixin->preservesOwnership() &&
136136
!isa<GuaranteedFirstArgForwardingSingleValueInst>(inst);
137137
}
@@ -141,7 +141,7 @@ bool swift::canOpcodeForwardOwnedValues(SILValue value) {
141141

142142
bool swift::canOpcodeForwardOwnedValues(Operand *use) {
143143
auto *user = use->getUser();
144-
if (auto *mixin = OwnershipForwardingMixin::get(user))
144+
if (auto *mixin = ForwardingInstruction::get(user))
145145
return mixin->preservesOwnership() &&
146146
!isa<GuaranteedFirstArgForwardingSingleValueInst>(user);
147147
return false;
@@ -1733,12 +1733,12 @@ bool swift::visitForwardedGuaranteedOperands(
17331733
if (inst->getNumRealOperands() == 0) {
17341734
return false;
17351735
}
1736-
if (isa<FirstArgOwnershipForwardingSingleValueInst>(inst)
1737-
|| isa<OwnershipForwardingConversionInst>(inst)
1738-
|| isa<OwnershipForwardingSelectEnumInstBase>(inst)
1739-
|| isa<OwnershipForwardingMultipleValueInstruction>(inst)
1740-
|| isa<MoveOnlyWrapperToCopyableValueInst>(inst)
1741-
|| isa<CopyableToMoveOnlyWrapperValueInst>(inst)) {
1736+
if (isa<FirstArgOwnershipForwardingSingleValueInst>(inst) ||
1737+
isa<OwnershipForwardingConversionInst>(inst) ||
1738+
isa<OwnershipForwardingSelectEnumInstBase>(inst) ||
1739+
isa<OwnershipForwardingMultipleValueInstruction>(inst) ||
1740+
isa<MoveOnlyWrapperToCopyableValueInst>(inst) ||
1741+
isa<CopyableToMoveOnlyWrapperValueInst>(inst)) {
17421742
assert(!isa<SingleValueInstruction>(inst)
17431743
|| !BorrowedValue(cast<SingleValueInstruction>(inst))
17441744
&& "forwarded operand cannot begin a borrow scope");

lib/SIL/Verifier/SILVerifier.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,7 +1306,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
13061306
}
13071307
}
13081308

1309-
if (I->getFunction()->hasOwnership() && OwnershipForwardingMixin::isa(I)) {
1309+
if (I->getFunction()->hasOwnership() && ForwardingInstruction::isa(I)) {
13101310
checkOwnershipForwardingInst(I);
13111311
}
13121312
}
@@ -1353,7 +1353,7 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
13531353
/// of its results, check forwarding invariants.
13541354
void checkOwnershipForwardingInst(SILInstruction *i) {
13551355
ValueOwnershipKind ownership =
1356-
OwnershipForwardingMixin::get(i)->getForwardingOwnershipKind();
1356+
ForwardingInstruction::get(i)->getForwardingOwnershipKind();
13571357

13581358
if (auto *o = dyn_cast<OwnedFirstArgForwardingSingleValueInst>(i)) {
13591359
ValueOwnershipKind kind = OwnershipKind::Owned;
@@ -1378,9 +1378,9 @@ class SILVerifier : public SILVerifierBase<SILVerifier> {
13781378
// representation. Non-destructive projection is allowed. Aggregation and
13791379
// destructive disaggregation is not allowed. See SIL.rst, Forwarding
13801380
// Addres-Only Values.
1381-
if (ownership == OwnershipKind::Guaranteed
1382-
&& OwnershipForwardingMixin::isAddressOnly(i)) {
1383-
require(OwnershipForwardingMixin::hasSameRepresentation(i),
1381+
if (ownership == OwnershipKind::Guaranteed &&
1382+
ForwardingInstruction::isAddressOnly(i)) {
1383+
require(ForwardingInstruction::hasSameRepresentation(i),
13841384
"Forwarding a guaranteed address-only value requires the same "
13851385
"representation since no move or copy is allowed.");
13861386
}

0 commit comments

Comments
 (0)