Skip to content

Factor the suite's generators into a monad-polymorphic Generable class - #24

Merged
joscoh merged 3 commits into
mainfrom
polymorphic-generators
Sep 14, 2026
Merged

joscoh merged 3 commits into
mainfrom
polymorphic-generators

Conversation

@mwhicks1

@mwhicks1 mwhicks1 commented Sep 2, 2026

Copy link
Copy Markdown
Collaborator

The purpose of this change is to prepare for use of different Basalt.Gen backends (including one backed by coverage-guided fuzzing), not just Plausible.Gen.

Description of changes:

Each shape the suite generates had a generator written specifically at Plausible.Gen (a genXWith per wrapper), even though the underlying genX combinators are already polymorphic in Basalt's Gen. Factor each into one interpretation-polymorphic genXG, add a Generable class naming the canonical generator per type, and derive every Arbitrary instance from it — calling genXG at Plausible.Gen with the existing Gen.sized/retryGen wrapping, so the draws are byte-for-byte unchanged and lake test behaves identically.

Retry is now explicitly a per-interpretation harness concern rather than part of the generator: genLExpr's retryCont (and the inner retryGen of the procedure/program generators) default to id in the canonical generator; the Plausible Arbitrary passes retryGen/retryGenArg on top.

Covers all twelve wrapper types (expressions, commands, functions, statements, procedures, programs, ADT / independent blocks). Doc references to the removed genXWith helpers are updated. No new dependency beyond Basalt's Gen class and no behavior change to the Plausible suite; the registry's generators can now run under any Gen interpretation.

Confirmed draw-for-draw identical to the original: because Plausible.Gen is a pure StateT (ULift StdGen) (ReaderT (ULift Nat) (Except GenError)), each Arbitrary can be run with an explicit mkStdGen seed and no global RNG. Dumping all twelve instances across a grid of seeds and sizes before and after the refactor produced byte-identical output (matching sha256).


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Each shape the suite generates had a generator written specifically at `Plausible.Gen` (a `genXWith`
per wrapper), even though the underlying `genX` combinators are already polymorphic in Basalt's `Gen`.
Factor each into one interpretation-polymorphic `genXG`, add a `Generable` class naming the canonical
generator per type, and derive every `Arbitrary` instance from it — calling `genXG` at `Plausible.Gen`
with the existing `Gen.sized`/`retryGen` wrapping, so the draws are byte-for-byte unchanged and
`lake test` behaves identically.

Retry is now explicitly a per-interpretation harness concern rather than part of the generator:
`genLExpr`'s `retryCont` (and the inner `retryGen` of the procedure/program generators) default to
`id` in the canonical generator; the Plausible `Arbitrary` passes `retryGen`/`retryGenArg` on top.

Covers all twelve wrapper types (expressions, commands, functions, statements, procedures, programs,
ADT / independent blocks). Doc references to the removed `genXWith` helpers are updated. No new
dependency beyond Basalt's `Gen` class and no behavior change to the Plausible suite; the registry's
generators can now run under any `Gen` interpretation.

Confirmed draw-for-draw identical to the original: because `Plausible.Gen` is a pure
`StateT (ULift StdGen) (ReaderT (ULift Nat) (Except GenError))`, each `Arbitrary` can be run with an
explicit `mkStdGen seed` and no global RNG. Dumping all twelve instances across a grid of seeds and
sizes before and after the refactor produced byte-identical output (matching sha256).

@ngernest ngernest left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks! I just left two small comments related to namespace management.

Comment thread StrataGenerators/TestScaffold.lean Outdated
Comment thread StrataGenerators/TestScaffold.lean Outdated
@joscoh
joscoh merged commit da3b287 into main Sep 14, 2026
6 checks passed
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.

3 participants