Repository navigation
perf(ts): return a Result of an Option of a number in a slot - #496
Merged
Merged
Conversation
Quest-Claim: bdef938c748b0c1f
An `Option` of a number is one JS value, that or `undefined`, so a local holds it as one part rather than a flag and the number. A `Result` whose `Ok` is numbers alone, an `Option` of one among them, such as `Decoder::varint_opt`'s `Result<Option<u64>, E>`, now hands back through the slot as `Result<u64, E>` does, with no `rt.Ok` per call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
kixelated
marked this pull request as ready for review
November 3, 2026 07:00
|
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 42 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. CodeRabbit Verify
|
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.
Problem
A crate function returning
Result<Option<u64>, E>, such asDecoder::varint_opt, made anrt.Okper call. #385's result slot refused anyOkpayload containing an enum, and the scalar layer held anOptionof a number as a flag plus the number, even though its JS value,T | undefined, is never an object.Approach
Shape::Leafnow covers anOptionof a number (an integer of any width, a float,bool,char, or a shared reference to one). That is one JS value, so a held local keeps it as one part, andnumbercounts it as one.ResultwhoseOkis numbers alone, with suchOptions among them, qualifies for the slot. Examples:Result<Option<u64>, E>,Result<(Option<u8>, u64), E>,Result<(u64, Option<i128>), E>, andResult<(Option<u16>, &[u8]), E>.Option, the callee writes it toout$Option_<T>.pand returns the error orundefined, asout$boolalready does. When the first part is a plain number, the existing return path is unchanged.varintOptand its caller incodec,made$Option_u8andunsetincellsandshapes, and anok_orinsplitswhoseOption<u8>error is now one part, sooption_okOrand itsrt.Resultdrop out.expected/bench.tsand everything it calls are unchanged (no bench workload callsvarint_opt). Nojust ts benchworkload runs different code, so none can be slower.returns::options) coverOptionofu8throughu128,usize,i8throughi128with their MIN/MAX,f32(including -0) andf64, both including NaN, plusboolandchar. Each hasNone,Some(0), an error, and arbitrary bytes. They also cover: a result returned as is and through?, anOptionfirst or last in a tuple and beside a slice, a drop that rewrites the slot, two results held at once, results kept in aVecand through afnpointer, and a loop.Impact
Resultof numbers in which anOptionof a number counts as one, returns its error orundefinedand leaves theOkin alib.tsslot such asout$Option_u64.ts/MIGRATE.md's existing entry is updated. Roots are unchanged.Alternatives
Optionitself, withnullmeaning an error (the error goes in the slot), to skip the slot write on success, as a plain number's first part does. Dropped: it adds a second sentinel to every slot path, and no bench workload callsvarint_optto measure it against (moq-net calls it 8 times, against 249 forvarint).Option<u64>as a flag plus its number inside the slot. Dropped: that writes two fields, andtake_apartandbuild_plainwould need enum support.Follow-ups
None. An
Optionof a tuple or slice in the slot (its JS value is an object) has no consumer in moq-net.Review
gpt-6.1-solat medium effort (quest review), round 1 on headd60a6e86, 0 findings. Since then the only changes are conflict-free merges oforigin/main(Folds from the back, and a crate's own folds #463, feat(ts): translate a pointer to a struct whose last field is a trait object #493, feat(ts): accept an empty iterator of mutable references as a place source #497), giving headadab4b0a.just cipasses onadab4b0a, andjust ts moqtranslates and type-checks moq-net.🤖 Generated with Claude Code