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
//! MIR frontend for Rust CFG extraction (future work)
//!
//! **CURRENT STATUS:** Placeholder for future RUSTC_WRAPPER implementation.
//!
//! The correct approach for MIR-based CFG extraction is the RUSTC_WRAPPER pattern
//! used by Clippy and Miri:
//!
//! ```bash
//! RUSTC_WRAPPER=magellan-mir-extract cargo build
//! ```
//!
//! **Architecture:**
//! 1. Create `magellan-mir-extract` binary (nightly, rustc_private)
//! 2. Wrapper calls `rustc_driver::run_compiler()` with custom `Callbacks`
//! 3. In `after_analysis()` callback: iterate `tcx.hir().items()` → `tcx.optimized_mir(def_id)`
//! 4. Extract CFG blocks/edges from MIR and write to database
//! 5. Compilation continues normally — zero overhead
//!
//! **Why per-file rustc --emit=mir failed:**
//! - Compiling individual source files breaks on external dependencies
//! - Module declarations (`mod foo;`) reference other files
//! - Macros and feature gates require whole-crate compilation
//! - Type resolution needs complete crate context
//!
//! **Future implementation:**
//! - Requires nightly Rust (rustc_private)
//! - ~200-300 LOC wrapper binary
//! - Whole-crate semantics, all deps resolved, macros expanded
//!
//! **Schema kept for future use:**
//! The `MirCfgResult`, `CfgBlock`, and `CfgEdge` types are preserved
//! for the RUSTC_WRAPPER implementation.
use crate;
use crateCfgBlock;
/// MIR extraction result with CFG blocks and edges
///
/// **NOTE:** This type is kept for future RUSTC_WRAPPER implementation.
/// The current `extract_cfg_from_rust_source` function is removed because
/// per-file compilation is fundamentally broken.
/// Extract CFG using MIR (NOT IMPLEMENTED)
///
/// **REMOVED:** Per-file `rustc --emit=mir` approach is broken.
///
/// **Future:** Implement as RUSTC_WRAPPER with rustc_driver::Callbacks.