Skip to content

refactor(macros): simplify internal layout and harden transition returns#20

Closed
eboody wants to merge 2 commits into
mainfrom
refactor/macro-simplification-tmp
Closed

refactor(macros): simplify internal layout and harden transition returns#20
eboody wants to merge 2 commits into
mainfrom
refactor/macro-simplification-tmp

Conversation

@eboody

@eboody eboody commented Apr 13, 2026

Copy link
Copy Markdown
Owner

Summary

  • reorganize statum-macros into clearer internal subsystems
  • move source-observation helpers under statum-macros/src/source/
  • split state, machine emission, and transition resolution into focused modules
  • add shared semantic contracts and an internal architecture note
  • restore the canonical primary-branch invariant for transition return types
  • add regression coverage for invalid primary-branch transition wrappers

Details

This keeps the public macro surface the same while making statum-macros easier to navigate as three internal layers:

  1. source observation
  2. semantic resolution
  3. emission and diagnostics

The structural changes in this PR are:

  • statum-macros/src/source/ now owns file analysis, module-path lookup, and source-backed candidate queries
  • statum-macros/src/state/ now owns #[state] parsing, validation, registry storage, and emission
  • statum-macros/src/machine/emission/ is split into support scaffolding, builders, and presentation/introspection output
  • statum-macros/src/transition/resolve/ is split into alias expansion, shape parsing, and strict-vs-relaxed strategy code
  • statum-macros/src/validators/ now has explicit contract and planning modules
  • statum-macros/src/contracts.rs provides shared internal handoff types
  • statum-macros/ARCHITECTURE.md documents the intended subsystem boundaries

This PR also fixes a transition-validation regression: wrapper return shapes now have to resolve to the target machine in the primary branch, instead of passing just because a later branch mentions the machine. That restores the documented canonical contract and closes the matching strict #[introspect(return = ...)] hole.

Validation

  • cargo fmt --all --check
  • cargo test --workspace --all-features
  • cargo clippy --workspace --all-targets --all-features -- -D warnings

Notes

  • The public API stays the same.
  • Strict introspection stays the authoritative fail-closed path.
  • Relaxed behavior stays source-backed.
  • Added regression coverage for invalid Result<Error, Machine<Next>>-style primary-branch shapes in both strict and non-strict modes.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR restructures statum-macros into clearer internal subsystems (source observation → semantic resolution → emission/diagnostics) while aiming to keep public macro behavior unchanged, and adds internal contract types + an architecture note to codify the intended boundaries.

Changes:

  • Introduces a source/ facade (analysis, callsite/module-path lookup, source-backed queries) and migrates callsite/query/pathing usage to it.
  • Splits major subsystems into smaller modules (notably state/, transition/resolve/, validators/, and machine/emission/) and replaces some ad-hoc plumbing with shared contracts.rs.
  • Adds targeted tests for transition return-shape parsing/collection and documents internal boundaries in ARCHITECTURE.md.

Reviewed changes

Copilot reviewed 35 out of 37 changed files in this pull request and generated no comments.

