From 540e4199d1e777bb961475674080e6a442ada2d6 Mon Sep 17 00:00:00 2001 From: Kai Schmidt Date: Tue, 5 Nov 2024 16:25:05 -0800 Subject: [PATCH] fix a bug in a fork optimization --- src/compile/modifier.rs | 7 ++++--- tests/optimized.ua | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/compile/modifier.rs b/src/compile/modifier.rs index d3eaf02ff..15d8e6570 100644 --- a/src/compile/modifier.rs +++ b/src/compile/modifier.rs @@ -453,9 +453,10 @@ impl Compiler { ); } let span = self.add_span(modified.modifier.span.clone()); - match f.sig.args { - 0 => Node::from_iter([g.node, f.node]), - 1 => Node::from_iter([Node::Mod(On, eco_vec![g], span), f.node]), + match (f.sig.args, g.sig.args) { + (0, _) => Node::from_iter([g.node, f.node]), + (1, 0) => Node::from_iter([Node::Mod(Dip, eco_vec![g], span), f.node]), + (1, _) => Node::from_iter([Node::Mod(On, eco_vec![g], span), f.node]), _ => Node::Mod(Fork, eco_vec![f, g], span), } } diff --git a/tests/optimized.ua b/tests/optimized.ua index ec464e204..8b3dd25c7 100644 --- a/tests/optimized.ua +++ b/tests/optimized.ua @@ -81,6 +81,10 @@ ⍤⤙≍ [⊞⊃+- .⇡5] [⊞⊃(+|-) .⇡5] ⍤⤙≍ {⊞(∘⊃(+|++))..⇡2} {⊞⊃(+|++)..⇡2} +# Fork reductions +⍤⤙≍ [5 ¯3] [⊃5¯] 3 +⍤⤙≍ [¯3 5] [⊃¯ 5] 3 + ⍤⤙≍ [0 0 0] ≡⋅0 ⇡3 ⍤⤙≍ [0 0 0] ∵⋅0 ⇡3 ⍤⤙≍ [0 0 0] ≡⋅0 ↯3_3 0