Broaden BigInt arbitraries independently of size and shrink large roots - #8282
Closed
adrian-gierakowski wants to merge 1 commit into
Closed
adrian-gierakowski wants to merge 1 commit into
adrian-gierakowski wants to merge 1 commit into
Conversation
Unbounded BigInts previously used only [-size^2, size^2], with the same small width applied to one-sided constraints. Default samples therefore missed unsafe integer conversions, large integer arithmetic and overflow when converting to a floating-point number. Mix small, ordinary and large ranges up to 2048 bits independently of collection size. This exercises near-zero values and both signs without allowing a single enormous uniform interval to crowd out ordinary integers. Center and clip each range against one-sided bounds, and add a boundary range when an explicit limit on the far side of zero lies outside the default magnitudes. Both-bound generation keeps its existing sampling behavior and supports arbitrary-width explicit intervals. Before halving a large initial shrink gap, try smaller power-of-two offsets while preserving the preceding passing-candidate context. This lets the new large roots shrink to ordinary failure boundaries under the default 100-attempt budget instead of stopping hundreds of digits away. Candidates remain between the valid target and original value. Add deterministic small-size coverage, signed one-sided limits (including limits beyond the default magnitudes), exact inclusive/exclusive edges, valid shrink candidates, default-budget failure shrinking at zero and large nonzero targets, and replay. This commit is independent of the preceding BigDecimal fix and has been checked without that change. Validation (repository Nix development shell): - pnpm test --run packages/effect/test/unstable/arbitrary/BigInt.test.ts packages/effect/test/unstable/arbitrary/BigDecimal.test.ts packages/effect/test/unstable/arbitrary/Arbitrary.test.ts (210 tests) - pnpm check - pnpm lint-fix - pnpm lint - With original Schema.ts restored temporarily: BigInt.test.ts and Arbitrary.test.ts (183 tests), plus pnpm check
adrian-gierakowski
requested a deployment
to
fork
September 17, 2026 16:01 — with
GitHub Actions
Waiting
adrian-gierakowski
requested a deployment
to
fork
September 17, 2026 16:01 — with
GitHub Actions
Waiting
🦋 Changeset detectedLatest commit: aef6de2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 30 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
Contributor
|
Closing in favor of #8296 |
Contributor
Author
Thanks! |
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
Unbounded BigInt arbitraries currently use roughly [-size², size²]. At the default size 10, only 201 integers are possible. One-sided constraints inherit a similarly narrow range, so ordinary samples miss unsafe integer conversions and very large integer arithmetic.
Simply widening one uniform interval would mostly generate huge values. Those values also expose a shrinking limitation: repeated halving exhausts the default 100-attempt budget before reaching useful small counterexamples.
Change
Mix small, ordinary and large ranges up to 2048 bits independently of collection size. Respect one-sided bounds and explicitly exercise their boundaries even when they lie outside the default magnitudes. Generation with both bounds supplied retains its existing behavior.
Before halving a large initial shrink gap, try smaller power-of-two offsets while retaining the previous passing candidate. This lets common failures shrink to useful boundaries within the default budget, including with large nonzero bounds.
This PR contains only the BigInt change and does not depend on the separate BigDecimal fix.
Validation
BigInt.test.tsandArbitrary.test.ts, with the original BigDecimal implementation, pluspnpm check.pnpm lint-fixandpnpm lintpassed in the repository's Nix development shell.The independent validation used Effect 4.0.0-rc.115 (
4a05d4914) as the base.