Skip to content

Commit 82145d0

Browse files
Fix: Phi sources preserve unassigned version_0.
1 parent 89c0d9b commit 82145d0

2 files changed

Lines changed: 22 additions & 32 deletions

File tree

compiler/src/modules/parser.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -244,16 +244,8 @@ impl<'src, I: Iterator<Item = Token>> Parser<'src, I> {
244244
let vb = *b.get(&name).unwrap_or(&0);
245245
if va == vb { continue; }
246246

247-
let ia = if va == 0 {
248-
self.chunk.push_name(&format!("{}_{}", name, vb))
249-
} else {
250-
self.chunk.push_name(&format!("{}_{}", name, va))
251-
};
252-
let ib = if vb == 0 {
253-
self.chunk.push_name(&format!("{}_{}", name, va))
254-
} else {
255-
self.chunk.push_name(&format!("{}_{}", name, vb))
256-
};
247+
let ia = self.chunk.push_name(&format!("{}_{}", name, va));
248+
let ib = self.chunk.push_name(&format!("{}_{}", name, vb));
257249

258250
let v = self.increment_version(&name);
259251
let ix = self.chunk.push_name(&format!("{}_{}", name, v));

compiler/tests/cases/parser_cases.json

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,8 @@
304304
{
305305
"src": "if a:\nx = 1",
306306
"constants": ["1"],
307-
"names": ["a_0", "x_1", "x_2"],
308-
"instructions": [["LoadName",0], ["JumpIfFalse",4], ["LoadConst",0], ["StoreName",1], ["Phi",2], ["ReturnValue",0]],
307+
"names": ["a_0", "x_1", "x_0", "x_2"],
308+
"instructions": [["LoadName",0], ["JumpIfFalse",4], ["LoadConst",0], ["StoreName",1], ["Phi",3], ["ReturnValue",0]],
309309
"annotations": {}
310310
},
311311
{
@@ -325,15 +325,15 @@
325325
{
326326
"src": "total = 0\nfor i in range(5):\ntotal = total + i",
327327
"constants": ["0", "5"],
328-
"names": ["total_1", "i_1", "total_2", "i_2", "total_3"],
329-
"instructions": [["LoadConst",0], ["StoreName",0], ["LoadConst",1], ["CallRange",1], ["GetIter",0], ["ForIter",12], ["StoreName",1], ["LoadName",0], ["LoadName",1], ["Add",0], ["StoreName",2], ["Jump",5], ["Phi",3], ["Phi",4], ["ReturnValue",0]],
328+
"names": ["total_1", "i_1", "total_2", "i_0", "i_2", "total_3"],
329+
"instructions": [["LoadConst",0], ["StoreName",0], ["LoadConst",1], ["CallRange",1], ["GetIter",0], ["ForIter",12], ["StoreName",1], ["LoadName",0], ["LoadName",1], ["Add",0], ["StoreName",2], ["Jump",5], ["Phi",4], ["Phi",5], ["ReturnValue",0]],
330330
"annotations": {}
331331
},
332332
{
333333
"src": "for i in range(3):\nprint(i)",
334334
"constants": ["3"],
335-
"names": ["i_1", "i_2"],
336-
"instructions": [["LoadConst",0], ["CallRange",1], ["GetIter",0], ["ForIter",8], ["StoreName",0], ["LoadName",0], ["CallPrint",0], ["Jump",3], ["Phi",1], ["ReturnValue",0]],
335+
"names": ["i_1", "i_0", "i_2"],
336+
"instructions": [["LoadConst",0], ["CallRange",1], ["GetIter",0], ["ForIter",8], ["StoreName",0], ["LoadName",0], ["CallPrint",0], ["Jump",3], ["Phi",2], ["ReturnValue",0]],
337337
"annotations": {}
338338
},
339339
{
@@ -381,8 +381,8 @@
381381
{
382382
"src": "s = 0\nfor i in range(10):\ns += i",
383383
"constants": ["0", "10"],
384-
"names": ["s_1", "i_1", "s_2", "i_2", "s_3"],
385-
"instructions": [["LoadConst",0], ["StoreName",0], ["LoadConst",1], ["CallRange",1], ["GetIter",0], ["ForIter",12], ["StoreName",1], ["LoadName",0], ["LoadName",1], ["Add",0], ["StoreName",2], ["Jump",5], ["Phi",3], ["Phi",4], ["ReturnValue",0]],
384+
"names": ["s_1", "i_1", "s_2", "i_0", "i_2", "s_3"],
385+
"instructions": [["LoadConst",0], ["StoreName",0], ["LoadConst",1], ["CallRange",1], ["GetIter",0], ["ForIter",12], ["StoreName",1], ["LoadName",0], ["LoadName",1], ["Add",0], ["StoreName",2], ["Jump",5], ["Phi",4], ["Phi",5], ["ReturnValue",0]],
386386
"annotations": {}
387387
},
388388
{
@@ -423,15 +423,15 @@
423423
{
424424
"src": "if True:\n x = 1\n y = 2\nz = x",
425425
"constants": ["1", "2"],
426-
"names": ["x_1", "y_1", "x_2", "y_2", "z_1"],
427-
"instructions": [["LoadTrue",0], ["JumpIfFalse",6], ["LoadConst",0], ["StoreName",0], ["LoadConst",1], ["StoreName",1], ["Phi",2], ["Phi",3], ["LoadName",2], ["StoreName",4], ["ReturnValue",0]],
426+
"names": ["x_1", "y_1", "x_0", "x_2", "y_0", "y_2", "z_1"],
427+
"instructions": [["LoadTrue",0], ["JumpIfFalse",6], ["LoadConst",0], ["StoreName",0], ["LoadConst",1], ["StoreName",1], ["Phi",3], ["Phi",5], ["LoadName",3], ["StoreName",6], ["ReturnValue",0]],
428428
"annotations": {}
429429
},
430430
{
431431
"src": "for i in range(3):\n x = i\n print(x)",
432432
"constants": ["3"],
433-
"names": ["i_1", "x_1", "i_2", "x_2"],
434-
"instructions": [["LoadConst",0], ["CallRange",1], ["GetIter",0], ["ForIter",10], ["StoreName",0], ["LoadName",0], ["StoreName",1], ["LoadName",1], ["CallPrint",0], ["Jump",3], ["Phi",2], ["Phi",3], ["ReturnValue",0]],
433+
"names": ["i_1", "x_1", "i_0", "i_2", "x_0", "x_2"],
434+
"instructions": [["LoadConst",0], ["CallRange",1], ["GetIter",0], ["ForIter",10], ["StoreName",0], ["LoadName",0], ["StoreName",1], ["LoadName",1], ["CallPrint",0], ["Jump",3], ["Phi",3], ["Phi",5], ["ReturnValue",0]],
435435
"annotations": {}
436436
},
437437
{
@@ -521,8 +521,8 @@
521521
{
522522
"src": "try:\n x = 1\nexcept:\n x = 2",
523523
"constants": ["1", "2"],
524-
"names": ["x_1", "x_2", "x_3"],
525-
"instructions": [["SetupExcept",5], ["LoadConst",0], ["StoreName",0], ["PopExcept",0], ["Jump",7], ["LoadConst",1], ["StoreName",1], ["Phi",2], ["ReturnValue",0]],
524+
"names": ["x_1", "x_2", "x_0", "x_3"],
525+
"instructions": [["SetupExcept",5], ["LoadConst",0], ["StoreName",0], ["PopExcept",0], ["Jump",7], ["LoadConst",1], ["StoreName",1], ["Phi",3], ["ReturnValue",0]],
526526
"annotations": {}
527527
},
528528
{
@@ -939,22 +939,20 @@
939939
{
940940
"src": "for i in range(3):\n pass\nelse:\n x = 1",
941941
"constants": ["3", "1"],
942-
"names": ["i_1", "x_1", "i_2", "x_2"],
943-
"instructions": [["LoadConst",0], ["CallRange",1], ["GetIter",0], ["ForIter",6], ["StoreName",0], ["Jump",3], ["LoadConst",1], ["StoreName",1], ["Phi",2], ["Phi",3], ["ReturnValue",0]],
942+
"names": ["i_1", "x_1", "i_0", "i_2", "x_0", "x_2"],
943+
"instructions": [["LoadConst",0], ["CallRange",1], ["GetIter",0], ["ForIter",6], ["StoreName",0], ["Jump",3], ["LoadConst",1], ["StoreName",1], ["Phi",3], ["Phi",5], ["ReturnValue",0]],
944944
"annotations": {}
945945
},
946946
{
947947
"src": "while x:\n pass\nelse:\n y = 1",
948948
"constants": ["1"],
949-
"names": ["x_0", "y_1", "y_2"],
950-
"instructions": [["LoadName",0], ["JumpIfFalse",3], ["Jump",0], ["LoadConst",0], ["StoreName",1], ["Phi",2], ["ReturnValue",0]],
949+
"names": ["x_0", "y_1", "y_0", "y_2"],
950+
"instructions": [["LoadName",0], ["JumpIfFalse",3], ["Jump",0], ["LoadConst",0], ["StoreName",1], ["Phi",3], ["ReturnValue",0]],
951951
"annotations": {}
952952
},
953953
{
954-
"src": "try:\n x = 1\nexcept:\n x = 2\nelse:\n x = 3",
955-
"constants": ["1", "2", "3"],
956-
"names": ["x_1", "x_2", "x_3", "x_4"],
957-
"instructions": [["SetupExcept",5], ["LoadConst",0], ["StoreName",0], ["PopExcept",0], ["Jump",7], ["LoadConst",1], ["StoreName",1], ["LoadConst",2], ["StoreName",2], ["Phi",3], ["ReturnValue",0]],
954+
"src": "try:\n x = 1\nexcept:\n x = 2\nelse:\n x = 3", "constants": ["1", "2", "3"], "names": ["x_1", "x_2", "x_3", "x_0", "x_4"],
955+
"instructions": [["SetupExcept",5], ["LoadConst",0], ["StoreName",0], ["PopExcept",0], ["Jump",7], ["LoadConst",1], ["StoreName",1], ["LoadConst",2], ["StoreName",2], ["Phi",4], ["ReturnValue",0]],
958956
"annotations": {}
959957
},
960958
{

0 commit comments

Comments
 (0)