Skip to content

Conversation

@aitoroses
Copy link
Owner

Summary

This PR introduces a significant refactoring of the workflow macro in floxide-macros and related components. The primary goals of these changes are to improve code clarity, enhance type safety, and streamline the handling of edge definitions, particularly for composite arms.

Key improvements include:

  • Refactored Workflow Macro: The workflow macro has been simplified by:
    • Consolidating imports and identifier generation.
    • Streamlining the handling of direct and composite edges.
    • Improving pattern matching logic for composite arms, including support for guards and wildcard bindings.
  • Enhanced Type Safety: Compile-time trait-based assertions have been introduced to ensure type compatibility between connected nodes. This provides clearer error messages that include the names of the involved nodes when a type mismatch occurs.
  • New floxide-macros-support Crate: A new crate, floxide-macros-support, has been created to house shared data structures and parsing logic for the macros, promoting better code organization and reusability.
  • Improved Test Coverage:
    • New tests have been added to specifically verify the compile-time type mismatch errors.
    • Tests for composite arm parsing have been added to ensure various syntaxes (unit, binding, wildcard, with/without guards) are handled correctly.
  • Updated Examples and Documentation: Documentation examples in retry.rs and lib.rs have been updated to reflect the latest API changes and best practices, including the use of SharedState. The branching example now returns meaningful output.

Changes by Crate

floxide-macros

  • workflow.rs:
    • Major refactoring of the macro parsing and code generation logic.
    • Moved WorkflowDef, EdgeKind, and CompositeArm to floxide-macros-support.
    • Simplified direct edge handling.
    • Enhanced composite arm pattern matching with support for unit variants, bindings, wildcards, and guards.
    • Added compile-time type assertions for direct edges to catch type mismatches between connected nodes.
  • Cargo.toml:
    • Added floxide-macros-support as a dependency.
    • Added trybuild as a dev-dependency for compile-fail tests.
  • Tests:
    • Added tests/compile_fail_tests.rs with type_mismatch.rs UI test.
    • Added tests/composite_arms.rs to test parsing of various composite arm syntaxes.
    • Updated tests/workflow.rs to reflect new syntax and remove unnecessary bindings in composite arms.

floxide-macros-support (New Crate)

  • Contains the definitions for WorkflowDef, EdgeKind, CompositeArm, and the associated parsing logic, extracted from floxide-macros/src/workflow.rs.
  • Improved parsing logic for clarity and maintainability.

examples/branching_example.rs

  • Updated node output types to String to provide more meaningful return values.
  • Adjusted assertions in the example run to match the new output.
  • Updated composite arm syntax to use wildcards (_) where bindings are not needed.

src/lib.rs

  • Updated the main library example to use SharedState for the context and reflect changes in node output types.

Detailed Commit History

  • Refactor workflow macro to streamline edge handling:
    • Simplified direct edge handling with if-let.
    • Removed unnecessary else branches in pattern matching.
    • Maintained type assertion generation.
  • Refactor workflow macro and improve test cases:
    • Consolidated imports and streamlined identifier generation.
    • Updated test file formatting.
    • Enhanced parsing logic in floxide-macros-support.
  • Update documentation examples in retry and lib modules:
    • Ignored compilation errors in retry.rs doc example.
    • Updated lib.rs example with SharedState and Node.
  • Enhance type assertion in workflow macro and add compile-time tests:
    • Improved type assertions to include node names in error messages.
    • Added type_mismatch.rs compile-fail test.
  • Refactor workflow macro and enhance pattern matching:
    • Consolidated composite arm handling and improved pattern matching.
    • Corrected BatchAction::Small parameter handling.
  • Update floxide-macros dependencies and refine workflow macro:
    • Added floxide-macros-support dependency.
    • Refined pattern matching in branch actions.
  • Update dependencies and enhance floxide-macros functionality:
    • Added various new dependencies in Cargo.lock.
    • Added trybuild dev-dependency.
    • Included type assertions for direct edges.
    • Fixed wildcard assertion in composite_arms.rs tests.
  • Add floxide-macros-support crate and integrate with floxide-macros:
    • Created floxide-macros-support crate.
    • Integrated it into floxide-macros.
    • Added composite arm tests.
    • Modified example workflow output.

This refactoring aims to make the workflow definition more robust, easier to understand, and less error-prone.

aitoroses added 8 commits May 5, 2025 20:08
- Introduced a new crate `floxide-macros-support` for shared macro functionality.
- Updated `Cargo.toml` and `Cargo.lock` to include `floxide-macros-support` as a dependency.
- Refactored `floxide-macros` to utilize types from `floxide-macros-support`.
- Added tests for composite arms in `floxide-macros` to ensure correct parsing and functionality.
- Modified example workflow to return meaningful output based on input conditions.
- Added new dependencies including `trybuild`, `glob`, `serde_spanned`, `target-triple`, `termcolor`, `toml`, `toml_datetime`, `toml_edit`, `toml_write`, and `winnow` in `Cargo.lock`.
- Updated `Cargo.toml` for `floxide-macros` to include `trybuild` as a development dependency.
- Enhanced the `workflow` macro in `floxide-macros` to include type assertions for direct edges, improving type safety.
- Fixed tests in `composite_arms.rs` to correctly assert wildcard behavior in edge definitions.
- Minor refactor in `floxide-macros-support` to clarify wildcard handling in variant bindings.
- Added `floxide-macros-support` as a dependency in `Cargo.toml` for floxide-macros.
- Refined the `workflow` macro to improve pattern matching by removing unnecessary variable bindings in the branch actions.
- Ensured consistency in the handling of `BatchAction::Small` by removing the unused variable in the macro definition.
- Simplified the `workflow` macro in `floxide-macros` by consolidating the handling of composite arms and improving the pattern matching logic.
- Updated the handling of `BatchAction::Small` to correctly accept a parameter, ensuring consistency in action definitions.
- Made adjustments in `floxide-macros-support` to clarify the parsing of composite edges and added debug logs for better traceability of parsed arms.
- Improved the `workflow` macro in `floxide-macros` to generate compile-time trait-based assertions for type compatibility between connected nodes, enhancing error messages with node names.
- Introduced a new test file `type_mismatch.rs` to verify that type mismatches produce appropriate compile-time errors, ensuring better type safety in workflows.
- Updated existing tests for consistency and clarity in edge definitions.
- Changed the Rust code block in the `retry.rs` documentation to ignore compilation errors for better clarity.
- Updated the example in `lib.rs` to include `SharedState` and `Node`, reflecting changes in the context struct and output type for improved functionality and consistency in the workflow examples.
- Simplified the `workflow` macro in `floxide-macros` by consolidating imports and streamlining identifier generation for traits and functions.
- Updated test files to ensure proper formatting and consistency, including adding newlines at the end of files for better compatibility with tools.
- Enhanced the parsing logic in `floxide-macros-support` to improve clarity and maintainability of edge definitions.
- Simplified the handling of direct edges in the `workflow` macro by replacing the match statement with an if-let construct for improved readability.
- Removed unnecessary else branches to enhance clarity in the pattern matching logic.
- Maintained the generation of compile-time trait-based assertions for type compatibility between connected nodes, ensuring consistent error messaging.
@aitoroses aitoroses merged commit f3f04ed into main May 6, 2025
4 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.

2 participants