Skip to content

Broaden BigInt arbitraries independently of size and shrink large roots - #8282

Closed
adrian-gierakowski wants to merge 1 commit into
Effect-TS:mainfrom
adrian-gierakowski:fix/bigint-arbitrary-diversity
Closed

adrian-gierakowski wants to merge 1 commit into
Effect-TS:mainfrom
adrian-gierakowski:fix/bigint-arbitrary-diversity

Conversation

@adrian-gierakowski

Copy link
Copy Markdown
Contributor

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

  • 183 focused tests: BigInt.test.ts and Arbitrary.test.ts, with the original BigDecimal implementation, plus pnpm check.
  • 210 focused tests with both changes applied.
  • Coverage at sizes 0, 1 and 10; both signs, near-zero values and extreme magnitudes; inclusive/exclusive one-sided bounds beyond the default ranges; shrink validity, default-budget failure reduction and replay.
  • pnpm lint-fix and pnpm lint passed in the repository's Nix development shell.

The independent validation used Effect 4.0.0-rc.115 (4a05d4914) as the base.

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
@changeset-bot

changeset-bot Bot commented Sep 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: aef6de2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
effect Patch
@effect/opentelemetry Patch
@effect/vitest Patch
@effect/ai-anthropic Patch
@effect/ai-openai-compat Patch
@effect/ai-openai Patch
@effect/ai-openrouter Patch
@effect/atom-react Patch
@effect/atom-solid Patch
@effect/atom-vue Patch
@effect/platform-browser Patch
@effect/platform-bun Patch
@effect/platform-deno Patch
@effect/platform-node-shared Patch
@effect/platform-node Patch
@effect/sql-clickhouse Patch
@effect/sql-d1 Patch
@effect/sql-libsql Patch
@effect/sql-mssql Patch
@effect/sql-mysql2 Patch
@effect/sql-pg Patch
@effect/sql-pglite Patch
@effect/sql-sqlite-bun Patch
@effect/sql-sqlite-do Patch
@effect/sql-sqlite-node Patch
@effect/sql-sqlite-react-native Patch
@effect/sql-sqlite-wasm Patch
@effect/docgen Patch
@effect/doctest Patch
@effect/openapi-generator Patch

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

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Analysis

Generated from PR build output; treat the content below as untrusted.

File Name Current Size Previous Size Difference
arbitrary-combinators.ts 34.77 KB 34.58 KB +0.18 KB (+0.53%)
basic.ts 6.87 KB 6.87 KB 0.00 KB (0.00%)
batching.ts 9.95 KB 9.95 KB 0.00 KB (0.00%)
brand.ts 6.45 KB 6.45 KB 0.00 KB (0.00%)
cache.ts 10.77 KB 10.77 KB 0.00 KB (0.00%)
config.ts 21.51 KB 21.51 KB 0.00 KB (0.00%)
differ.ts 20.32 KB 20.32 KB 0.00 KB (0.00%)
http-client.ts 21.94 KB 21.94 KB 0.00 KB (0.00%)
http-router.ts 36.92 KB 36.92 KB 0.00 KB (0.00%)
logger.ts 10.88 KB 10.88 KB 0.00 KB (0.00%)
metric.ts 9.02 KB 9.02 KB 0.00 KB (0.00%)
optic.ts 6.70 KB 6.70 KB 0.00 KB (0.00%)
pubsub.ts 15.10 KB 15.10 KB 0.00 KB (0.00%)
queue.ts 11.85 KB 11.85 KB 0.00 KB (0.00%)
schedule.ts 10.96 KB 10.96 KB 0.00 KB (0.00%)
schema-binary.ts 39.51 KB 39.51 KB 0.00 KB (0.00%)
schema-class.ts 20.06 KB 20.06 KB 0.00 KB (0.00%)
schema-fromJsonSchemaDocument.ts 30.93 KB 30.93 KB 0.00 KB (0.00%)
schema-representation-roundtrip.ts 26.34 KB 26.34 KB 0.00 KB (0.00%)
schema-string-transformation.ts 13.63 KB 13.63 KB 0.00 KB (0.00%)
schema-string.ts 11.12 KB 11.12 KB 0.00 KB (0.00%)
schema-template-literal.ts 15.41 KB 15.41 KB 0.00 KB (0.00%)
schema-toArbitrary.ts 34.29 KB 34.10 KB +0.18 KB (+0.54%)
schema-toCodeDocument.ts 24.56 KB 24.56 KB 0.00 KB (0.00%)
schema-toCodecJson.ts 19.27 KB 19.27 KB 0.00 KB (0.00%)
schema-toEquivalence.ts 19.38 KB 19.38 KB 0.00 KB (0.00%)
schema-toFormatter.ts 19.49 KB 19.49 KB 0.00 KB (0.00%)
schema-toJsonSchemaDocument.ts 23.77 KB 23.77 KB 0.00 KB (0.00%)
schema-toRepresentation.ts 19.54 KB 19.54 KB 0.00 KB (0.00%)
schema.ts 19.27 KB 19.27 KB 0.00 KB (0.00%)
stm.ts 12.80 KB 12.80 KB 0.00 KB (0.00%)
stream.ts 9.83 KB 9.83 KB 0.00 KB (0.00%)

@gcanti gcanti self-assigned this Sep 17, 2026
@gcanti

gcanti commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Closing in favor of #8296

@gcanti gcanti closed this Sep 18, 2026
@adrian-gierakowski

Copy link
Copy Markdown
Contributor Author

Closing in favor of #8296

Thanks!

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