Skip to main content

ryo_executor/engine/impls/
mod_decl.rs

1//! ASTRegApply implementation for module mutations
2//!
3//! Note: AddMod was consolidated into CreateMod.
4
5use ryo_analysis::SymbolKind;
6use ryo_mutations::basic::RemoveModMutation;
7use ryo_mutations::MutationResult;
8
9use crate::engine::{ASTMutationContext, ASTRegApply, MutationEvent};
10
11impl ASTRegApply for RemoveModMutation {
12    fn apply_to_registry(&self, ctx: &mut ASTMutationContext) -> MutationResult {
13        // Use the provided SymbolId for O(1) access
14        let target_id = self.module_id;
15
16        // Verify the module exists
17        if ctx.symbol_registry.kind(target_id) != Some(SymbolKind::Mod) {
18            return MutationResult {
19                mutation_type: "RemoveMod".to_string(),
20                changes: 0,
21                description: format!("Symbol {} is not a module", target_id),
22            };
23        }
24
25        // Get the path before removing
26        let path = ctx.symbol_registry.path(target_id).cloned();
27
28        // Remove from registries
29        ctx.symbol_registry.remove(target_id);
30        ctx.ast_registry.remove(target_id);
31
32        // Emit event
33        if let Some(path) = path {
34            ctx.emit(MutationEvent::SymbolRemoved { path });
35        }
36
37        MutationResult {
38            mutation_type: "RemoveMod".to_string(),
39            changes: 1,
40            description: format!("Removed mod {}", target_id),
41        }
42    }
43}