Skip to content

Commit 611511a

Browse files
committed
[NFC] SIL: Typed alloc_stack's wasMoved.
Help avoid errors with boolean flags by introducing UsesMoveableValueDebugInfo_t.
1 parent 5ccec0e commit 611511a

File tree

8 files changed

+45
-36
lines changed

8 files changed

+45
-36
lines changed

include/swift/SIL/SILBridgingImpl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,9 +1461,9 @@ BridgedInstruction BridgedBuilder::createIntegerLiteral(BridgedType type, SwiftI
14611461

14621462
BridgedInstruction BridgedBuilder::createAllocStack(BridgedType type,
14631463
bool hasDynamicLifetime, bool isLexical, bool wasMoved) const {
1464-
return {unbridged().createAllocStack(regularLoc(), type.unbridged(),
1465-
std::nullopt, hasDynamicLifetime,
1466-
isLexical, wasMoved)};
1464+
return {unbridged().createAllocStack(
1465+
regularLoc(), type.unbridged(), std::nullopt, hasDynamicLifetime,
1466+
isLexical, swift::UsesMoveableValueDebugInfo_t(wasMoved))};
14671467
}
14681468

14691469
BridgedInstruction BridgedBuilder::createAllocVector(BridgedValue capacity, BridgedType type) const {

include/swift/SIL/SILBuilder.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,11 +402,12 @@ class SILBuilder {
402402
substituteAnonymousArgs(llvm::SmallString<4> Name,
403403
std::optional<SILDebugVariable> Var, SILLocation Loc);
404404

405-
AllocStackInst *
406-
createAllocStack(SILLocation Loc, SILType elementType,
407-
std::optional<SILDebugVariable> Var = std::nullopt,
408-
bool hasDynamicLifetime = false, bool isLexical = false,
409-
bool wasMoved = false, bool skipVarDeclAssert = false) {
405+
AllocStackInst *createAllocStack(
406+
SILLocation Loc, SILType elementType,
407+
std::optional<SILDebugVariable> Var = std::nullopt,
408+
bool hasDynamicLifetime = false, bool isLexical = false,
409+
UsesMoveableValueDebugInfo_t wasMoved = DoesNotUseMoveableValueDebugInfo,
410+
bool skipVarDeclAssert = false) {
410411
llvm::SmallString<4> Name;
411412
Loc.markAsPrologue();
412413
#ifndef NDEBUG

include/swift/SIL/SILInstruction.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,11 @@ class AllocationInst : public SingleValueInstruction {
19631963

19641964
class DeallocStackInst;
19651965

1966+
enum UsesMoveableValueDebugInfo_t : bool {
1967+
DoesNotUseMoveableValueDebugInfo = false,
1968+
UsesMoveableValueDebugInfo = true,
1969+
};
1970+
19661971
/// AllocStackInst - This represents the allocation of an unboxed (i.e., no
19671972
/// reference count) stack memory. The memory is provided uninitialized.
19681973
class AllocStackInst final
@@ -1982,13 +1987,14 @@ class AllocStackInst final
19821987
AllocStackInst(SILDebugLocation Loc, SILType elementType,
19831988
ArrayRef<SILValue> TypeDependentOperands, SILFunction &F,
19841989
std::optional<SILDebugVariable> Var, bool hasDynamicLifetime,
1985-
bool isLexical, bool usesMoveableValueDebugInfo);
1990+
bool isLexical,
1991+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo);
19861992

19871993
static AllocStackInst *create(SILDebugLocation Loc, SILType elementType,
19881994
SILFunction &F,
19891995
std::optional<SILDebugVariable> Var,
19901996
bool hasDynamicLifetime, bool isLexical,
1991-
bool usesMoveableValueDebugInfo);
1997+
UsesMoveableValueDebugInfo_t wasMoved);
19921998

19931999
SIL_DEBUG_VAR_SUPPLEMENT_TRAILING_OBJS_IMPL()
19942000

@@ -2006,13 +2012,15 @@ class AllocStackInst final
20062012
}
20072013

20082014
void markUsesMoveableValueDebugInfo() {
2009-
sharedUInt8().AllocStackInst.usesMoveableValueDebugInfo = true;
2015+
sharedUInt8().AllocStackInst.usesMoveableValueDebugInfo =
2016+
(bool)UsesMoveableValueDebugInfo;
20102017
}
20112018

20122019
/// Set to true if this alloc_stack's memory location was passed to _move at
20132020
/// any point of the program.
2014-
bool usesMoveableValueDebugInfo() const {
2015-
return sharedUInt8().AllocStackInst.usesMoveableValueDebugInfo;
2021+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo() const {
2022+
return UsesMoveableValueDebugInfo_t(
2023+
sharedUInt8().AllocStackInst.usesMoveableValueDebugInfo);
20162024
}
20172025

20182026
/// Set to true that this alloc_stack contains a value whose lifetime can not

lib/SIL/IR/SILInstructions.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,12 +222,11 @@ SILDebugVariable::createFromAllocation(const AllocationInst *AI) {
222222
return VarInfo;
223223
}
224224

225-
AllocStackInst::AllocStackInst(SILDebugLocation Loc, SILType elementType,
226-
ArrayRef<SILValue> TypeDependentOperands,
227-
SILFunction &F,
228-
std::optional<SILDebugVariable> Var,
229-
bool hasDynamicLifetime, bool isLexical,
230-
bool usesMoveableValueDebugInfo)
225+
AllocStackInst::AllocStackInst(
226+
SILDebugLocation Loc, SILType elementType,
227+
ArrayRef<SILValue> TypeDependentOperands, SILFunction &F,
228+
std::optional<SILDebugVariable> Var, bool hasDynamicLifetime,
229+
bool isLexical, UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo)
231230
: InstructionBase(Loc, elementType.getAddressType()),
232231
SILDebugVariableSupplement(Var ? Var->DIExpr.getNumElements() : 0,
233232
Var ? Var->Type.has_value() : false,
@@ -239,7 +238,7 @@ AllocStackInst::AllocStackInst(SILDebugLocation Loc, SILType elementType,
239238
sharedUInt8().AllocStackInst.dynamicLifetime = hasDynamicLifetime;
240239
sharedUInt8().AllocStackInst.lexical = isLexical;
241240
sharedUInt8().AllocStackInst.usesMoveableValueDebugInfo =
242-
usesMoveableValueDebugInfo || elementType.isMoveOnly();
241+
(bool)usesMoveableValueDebugInfo || elementType.isMoveOnly();
243242
sharedUInt32().AllocStackInst.numOperands = TypeDependentOperands.size();
244243

245244
// VarInfo must be initialized after
@@ -266,7 +265,7 @@ AllocStackInst *AllocStackInst::create(SILDebugLocation Loc,
266265
SILType elementType, SILFunction &F,
267266
std::optional<SILDebugVariable> Var,
268267
bool hasDynamicLifetime, bool isLexical,
269-
bool wasMoved) {
268+
UsesMoveableValueDebugInfo_t wasMoved) {
270269
SmallVector<SILValue, 8> TypeDependentOperands;
271270
collectTypeDependentOperands(TypeDependentOperands, F,
272271
elementType.getASTType());

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4740,7 +4740,8 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
47404740
case SILInstructionKind::AllocStackInst: {
47414741
bool hasDynamicLifetime = false;
47424742
bool isLexical = false;
4743-
bool usesMoveableValueDebugInfo = false;
4743+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo =
4744+
DoesNotUseMoveableValueDebugInfo;
47444745

47454746
StringRef attributeName;
47464747
SourceLoc attributeLoc;
@@ -4750,7 +4751,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
47504751
else if (attributeName == "lexical")
47514752
isLexical = true;
47524753
else if (attributeName == "moveable_value_debuginfo")
4753-
usesMoveableValueDebugInfo = true;
4754+
usesMoveableValueDebugInfo = UsesMoveableValueDebugInfo;
47544755
else {
47554756
P.diagnose(attributeLoc, diag::sil_invalid_attribute_for_instruction,
47564757
attributeName, "alloc_stack");
@@ -4767,7 +4768,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
47674768
return true;
47684769

47694770
if (Ty.isMoveOnly())
4770-
usesMoveableValueDebugInfo = true;
4771+
usesMoveableValueDebugInfo = UsesMoveableValueDebugInfo;
47714772

47724773
// It doesn't make sense to attach a debug var info if the name is empty
47734774
if (VarInfo.Name.size())

lib/SILGen/SILGenExpr.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,13 +1100,13 @@ SILValue SILGenFunction::emitTemporaryAllocation(SILLocation loc, SILType ty,
11001100
if (generateDebugInfo)
11011101
if (auto *VD = loc.getAsASTNode<VarDecl>())
11021102
DbgVar = SILDebugVariable(VD->isLet(), 0);
1103-
auto *alloc =
1104-
B.createAllocStack(loc, ty, DbgVar, hasDynamicLifetime, isLexical, false
1103+
auto *alloc = B.createAllocStack(loc, ty, DbgVar, hasDynamicLifetime,
1104+
isLexical, DoesNotUseMoveableValueDebugInfo
11051105
#ifndef NDEBUG
1106-
,
1107-
!generateDebugInfo
1106+
,
1107+
!generateDebugInfo
11081108
#endif
1109-
);
1109+
);
11101110
enterDeallocStackCleanup(alloc);
11111111
return alloc;
11121112
}

lib/SILOptimizer/Transforms/AllocBoxToStack.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -649,14 +649,14 @@ static bool rewriteAllocBoxAsAllocStack(AllocBoxInst *ABI) {
649649
}
650650
return false;
651651
};
652-
auto *ASI =
653-
Builder.createAllocStack(ABI->getLoc(), ty, ABI->getVarInfo(),
654-
ABI->hasDynamicLifetime(), isLexical(), false
652+
auto *ASI = Builder.createAllocStack(ABI->getLoc(), ty, ABI->getVarInfo(),
653+
ABI->hasDynamicLifetime(), isLexical(),
654+
DoesNotUseMoveableValueDebugInfo
655655
#ifndef NDEBUG
656-
,
657-
true
656+
,
657+
true
658658
#endif
659-
);
659+
);
660660

661661
// Transfer a mark_uninitialized if we have one.
662662
SingleValueInstruction *StackBox = ASI;

lib/Serialization/DeserializeSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
13931393
assert(RecordKind == SIL_ONE_TYPE && "Layout should be OneType.");
13941394
bool hasDynamicLifetime = Attr & 0x1;
13951395
bool isLexical = (Attr >> 1) & 0x1;
1396-
bool wasMoved = (Attr >> 2) & 0x1;
1396+
auto wasMoved = UsesMoveableValueDebugInfo_t((Attr >> 2) & 0x1);
13971397
ResultInst = Builder.createAllocStack(
13981398
Loc, getSILType(MF->getType(TyID), (SILValueCategory)TyCategory, Fn),
13991399
std::nullopt, hasDynamicLifetime, isLexical, wasMoved);

0 commit comments

Comments
 (0)