Skip to content

Commit

Permalink
fix a bug in a fork optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
kaikalii committed Nov 6, 2024
1 parent 43e8100 commit 540e419
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/compile/modifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
Expand Down
4 changes: 4 additions & 0 deletions tests/optimized.ua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 540e419

Please sign in to comment.