From d7842c79e3b1ea16db0a8a78b3654ea14bfbf6f0 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Fri, 24 Apr 2020 15:14:58 -0500 Subject: [PATCH 1/2] Disable the unpack optimization --- compiler/src/peephole.rs | 2 +- compiler/src/peephole/optimizations.rs | 47 +++++++++++++------------- 2 files changed, 25 insertions(+), 24 deletions(-) diff --git a/compiler/src/peephole.rs b/compiler/src/peephole.rs index 67a4b9efe0..aaec0470c7 100644 --- a/compiler/src/peephole.rs +++ b/compiler/src/peephole.rs @@ -92,7 +92,7 @@ impl PeepholeOptimizer { } fn optimize(&mut self) { - apply_optimizations!(self, operator, unpack); + apply_optimizations!(self, operator /* , unpack */); } } diff --git a/compiler/src/peephole/optimizations.rs b/compiler/src/peephole/optimizations.rs index 28bac862c9..461baa7cc2 100644 --- a/compiler/src/peephole/optimizations.rs +++ b/compiler/src/peephole/optimizations.rs @@ -73,26 +73,27 @@ pub fn operator(buf: &mut impl OptimizationBuffer) { } } -pub fn unpack(buf: &mut impl OptimizationBuffer) { - let (instruction, meta) = buf.pop(); - if let Instruction::UnpackSequence { size } = instruction { - let (arg, arg_meta) = buf.pop(); - match arg { - Instruction::BuildTuple { - size: tup_size, - unpack, - } if !unpack && tup_size == size => { - buf.emit( - Instruction::Reverse { amount: size }, - vec![arg_meta, meta].into(), - ); - } - arg => { - buf.emit(arg, arg_meta); - buf.emit(instruction, meta); - } - } - } else { - buf.emit(instruction, meta) - } -} +// TODO: make a version of this that doesn't miscompile `a, b = (1, 2) if True else (3, 4)` +// pub fn unpack(buf: &mut impl OptimizationBuffer) { +// let (instruction, meta) = buf.pop(); +// if let Instruction::UnpackSequence { size } = instruction { +// let (arg, arg_meta) = buf.pop(); +// match arg { +// Instruction::BuildTuple { +// size: tup_size, +// unpack, +// } if !unpack && tup_size == size => { +// buf.emit( +// Instruction::Reverse { amount: size }, +// vec![arg_meta, meta].into(), +// ); +// } +// arg => { +// buf.emit(arg, arg_meta); +// buf.emit(instruction, meta); +// } +// } +// } else { +// buf.emit(instruction, meta) +// } +// } From c50ab85bbb971328be75f0418ea80af7dd19bbb9 Mon Sep 17 00:00:00 2001 From: Noah <33094578+coolreader18@users.noreply.github.com> Date: Sat, 25 Apr 2020 02:15:14 -0500 Subject: [PATCH 2/2] Add test for unpack regression --- tests/snippets/if_expressions.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/snippets/if_expressions.py b/tests/snippets/if_expressions.py index 143cb64580..ac5f492730 100644 --- a/tests/snippets/if_expressions.py +++ b/tests/snippets/if_expressions.py @@ -24,3 +24,7 @@ def func2(): return 20 assert ret(func1() or func2()) == 20 + +a, b = (1, 2) if True else (3, 4) +assert a == 1 +assert b == 2