Skip to content

Commit 7fecf61

Browse files
committed
[NFC] SIL: Typed begin_borrow's isFixed.
1 parent 46b08bd commit 7fecf61

File tree

8 files changed

+38
-31
lines changed

8 files changed

+38
-31
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -826,7 +826,8 @@ class SILBuilder {
826826
BeginBorrowInst *createBeginBorrow(
827827
SILLocation Loc, SILValue LV, IsLexical_t isLexical = IsNotLexical,
828828
HasPointerEscape_t hasPointerEscape = DoesNotHavePointerEscape,
829-
bool fromVarDecl = false, bool fixed = false) {
829+
bool fromVarDecl = false,
830+
BeginBorrowInst::IsFixed_t fixed = BeginBorrowInst::IsNotFixed) {
830831
assert(getFunction().hasOwnership());
831832
assert(!LV->getType().isAddress());
832833
return insert(new (getModule())

include/swift/SIL/SILInstruction.h

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4563,15 +4563,22 @@ class BeginBorrowInst
45634563

45644564
USE_SHARED_UINT8;
45654565

4566+
public:
4567+
enum IsFixed_t : bool {
4568+
IsNotFixed = false,
4569+
IsFixed = true,
4570+
};
4571+
4572+
private:
45664573
BeginBorrowInst(SILDebugLocation DebugLoc, SILValue LValue,
45674574
IsLexical_t isLexical, HasPointerEscape_t hasPointerEscape,
4568-
bool fromVarDecl, bool fixed)
4575+
bool fromVarDecl, IsFixed_t fixed)
45694576
: UnaryInstructionBase(DebugLoc, LValue,
45704577
LValue->getType().getObjectType()) {
45714578
sharedUInt8().BeginBorrowInst.lexical = isLexical;
45724579
sharedUInt8().BeginBorrowInst.pointerEscape = hasPointerEscape;
45734580
sharedUInt8().BeginBorrowInst.fromVarDecl = fromVarDecl;
4574-
sharedUInt8().BeginBorrowInst.fixed = fixed;
4581+
sharedUInt8().BeginBorrowInst.fixed = (bool)fixed;
45754582
}
45764583

45774584
public:
@@ -4610,8 +4617,8 @@ class BeginBorrowInst
46104617

46114618
/// Whether the borrow scope is fixed during move checking and should be
46124619
/// treated as an opaque use of the value.
4613-
bool isFixed() const {
4614-
return sharedUInt8().BeginBorrowInst.fixed;
4620+
IsFixed_t isFixed() const {
4621+
return IsFixed_t(sharedUInt8().BeginBorrowInst.fixed);
46154622
}
46164623

46174624
/// Return a range over all EndBorrow instructions for this BeginBorrow.

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3743,7 +3743,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
37433743
auto isLexical = IsNotLexical;
37443744
auto hasPointerEscape = DoesNotHavePointerEscape;
37453745
bool fromVarDecl = false;
3746-
bool fixed = false;
3746+
auto fixed = BeginBorrowInst::IsNotFixed;
37473747

37483748
StringRef AttrName;
37493749
SourceLoc AttrLoc;
@@ -3755,7 +3755,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
37553755
else if (AttrName == "var_decl")
37563756
fromVarDecl = true;
37573757
else if (AttrName == "fixed")
3758-
fixed = true;
3758+
fixed = BeginBorrowInst::IsFixed;
37593759
else {
37603760
P.diagnose(InstLoc.getSourceLoc(),
37613761
diag::sil_invalid_attribute_for_instruction, AttrName,

lib/SILGen/SILGenBuilder.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1102,21 +1102,20 @@ SILGenBuilder::createFormalAccessOpaqueConsumeBeginAccess(SILLocation loc,
11021102
return SGF.emitFormalAccessManagedRValueWithCleanup(loc, access);
11031103
}
11041104

1105-
ManagedValue SILGenBuilder::createBeginBorrow(SILLocation loc,
1106-
ManagedValue value,
1107-
IsLexical_t isLexical,
1108-
bool isFixed) {
1105+
ManagedValue
1106+
SILGenBuilder::createBeginBorrow(SILLocation loc, ManagedValue value,
1107+
IsLexical_t isLexical,
1108+
BeginBorrowInst::IsFixed_t isFixed) {
11091109
auto *newValue =
11101110
SILBuilder::createBeginBorrow(loc, value.getValue(), isLexical,
11111111
DoesNotHavePointerEscape, false, isFixed);
11121112
SGF.emitManagedBorrowedRValueWithCleanup(newValue);
11131113
return ManagedValue::forBorrowedObjectRValue(newValue);
11141114
}
11151115

1116-
ManagedValue SILGenBuilder::createFormalAccessBeginBorrow(SILLocation loc,
1117-
ManagedValue value,
1118-
IsLexical_t isLexical,
1119-
bool isFixed) {
1116+
ManagedValue SILGenBuilder::createFormalAccessBeginBorrow(
1117+
SILLocation loc, ManagedValue value, IsLexical_t isLexical,
1118+
BeginBorrowInst::IsFixed_t isFixed) {
11201119
auto *newValue =
11211120
SILBuilder::createBeginBorrow(loc, value.getValue(), isLexical,
11221121
DoesNotHavePointerEscape, false, isFixed);

lib/SILGen/SILGenBuilder.h

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -479,14 +479,13 @@ class SILGenBuilder : public SILBuilder {
479479
ManagedValue address);
480480

481481
using SILBuilder::createBeginBorrow;
482-
ManagedValue createBeginBorrow(SILLocation loc, ManagedValue value,
483-
IsLexical_t isLexical = IsNotLexical,
484-
bool isFixed = false);
482+
ManagedValue createBeginBorrow(
483+
SILLocation loc, ManagedValue value, IsLexical_t isLexical = IsNotLexical,
484+
BeginBorrowInst::IsFixed_t isFixed = BeginBorrowInst::IsNotFixed);
485485

486-
ManagedValue
487-
createFormalAccessBeginBorrow(SILLocation loc, ManagedValue value,
488-
IsLexical_t isLexical = IsNotLexical,
489-
bool isFixed = false);
486+
ManagedValue createFormalAccessBeginBorrow(
487+
SILLocation loc, ManagedValue value, IsLexical_t isLexical = IsNotLexical,
488+
BeginBorrowInst::IsFixed_t isFixed = BeginBorrowInst::IsNotFixed);
490489

491490
using SILBuilder::createMoveValue;
492491
ManagedValue createMoveValue(SILLocation loc, ManagedValue value,

lib/SILGen/SILGenLValue.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4394,7 +4394,7 @@ LValue SILGenLValue::visitBindOptionalExpr(BindOptionalExpr *e,
43944394
}
43954395
} else {
43964396
optBase = SGF.B.createFormalAccessBeginBorrow(e, optBase, IsNotLexical,
4397-
/*fixed*/ true);
4397+
BeginBorrowInst::IsFixed);
43984398
}
43994399
}
44004400
} else {

lib/SILGen/SILGenPattern.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3408,11 +3408,12 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
34083408
} else {
34093409
// Initiate a fixed borrow on the subject, so that it's treated as
34103410
// opaque by the move checker.
3411-
subjectMV = subjectUndergoesFormalAccess
3412-
? B.createFormalAccessBeginBorrow(
3413-
S, subjectMV, IsNotLexical, /*fixed*/ true)
3414-
: B.createBeginBorrow(S, subjectMV, IsNotLexical,
3415-
/*fixed*/ true);
3411+
subjectMV =
3412+
subjectUndergoesFormalAccess
3413+
? B.createFormalAccessBeginBorrow(
3414+
S, subjectMV, IsNotLexical, BeginBorrowInst::IsFixed)
3415+
: B.createBeginBorrow(S, subjectMV, IsNotLexical,
3416+
BeginBorrowInst::IsFixed);
34163417
}
34173418
return {subjectMV, CastConsumptionKind::BorrowAlways};
34183419

@@ -3440,8 +3441,8 @@ void SILGenFunction::emitSwitchStmt(SwitchStmt *S) {
34403441
if (subjectMV.getType().isAddress()) {
34413442
subjectMV = B.createOpaqueBorrowBeginAccess(S, subjectMV);
34423443
} else {
3443-
subjectMV =
3444-
B.createBeginBorrow(S, subjectMV, IsNotLexical, /*fixed*/ true);
3444+
subjectMV = B.createBeginBorrow(S, subjectMV, IsNotLexical,
3445+
BeginBorrowInst::IsFixed);
34453446
}
34463447
return {subjectMV, CastConsumptionKind::BorrowAlways};
34473448
}

lib/Serialization/DeserializeSIL.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2272,7 +2272,7 @@ bool SILDeserializer::readSILInstruction(SILFunction *Fn,
22722272
auto isLexical = IsLexical_t(Attr & 0x1);
22732273
auto hasPointerEscape = HasPointerEscape_t((Attr >> 1) & 0x1);
22742274
bool fromVarDecl = (Attr >> 2) & 0x1;
2275-
bool isFixed = (Attr >> 3) & 0x1;
2275+
auto isFixed = BeginBorrowInst::IsFixed_t((Attr >> 3) & 0x1);
22762276
ResultInst = Builder.createBeginBorrow(
22772277
Loc,
22782278
getLocalValue(

0 commit comments

Comments
 (0)