Skip to content

Commit dfa5c98

Browse files
committed
[NFC] SIL: Typed alloc_stack's hasDynamicLifetime.
1 parent 11dd0e4 commit dfa5c98

File tree

12 files changed

+50
-36
lines changed

12 files changed

+50
-36
lines changed

include/swift/SIL/SILBridgingImpl.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,8 +1462,9 @@ BridgedInstruction BridgedBuilder::createIntegerLiteral(BridgedType type, SwiftI
14621462
BridgedInstruction BridgedBuilder::createAllocStack(BridgedType type,
14631463
bool hasDynamicLifetime, bool isLexical, bool wasMoved) const {
14641464
return {unbridged().createAllocStack(
1465-
regularLoc(), type.unbridged(), std::nullopt, hasDynamicLifetime,
1466-
isLexical, swift::UsesMoveableValueDebugInfo_t(wasMoved))};
1465+
regularLoc(), type.unbridged(), std::nullopt,
1466+
swift::HasDynamicLifetime_t(hasDynamicLifetime), isLexical,
1467+
swift::UsesMoveableValueDebugInfo_t(wasMoved))};
14671468
}
14681469

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

include/swift/SIL/SILBuilder.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,8 @@ class SILBuilder {
405405
AllocStackInst *createAllocStack(
406406
SILLocation Loc, SILType elementType,
407407
std::optional<SILDebugVariable> Var = std::nullopt,
408-
bool hasDynamicLifetime = false, bool isLexical = false,
408+
HasDynamicLifetime_t dynamic = DoesNotHaveDynamicLifetime,
409+
bool isLexical = false,
409410
UsesMoveableValueDebugInfo_t wasMoved = DoesNotUseMoveableValueDebugInfo,
410411
bool skipVarDeclAssert = false) {
411412
llvm::SmallString<4> Name;
@@ -419,8 +420,7 @@ class SILBuilder {
419420
#endif
420421
return insert(AllocStackInst::create(
421422
getSILDebugLocation(Loc, true), elementType, getFunction(),
422-
substituteAnonymousArgs(Name, Var, Loc), hasDynamicLifetime, isLexical,
423-
wasMoved));
423+
substituteAnonymousArgs(Name, Var, Loc), dynamic, isLexical, wasMoved));
424424
}
425425

426426
AllocVectorInst *

include/swift/SIL/SILInstruction.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1968,6 +1968,11 @@ enum UsesMoveableValueDebugInfo_t : bool {
19681968
UsesMoveableValueDebugInfo = true,
19691969
};
19701970

1971+
enum HasDynamicLifetime_t : bool {
1972+
DoesNotHaveDynamicLifetime = false,
1973+
HasDynamicLifetime = true,
1974+
};
1975+
19711976
/// AllocStackInst - This represents the allocation of an unboxed (i.e., no
19721977
/// reference count) stack memory. The memory is provided uninitialized.
19731978
class AllocStackInst final
@@ -1986,14 +1991,15 @@ class AllocStackInst final
19861991

19871992
AllocStackInst(SILDebugLocation Loc, SILType elementType,
19881993
ArrayRef<SILValue> TypeDependentOperands, SILFunction &F,
1989-
std::optional<SILDebugVariable> Var, bool hasDynamicLifetime,
1990-
bool isLexical,
1994+
std::optional<SILDebugVariable> Var,
1995+
HasDynamicLifetime_t hasDynamicLifetime, bool isLexical,
19911996
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo);
19921997

19931998
static AllocStackInst *create(SILDebugLocation Loc, SILType elementType,
19941999
SILFunction &F,
19952000
std::optional<SILDebugVariable> Var,
1996-
bool hasDynamicLifetime, bool isLexical,
2001+
HasDynamicLifetime_t hasDynamicLifetime,
2002+
bool isLexical,
19972003
UsesMoveableValueDebugInfo_t wasMoved);
19982004

19992005
SIL_DEBUG_VAR_SUPPLEMENT_TRAILING_OBJS_IMPL()
@@ -2028,14 +2034,18 @@ class AllocStackInst final
20282034
///
20292035
/// As an example if an alloc_stack is known to be only conditionally
20302036
/// initialized.
2031-
void setDynamicLifetime() { sharedUInt8().AllocStackInst.dynamicLifetime = true; }
2037+
void setDynamicLifetime() {
2038+
sharedUInt8().AllocStackInst.dynamicLifetime = (bool)HasDynamicLifetime;
2039+
}
20322040

