-
Notifications
You must be signed in to change notification settings - Fork 1
fix(analyser): widen Binding::Dynamic result to Any 🪟 #140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
timfennis
merged 4 commits into
master
from
bugfix/issue-139-vectorized-tuple-arith-chained
May 20, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
df19b0a
test: reproduce issue #139 chained vectorized tuple arithmetic 🧪
timfennis 8f964d0
fix(analyser): infer tuple type for vectorizable binary ops 🧮
timfennis 812b14f
fix(analyser): treat tuple-of-Any as vectorizable 🎯
timfennis d00dee5
refactor(analyser): widen Binding::Dynamic result to Any
timfennis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
tests/functional/programs/900_bugs/bug0021_chained_vectorized_tuple_arith.ndc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // BUG#0021 (issue #139): vectorized tuple arithmetic broke when the result | ||
| // of one tuple op was fed into another. The analyser inferred the result of | ||
| // `a - b` as `Number` (the LUB of the dynamic candidates' return types), so | ||
| // `diff * diff` resolved statically to a `(Number, Number) -> Number` | ||
| // overload via `Binding::Resolved` and bypassed OverloadSet dispatch — and | ||
| // therefore the VM's vectorized fallback. The native then bailed with | ||
| // "expected number, got Tuple<Int, Int, Int>". | ||
| let a = (1, 2, 3); | ||
| let b = (4, 5, 6); | ||
|
|
||
| assert_eq(a * b, (4, 10, 18)); | ||
|
|
||
| let diff = a - b; | ||
| assert_eq(diff, (-3, -3, -3)); | ||
| assert_eq(diff * diff, (9, 9, 9)); | ||
|
|
||
| assert_eq((a - b) * (a - b), (9, 9, 9)); | ||
|
|
||
| // Same hazard but the tuple elements are statically `Any`. `id` here erases | ||
| // type information so the tuples below are `Tuple<Any, Any, Any>`; this | ||
| // mirrors what happens with stdlib natives whose `Value` return type infers | ||
| // to `Any`. The vectorization detection must treat `Any` as a potentially- | ||
| // numeric element so chained ops still go through dynamic dispatch. | ||
| fn id(x) -> Any => x; | ||
| let av = (id(1), id(2), id(3)); | ||
| let bv = (id(4), id(5), id(6)); | ||
| let cv = av - bv; | ||
| assert_eq(cv, (-3, -3, -3)); | ||
| assert_eq(cv * cv, (9, 9, 9)); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.