Skip to content

Commit fc8f264

Browse files
committed
SIL: add some instruction APIs
* some APIs for `MarkUnresolvedNonCopyableValueInst` * `AllocBoxInst.hasDynamicLifetime`
1 parent 2259fe6 commit fc8f264

File tree

4 files changed

+53
-1
lines changed

4 files changed

+53
-1
lines changed

SwiftCompilerSources/Sources/SIL/Instruction.swift

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,41 @@ final public class IsUniqueInst : SingleValueInstruction, UnaryInstruction {}
12881288

12891289
final public class DestroyNotEscapedClosureInst : SingleValueInstruction, UnaryInstruction {}
12901290

1291-
final public class MarkUnresolvedNonCopyableValueInst: SingleValueInstruction, UnaryInstruction {}
1291+
final public class MarkUnresolvedNonCopyableValueInst: SingleValueInstruction, UnaryInstruction {
1292+
// The raw values must match swift::MarkUnresolvedNonCopyableValueInst::CheckKind
1293+
public enum CheckKind: Int {
1294+
case invalid = 0
1295+
1296+
/// A signal to the move only checker to perform checking that allows for
1297+
/// this value to be consumed along its boundary (in the case of let/var
1298+
/// semantics) and also written over in the case of var semantics. NOTE: Of
1299+
/// course this still implies the value cannot be copied and can be consumed
1300+
/// only once along all program paths.
1301+
case consumableAndAssignable
1302+
1303+
/// A signal to the move only checker to perform no consume or assign
1304+
/// checking. This forces the result of this instruction owned value to
1305+
/// never be consumed (for let/var semantics) or assigned over (for var
1306+
/// semantics). Of course, we still allow for non-consuming uses.
1307+
case noConsumeOrAssign
1308+
1309+
/// A signal to the move checker that the given value cannot be consumed,
1310+
/// but is allowed to be assigned over. This is used for situations like
1311+
/// global_addr/ref_element_addr/closure escape where we do not want to
1312+
/// allow for the user to take the value (leaving the memory in an
1313+
/// uninitialized state), but we are ok with the user assigning a new value,
1314+
/// completely assigning over the value at once.
1315+
case assignableButNotConsumable
1316+
1317+
/// A signal to the move checker that the given value cannot be consumed or
1318+
/// assigned, but is allowed to be initialized. This is used for situations
1319+
/// like class initializers.
1320+
case initableButNotConsumable
1321+
}
1322+
1323+
var checkKind: CheckKind { CheckKind(rawValue: bridged.MarkUnresolvedNonCopyableValue_getCheckKind())! }
1324+
var isStrict: Bool { bridged.MarkUnresolvedNonCopyableValue_isStrict() }
1325+
}
12921326

12931327
final public class MarkUnresolvedReferenceBindingInst : SingleValueInstruction {}
12941328

@@ -1404,6 +1438,8 @@ final public class AllocBoxInst : SingleValueInstruction, Allocation, DebugVaria
14041438
public var debugVariable: DebugVariable? {
14051439
return bridged.AllocBox_hasVarInfo() ? bridged.AllocBox_getVarInfo() : nil
14061440
}
1441+
1442+
public var hasDynamicLifetime: Bool { bridged.AllocBoxInst_hasDynamicLifetime() }
14071443
}
14081444

14091445
final public class AllocExistentialBoxInst : SingleValueInstruction, Allocation {

include/swift/SIL/SILBridging.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -799,6 +799,7 @@ struct BridgedInstruction {
799799
BRIDGED_INLINE bool AllocStackInst_isFromVarDecl() const;
800800
BRIDGED_INLINE bool AllocStackInst_usesMoveableValueDebugInfo() const;
801801
BRIDGED_INLINE bool AllocStackInst_isLexical() const;
802+
BRIDGED_INLINE bool AllocBoxInst_hasDynamicLifetime() const;
802803
BRIDGED_INLINE bool AllocRefInstBase_isObjc() const;
803804
BRIDGED_INLINE bool AllocRefInstBase_canAllocOnStack() const;
804805
BRIDGED_INLINE SwiftInt AllocRefInstBase_getNumTailTypes() const;
@@ -828,6 +829,8 @@ struct BridgedInstruction {
828829
BRIDGED_INLINE bool ExplicitCopyAddrInst_isTakeOfSrc() const;
829830
BRIDGED_INLINE bool ExplicitCopyAddrInst_isInitializationOfDest() const;
830831
BRIDGED_INLINE SwiftInt MarkUninitializedInst_getKind() const;
832+
BRIDGED_INLINE SwiftInt MarkUnresolvedNonCopyableValue_getCheckKind() const;
833+
BRIDGED_INLINE bool MarkUnresolvedNonCopyableValue_isStrict() const;
831834
BRIDGED_INLINE void RefCountingInst_setIsAtomic(bool isAtomic) const;
832835
BRIDGED_INLINE bool RefCountingInst_getIsAtomic() const;
833836
BRIDGED_INLINE SwiftInt CondBranchInst_getNumTrueArgs() const;

include/swift/SIL/SILBridgingImpl.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,10 @@ bool BridgedInstruction::AllocStackInst_isLexical() const {
13701370
return getAs<swift::AllocStackInst>()->isLexical();
13711371
}
13721372

1373+
bool BridgedInstruction::AllocBoxInst_hasDynamicLifetime() const {
1374+
return getAs<swift::AllocBoxInst>()->hasDynamicLifetime();
1375+
}
1376+
13731377
bool BridgedInstruction::AllocRefInstBase_isObjc() const {
13741378
return getAs<swift::AllocRefInstBase>()->isObjC();
13751379
}
@@ -1496,6 +1500,14 @@ SwiftInt BridgedInstruction::MarkUninitializedInst_getKind() const {
14961500
return (SwiftInt)getAs<swift::MarkUninitializedInst>()->getMarkUninitializedKind();
14971501
}
14981502

1503+
SwiftInt BridgedInstruction::MarkUnresolvedNonCopyableValue_getCheckKind() const {
1504+
return (SwiftInt)getAs<swift::MarkUnresolvedNonCopyableValueInst>()->getCheckKind();
1505+
}
1506+
1507+
bool BridgedInstruction::MarkUnresolvedNonCopyableValue_isStrict() const {
1508+
return getAs<swift::MarkUnresolvedNonCopyableValueInst>()->isStrict();
1509+
}
1510+
14991511
void BridgedInstruction::RefCountingInst_setIsAtomic(bool isAtomic) const {
15001512
getAs<swift::RefCountingInst>()->setAtomicity(
15011513
isAtomic ? swift::RefCountingInst::Atomicity::Atomic

include/swift/SIL/SILInstruction.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9270,6 +9270,7 @@ class MarkUnresolvedNonCopyableValueInst
92709270
friend class SILBuilder;
92719271

92729272
public:
9273+
// The raw values must match Instruction.MarkUnresolvedNonCopyableValueInst.CheckKind
92739274
enum class CheckKind : unsigned {
92749275
Invalid = 0,
92759276

0 commit comments

Comments
 (0)