Repository navigation
docs(adr): draft ADR-0028, what a string index counts (#831) - #844
Merged
Merged
Conversation
A draft decision record for the owner. It changes no semantics. - Usage of len, string_get, string_sub, string_char_code_at and char_to_int across the repository, the stdlib and the satellites, with the len sites classified by argument type. - A Bun benchmark of candidate lowerings (UTF-16 units, octets with and without a cached UTF-8 view, code points, a Uint8Array representation) and a wasm measurement of the boundary check. - Five options with migration cost, Char interaction, wasm cost and proof-friendliness, rated, with a recommendation. Refs #831 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J4QvDhJog6g9kprphCAadr
|
Review these changes at https://app.gitnotebooks.com/hyperpolymath/affinescript/pull/844 |
This was referenced Dec 1, 2026
hyperpolymath
marked this pull request as ready for review
December 1, 2026 18:33
hyperpolymath
enabled auto-merge (squash)
December 1, 2026 18:36
hyperpolymath
disabled auto-merge
December 1, 2026 18:37
hyperpolymath
enabled auto-merge (squash)
December 1, 2026 18:37
hyperpolymath
disabled auto-merge
December 1, 2026 19:00
hyperpolymath
enabled auto-merge (squash)
December 1, 2026 19:17
Contributor
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 48 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
|
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.



Depends on: #829
Refs #831. This PR does not close #831: the owner decides.
What this is
A draft decision record,
docs/decisions/0028-string-index-units.adoc, plus one line indocs/NAVIGATION.adoc. It changes no semantics and no code.It depends on #829 only because it cites
docs/UNICODE-STRINGS.adoc, which that PR adds.Usage (main
4248912, 575 tracked.affinefiles)Call sites outside comment lines:
stdlib/tests/+test/lenstring_lengthstring_getstring_substring_char_code_atchar_to_intlensites are on strings (29 stdlib, 19 tests). All 48 satellite sites are array lengths, so no satellite indexes a string.encoding::to_base64("é")isw6k=on core wasm (correct) and6Q==on Bun;to_base64("🦜")is8J+mnA==on wasm andP5w=on Bun.Bun benchmark (Bun 1.4.4, median of three runs)
Uint8Arraystringslenonce, index every position)++lenafter each, 1k ASCIIBuffer.byteLength)lenof a 100k mixed stringBuffer.byteLength)Re-encoding on every call (no cache) makes the scan loop 190 to 1 400 times slower at 1k, so it is ruled out. The full table, the candidates and the limits of the measurement are in the record.
wasm
A boundary check costs at most about 0.6 ns per checked offset (43.2 M index operations: 51–58 ms without the check, 76–87 ms with it). Code-point indexing at size could not be measured: core wasm overwrites its own literals after about 1 KiB of allocation, a bug #829 already records.
Options and recommendation
Rated 1 (worst) to 5 (best).
lenStringas aUint8Arrayon BunBytesfor byte code, and noIntindex into text (opaque offsets)Recommended: A now, with E recorded as the direction of travel. A makes the backends agree, makes base64/hex/JSON escaping correct on Bun, and gives the DEED printer proof a single measure. Its migration here is small: 4 slice sites and 11
string_getsites in the stdlib, no satellite changes, no existing test expectation changes. Its cost is about 2 times on scan loops at size, andlenis no longer O(1) on Bun. E is the more final answer (unit confusion becomes a type error) but is the largest migration; A's offsets are the values E's offset type would wrap.Charas a Unicode scalar value follows from A but is a separate change.Things for the owner to know
.mjsfile, because the policy bans new hand-written JS. It measures candidate text the compiler would emit. Say if you would rather it were removed or kept elsewhere.let mut i = 0; i = i + 1;stops withExpected mutable referencethere (the known gap indocs/CAPABILITY-MATRIX.adoc).lenstring/array split was done by reading each site, not by the type checker.Checks
just guardpasses (doc-truthing, deed gates, soundness ledger, capability anchors).asciidoctor --failure-level WARNrenders the record with no warnings.Generated by Claude Code