Show a summary per file
File Description
statum-macros/src/validators/resolution.rs Migrates source-backed candidate lookup helpers to the new source facade and updates formatting helpers.
statum-macros/src/validators/plan.rs New validator planning pass to collect checks/report checks and async-ness.
statum-macros/src/validators/contract.rs New internal “contract” helpers for validator planning/emission (variant specs, path helpers, type qualification).
statum-macros/src/validators.rs Refactors #[validators] orchestration to use contract/planning modules and ValidatorContract.
statum-macros/src/transition/resolve/mod.rs New split resolve module that re-exports alias/shape/strategy utilities + hosts resolve tests.
statum-macros/src/transition/resolve/alias.rs New alias-expansion logic using source queries for source-backed type aliases.
statum-macros/src/transition/resolve/shape.rs New return-shape parsing helpers (target matching, wrapper detection, generic extraction).
statum-macros/src/transition/resolve/strategy.rs New strict vs relaxed resolution strategies + collectors for all targets in wrapper shapes.
statum-macros/src/transition/resolve.rs Deleted monolithic resolve implementation; logic moved under transition/resolve/.
statum-macros/src/transition/parse.rs Updates transition return-shape resolution flow to use new resolve exports and only the multi-target path.
statum-macros/src/transition/diagnostics.rs Migrates candidate formatting and source helpers to source facade.
statum-macros/src/transition/contract.rs New contract builder that produces TransitionContract from parsed transition info.
statum-macros/src/transition.rs Refactors transition validation to build/use a transition contract (next-states list).
statum-macros/src/state/mod.rs New #[state] subsystem module (parse/validate/store/emit) replacing the previous monolith.
statum-macros/src/state/validation.rs New extracted validation logic for legal #[state] enum shapes.
statum-macros/src/state/registry.rs New extracted state registry storage/lookup + currentness checks.
statum-macros/src/state/emission.rs New extracted state marker/data surface emission.
statum-macros/src/state.rs Deleted monolithic state implementation; functionality moved under state/.
statum-macros/src/source/mod.rs New source-observation facade module re-exporting callsite/pathing/query/syntax helpers.
statum-macros/src/source/analysis.rs New file analysis implementation for discovering items + line numbers with macro-body skipping.
statum-macros/src/source/cache.rs Migrates line/module caching under source/ namespace.
statum-macros/src/source/callsite.rs Migrates callsite helpers under source/ and removes a test-only helper.
statum-macros/src/source/module_path.rs Migrates module-path resolution to source/ and updates internal imports/tests.
statum-macros/src/source/parser.rs Migrates module parsing helpers to source/ and updates imports.
statum-macros/src/source/pathing.rs New pathing utilities (normalization, module-path ↔ file mapping).
statum-macros/src/source/query.rs Migrates query utilities to source/ and updates analysis type usage.
statum-macros/src/source/syntax.rs Migrates syntax helpers to source/ and updates callsite import path.
statum-macros/src/machine/mod.rs Updates exports/docs and exposes ParsedMachineInfo for internal contracts.
statum-macros/src/machine/metadata.rs Migrates source-backed helpers to source, replaces removed callsite helper usage, adds clone derives for parsed types.
statum-macros/src/machine/emission/mod.rs New machine emission module split (support/builders/presentation) orchestrator.
statum-macros/src/machine/emission/support.rs New extracted support utilities for generics, transition traits, aliases, struct definition emission.
statum-macros/src/machine/emission/builders.rs New extracted builder emission logic for state-specific builders and RA shim.
statum-macros/src/machine/emission/presentation.rs New extracted presentation/introspection surface emission.
statum-macros/src/machine/emission.rs Deleted monolithic machine emission; logic moved under machine/emission/.
statum-macros/src/lib.rs Introduces contracts and source modules and updates root wiring/imports accordingly.
statum-macros/src/contracts.rs Adds shared internal contract types used across subsystems (validators/transitions).
statum-macros/ARCHITECTURE.md Documents internal subsystem boundaries and dependency direction expectations.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3ecae65d50

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +80 to +84
let contract = match build_transition_contract(func, &tr_impl.target_type) {
Ok(contract) => contract,
Err(err) => return Some(err),
};
for return_state in return_states {
for return_state in contract.next_states {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Restore primary branch validation for transition returns

validate_transition_functions now validates only contract.next_states, which are collected from any matching branch in wrapper return types, but it no longer enforces that the primary return shape itself resolves to the target machine. This allows signatures like Result<Error, Machine<Done>> (or analogous Branch forms) to pass even though the documented canonical contract is Result<Machine<Next>, E>, so strict/introspection metadata can accept and register transitions where the primary branch is not a machine transition.

Useful? React with 👍 / 👎.

@eboody eboody changed the title refactor(macros): simplify internal subsystem layout refactor(macros): simplify internal layout and harden transition returns Apr 14, 2026
@eboody

eboody commented Apr 14, 2026

Copy link
Copy Markdown
Owner Author

Closing as obsolete: the simplification and transition-return work already landed directly on main in follow-up commits, so this branch is stale/conflicting and has no unique code left to merge.

@eboody eboody closed this Apr 14, 2026
@eboody eboody deleted the refactor/macro-simplification-tmp branch April 14, 2026 02:00
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