Add RandomGenerable and the opt-in @RandomGenerable derivation macro (Derive trait) - #14
Merged
Merged
Conversation
…acro - RandomGenerable protocol with default generators for standard types (always available, no trait required) - New Derive package trait (off by default): enables the @RandomGenerable extension macro for structs and enums, plus @gen per-property overrides; swift-syntax is only built by consumers who enable the trait - swift-tools-version 6.0 -> 6.1 (required for package traits) - Macro expansion tests via MacroTesting in a dedicated test target; runtime tests for derived generators; both trait configurations in CI
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.
Summary
Adds generator derivation for user-defined types, gated behind a new opt-in
Derivepackage trait so the swift-syntax build cost is only paid by consumers who want the macro.RandomGenerableprotocol (always available, no trait needed): types expose a canonicalstatic var generator. Standard types ship pre-conformed with simple, documented defaults — fixed-width integers (full range),Double/Float(0...1),Bool,String(8 alphanumerics),Character(ASCII letter),Optional(nilhalf the time),Array(0–10 elements).@RandomGenerablemacro (requires theDerivetrait): derives a conformance for structs (through the memberwise initializer) and enums (uniform case selection, associated values included).@Gen(...)overrides the generator for a single stored property. Derived generators are ordinary generators — combinators and seeded RNGs apply.Consumers opt in from their manifest (Swift 6.1+), or in Xcode 26.4+ via package-trait settings:
Implementation notes
swift-tools-version6.0 → 6.1 (required for traits). Older toolchains keep resolving 2.1.0; SwiftPM skips manifests it cannot read.condition: .when(traits: ["Derive"])edges, so nothing macro-related enters a trait-off consumer's build graph.@Genon multi-bindings or non-properties, case-less enums.SwiftRandomKitMacrosTeststarget; runtime behavior (determinism,@Genranges, enum coverage, nesting, combinators) is covered in the main test target behind#if Derive.--disable-experimental-prebuilts: MacroTesting links swift-syntax as a library, which is incompatible with SwiftPM's prebuilt swift-syntax binaries.Test plan
swift test(trait off): 187 tests, 38 suites — passswift test --traits Derive --disable-experimental-prebuilts: 208 tests, 40 suites — passswift test -c release: passmacos-15and the prebuilts flag on SwiftPM 6.1Release intent: 2.2.0 (additive; changelog entry is staged as Unreleased — date/tag on release).