fix: at xs i auto-floors fractional indices#304
Merged
Conversation
Previously `at xs 1.5` errored with "index must be an integer", forcing every `at xs (/ k 2)` idiom (median bucket and similar) to be wrapped in `flr`. Drop the fract!=0 guard and `.floor() as i64` the numeric value before the existing negative-index resolution + bounds check. Negative fractions floor toward negative infinity, so `at xs -0.5` lands on `-1` (the last element after Python-style resolution). Non-numeric indices still error. Replaces interp_at_fractional_index_errors with three coverage tests for the new contract: positive fractional, negative fractional, and the non-numeric error guard.
Mirrors the interpreter change for the register VM (OP_AT) and the Cranelift JIT helper (jit_at). Both drop the fract!=0 guard and floor the numeric index before the existing negative-index resolution. Replaces the jit_at_fractional_index_returns_nil unit test with three positive-coverage tests pinning the auto-floor contract: 1.7 floors to 1, -0.5 floors to -1, -1.5 floors to -2.
Adds positive-coverage tests across tree / VM / cranelift for the new auto-floor contract: `at xs 1.0`, `at xs 1.7`, `at xs -1.5`, `at xs -0.5`, and the originating `at xs (len/2)` computed-float idiom. Also keeps a non-numeric-index error test to pin the preserved type guard. Replaces the prior `at xs -0.5 must error` cases (now positive coverage for the same input). Removes the fractional-index span-parity test in regression_cranelift_error_span.rs since that error path no longer exists; jit_at's runtime error path stays covered by the OOB span tests.
Four functions covering the canonical shapes (frac / neghalf / neg32 / mid), with `-- run:` / `-- out:` assertions so the examples_engines harness exercises every engine. `mid` is the originating idiom from the html-scraper rerun (median bucket via `len xs / 2`).
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
One-line note in the SPEC builtins table and ai.txt entry; explicit SKILL.md note under the List builtins line so agents pick up the new contract without re-reading the full spec.
6e232d6 to
8b53f61
Compare
2 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
at xs iused to error withILO-R009 at: index must be an integerwhenevericame from arithmetic like/ k 2or any other division. Every persona writing the median-bucket idiom (at xs (len/2)) had to wrap the index inflr(originating entry: html-scraper rerun3 friction #3,ilo_assessment_feedback.md:2542).Auto-flooring at the
atbuiltin boundary kills the ceremony. The fract!=0 guard is dropped across tree, VM, and Cranelift, and the index is.floor() as i64-ed before the existing negative-index resolution and bounds check. Non-numeric still errors.Repro
Before:
After:
What's in the diff
interp: dropfract!=0guard, floor the numeric index, unit tests for positive frac / negative frac / non-numeric error guard.vm: same change in OP_AT and jit_at. Replaces thejit_at_fractional_index_returns_nilunit test with three positive-coverage tests (1.7→ 1,-0.5→ -1,-1.5→ -2).test: cross-engine regression (tests/regression_at_builtin.rs) coveringat xs 1.0,at xs 1.7,at xs -1.5,at xs -0.5, the computed-floatlen/2idiom, and a preserved non-numeric error case. Removes the obsoleteat_fractional_index_span_matches_vm(jit_at span parity stays covered by the existing OOB tests).example:examples/at-float-index.ilopins the new contract with-- run:/-- out:assertions soexamples_enginesexercises it across every engine.docs: one-line note in SPEC.md, ai.txt, skills/ilo/SKILL.md. Site builtins.md gets a separate PR inilo-lang/site.Floor semantics: negative fractions go toward negative infinity, so
at xs -0.5 == at xs -1(last element) andat xs -1.5 == at xs -2(second-from-last on a len-3 list). Consistent with howflris documented elsewhere.Test plan
cargo test --release --features craneliftclean (all suites)regression_at_builtincovers tree / vm / cranelift for: integer index, integral float, positive frac, negative frac, negative half (was the prior error case), computed-float idiom, and non-numeric error preservationinterp_at_fractional_index_floors+ negative-frac + non-numeric variants in the tree-walkerjit_at_fractional_*_floorsx3 in the JIT helperexamples_enginesrunsexamples/at-float-index.iloacross every enginecargo fmt --checkcleancargo clippy --release --features cranelift --tests -- -D warningscleanFollow-ups
docs/reference/builtins.mdwas missingatentirely; row added in a parallel commit to the site repo.