1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! ASTRegApply trait - Apply mutations to ASTRegistry
//!
//! This trait extends Mutation with registry-based execution capability.
//! Defined in ryo-executor to avoid circular dependency between
//! ryo-mutations and ryo-analysis.
//!
//! # Design
//!
//! ```text
//! ryo-mutations ryo-analysis ryo-executor
//! ┌──────────────┐ ┌──────────────┐ ┌──────────────┐
//! │ Mutation │ │ ASTRegistry │ │ ASTRegApply │
//! │ (base trait) │ │ SymbolReg │ │ (ext trait) │
//! └──────────────┘ └──────────────┘ └──────────────┘
//! ↑ ↑ │
//! └─────────────────────┴──────────────────────┘
//! ASTRegApply: Mutation
//! ```
//!
//! # Quality Policy for V2 Implementations
//!
//! When implementing `ASTRegApply` for mutations:
//!
//! ## DO:
//! - Design the implementation to work naturally with ASTRegistry/SymbolRegistry
//! - Add comprehensive snapshot tests that verify exact output
//! - Consider if the ASTMutationContext API needs extension for new capabilities
//!
//! ## DON'T:
//! - Create hacky workarounds just to make tests pass
//! - Use temporary allocations or intermediate representations (defeats V2 purpose)
//! - Copy V1 patterns that don't fit the registry-based model
//!
//! ## When V2 Cannot Handle a Mutation Cleanly:
//!
//! If a mutation cannot be implemented cleanly with the current V2 API:
//!
//! 1. **Do NOT** hack the implementation or tests to force it to work
//! 2. **Do** evaluate if ASTMutationContext needs new methods
//! 3. **Do** consider if ASTRegistry/SymbolRegistry need enhancements
//! 4. **Do** document the design gap and propose a proper solution
//!
//! The goal is a clean, maintainable architecture - not 100% feature coverage
//! through workarounds.
//!
//! # Usage
//!
//! ```ignore
//! use ryo_executor::engine::ASTRegApply;
//!
//! impl ASTRegApply for AddFieldMutation {
//! fn apply_to_registry(&self, ctx: &mut ASTMutationContext) -> MutationResult {
//! // Get target struct from registry
//! let id = ctx.lookup(&self.target_path)?;
//! let ast = ctx.get_ast_mut(id)?;
//!
//! // Modify AST
//! if let PureItem::Struct(s) = ast {
//! s.fields.push(new_field);
//! }
//!
//! ctx.emit_modified(id, ModificationType::FieldAdded(name));
//! MutationResult { ... }
//! }
//! }
//! ```
use ;
use ASTMutationContext;
/// Trait for mutations that can be applied to ASTRegistry
///
/// Extends the base `Mutation` trait with registry-based execution.
/// This is the primary execution path for the new AST-centric architecture.
///
/// # Implementing
///
/// Mutations that want to support registry-based execution should:
/// 1. Implement this trait
/// 2. Use `ctx.lookup()` to find target symbols
/// 3. Use `ctx.get_ast_mut()` to modify AST
/// 4. Use `ctx.emit_*()` to record changes
///
/// # Fallback
///
/// If a mutation doesn't implement this trait, ASTMutationEngine
/// will return no changes. The legacy `apply(&mut PureFile)` path
/// remains available for backward compatibility.