Skip to content

Commit c6eb311

Browse files
committed
[NFC] SIL: Typed alloc_stack's isLexical.
1 parent ec6b447 commit c6eb311

File tree

12 files changed

+36
-29
lines changed

12 files changed

+36
-29
lines changed

include/swift/SIL/SILBridgingImpl.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,8 @@ BridgedInstruction BridgedBuilder::createAllocStack(BridgedType type,
14631463
bool hasDynamicLifetime, bool isLexical, bool wasMoved) const {
14641464
return {unbridged().createAllocStack(
14651465
regularLoc(), type.unbridged(), std::nullopt,
1466-
swift::HasDynamicLifetime_t(hasDynamicLifetime), isLexical,
1466+
swift::HasDynamicLifetime_t(hasDynamicLifetime),
1467+
swift::IsLexical_t(isLexical),
14671468
swift::UsesMoveableValueDebugInfo_t(wasMoved))};
14681469
}
14691470

include/swift/SIL/SILBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ class SILBuilder {
406406
SILLocation Loc, SILType elementType,
407407
std::optional<SILDebugVariable> Var = std::nullopt,
408408
HasDynamicLifetime_t dynamic = DoesNotHaveDynamicLifetime,
409-
bool isLexical = false,
409+
IsLexical_t isLexical = IsNotLexical,
410410
UsesMoveableValueDebugInfo_t wasMoved = DoesNotUseMoveableValueDebugInfo,
411411
bool skipVarDeclAssert = false) {
412412
llvm::SmallString<4> Name;

include/swift/SIL/SILInstruction.h

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,11 @@ enum HasDynamicLifetime_t : bool {
19731973
HasDynamicLifetime = true,
19741974
};
19751975

1976+
enum IsLexical_t : bool {
1977+
IsNotLexical = false,
1978+
IsLexical = true,
1979+
};
1980+
19761981
/// AllocStackInst - This represents the allocation of an unboxed (i.e., no
19771982
/// reference count) stack memory. The memory is provided uninitialized.
19781983
class AllocStackInst final
@@ -1992,14 +1997,14 @@ class AllocStackInst final
19921997
AllocStackInst(SILDebugLocation Loc, SILType elementType,
19931998
ArrayRef<SILValue> TypeDependentOperands, SILFunction &F,
19941999
std::optional<SILDebugVariable> Var,
1995-
HasDynamicLifetime_t hasDynamicLifetime, bool isLexical,
2000+
HasDynamicLifetime_t hasDynamicLifetime, IsLexical_t isLexical,
19962001
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo);
19972002

19982003
static AllocStackInst *create(SILDebugLocation Loc, SILType elementType,
19992004
SILFunction &F,
20002005
std::optional<SILDebugVariable> Var,
20012006
HasDynamicLifetime_t hasDynamicLifetime,
2002-
bool isLexical,
2007+
IsLexical_t isLexical,
20032008
UsesMoveableValueDebugInfo_t wasMoved);
20042009

20052010
SIL_DEBUG_VAR_SUPPLEMENT_TRAILING_OBJS_IMPL()
@@ -2048,15 +2053,21 @@ class AllocStackInst final
20482053
}
20492054

20502055
/// Whether the alloc_stack instruction corresponds to a source-level VarDecl.
2051-
bool isLexical() const { return sharedUInt8().AllocStackInst.lexical; }
2056+
IsLexical_t isLexical() const {
2057+
return IsLexical_t(sharedUInt8().AllocStackInst.lexical);
2058+
}
20522059

20532060
/// If this is a lexical alloc_stack, eliminate the lexical bit. If this
20542061
/// alloc_stack doesn't have a lexical bit, do not do anything.
2055-
void removeIsLexical() { sharedUInt8().AllocStackInst.lexical = false; }
2062+
void removeIsLexical() {
2063+
sharedUInt8().AllocStackInst.lexical = (bool)IsNotLexical;
2064+
}
20562065

20572066
/// If this is not a lexical alloc_stack, set the lexical bit. If this
20582067
/// alloc_stack is already lexical, this does nothing.
2059-
void setIsLexical() { sharedUInt8().AllocStackInst.lexical = true; }
2068+
void setIsLexical() {
2069+
sharedUInt8().AllocStackInst.lexical = (bool)IsLexical;
2070+
}
20602071