20332041
/// Returns true if the alloc_stack's initialization can not be ascertained
20342042
/// from uses directly (so should be treated conservatively).
20352043
///
20362044
/// An example of an alloc_stack with dynamic lifetime is an alloc_stack that
20372045
/// is conditionally initialized.
2038-
bool hasDynamicLifetime() const { return sharedUInt8().AllocStackInst.dynamicLifetime; }
2046+
HasDynamicLifetime_t hasDynamicLifetime() const {
2047+
return HasDynamicLifetime_t(sharedUInt8().AllocStackInst.dynamicLifetime);
2048+
}
20392049

20402050
/// Whether the alloc_stack instruction corresponds to a source-level VarDecl.
20412051
bool isLexical() const { return sharedUInt8().AllocStackInst.lexical; }

lib/SIL/IR/SILInstructions.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,9 @@ SILDebugVariable::createFromAllocation(const AllocationInst *AI) {
225225
AllocStackInst::AllocStackInst(
226226
SILDebugLocation Loc, SILType elementType,
227227
ArrayRef<SILValue> TypeDependentOperands, SILFunction &F,
228-
std::optional<SILDebugVariable> Var, bool hasDynamicLifetime,
229-
bool isLexical, UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo)
228+
std::optional<SILDebugVariable> Var,
229+
HasDynamicLifetime_t hasDynamicLifetime, bool isLexical,
230+
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo)
230231
: InstructionBase(Loc, elementType.getAddressType()),
231232
SILDebugVariableSupplement(Var ? Var->DIExpr.getNumElements() : 0,
232233
Var ? Var->Type.has_value() : false,
@@ -235,7 +236,7 @@ AllocStackInst::AllocStackInst(
235236
// Initialize VarInfo with a temporary raw value of 0. The real
236237
// initialization can only be done after `numOperands` is set (see below).
237238
VarInfo(0) {
238-
sharedUInt8().AllocStackInst.dynamicLifetime = hasDynamicLifetime;
239+
sharedUInt8().AllocStackInst.dynamicLifetime = (bool)hasDynamicLifetime;
239240
sharedUInt8().AllocStackInst.lexical = isLexical;
240241
sharedUInt8().AllocStackInst.usesMoveableValueDebugInfo =
241242
(bool)usesMoveableValueDebugInfo || elementType.isMoveOnly();
@@ -264,7 +265,8 @@ AllocStackInst::AllocStackInst(
264265
AllocStackInst *AllocStackInst::create(SILDebugLocation Loc,
265266
SILType elementType, SILFunction &F,
266267
std::optional<SILDebugVariable> Var,
267-
bool hasDynamicLifetime, bool isLexical,
268+
HasDynamicLifetime_t hasDynamicLifetime,
269+
bool isLexical,
268270
UsesMoveableValueDebugInfo_t wasMoved) {
269271
SmallVector<SILValue, 8> TypeDependentOperands;
270272
collectTypeDependentOperands(TypeDependentOperands, F,

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4740,7 +4740,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
47404740
break;
47414741
}
47424742
case SILInstructionKind::AllocStackInst: {
4743-
bool hasDynamicLifetime = false;
4743+
auto hasDynamicLifetime = DoesNotHaveDynamicLifetime;
47444744
bool isLexical = false;
47454745
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo =
47464746
DoesNotUseMoveableValueDebugInfo;
@@ -4749,7 +4749,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
47494749
SourceLoc attributeLoc;
47504750
while (parseSILOptional(attributeName, attributeLoc, *this)) {
47514751
if (attributeName == "dynamic_lifetime")
4752-
hasDynamicLifetime = true;
4752+
hasDynamicLifetime = HasDynamicLifetime;
47534753
else if (attributeName == "lexical")
47544754
isLexical = true;
47554755
else if (attributeName == "moveable_value_debuginfo")

lib/SILGen/ResultPlan.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1077,9 +1077,8 @@ class ForeignErrorInitializationPlan final : public ResultPlan {
10771077
// Allocate a temporary.
10781078
// It's flagged with "hasDynamicLifetime" because it's not possible to
10791079
// statically verify the lifetime of the value.
1080-
SILValue errorTemp =
1081-
SGF.emitTemporaryAllocation(loc, errorTL.getLoweredType(),
1082-
/*hasDynamicLifetime*/ true);
1080+
SILValue errorTemp = SGF.emitTemporaryAllocation(
1081+
loc, errorTL.getLoweredType(), HasDynamicLifetime);
10831082

10841083
// Nil-initialize it.
10851084
SGF.emitInjectOptionalNothingInto(loc, errorTemp, errorTL);

lib/SILGen/SILGenDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ class LetValueInitialization : public Initialization {
711711
auto isLexical = lexicalLifetimesEnabled && lifetime.isLexical();
712712
address =
713713
SGF.emitTemporaryAllocation(vd, lowering->getLoweredType(),
714-
/*hasDynamicLifetime=*/false, isLexical);
714+
DoesNotHaveDynamicLifetime, isLexical);
715715
if (isUninitialized)
716716
address = SGF.B.createMarkUninitializedVar(vd, address);
717717
DestroyCleanup = SGF.enterDormantTemporaryCleanup(address, *lowering);

lib/SILGen/SILGenExpr.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,16 +1092,16 @@ RValue RValueEmitter::visitLoadExpr(LoadExpr *E, SGFContext C) {
10921092
}
10931093

10941094
SILValue SILGenFunction::emitTemporaryAllocation(SILLocation loc, SILType ty,
1095-
bool hasDynamicLifetime,
1095+
HasDynamicLifetime_t dynamic,
10961096
bool isLexical,
10971097
bool generateDebugInfo) {
10981098
ty = ty.getObjectType();
10991099
std::optional<SILDebugVariable> DbgVar;
11001100
if (generateDebugInfo)
11011101
if (auto *VD = loc.getAsASTNode<VarDecl>())
11021102
DbgVar = SILDebugVariable(VD->isLet(), 0);
1103-
auto *alloc = B.createAllocStack(loc, ty, DbgVar, hasDynamicLifetime,
1104-
isLexical, DoesNotUseMoveableValueDebugInfo
1103+
auto *alloc = B.createAllocStack(loc, ty, DbgVar, dynamic, isLexical,
1104+
DoesNotUseMoveableValueDebugInfo
11051105
#ifndef NDEBUG
11061106
,
11071107
!generateDebugInfo

lib/SILGen/SILGenFunction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -699,8 +699,9 @@ void SILGenFunction::emitCaptures(SILLocation loc,
699699

700700
assert(!isPack);
701701

702-
auto addr = emitTemporaryAllocation(vd, entryValue->getType(), false,
703-
false, /*generateDebugInfo*/ false);
702+
auto addr = emitTemporaryAllocation(vd, entryValue->getType(),
703+
DoesNotHaveDynamicLifetime, false,
704+
/*generateDebugInfo*/ false);
704705
auto val = B.emitCopyValueOperation(loc, entryValue);
705706
auto &lowering = getTypeLowering(entryValue->getType());
706707
lowering.emitStore(B, loc, val, addr, StoreOwnershipQualifier::Init);

lib/SILGen/SILGenFunction.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1332,10 +1332,10 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
13321332
///
13331333
/// \p isLexical if set to true, this is a temporary that we are using for a
13341334
/// local let that we need to mark with the lexical flag.
1335-
SILValue emitTemporaryAllocation(SILLocation loc, SILType ty,
1336-
bool hasDynamicLifetime = false,
1337-
bool isLexical = false,
1338-
bool generateDebugInfo = true);
1335+
SILValue emitTemporaryAllocation(
1336+
SILLocation loc, SILType ty,
1337+
HasDynamicLifetime_t hasDynamicLifetime = DoesNotHaveDynamicLifetime,
1338+
bool isLexical = false, bool generateDebugInfo = true);
13391339

13401340
/// Emits a temporary allocation for a pack that will be deallocated
13411341
/// automatically at the end of the current scope. Returns the address

0 commit comments

Comments
 (0)