Skip to content

Commit 63e7561

Browse files
committed
[SIL] InitAccessors: Introduce a new Out kind to MarkUninitializedInst
`Out` marks indirect results that have to be fully initialized before their lifetime ends.
1 parent 69269e6 commit 63e7561

File tree

7 files changed

+18
-2
lines changed

7 files changed

+18
-2
lines changed

include/swift/SIL/SILBuilder.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1018,7 +1018,11 @@ class SILBuilder {
10181018
SILValue src) {
10191019
return createMarkUninitialized(Loc, src, MarkUninitializedInst::RootSelf);
10201020
}
1021-
1021+
MarkUninitializedInst *createMarkUninitializedOut(SILLocation Loc,
1022+
SILValue src) {
1023+
return createMarkUninitialized(Loc, src, MarkUninitializedInst::Out);
1024+
}
1025+
10221026
MarkFunctionEscapeInst *createMarkFunctionEscape(SILLocation Loc,
10231027
ArrayRef<SILValue> vars) {
10241028
return insert(

include/swift/SIL/SILInstruction.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5029,6 +5029,10 @@ class MarkUninitializedInst
50295029
/// DelegatingSelfAllocated designates "self" in a delegating class
50305030
/// initializer where memory has already been allocated.
50315031
DelegatingSelfAllocated,
5032+
5033+
/// Out designates an indirectly returned result.
5034+
/// This is the result that has to be checked for initialization.
5035+
Out,
50325036
};
50335037
private:
50345038
Kind ThisKind;
@@ -5043,6 +5047,7 @@ class MarkUninitializedInst
50435047
Kind getMarkUninitializedKind() const { return ThisKind; }
50445048

50455049
bool isVar() const { return ThisKind == Var; }
5050+
bool isOut() const { return ThisKind == Out; }
50465051
bool isRootSelf() const {
50475052
return ThisKind == RootSelf;
50485053
}

lib/SIL/IR/SILPrinter.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1797,6 +1797,9 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17971797
case MarkUninitializedInst::DelegatingSelfAllocated:
17981798
*this << "[delegatingselfallocated] ";
17991799
break;
1800+
case MarkUninitializedInst::Out:
1801+
*this << "[out] ";
1802+
break;
18001803
}
18011804
*this << getIDAndType(MU->getOperand());
18021805
printForwardingOwnershipKind(MU, MU->getOperand());

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4489,6 +4489,8 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
44894489
Kind = MarkUninitializedInst::DelegatingSelf;
44904490
else if (KindId.str() == "delegatingselfallocated")
44914491
Kind = MarkUninitializedInst::DelegatingSelfAllocated;
4492+
else if (KindId.str() == "out")
4493+
Kind = MarkUninitializedInst::Out;
44924494
else {
44934495
P.diagnose(KindLoc, diag::expected_tok_in_sil_instr,
44944496
"var, rootself, crossmodulerootself, derivedself, "

lib/SILOptimizer/Mandatory/DIMemoryUseCollector.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ class DIMemoryObjectInfo {
200200
bool isNonDelegatingInit() const {
201201
switch (MemoryInst->getMarkUninitializedKind()) {
202202
case MarkUninitializedInst::Var:
203+
case MarkUninitializedInst::Out:
203204
return false;
204205
case MarkUninitializedInst::RootSelf:
205206
case MarkUninitializedInst::CrossModuleRootSelf:

lib/SILOptimizer/Mandatory/DiagnoseInvalidEscapingCaptures.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ bool isUseOfSelfInInitializer(Operand *oper) {
183183
if (auto *MUI = dyn_cast<MarkUninitializedInst>(value)) {
184184
switch (MUI->getMarkUninitializedKind()) {
185185
case MarkUninitializedInst::Kind::Var:
186+
case MarkUninitializedInst::Kind::Out:
186187
return false;
187188
case MarkUninitializedInst::Kind::RootSelf:
188189
case MarkUninitializedInst::Kind::CrossModuleRootSelf:

lib/Serialization/ModuleFormat.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
5858
/// describe what change you made. The content of this comment isn't important;
5959
/// it just ensures a conflict if two people change the module format.
6060
/// Don't worry about adhering to the 80-column limit for this line.
61-
const uint16_t SWIFTMODULE_VERSION_MINOR = 789; // assign or init instruction
61+
const uint16_t SWIFTMODULE_VERSION_MINOR = 790; // add `out` kind to mark uninitialized instruction
6262

6363
/// A standard hash seed used for all string hashes in a serialized module.
6464
///

0 commit comments

Comments
 (0)