Skip to content

Commit e147d3e

Browse files
authored
Merge pull request RustPython#1884 from RustPython/coolreader18/disable-unpack-opt
Disable the unpack optimization
2 parents a6b674c + c50ab85 commit e147d3e

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

compiler/src/peephole.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl<O: OutputStream> PeepholeOptimizer<O> {
9292
}
9393

9494
fn optimize(&mut self) {
95-
apply_optimizations!(self, operator, unpack);
95+
apply_optimizations!(self, operator /* , unpack */);
9696
}
9797
}
9898

compiler/src/peephole/optimizations.rs

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,27 @@ pub fn operator(buf: &mut impl OptimizationBuffer) {
7373
}
7474
}
7575

76-
pub fn unpack(buf: &mut impl OptimizationBuffer) {
77-
let (instruction, meta) = buf.pop();
78-
if let Instruction::UnpackSequence { size } = instruction {
79-
let (arg, arg_meta) = buf.pop();
80-
match arg {
81-
Instruction::BuildTuple {
82-
size: tup_size,
83-
unpack,
84-
} if !unpack && tup_size == size => {
85-
buf.emit(
86-
Instruction::Reverse { amount: size },
87-
vec![arg_meta, meta].into(),
88-
);
89-
}
90-
arg => {
91-
buf.emit(arg, arg_meta);
92-
buf.emit(instruction, meta);
93-
}
94-
}
95-
} else {
96-
buf.emit(instruction, meta)
97-
}
98-
}
76+
// TODO: make a version of this that doesn't miscompile `a, b = (1, 2) if True else (3, 4)`
77+
// pub fn unpack(buf: &mut impl OptimizationBuffer) {
78+
// let (instruction, meta) = buf.pop();
79+
// if let Instruction::UnpackSequence { size } = instruction {
80+
// let (arg, arg_meta) = buf.pop();
81+
// match arg {
82+
// Instruction::BuildTuple {
83+
// size: tup_size,
84+
// unpack,
85+
// } if !unpack && tup_size == size => {
86+
// buf.emit(
87+
// Instruction::Reverse { amount: size },
88+
// vec![arg_meta, meta].into(),
89+
// );
90+
// }
91+
// arg => {
92+
// buf.emit(arg, arg_meta);
93+
// buf.emit(instruction, meta);
94+
// }
95+
// }
96+
// } else {
97+
// buf.emit(instruction, meta)
98+
// }
99+
// }

tests/snippets/if_expressions.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,7 @@ def func2():
2424
return 20
2525

2626
assert ret(func1() or func2()) == 20
27+
28+
a, b = (1, 2) if True else (3, 4)
29+
assert a == 1
30+
assert b == 2

0 commit comments

Comments
 (0)