Skip to content

Commit 85a8a05

Browse files
committed
[SILParse] InitAccessors: Print/parse "mode" of assign_or_init instructions when its known
1 parent c82559e commit 85a8a05

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

lib/SIL/IR/SILPrinter.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1777,6 +1777,16 @@ class SILPrinter : public SILInstructionVisitor<SILPrinter> {
17771777
}
17781778

17791779
void visitAssignOrInitInst(AssignOrInitInst *AI) {
1780+
switch (AI->getMode()) {
1781+
case AssignOrInitInst::Unknown:
1782+
break;
1783+
case AssignOrInitInst::Init:
1784+
*this << "[init] ";
1785+
break;
1786+
case AssignOrInitInst::Set:
1787+
*this << "[set] ";
1788+
break;
1789+
}
17801790
*this << getIDAndType(AI->getSrc());
17811791
*this << ", init " << getIDAndType(AI->getInitializer())
17821792
<< ", set " << getIDAndType(AI->getSetter());

lib/SIL/Parser/ParseSIL.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4701,8 +4701,7 @@ bool SILParser::parseSpecificSILInstruction(SILBuilder &B,
47014701
SILValue Src, InitFn, SetFn;
47024702
AssignOrInitInst::Mode Mode;
47034703

4704-
if (parseTypedValueRef(Src, B) ||
4705-
parseAssignOrInitMode(Mode, *this) ||
4704+
if (parseAssignOrInitMode(Mode, *this) || parseTypedValueRef(Src, B) ||
47064705
P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ",") ||
47074706
parseVerbatim("init") || parseTypedValueRef(InitFn, B) ||
47084707
P.parseToken(tok::comma, diag::expected_tok_in_sil_instr, ",") ||
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %target-swift-frontend -enable-experimental-feature InitAccessors -Xllvm -sil-print-after=definite-init -emit-sil %s -o /dev/null 2>&1 | %FileCheck %s
2+
3+
struct Test1 {
4+
var _a: Int
5+
var _b: String
6+
7+
var a: Int {
8+
init(initialValue) initializes(_a) {
9+
_a = initialValue
10+
}
11+
12+
get { _a }
13+
set { }
14+
}
15+
16+
var b: String {
17+
init(initialValue) initializes(_a, _b) {
18+
_a = 0
19+
_b = initialValue
20+
}
21+
22+
get { _b }
23+
set { }
24+
}
25+
26+
// CHECK-LABEL: sil hidden [ossa] @$s4null5Test1V1aACSi_tcfC : $@convention(method) (Int, @thin Test1.Type) -> @owned Test1
27+
// CHECK: assign_or_init [init] {{.*}} : $Int, init {{.*}} : $@convention(thin) (Int) -> @out Int, set {{.*}} : $@callee_guaranteed (Int) -> ()
28+
// CHECK: assign_or_init [init] {{.*}} : $String, init {{.*}} : $@convention(thin) (@owned String) -> (@out Int, @out String), set {{.*}} : $@callee_guaranteed (@owned String) -> ()
29+
// CHECK: assign_or_init [set] {{.*}} : $Int, init {{.*}} : $@convention(thin) (Int) -> @out Int, set {{.*}} : $@callee_guaranteed (Int) -> ()
30+
init(a: Int) {
31+
self.a = a
32+
self.a = -1
33+
self.b = ""
34+
self.a = a
35+
}
36+
}

0 commit comments

Comments
 (0)