Skip to content

Split blocks with more than two branches in functional - #165

Merged
CarloLucibello merged 1 commit into
masterfrom
cl/functional-multibranch
Oct 15, 2026
Merged

CarloLucibello merged 1 commit into
masterfrom
cl/functional-multibranch

Conversation

@CarloLucibello

Copy link
Copy Markdown
Member

Fixes #100.

functional asserted that every block ends in at most two branches. f(x, y) = x && y && error() lowers to a block with three branches (br 4 unless %2; br 3 unless %3; br 2), so it failed with AssertionError: length(branches(bl)) == 2. A chain of conditional branches is just a nested if/else. functional now first splits such blocks: each one keeps its first branch and moves the rest into a new block placed right after it.

The tests run the functional form through the existing anf dynamo and compare it with the original function on all inputs:

  • f above, on all four Bool combinations;
  • a four-branch a && b && c && d && error(), on all 16 combinations;
  • the same pattern inside a loop.

(The original Dict getindex example from the issue already works on master.)

🤖 Generated with Claude Code

`functionalbranches!` only translated blocks ending in one or two branches
and asserted otherwise, so blocks with a chain of conditional branches
(e.g. from `x && y && error()`) failed. A chain of conditionals is a nested
if/else, so split such blocks beforehand: keep the first branch and move the
rest to a new block right after it, reached by an unconditional branch.

Fixes #100.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.69%. Comparing base (7400eca) to head (499edcb).
⚠️ Report is 3 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #165      +/-   ##
==========================================
+ Coverage   77.14%   77.69%   +0.55%     
==========================================
  Files          15       16       +1     
  Lines        1597     1614      +17     
==========================================
+ Hits         1232     1254      +22     
+ Misses        365      360       -5     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@CarloLucibello
CarloLucibello force-pushed the cl/functional-multibranch branch from 5a23e2b to 499edcb Compare October 15, 2026 15:56
@CarloLucibello
CarloLucibello merged commit a673a39 into master Oct 15, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Calling functional with IR for Dict getindex raises AssertionError

1 participant