Skip to content

refactor(ascii): drop the duplicate scalar decode loop in JS decode - #4235

Merged
bobzhang merged 1 commit into
mainfrom
codex/de-slop-ascii-decode
Sep 22, 2026
Merged

bobzhang merged 1 commit into
mainfrom
codex/de-slop-ascii-decode

Conversation

@bobzhang

@bobzhang bobzhang commented Sep 12, 2026 •

Copy link
Copy Markdown
Contributor

What

encoding/ascii/decode.mbt carried the same scalar ASCII decode loop twice:
once as the private decode_scalar (gated #cfg(not(target="js"))) and once
open-coded inside the JS pub fn decode (#cfg(target="js")). The two bodies
were byte-identical — verified by direct comparison of the pre-edit file: the
12 loop lines inside the JS decode equal decode_scalar's body, including the
(_, _ as bytes) => raise Malformed(bytes) arm and the shared finish_string
tail.

Before: on JS the ASCII acceptance rule and the Malformed payload
construction existed in a second, hand-maintained copy, separated from
decode_scalar by ~60 lines of v128 code.
After: decode_scalar loses the cfg and keeps its #inline (it names no
@v128 API, unlike decode_v128), and the JS decode body becomes
decode_scalar(bytes). Net −12 duplicated lines, −1 #cfg; the JS public doc
comment stays on the public function.

Behavior is unchanged:

  • The JS success string is identical — the same code path runs.
  • On JS the Malformed payload is still the remaining BytesView starting at
    the first non-ASCII byte, still a view (not a copy), and its Debug rendering
    (Malformed(<BytesView: [0xff]>)) is unchanged.
  • The non-JS optimized decode, its 64-byte crossover to decode_v128,
    decode_v128's error slicing and suppress_unused_v128_import_on_js are
    untouched.
  • Public API unchanged: pkg.generated.mbti has no diff, and no test snapshot
    changed.

This follows the doctrine already used by the sibling encodings:
encoding/hex/decode.mbt, encoding/base64/decode.mbt and
encoding/utf16/decode.mbt each keep a single decode_scalar and have their
non-vector decode delegate to it (encoding/utf16/decode.mbt:213-219 is the
same JS decode → decode_scalar delegation).

Validation

Run on this exact tree, base a0f0fb87cc0b506364f818c84725152bffbdbb97:

  • moon test encoding/ascii --target all → 15/15 wasm, 15/15 wasm-gc, 12/12 js,
    15/15 native, exit 0 — identical counts to the pre-edit baseline.
  • moon check --target all --deny-warn → exit 0.
  • moon test (full repository) → 7609 passed, 0 failed, exit 0.
  • moon bundle --all → exit 0.
  • moon info → exit 0, no .mbti changes.
  • moon fmt → exit 0, file unchanged.

Changed paths: encoding/ascii/decode.mbt only (1 insertion, 13 deletions).

CI at the single post-publication snapshot (gh pr checks 4235, taken
immediately after opening): version-check, misc-check, stable-check
(ubuntu/windows/macos) and stable-native-opt-test (ubuntu/windows/macos) are
pending; nightly-check is skipping; Devin Review and
GitGuardian Security Checks pass. Pending is recorded as pending — no CI wait
or polling was performed.

@coveralls

coveralls commented Sep 12, 2026 •

Copy link
Copy Markdown
Collaborator

Coverage Report for CI Build 6690

Coverage increased (+0.03%) to 89.386%

Details

  • Coverage increased (+0.03%) from the base build.
  • Patch coverage: 1 uncovered change across 1 file (0 of 1 lines covered, 0.0%).
  • No coverage regressions found.

Uncovered Changes

File Changed Covered %
encoding/ascii/decode.mbt 1 0 0.0%

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 18353
Covered Lines: 16405
Line Coverage: 89.39%
Coverage Strength: 275825.15 hits per line

💛 - Coveralls

decode_scalar was gated to non-JS targets while the JS pub fn decode
repeated its body verbatim. The function names no @v128 API, so remove
the cfg and delegate the JS decode to it, giving the ASCII acceptance
rule and the Malformed payload a single definition. The non-JS vector
path, its 64-byte crossover and decode_v128's error slicing are unchanged.

Co-Authored-By: SeekMoon <seekmoon@moonbitlang.com>
@bobzhang
bobzhang force-pushed the codex/de-slop-ascii-decode branch from cb404df to be9f33d Compare September 22, 2026 04:02
@bobzhang
bobzhang merged commit 0172c03 into main Sep 22, 2026
16 checks passed
@bobzhang
bobzhang deleted the codex/de-slop-ascii-decode branch September 22, 2026 04:09
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.

2 participants