refactor(swiflowui): funnel Double→Int crossings through one WasmSafeInt gate#266
Merged
Conversation
…Int gate cssPixelInt and formatControlNumber independently guarded the same wasm32 32-bit-Int trap class with their own hand-rolled bounds. Both now funnel through WasmSafeInt.exact/pixelClamp, so a new call site can't reintroduce the trap with a slightly-wrong cutoff. The gate's range check (value >= Int32.min && value <= Int32.max) also rejects NaN/±∞ for free, so the Int(_:) behind it is unconditionally trap-free. Behavior refinement: formatControlNumber now integer-formats exactly Int32.min (-2147483648) — representable and trap-free — where the old magnitude<2^31 predicate fell it to the Double rendering. New WasmSafeIntTests pin both ends of the range plus the non-finite and clamp cases. Whole-package swift test: 1922 green. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
📦 Bundle size
✅ Within budget (≤5% growth allowed). Baseline: Swift 6.3, WASM SDK 6.3-RELEASE, measured 2026-06-18. |
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.
Follow-up from the post-#251 swift-innovator review: collapse the two divergent wasm32-Int-trap guards into one home so the class can't recur via a new call site.
WasmSafeIntenum withexact(_:) -> Int?(nil outside signed-32-bit range, which also rejects NaN/±∞) andpixelClamp(_:) -> Int(non-negative floor, 32-bit ceiling).cssPixelIntandformatControlNumberkeep their names/signatures (call sites and existing tests untouched) but now funnel throughWasmSafeInt— a new Double→Int crossing has one obvious, tested helper to reach for instead of a hand-rolledInt(min(max(...))).formatControlNumbernow integer-formats exactlyInt32.min(representable, trap-free) where the oldmagnitude < 2^31predicate fell it to theDoublerendering.WasmSafeIntTestspin both range ends, the just-past-either-end nils, NaN/∞, truncation, and the pixel clamp.Note: the SwiflowDOM
Int(exactly:)sites (DispatcherBridge, HMRBridge) are already correct and self-documented; this scopes to the two SwiflowUI helpers the review named (SwiflowDOM can't import SwiflowUI anyway).Whole-package
swift test: 1922 green.🤖 Generated with Claude Code