Merge pull request #164 from input-output-hk/jj/refactor-genForCTree
Move the generators for each term in `genForCTree` into top-level functions
Move the generators for each term in `genForCTree` into top-level functions
The golden tests depended on deterministic PRNG output from a fixed seed, but stack and cabal resolve different versions of the random library producing different sequences. Remove the golden tests and the Utils module, restoring tryResolveHuddle to GeneratorSpec.
Extract annotation logic into annotateTerm, which derives labels from CTree nodes. Use specific type names for postludes (e.g. "uint" instead of "postlude"), make control/choice/occur transparent, and remove the internal genBetween annotation. Add golden tests for refs and custom generators with decision points.
Extract tryResolveHuddle into shared Utils module and add 7 golden tests that verify annotation paths produced by zapAntiGenResult.
Replace the old generate-then-deduplicate approach with a stateful map builder that generates unique keys directly. This handles occurrence indicators (optional, zero-or-more, one-or-more, bounded) inline during map construction, retrying key generation on collisions instead of silently dropping duplicate entries. Required nodes are sorted first to prioritize generating mandatory entries.
Extract each case of genForCTree into its own named function (genMap, genArray, genKV, genRange, genControl, genEnum, genTag) and convert the top-level dispatch to use LambdaCase. Add annotation wrappers for each case to aid debugging. Bump antigen to 0.4 for withAnnotation support. No behavioral changes - all logic is preserved as-is.
Extract each case of genForCTree into its own named function (genMap, genArray, genKV, genRange, genControl, genEnum, genTag) and convert the top-level dispatch to use LambdaCase. Add annotation wrappers for each case to aid debugging. Bump antigen to 0.4 for withAnnotation support. No behavioral changes - all logic is preserved as-is.
genMap's cont used scale (\s -> s - 1) which drove the QuickCheck size parameter negative when generating multiple required map entries. At negative sizes, arbitrary for Word16 (used by genHalf) throws arithmetic overflow. Clamp size to 0 minimum.
Add back withAnnotation for key/value and per-KV-pair index annotations in genMap's tryGenKV/genNodes, matching the pattern used in genArray.
Add back withAnnotation for key/value and per-KV-pair index annotations in genMap's tryGenKV/genNodes, matching the pattern used in genArray.
Re-add the special case for tags 2/3 (biguint/bignint) that disables indefinite-length byte string encoding, lost during rebase. Without this, cborg fails to decode generated bignums with "expected integer".
Re-add the special case for tags 2/3 (biguint/bignint) that disables indefinite-length byte string encoding, lost during rebase. Without this, cborg fails to decode generated bignums with "expected integer".
- Fix Word64 underflow in OIBounded bounds decrementing by using saturating subtraction (clampedPred) instead of regular subtraction - Fix KV case to continue processing remaining nodes instead of returning early - Use max 0 sz in frequency to handle negative sizes - Add proper error message for map generation failure Co-Authored-By: Claude Opus 4.5 <[email protected]>
- Fix Word64 underflow in OIBounded bounds decrementing by using saturating subtraction (clampedPred) instead of regular subtraction - Fix KV case to continue processing remaining nodes instead of returning early - Use max 0 sz in frequency to handle negative sizes - Add proper error message for map generation failure