Skip to main content

airl_patch/
ops.rs

1//! Patch operation types and patch bundle structure.
2
3use airl_ir::effects::Effect;
4use airl_ir::ids::{FuncId, NodeId};
5use airl_ir::module::{FuncDef, Import};
6use airl_ir::node::Node;
7use serde::{Deserialize, Serialize};
8
9/// A single patch operation.
10#[derive(Clone, Debug, Serialize, Deserialize)]
11#[serde(tag = "kind")]
12pub enum PatchOp {
13    /// Replace a node (identified by NodeId) with a new node.
14    /// The replacement's root may have a different NodeId.
15    ReplaceNode {
16        /// The ID of the node to replace.
17        target: NodeId,
18        /// The new subtree to splice in.
19        replacement: Node,
20    },
21
22    /// Add a new function to the module.
23    AddFunction {
24        /// The new function definition.
25        func: FuncDef,
26    },
27
28    /// Remove a function by its FuncId.
29    RemoveFunction {
30        /// The ID of the function to remove.
31        func_id: FuncId,
32    },
33
34    /// Add an import to the module.
35    AddImport {
36        /// The import to add.
37        import: Import,
38    },
39
40    /// Remove an import from the module.
41    RemoveImport {
42        /// The import to remove.
43        import: Import,
44    },
45
46    /// Rename a symbol (variable, function name, call target) throughout the module
47    /// or within a specific function scope.
48    RenameSymbol {
49        /// The existing name to replace.
50        old_name: String,
51        /// The new name.
52        new_name: String,
53        /// If Some, only rename within this function. If None, rename globally.
54        scope: Option<FuncId>,
55    },
56
57    /// Add an effect to a function's declared effect list.
58    AddEffect {
59        /// The function to modify.
60        func_id: FuncId,
61        /// The effect to add.
62        effect: Effect,
63    },
64
65    /// Remove an effect from a function's declared effect list.
66    RemoveEffect {
67        /// The function to modify.
68        func_id: FuncId,
69        /// The effect to remove.
70        effect: Effect,
71    },
72}
73
74/// A patch is an ordered list of operations with metadata.
75#[derive(Clone, Debug, Serialize, Deserialize)]
76pub struct Patch {
77    /// Unique patch identifier.
78    pub id: String,
79    /// The VersionId (hex) of the module state this patch applies to.
80    pub parent_version: String,
81    /// Ordered list of operations to apply.
82    pub operations: Vec<PatchOp>,
83    /// Human/agent-readable rationale for the change.
84    pub rationale: String,
85    /// Author identifier (agent ID or human).
86    pub author: String,
87}