Skip to content

Commit 9f6c309

Browse files
committed
[NFC] SIL: Typed begin_borrow's isLexical.
1 parent c6eb311 commit 9f6c309

File tree

15 files changed

+43
-39
lines changed

15 files changed

+43
-39
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -823,7 +823,7 @@ class SILBuilder {
823823
}
824824

825825
BeginBorrowInst *createBeginBorrow(SILLocation Loc, SILValue LV,
826-
bool isLexical = false,
826+
IsLexical_t isLexical = IsNotLexical,
827827
bool hasPointerEscape = false,
828828
bool fromVarDecl = false,
829829
bool fixed = false) {
@@ -851,7 +851,7 @@ class SILBuilder {
851851
}
852852

853853
SILValue emitBeginBorrowOperation(SILLocation loc, SILValue v,
854-
bool isLexical = false,
854+
IsLexical_t isLexical = IsNotLexical,
855855
bool hasPointerEscape = false,
856856
bool fromVarDecl = false) {
857857
if (!hasOwnership() ||

include/swift/SIL/SILInstruction.h

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4558,8 +4558,9 @@ class BeginBorrowInst
45584558

45594559
USE_SHARED_UINT8;
45604560

4561-
BeginBorrowInst(SILDebugLocation DebugLoc, SILValue LValue, bool isLexical,
4562-
bool hasPointerEscape, bool fromVarDecl, bool fixed)
4561+
BeginBorrowInst(SILDebugLocation DebugLoc, SILValue LValue,
4562+
IsLexical_t isLexical, bool hasPointerEscape,
4563+
bool fromVarDecl, bool fixed)
45634564
: UnaryInstructionBase(DebugLoc, LValue,
45644565
LValue->getType().getObjectType()) {
45654566
sharedUInt8().BeginBorrowInst.lexical = isLexical;
@@ -4580,11 +4581,15 @@ class BeginBorrowInst
45804581

45814582
/// Whether the borrow scope introduced by this instruction corresponds to a
45824583
/// source-level lexical scope.
4583-
bool isLexical() const { return sharedUInt8().BeginBorrowInst.lexical; }
4584+
IsLexical_t isLexical() const {
4585+
return IsLexical_t(sharedUInt8().BeginBorrowInst.lexical);
4586+
}
45844587

45854588
/// If this is a lexical borrow, eliminate the lexical bit. If this borrow
45864589
/// doesn't have a lexical bit, do not do anything.
4587-
void removeIsLexical() { sharedUInt8().BeginBorrowInst.lexical = false; }
4590+
void removeIsLexical() {
4591+
sharedUInt8().BeginBorrowInst.lexical = (bool)IsNotLexical;
4592+
}
45884593

45894594
/// WARNING: this flag is not yet implemented!
45904595
bool hasPointerEscape() const {

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3740,7 +3740,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
37403740
case SILInstructionKind::BeginBorrowInst: {
37413741
SourceLoc AddrLoc;
37423742

3743-
bool isLexical = false;
3743+
auto isLexical = IsNotLexical;
37443744
bool hasPointerEscape = false;
37453745
bool fromVarDecl = false;
37463746
bool fixed = false;
@@ -3749,7 +3749,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
37493749
SourceLoc AttrLoc;
37503750
while (parseSILOptional(AttrName, AttrLoc, *this)) {
37513751
if (AttrName == "lexical")
3752-
isLexical = true;
3752+
isLexical = IsLexical;
37533753
else if (AttrName == "pointer_escape")
37543754
hasPointerEscape = true;
37553755
else if (AttrName == "var_decl")

lib/SIL/Utils/OwnershipUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2282,7 +2282,7 @@ bool swift::isNestedLexicalBeginBorrow(BeginBorrowInst *bbi) {
22822282
roots);
22832283
return llvm::all_of(roots, [](auto root) {
22842284
if (auto *outerBBI = dyn_cast<BeginBorrowInst>(root)) {
2285-
return outerBBI->isLexical();
2285+
return (bool)outerBBI->isLexical();
22862286
}
22872287
if (auto *arg = dyn_cast<SILFunctionArgument>(root)) {
22882288
return arg->getOwnershipKind() == OwnershipKind::Guaranteed;

lib/SILGen/ResultPlan.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class IndirectOpenedSelfResultPlan final : public ResultPlan {
200200
boxLayout,
201201
layoutSubs));
202202
if (SGF.getASTContext().SILOpts.supportsLexicalLifetimes(SGF.getModule())) {
203-
resultBox = SGF.B.createBeginBorrow(loc, resultBox, /*isLexical=*/true);
203+
resultBox = SGF.B.createBeginBorrow(loc, resultBox, IsLexical);
204204
}
205205

206206
// Complete the cleanup to deallocate this buffer later, after we're

lib/SILGen/SILGenBuilder.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ SILGenBuilder::createFormalAccessOpaqueConsumeBeginAccess(SILLocation loc,
11041104

11051105
ManagedValue SILGenBuilder::createBeginBorrow(SILLocation loc,
11061106
ManagedValue value,
1107-
bool isLexical,
1107+
IsLexical_t isLexical,
11081108
bool isFixed) {
11091109
auto *newValue =
11101110
SILBuilder::createBeginBorrow(loc, value.getValue(),
@@ -1114,9 +1114,9 @@ ManagedValue SILGenBuilder::createBeginBorrow(SILLocation loc,
11141114
}
11151115

11161116
ManagedValue SILGenBuilder::createFormalAccessBeginBorrow(SILLocation loc,
1117-
ManagedValue value,
1118-
bool isLexical,
1119-
bool isFixed) {
1117+
ManagedValue value,
1118+
IsLexical_t isLexical,
1119+
bool isFixed) {
11201120
auto *newValue =
11211121
SILBuilder::createBeginBorrow(loc, value.getValue(),
11221122
isLexical, false, false, isFixed);

lib/SILGen/SILGenBuilder.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -480,13 +480,13 @@ class SILGenBuilder : public SILBuilder {
480480

481481
using SILBuilder::createBeginBorrow;
482482
ManagedValue createBeginBorrow(SILLocation loc, ManagedValue value,
483-
bool isLexical = false,
483+
IsLexical_t isLexical = IsNotLexical,
484484
bool isFixed = false);
485485

486-
ManagedValue createFormalAccessBeginBorrow(SILLocation loc,
487-
ManagedValue value,
488-
bool isLexical = false,
489-
bool isFixed = false);
486+
ManagedValue
487+
createFormalAccessBeginBorrow(SILLocation loc, ManagedValue value,
488+
IsLexical_t isLexical = IsNotLexical,
489+
bool isFixed = false);
490490

491491
using SILBuilder::createMoveValue;
492492
ManagedValue createMoveValue(SILLocation loc, ManagedValue value,

lib/SILGen/SILGenDecl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -572,7 +572,7 @@ class LocalVariableInitialization : public SingleBufferInitialization {
572572
// Only add a lexical lifetime to the box if the variable it stores
573573
// requires one.
574574
Box = SGF.B.createBeginBorrow(
575-
decl, Box, /*isLexical=*/lifetime.isLexical(),
575+
decl, Box, IsLexical_t(lifetime.isLexical()),
576576
/*hasPointerEscape=*/false, /*fromVarDecl=*/true);
577577
}
578578

@@ -862,7 +862,7 @@ class LetValueInitialization : public Initialization {
862862
/*hasPointerEscape=*/false,
863863
/*fromVarDecl=*/true);
864864

865-
return SGF.B.createBeginBorrow(PrologueLoc, value, /*isLexical*/ isLexical,
865+
return SGF.B.createBeginBorrow(PrologueLoc, value, IsLexical_t(isLexical),
866866
/*hasPointerEscape=*/false,
867867
/*fromVarDecl=*/true);
868868
}

lib/SILGen/SILGenLValue.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,7 @@ namespace {
985985
if (!base.getValue()->getType().isAddress()) {
986986
assert(!SGF.useLoweredAddresses());
987987
auto borrow =
988-
SGF.B.createBeginBorrow(loc, base.getValue(), /*isLexical=*/false,
988+
SGF.B.createBeginBorrow(loc, base.getValue(), IsNotLexical,
989989
/*hasPointerEscape=*/false);
990990
auto value =
991991
SGF.B.createOpenExistentialValue(loc, borrow, getTypeOfRValue());
@@ -4394,8 +4394,7 @@ LValue SILGenLValue::visitBindOptionalExpr(BindOptionalExpr *e,
43944394
optBase = SGF.B.createFormalAccessLoadBorrow(e, optBase);
43954395
}
43964396
} else {
4397-
optBase = SGF.B.createFormalAccessBeginBorrow(e, optBase,
4398-
false,
4397+
optBase = SGF.B.createFormalAccessBeginBorrow(e, optBase, IsNotLexical,
43994398
/*fixed*/ true);
44004399
}
44014400
}

lib/SILGen/SILGenPattern.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3409,9 +3409,10 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
34093409
// Initiate a fixed borrow on the subject, so that it's treated as
34103410
// opaque by the move checker.
34113411
subjectMV = subjectUndergoesFormalAccess
3412-
? B.createFormalAccessBeginBorrow(S, subjectMV,
3413-
false, /*fixed*/true)
3414-
: B.createBeginBorrow(S, subjectMV, false, /*fixed*/ true);
3412+
? B.createFormalAccessBeginBorrow(
3413+
S, subjectMV, IsNotLexical, /*fixed*/ true)
3414+
: B.createBeginBorrow(S, subjectMV, IsNotLexical,
3415+
/*fixed*/ true);
34153416
}
34163417
return {subjectMV, CastConsumptionKind::BorrowAlways};
34173418

@@ -3439,8 +3440,8 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
34393440
if (subjectMV.getType().isAddress()) {
34403441
subjectMV = B.createOpaqueBorrowBeginAccess(S, subjectMV);
34413442
} else {
3442-
subjectMV = B.createBeginBorrow(S, subjectMV,
3443-
false, /*fixed*/ true);
3443+
subjectMV =
3444+
B.createBeginBorrow(S, subjectMV, IsNotLexical, /*fixed*/ true);
34443445
}
34453446
return {subjectMV, CastConsumptionKind::BorrowAlways};
34463447
}

0 commit comments

Comments
 (0)