Commit 07ea0c2
committed
fix: lower tuple-returning cond (multi-output) natively
A `cond`/`if` whose branches return a tuple crashed the native compiler
with a FunctionClauseError: the :cond lowering passed the tuple branch
straight to lower_node/2, which only matches a single tensor. Worse, a
FunctionClauseError escapes the compiler's graceful-fallback rescue (which
only traps ArgumentError), so it hard-faulted instead of degrading to the
evaluator. Surfaced by a Whisper encoder forward under native: true
(transpose(elem(cond -> {f32[1,1500,6,64] x N}, i))).
Lower a tuple cond to one where-chain per leaf position — identical
wholesale-select semantics to the single-output cond (the predicate is a
whole-tensor scalar bool; every branch is still computed) — and return a
{:multi_refs, [...]} handle that :elem projects, shared across sibling
:elems via lower_node's memo (like while). A nested / non-tensor container
raises a clean ArgumentError, so it falls back gracefully rather than
crashing.
- ir.ex: split the :cond clause (single-tensor head unchanged; new
is_tuple head for the multi-output case); extend :elem to project
{:multi_refs, refs}; add the tensors?/1 guard.
- compiler_control_flow_test.exs: tuple if + multi-clause tuple cond with
mixed-shape (vector + scalar) leaves, native-vs-evaluator bit-identical.1 parent 7988ca8 commit 07ea0c2
2 files changed
Lines changed: 94 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
870 | 870 | | |
871 | 871 | | |
872 | 872 | | |
873 | | - | |
| 873 | + | |
874 | 874 | | |
875 | 875 | | |
876 | 876 | | |
| |||
884 | 884 | | |
885 | 885 | | |
886 | 886 | | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
| 903 | + | |
| 904 | + | |
| 905 | + | |
| 906 | + | |
| 907 | + | |
| 908 | + | |
| 909 | + | |
| 910 | + | |
| 911 | + | |
| 912 | + | |
| 913 | + | |
| 914 | + | |
| 915 | + | |
| 916 | + | |
| 917 | + | |
| 918 | + | |
| 919 | + | |
| 920 | + | |
| 921 | + | |
| 922 | + | |
| 923 | + | |
| 924 | + | |
| 925 | + | |
| 926 | + | |
| 927 | + | |
| 928 | + | |
| 929 | + | |
| 930 | + | |
| 931 | + | |
| 932 | + | |
887 | 933 | | |
888 | 934 | | |
889 | 935 | | |
| |||
955 | 1001 | | |
956 | 1002 | | |
957 | 1003 | | |
| 1004 | + | |
| 1005 | + | |
| 1006 | + | |
958 | 1007 | | |
959 | 1008 | | |
960 | 1009 | | |
961 | | - | |
962 | | - | |
| 1010 | + | |
| 1011 | + | |
963 | 1012 | | |
964 | 1013 | | |
965 | 1014 | | |
| |||
1157 | 1206 | | |
1158 | 1207 | | |
1159 | 1208 | | |
| 1209 | + | |
| 1210 | + | |
1160 | 1211 | | |
1161 | 1212 | | |
1162 | 1213 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
48 | 76 | | |
49 | 77 | | |
50 | 78 | | |
| |||
71 | 99 | | |
72 | 100 | | |
73 | 101 | | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
74 | 114 | | |
75 | 115 | | |
76 | 116 | | |
| |||
0 commit comments