-
Notifications
You must be signed in to change notification settings - Fork 26
Description
Problem Statement
The current Pliron Declarative Syntax Specification presents the following pain points:
- Inconsistent Syntax: Disparate syntax between operations/types/attributes (e.g.
#[def_op]vs#[def_type]), appearing fragmented - Verbose Trait Derivation: Overly cumbersome macros like
#[derive_op_interface_impl(...)] - Scattered Implementation: Field-level attributes mixed with implementation blocks (e.g.
impl_verify_succ!)
Proposed Solution
This proposal addresses the above issues through:
- Adoption of standardized
#[derive(Operation/Type/Attribute)]syntax - Consolidation of all metadata within
#[definition]attributes - Support for direct field-level attribute application
Note: Established macro patterns from popular crates like serde and clap can serve as references to improve consistency.
Current vs Proposed Implementation Comparison
1. Operation Definition
Current Implementation:
#[format_op("`(`$0`)` region($0)")]
#[def_op("test.if_op")]
#[derive_op_interface_impl(OneOpdInterface, ZeroResultInterface, OneRegionInterface)]
struct IfOp {}
impl_verify_succ!(IfOp);Proposed Implementation:
#[derive(Operation)]
#[definition(
name = "test.if_op",
format = "`(`$0`)` region($0)",
interfaces = [OneOpd, ZeroResult, OneRegion],
verifier = "succ"
)]
struct IfOp {}2. Type Definition
Current Implementation:
#[format_type("`type` `{` $flags `}`")]
#[def_type("test.flags_type")]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct FlagsType {
flags: u32,
}
impl_verify_succ!(FlagsType);Proposed Implementation:
#[derive(Type)]
#[definition(
name = "test.flags_type",
format = "`type` `{` $flags `}`",
verifier = "succ"
)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
struct FlagsType {
flags: u32,
}3. Attribute Definition
Current Implementation:
#[format_attribute("`attr` `(` $value `)`")]
#[def_attribute("test.string_attr")]
#[derive(Debug, Clone, PartialEq, Eq)]
struct StringAttr {
value: String,
}
impl_verify_succ!(StringAttr);Proposed Implementation:
#[derive(Attribute)]
#[definition(
name = "test.string_attr",
format = "`attr` `(` $value `)`",
verifier = "succ"
)]
#[derive(Debug, Clone, PartialEq, Eq)]
struct StringAttr {
value: String,
}Key Benefits
- Consistency: Unified
#[definition]pattern across all IR entities - Readability: Clear visibility of field roles within struct definitions
- Maintainability: Centralized management of all metadata
- Extensibility: Simplified addition of new attributes (e.g.
docs = "...")
Implementation Notes
The above examples are illustrative only. The proposed solution may not fully correspond with actual macro definitions in the codebase. This proposal presents preliminary concepts requiring further design refinement for discussion purposes.
Regarding actual refactoring approaches, forward compatibility considerations suggest two options:
- Complete refactoring through incremental sub-Pull Requests
- Transitional implementation via a new pliron-macros module
The specific implementation approach remains open for discussion.