Skip to content

Commit e10d595

Browse files
committed
[NFC] SIL: Typed alloc_box's wasMoved.
Help avoid errors with boolean flags by using the new UsesMoveableValueDebugInfo_t.
1 parent 611511a commit e10d595

File tree

7 files changed

+40
-32
lines changed

7 files changed

+40
-32
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@ class SILBuilder {
478478
createAllocBox(SILLocation loc, SILType fieldType,
479479
std::optional<SILDebugVariable> Var = std::nullopt,
480480
bool hasDynamicLifetime = false, bool reflection = false,
481-
bool usesMoveableValueDebugInfo = false,
481+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo =
482+
DoesNotUseMoveableValueDebugInfo,
482483
bool hasPointerEscape = false) {
483484
return createAllocBox(loc, SILBoxType::get(fieldType.getASTType()), Var,
484485
hasDynamicLifetime, reflection,
@@ -491,7 +492,8 @@ class SILBuilder {
491492
createAllocBox(SILLocation Loc, CanSILBoxType BoxType,
492493
std::optional<SILDebugVariable> Var = std::nullopt,
493494
bool hasDynamicLifetime = false, bool reflection = false,
494-
bool usesMoveableValueDebugInfo = false,
495+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo =
496+
DoesNotUseMoveableValueDebugInfo,
495497
bool skipVarDeclAssert = false,
496498
bool hasPointerEscape = false) {
497499
#if NDEBUG

include/swift/SIL/SILCloner.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -971,9 +971,8 @@ SILCloner<ImplClass>::visitAllocBoxInst(AllocBoxInst *Inst) {
971971
getBuilder().createAllocBox(
972972
Loc, this->getOpType(Inst->getType()).template castTo<SILBoxType>(),
973973
VarInfo, /*hasDynamicLifetime*/ false,
974-
/*reflection*/ false,
975-
/*usesMoveableValueDebugInfo*/ false, /*skipVarDeclAssert*/ true
976-
));
974+
/*reflection*/ false, DoesNotUseMoveableValueDebugInfo,
975+
/*skipVarDeclAssert*/ true));
977976
}
978977

979978
template<typename ImplClass>

include/swift/SIL/SILInstruction.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2424,15 +2424,17 @@ class AllocBoxInst final
24242424
AllocBoxInst(SILDebugLocation DebugLoc, CanSILBoxType BoxType,
24252425
ArrayRef<SILValue> TypeDependentOperands, SILFunction &F,
24262426
std::optional<SILDebugVariable> Var, bool hasDynamicLifetime,
2427-
bool reflection = false, bool usesMoveableValueDebugInfo = false,
2427+
bool reflection = false,
2428+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo =
2429+
DoesNotUseMoveableValueDebugInfo,
24282430
bool hasPointerEscape = false);
24292431

2430-
static AllocBoxInst *create(SILDebugLocation Loc, CanSILBoxType boxType,
2431-
SILFunction &F,
2432-
std::optional<SILDebugVariable> Var,
2433-
bool hasDynamicLifetime, bool reflection = false,
2434-
bool usesMoveableValueDebugInfo = false,
2435-
bool hasPointerEscape = false);
2432+
static AllocBoxInst *create(
2433+
SILDebugLocation Loc, CanSILBoxType boxType, SILFunction &F,
2434+
std::optional<SILDebugVariable> Var, bool hasDynamicLifetime,
2435+
bool reflection = false,
2436+
UsesMoveableValueDebugInfo_t wasMoved = DoesNotUseMoveableValueDebugInfo,
2437+
bool hasPointerEscape = false);
24362438

24372439
public:
24382440
CanSILBoxType getBoxType() const {
@@ -2470,7 +2472,8 @@ class AllocBoxInst final
24702472
};
24712473

24722474
void setUsesMoveableValueDebugInfo() {
2473-
sharedUInt8().AllocBoxInst.usesMoveableValueDebugInfo = true;
2475+
sharedUInt8().AllocBoxInst.usesMoveableValueDebugInfo =
2476+
(bool)UsesMoveableValueDebugInfo;
24742477
}
24752478

24762479
bool usesMoveableValueDebugInfo() const {

lib/SIL/IR/SILInstructions.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,12 @@ bool AllocRefDynamicInst::isDynamicTypeDeinitAndSizeKnownEquivalentToBaseType()
389389
return false;
390390
}
391391

392-
AllocBoxInst::AllocBoxInst(SILDebugLocation Loc, CanSILBoxType BoxType,
393-
ArrayRef<SILValue> TypeDependentOperands,
394-
SILFunction &F, std::optional<SILDebugVariable> Var,
395-
bool hasDynamicLifetime, bool reflection,
396-
bool usesMoveableValueDebugInfo,
397-
bool hasPointerEscape)
392+
AllocBoxInst::AllocBoxInst(
393+
SILDebugLocation Loc, CanSILBoxType BoxType,
394+
ArrayRef<SILValue> TypeDependentOperands, SILFunction &F,
395+
std::optional<SILDebugVariable> Var, bool hasDynamicLifetime,
396+
bool reflection, UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo,
397+
bool hasPointerEscape)
398398
: NullaryInstructionWithTypeDependentOperandsBase(
399399
Loc, TypeDependentOperands, SILType::getPrimitiveObjectType(BoxType)),
400400
VarInfo(Var, getTrailingObjects<char>()) {
@@ -404,20 +404,22 @@ AllocBoxInst::AllocBoxInst(SILDebugLocation Loc, CanSILBoxType BoxType,
404404
// If we have a noncopyable type, always set uses mvoeable value debug info.
405405
auto fieldTy = getSILBoxFieldType(F.getTypeExpansionContext(), BoxType,
406406
F.getModule().Types, 0);
407-
usesMoveableValueDebugInfo |= fieldTy.isMoveOnly();
407+
if (fieldTy.isMoveOnly()) {
408+
usesMoveableValueDebugInfo = UsesMoveableValueDebugInfo;
409+
}
408410

409411
sharedUInt8().AllocBoxInst.usesMoveableValueDebugInfo =
410-
usesMoveableValueDebugInfo;
412+
(bool)usesMoveableValueDebugInfo;
411413

412414
sharedUInt8().AllocBoxInst.pointerEscape = hasPointerEscape;
413415
}
414416

415-
AllocBoxInst *AllocBoxInst::create(SILDebugLocation Loc, CanSILBoxType BoxType,
416-
SILFunction &F,
417-
std::optional<SILDebugVariable> Var,
418-
bool hasDynamicLifetime, bool reflection,
419-
bool usesMoveableValueDebugInfo,
420-
bool hasPointerEscape) {
417+
AllocBoxInst *
418+
AllocBoxInst::create(SILDebugLocation Loc, CanSILBoxType BoxType,
419+
SILFunction &F, std::optional<SILDebugVariable> Var,
420+
bool hasDynamicLifetime, bool reflection,
421+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo,
422+
bool hasPointerEscape) {
421423
SmallVector<SILValue, 8> TypeDependentOperands;
422424
collectTypeDependentOperands(TypeDependentOperands, F, BoxType);
423425
auto Sz = totalSizeToAlloc<swift::Operand, char>(TypeDependentOperands.size(),

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2606,7 +2606,8 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
26062606
case SILInstructionKind::AllocBoxInst: {
26072607
bool hasDynamicLifetime = false;
26082608
bool hasReflection = false;
2609-
bool usesMoveableValueDebugInfo = false;
2609+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo =
2610+
DoesNotUseMoveableValueDebugInfo;
26102611
bool hasPointerEscape = false;
26112612
StringRef attrName;
26122613
SourceLoc attrLoc;
@@ -2616,7 +2617,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
26162617
} else if (attrName.equals("reflection")) {
26172618
hasReflection = true;
26182619
} else if (attrName.equals("moveable_value_debuginfo")) {
2619-
usesMoveableValueDebugInfo = true;
2620+
usesMoveableValueDebugInfo = UsesMoveableValueDebugInfo;
26202621
} else if (attrName.equals("pointer_escape")) {
26212622
hasPointerEscape = true;
26222623
} else {
@@ -2636,7 +2637,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
26362637
return true;
26372638

26382639
if (Ty.isMoveOnly())
2639-
usesMoveableValueDebugInfo = true;
2640+
usesMoveableValueDebugInfo = UsesMoveableValueDebugInfo;
26402641

26412642
ResultVal = B.createAllocBox(InstLoc, Ty.castTo<SILBoxType>(), VarInfo,
26422643
hasDynamicLifetime, hasReflection,

lib/SILGen/SILGenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ class LocalVariableInitialization : public SingleBufferInitialization {
550550
DbgVar = SILDebugVariable(decl->isLet(), ArgNo);
551551
Box = SGF.B.createAllocBox(
552552
decl, boxType, DbgVar, /*hasDynamicLifetime*/ false,
553-
/*reflection*/ false, /*usesMoveableValueDebugInfo*/ false,
553+
/*reflection*/ false, DoesNotUseMoveableValueDebugInfo,
554554
!generateDebugInfo);
555555

556556
// Mark the memory as uninitialized, so DI will track it for us.

lib/Serialization/DeserializeSIL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1380,7 +1380,8 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
13801380
assert(RecordKind == SIL_ONE_TYPE && "Layout should be OneType.");
13811381
bool hasDynamicLifetime = Attr & 0x1;
13821382
bool reflection = (Attr >> 1) & 0x1;
1383-
bool usesMoveableValueDebugInfo = (Attr >> 2) & 0x1;
1383+
auto usesMoveableValueDebugInfo =
1384+
UsesMoveableValueDebugInfo_t((Attr >> 2) & 0x1);
13841385
bool pointerEscape = (Attr >> 3) & 0x1;
13851386
ResultInst = Builder.createAllocBox(
13861387
Loc, cast<SILBoxType>(MF->getType(TyID)->getCanonicalType()),

0 commit comments

Comments
 (0)