Repository navigation
refactor(ascii): drop the duplicate scalar decode loop in JS decode - #4235
Merged
Merged
Conversation
Collaborator
Coverage Report for CI Build 6690Coverage increased (+0.03%) to 89.386%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - 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
force-pushed
the
codex/de-slop-ascii-decode
branch
from
September 22, 2026 04:02
cb404df to
be9f33d
Compare
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.
What
encoding/ascii/decode.mbtcarried the same scalar ASCII decode loop twice:once as the private
decode_scalar(gated#cfg(not(target="js"))) and onceopen-coded inside the JS
pub fn decode(#cfg(target="js")). The two bodieswere byte-identical — verified by direct comparison of the pre-edit file: the
12 loop lines inside the JS
decodeequaldecode_scalar's body, including the(_, _ as bytes) => raise Malformed(bytes)arm and the sharedfinish_stringtail.
Before: on JS the ASCII acceptance rule and the
Malformedpayloadconstruction existed in a second, hand-maintained copy, separated from
decode_scalarby ~60 lines of v128 code.After:
decode_scalarloses the cfg and keeps its#inline(it names no@v128API, unlikedecode_v128), and the JSdecodebody becomesdecode_scalar(bytes). Net −12 duplicated lines, −1#cfg; the JS public doccomment stays on the public function.
Behavior is unchanged:
Malformedpayload is still the remainingBytesViewstarting atthe first non-ASCII byte, still a view (not a copy), and its
Debugrendering(
Malformed(<BytesView: [0xff]>)) is unchanged.decode, its 64-byte crossover todecode_v128,decode_v128's error slicing andsuppress_unused_v128_import_on_jsareuntouched.
pkg.generated.mbtihas no diff, and no test snapshotchanged.
This follows the doctrine already used by the sibling encodings:
encoding/hex/decode.mbt,encoding/base64/decode.mbtandencoding/utf16/decode.mbteach keep a singledecode_scalarand have theirnon-vector
decodedelegate to it (encoding/utf16/decode.mbt:213-219is thesame JS
decode→decode_scalardelegation).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.mbtichanges.moon fmt→ exit 0, file unchanged.Changed paths:
encoding/ascii/decode.mbtonly (1 insertion, 13 deletions).CI at the single post-publication snapshot (
gh pr checks 4235, takenimmediately after opening):
version-check,misc-check,stable-check(ubuntu/windows/macos) and
stable-native-opt-test(ubuntu/windows/macos) arepending;
nightly-checkis skipping;Devin ReviewandGitGuardian Security Checkspass. Pending is recorded as pending — no CI waitor polling was performed.