Skip to content

Commit 7db84f2

Browse files
committed
[NFC] SIL: Typed move_value's isLexical.
1 parent 9f6c309 commit 7db84f2

File tree

11 files changed

+32
-28
lines changed

11 files changed

+32
-28
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1426,7 +1426,7 @@ class SILBuilder {
14261426
}
14271427

14281428
MoveValueInst *createMoveValue(SILLocation loc, SILValue operand,
1429-
bool isLexical = false,
1429+
IsLexical_t isLexical = IsNotLexical,
14301430
bool hasPointerEscape = false,
14311431
bool fromVarDecl = false) {
14321432
assert(getFunction().hasOwnership());
@@ -2849,7 +2849,7 @@ class SILBuilder {
28492849
/// Convenience function that is a no-op for trivial values and inserts a
28502850
/// move_value on non-trivial instructions.
28512851
SILValue emitMoveValueOperation(SILLocation Loc, SILValue v,
2852-
bool isLexical = false,
2852+
IsLexical_t isLexical = IsNotLexical,
28532853
bool hasPointerEscape = false,
28542854
bool fromVarDecl = false) {
28552855
assert(!v->getType().isAddress());

include/swift/SIL/SILInstruction.h

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8674,10 +8674,10 @@ class MoveValueInst
86748674

86758675
USE_SHARED_UINT8;
86768676

8677-
MoveValueInst(SILDebugLocation DebugLoc, SILValue operand, bool isLexical,
8678-
bool hasPointerEscape, bool fromVarDecl)
8677+
MoveValueInst(SILDebugLocation DebugLoc, SILValue operand,
8678+
IsLexical_t isLexical, bool hasPointerEscape, bool fromVarDecl)
86798679
: UnaryInstructionBase(DebugLoc, operand, operand->getType()) {
8680-
sharedUInt8().MoveValueInst.lexical = isLexical;
8680+
sharedUInt8().MoveValueInst.lexical = (bool)isLexical;
86818681
sharedUInt8().MoveValueInst.pointerEscape = hasPointerEscape;
86828682
sharedUInt8().MoveValueInst.fromVarDecl = fromVarDecl;
86838683
}
@@ -8693,8 +8693,12 @@ class MoveValueInst
86938693
sharedUInt8().MoveValueInst.allowDiagnostics = newValue;
86948694
}
86958695

8696-
bool isLexical() const { return sharedUInt8().MoveValueInst.lexical; }
8697-
void removeIsLexical() { sharedUInt8().MoveValueInst.lexical = false; }
8696+
IsLexical_t isLexical() const {
8697+
return IsLexical_t(sharedUInt8().MoveValueInst.lexical);
8698+
}
8699+
void removeIsLexical() {
8700+
sharedUInt8().MoveValueInst.lexical = (bool)IsNotLexical;
8701+
}
86988702

86998703
bool hasPointerEscape() const {
87008704
return sharedUInt8().MoveValueInst.pointerEscape;

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3494,7 +3494,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
34943494

34953495
case SILInstructionKind::MoveValueInst: {
34963496
bool allowsDiagnostics = false;
3497-
bool isLexical = false;
3497+
auto isLexical = IsNotLexical;
34983498
bool hasPointerEscape = false;
34993499
bool fromVarDecl = false;
35003500

@@ -3504,7 +3504,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
35043504
if (AttrName == "allows_diagnostics")
35053505
allowsDiagnostics = true;
35063506
else if (AttrName == "lexical")
3507-
isLexical = true;
3507+
isLexical = IsLexical;
35083508
else if (AttrName == "pointer_escape")
35093509
hasPointerEscape = true;
35103510
else if (AttrName == "var_decl")

lib/SILGen/SILGenBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1125,7 +1125,7 @@ ManagedValue SILGenBuilder::createFormalAccessBeginBorrow(SILLocation loc,
11251125
}
11261126

11271127
ManagedValue SILGenBuilder::createMoveValue(SILLocation loc, ManagedValue value,
1128-
bool isLexical) {
1128+
IsLexical_t isLexical) {
11291129
assert(value.isPlusOne(SGF) && "Must be +1 to be moved!");
11301130
auto *mdi =
11311131
createMoveValue(loc, value.forward(getSILGenFunction()), isLexical);

lib/SILGen/SILGenBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ class SILGenBuilder : public SILBuilder {
490490

491491
using SILBuilder::createMoveValue;
492492
ManagedValue createMoveValue(SILLocation loc, ManagedValue value,
493-
bool isLexical = false);
493+
IsLexical_t isLexical = IsNotLexical);
494494

495495
using SILBuilder::createOwnedMoveOnlyWrapperToCopyableValue;
496496
ManagedValue createOwnedMoveOnlyWrapperToCopyableValue(SILLocation loc,

lib/SILGen/SILGenDecl.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ class LetValueInitialization : public Initialization {
781781
// Then check if we have a pure move only type. In that case, we need to
782782
// insert a no implicit copy
783783
if (value->getType().isMoveOnly(/*orWrapped=*/false)) {
784-
value = SGF.B.createMoveValue(PrologueLoc, value, /*isLexical*/ true);
784+
value = SGF.B.createMoveValue(PrologueLoc, value, IsLexical);
785785
return SGF.B.createMarkUnresolvedNonCopyableValueInst(
786786
PrologueLoc, value,
787787
MarkUnresolvedNonCopyableValueInst::CheckKind::
@@ -797,7 +797,7 @@ class LetValueInitialization : public Initialization {
797797
// move only wrapper and mark it as needing checking by the move cherk.
798798
value =
799799
SGF.B.createOwnedCopyableToMoveOnlyWrapperValue(PrologueLoc, value);
800-
value = SGF.B.createMoveValue(PrologueLoc, value, /*isLexical*/ true);
800+
value = SGF.B.createMoveValue(PrologueLoc, value, IsLexical);
801801
return SGF.B.createMarkUnresolvedNonCopyableValueInst(
802802
PrologueLoc, value,
803803
MarkUnresolvedNonCopyableValueInst::CheckKind::
@@ -831,7 +831,7 @@ class LetValueInitialization : public Initialization {
831831
// types do not have no implicit copy attr on them.
832832
if (value->getOwnershipKind() == OwnershipKind::Owned &&
833833
value->getType().isMoveOnly(/*orWrapped=*/false)) {
834-
value = SGF.B.createMoveValue(PrologueLoc, value, true /*isLexical*/);
834+
value = SGF.B.createMoveValue(PrologueLoc, value, IsLexical);
835835
return SGF.B.createMarkUnresolvedNonCopyableValueInst(
836836
PrologueLoc, value,
837837
MarkUnresolvedNonCopyableValueInst::CheckKind::
@@ -841,7 +841,7 @@ class LetValueInitialization : public Initialization {
841841
// If we have a no implicit copy lexical, emit the instruction stream so
842842
// that the move checker knows to check this variable.
843843
if (vd->isNoImplicitCopy()) {
844-
value = SGF.B.createMoveValue(PrologueLoc, value, /*isLexical*/ true,
844+
value = SGF.B.createMoveValue(PrologueLoc, value, IsLexical,
845845
/*hasPointerEscape=*/false,
846846
/*fromVarDecl=*/true);
847847
value =
@@ -855,14 +855,15 @@ class LetValueInitialization : public Initialization {
855855
// Otherwise, if we do not have a no implicit copy variable, just follow
856856
// the "normal path".
857857

858-
auto isLexical = SGF.F.getLifetime(vd, value->getType()).isLexical();
858+
auto isLexical =
859+
IsLexical_t(SGF.F.getLifetime(vd, value->getType()).isLexical());
859860

860861
if (value->getOwnershipKind() == OwnershipKind::Owned)
861-
return SGF.B.createMoveValue(PrologueLoc, value, /*isLexical*/ isLexical,
862+
return SGF.B.createMoveValue(PrologueLoc, value, isLexical,
862863
/*hasPointerEscape=*/false,
863864
/*fromVarDecl=*/true);
864865

865-
return SGF.B.createBeginBorrow(PrologueLoc, value, IsLexical_t(isLexical),
866+
return SGF.B.createBeginBorrow(PrologueLoc, value, isLexical,
866867
/*hasPointerEscape=*/false,
867868
/*fromVarDecl=*/true);
868869
}

lib/SILGen/SILGenProlog.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ class ArgumentInitHelper {
789789
SILValue value = SGF.B.createOwnedCopyableToMoveOnlyWrapperValue(
790790
loc, argrv.getValue());
791791
argrv = SGF.emitManagedRValueWithCleanup(value);
792-
argrv = SGF.B.createMoveValue(loc, argrv, /*isLexical=*/true);
792+
argrv = SGF.B.createMoveValue(loc, argrv, IsLexical);
793793

794794
// If our argument was owned, we use no implicit copy. Otherwise, we
795795
// use no copy.
@@ -824,7 +824,7 @@ class ArgumentInitHelper {
824824
// If we have an owned value, forward it into the
825825
// mark_unresolved_non_copyable_value to avoid an extra destroy_value.
826826
argrv = SGF.B.createOwnedCopyableToMoveOnlyWrapperValue(loc, argrv);
827-
argrv = SGF.B.createMoveValue(loc, argrv, true /*is lexical*/);
827+
argrv = SGF.B.createMoveValue(loc, argrv, IsLexical);
828828
argrv = SGF.B.createMarkUnresolvedNonCopyableValueInst(
829829
loc, argrv,
830830
MarkUnresolvedNonCopyableValueInst::CheckKind::

lib/SILOptimizer/Transforms/SILMem2Reg.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -777,7 +777,7 @@ beginOwnedLexicalLifetimeAfterStore(AllocStackInst *asi, StoreInst *inst) {
777777

778778
MoveValueInst *mvi = nullptr;
779779
SILBuilderWithScope::insertAfter(inst, [&](SILBuilder &builder) {
780-
mvi = builder.createMoveValue(loc, stored, /*isLexical*/ true);
780+
mvi = builder.createMoveValue(loc, stored, IsLexical);
781781
});
782782
StorageStateTracking<LiveValues> vals = {LiveValues::forOwned(stored, mvi),
783783
/*isStorageValid=*/true};

lib/SILOptimizer/Utils/LexicalDestroyFolding.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,8 +498,7 @@ bool Rewriter::createMove() {
498498
auto introducerBuilder = SILBuilderWithScope(context.introducer);
499499
mvi = introducerBuilder.createMoveValue(
500500
RegularLocation::getAutoGeneratedLocation(context.introducer->getLoc()),
501-
context.borrowee,
502-
/*isLexical=*/true);
501+
context.borrowee, IsLexical);
503502
context.introducer->setOperand(mvi);
504503
return true;
505504
}

lib/SILOptimizer/Utils/SILInliner.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -743,16 +743,16 @@ SILValue SILInlineCloner::moveFunctionArgument(SILValue callArg,
743743
unsigned index) {
744744
auto scope = scopeForArgument(Scope::None, callArg, index,
745745
Apply.getFunction(), getCalleeFunction());
746-
bool isLexical;
746+
IsLexical_t isLexical;
747747
switch (scope) {
748748
case Scope::None:
749749
return SILValue();
750750
case Scope::Bare:
751751
assert(false && "Non-lexical move produced during inlining!?");
752-
isLexical = false;
752+
isLexical = IsNotLexical;
753753
break;
754754
case Scope::Lexical:
755-
isLexical = true;
755+
isLexical = IsLexical;
756756
break;
757757
}
758758
SILBuilderWithScope beginBuilder(Apply.getInstruction(), getBuilder());

0 commit comments

Comments
 (0)