Skip to content

barcodes: spell the package in the syntax the compiler now supports - #313

Merged
shreeve merged 1 commit into
mainfrom
barcodes-syntax
Sep 16, 2026
Merged

shreeve merged 1 commit into
mainfrom
barcodes-syntax

Conversation

@shreeve

@shreeve shreeve commented Sep 16, 2026

Copy link
Copy Markdown
Owner

Summary

packages/barcodes was written around five compiler limitations that PRs #308#312 removed. This replaces every workaround with the direct spelling. Behavior is unchanged: dom.rip emits byte-identical JS but for one semicolon, the encoder oracle is byte-identical on 1452 checks, the decoder oracle identical on 192, and the bench keeps its margins over the reference implementation.

Changes

  • Void definitions (f! =! ->, m!: ->): 33 functions and methods whose value is never used are bang-named; the 27 bare trailing return lines that stopped trailing-loop collection are deleted. The 9 bare returns left are early exits.
  • Range loops in every form: 20 hand-counted while loops are ranges again (including descending by -1, stepped by 2, and variable-step chunk loops under a cooperative yield); 3 push-built arrays are comprehensions; one-statement block loops fold to postfix. Per-pixel hot loops keep block form for readability (identical header either way). copyWords splits quad and remainder passes into two ranges. decodeText indexes directly, so the GS1 position check moves from post-increment slot 2 to slot 1 (covered by the existing GS1 tests).
  • yield* at the three delegation sites.
  • Tail try: decode, decodeAsync, decodeQR return in place instead of hoisting a result; decodeQR raises inside the try so clean() runs during the unwind.
  • own restored as the Code 128 subset planner's local, next to other.

Diff: 6 files, +114 / −228.

Verification

  • packages/barcodes tests: 33/33
  • bun run test:all: 26 lanes, 9895 tests (includes the package style lint)
  • Encoder parity oracle: 1452 checks, 0 mismatches; decoder oracle: 192 checks, 0 mismatches
  • Bench, same session (µs, rip / reference): encode v8 19.2 / 17.7, v18 55.9 / 59.0; decode raster 38.8 / 116.4, 720p 652 / 1030, 1080p 1490 / 2230, 1080p miss 22800 / 23640. Same ratios as the pre-change run.

The package was written around five compiler limitations that no longer
exist. Every workaround is replaced by the direct spelling; the emitted
JS is equivalent (dom.rip emits byte-identical code but for one
semicolon), the encoder oracle is byte-identical on 1452 checks, the
decoder oracle identical on 192, and the bench holds its margins.

Void definitions compose with readonly. Thirty-three functions and
methods whose value nobody uses are now bang-named (`matSet! =!`,
`clean!: =>`, `binarize!:`), and the 27 bare trailing `return` lines
that stopped a trailing loop from being collected are gone. The nine
bare returns that remain are early exits.

Range loops count in every form. Twenty hand-counted `while` loops are
ranges again (`for i in [n - 1..0] by -1`, `for at in [first...n - 5]
by 2`, `for y in [0...bHeight] by chunk` under a cooperative yield),
three push-built arrays are comprehensions, and one-statement block
loops fold to postfix lines. Per-pixel loops (block thresholds, bitmap
rows, resize, finder search) keep block form for readability; the
emitted header is the same either way. copyWords splits its quad and
remainder passes into two ranges instead of sharing a counter.
decodeText indexes its codeword loop directly, so the GS1 position test
moves from the post-increment slot 2 to slot 1.

`yield from` is `yield*` at its three delegation sites. The three
functions that hoisted a result around a tail try/finally return in
place, and decodeQR raises its error inside the try so clean() runs
during the unwind. The Code 128 subset planner's `own` local is `own`
again next to `other`.

Verified: package tests 33/33, test:all 26 lanes / 9895 tests, both
parity oracles clean. Bench (same session, µs, rip / Paul): encode v8
19.2 / 17.7, v18 55.9 / 59.0; decode raster 38.8 / 116.4, 720p 652 /
1030, 1080p 1490 / 2230, 1080p miss 22800 / 23640 — the same ratios as
before the change.
@shreeve
shreeve merged commit 71419ac into main Sep 16, 2026
2 checks passed
@shreeve
shreeve deleted the barcodes-syntax branch September 16, 2026 08:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant