Ambyte: checked narrowing of a byte value to a smaller literal bound
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 38/100
Research direction
Start with the language typing and static charge logic in fold_work.rs, then trace the matching rules in Echo’s lowerer and verifier and the runtime charge. The issue’s RED test is the guarded slice; add coverage for the stated narrow(a, 57) type, bound independent charge, and 58-byte input. Done means those checks pass and the jedit#410 rope package records the before and after U measurements.
Written by the indexing model from the issue text.
Description
.dag: issue-dag/2
.id: ambyte-lang/ambyte#437
.kind: task
.type: feature
.blocks: [flyingrobots/jim#5]
.size_hours: 6
Outcome
Source can narrow a byte value to a smaller literal bound with a check, for example narrow(b, 57) -> Option<Bytes<max=57>>, which is none when len(b) > 57. The narrowing costs a constant plus at most the new bound, never the old one, and the value's later uses are charged at the new bound.
Why
There is no way in the language to do this today:
slicekeeps its input's bound.if len(a) <= 57 then slice(a, 0, len(a)) else b""is refused with "conditional branches do not match the expected type".- Copying octet by octet into
Bytes<max=57>passes the 4,352-byte atom on everyat, so it costs more than it saves.
Under amblicit main (a0542b53, with #424 and #432), every use of a Bytes<max=4352> local as a call argument is still charged at 4,352 bytes. A canonical Branch fact is at most 57 bytes.
Projected savings, measured by simulation
jedit#410 at 9e5863d: static U is 83,964,734 steps and 173,660,515 bytes. I replaced the two branchFact call sites (the closure selector and loadStep) with a parser typed on Bytes<max=57>, fed by a stub that costs one atom use. U fell to 77,883,198 steps and 167,161,699 bytes: 6,081,536 steps (7.2%) and 6,498,816 bytes (3.7%) saved.
Scope
- A builtin or a checked form, its typing, the static charge rule in
fold_work.rs, and the matching rule in Echo's lowerer and verifier, plus the runtime charge. - Not in scope: narrowing whose bound is not a literal.
Test Plan
- RED: the guarded slice above is refused.
- GREEN:
narrow(a, 57)type-checks asOption<Bytes<max=57>>; its charge is independent ofa's bound; it isnonefor a 58-byte input. - Rebuild jedit#410's rope package with
branchFacton the narrowed value and record U before and after.
- Dominant language
- Rust
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from flyingrobots/edict
-
Update Wasmtime to 48.0.11 for RUSTSEC-2026-0648Possibly taken @flyingrobots claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
flyingrobots/edict#457 ·
-
enhancement type: goalpost
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
flyingrobots/edict#355 ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
flyingrobots/edict#306 ·
-
enhancement type: goalpost
Difficulty 4/5 3-5 days Newbie friendliness 42/100
flyingrobots/edict#451 ·
-
enhancement release:target-ir
Difficulty 5/5 Over a week Newbie friendliness 28/100
flyingrobots/edict#450 · 1 comment · 1 reaction ·
All issues in flyingrobots/edict
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
autofixer: follow-up triage: bug triage: classified triage: correctness triage: has-reproducer
Difficulty 2/5 1-3 hours Newbie friendliness 67/100
tursodatabase/turso#13221 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 72/100
-
O-windows relnotes relnotes-needs-review relnotes-tracking-issue T-libs
Difficulty 1/5 Under an hour Newbie friendliness 68/100
Maintainers usually reply within 1 day
-
approved
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
fritzprix/libr-agent#3266 ·
Maintainers usually reply within 1 day