20612072
/// Return the debug variable information attached to this instruction.
20622073
std::optional<SILDebugVariable> getVarInfo() const {

include/swift/SIL/TypeLowering.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,6 @@ enum IsInfiniteType_t : bool {
170170
IsInfiniteType = true,
171171
};
172172

173-
/// Does this type contain at least one non-trivial, non-eager-move type?
174-
enum IsLexical_t : bool {
175-
IsNotLexical = false,
176-
IsLexical = true,
177-
};
178-
179173
/// Does this type contain any pack-like thing.
180174
enum HasPack_t : bool {
181175
HasNoPack = false,

lib/SIL/IR/SILInstructions.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ AllocStackInst::AllocStackInst(
226226
SILDebugLocation Loc, SILType elementType,
227227
ArrayRef<SILValue> TypeDependentOperands, SILFunction &F,
228228
std::optional<SILDebugVariable> Var,
229-
HasDynamicLifetime_t hasDynamicLifetime, bool isLexical,
229+
HasDynamicLifetime_t hasDynamicLifetime, IsLexical_t isLexical,
230230
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo)
231231
: InstructionBase(Loc, elementType.getAddressType()),
232232
SILDebugVariableSupplement(Var ? Var->DIExpr.getNumElements() : 0,
@@ -237,7 +237,7 @@ AllocStackInst::AllocStackInst(
237237
// initialization can only be done after `numOperands` is set (see below).
238238
VarInfo(0) {
239239
sharedUInt8().AllocStackInst.dynamicLifetime = (bool)hasDynamicLifetime;
240-
sharedUInt8().AllocStackInst.lexical = isLexical;
240+
sharedUInt8().AllocStackInst.lexical = (bool)isLexical;
241241
sharedUInt8().AllocStackInst.usesMoveableValueDebugInfo =
242242
(bool)usesMoveableValueDebugInfo || elementType.isMoveOnly();
243243
sharedUInt32().AllocStackInst.numOperands = TypeDependentOperands.size();
@@ -266,7 +266,7 @@ AllocStackInst *AllocStackInst::create(SILDebugLocation Loc,
266266
SILType elementType, SILFunction &F,
267267
std::optional<SILDebugVariable> Var,
268268
HasDynamicLifetime_t hasDynamicLifetime,
269-
bool isLexical,
269+
IsLexical_t isLexical,
270270
UsesMoveableValueDebugInfo_t wasMoved) {
271271
SmallVector<SILValue, 8> TypeDependentOperands;
272272
collectTypeDependentOperands(TypeDependentOperands, F,

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4741,7 +4741,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
47414741
}
47424742
case SILInstructionKind::AllocStackInst: {
47434743
auto hasDynamicLifetime = DoesNotHaveDynamicLifetime;
4744-
bool isLexical = false;
4744+
auto isLexical = IsNotLexical;
47454745
UsesMoveableValueDebugInfo_t usesMoveableValueDebugInfo =
47464746
DoesNotUseMoveableValueDebugInfo;
47474747

@@ -4751,7 +4751,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
47514751
if (attributeName == "dynamic_lifetime")
47524752
hasDynamicLifetime = HasDynamicLifetime;
47534753
else if (attributeName == "lexical")
4754-
isLexical = true;
4754+
isLexical = IsLexical;
47554755
else if (attributeName == "moveable_value_debuginfo")
47564756
usesMoveableValueDebugInfo = UsesMoveableValueDebugInfo;
47574757
else {

lib/SILGen/SILGenDecl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -708,7 +708,8 @@ class LetValueInitialization : public Initialization {
708708
bool lexicalLifetimesEnabled =
709709
SGF.getASTContext().SILOpts.supportsLexicalLifetimes(SGF.getModule());
710710
auto lifetime = SGF.F.getLifetime(vd, lowering->getLoweredType());
711-
auto isLexical = lexicalLifetimesEnabled && lifetime.isLexical();
711+
auto isLexical =
712+
IsLexical_t(lexicalLifetimesEnabled && lifetime.isLexical());
712713
address =
713714
SGF.emitTemporaryAllocation(vd, lowering->getLoweredType(),
714715
DoesNotHaveDynamicLifetime, isLexical);

lib/SILGen/SILGenExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1093,7 +1093,7 @@ RValue RValueEmitter::visitLoadExpr(LoadExpr *E, SGFContext C) {
10931093

10941094
SILValue SILGenFunction::emitTemporaryAllocation(SILLocation loc, SILType ty,
10951095
HasDynamicLifetime_t dynamic,
1096-
bool isLexical,
1096+
IsLexical_t isLexical,
10971097
bool generateDebugInfo) {
10981098
ty = ty.getObjectType();
10991099
std::optional<SILDebugVariable> DbgVar;

lib/SILGen/SILGenFunction.cpp

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

700700
assert(!isPack);
701701

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

lib/SILGen/SILGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1335,7 +1335,7 @@ class LLVM_LIBRARY_VISIBILITY SILGenFunction
13351335
SILValue emitTemporaryAllocation(
13361336
SILLocation loc, SILType ty,
13371337
HasDynamicLifetime_t hasDynamicLifetime = DoesNotHaveDynamicLifetime,
1338-
bool isLexical = false, bool generateDebugInfo = true);
1338+
IsLexical_t isLexical = IsNotLexical, 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)