baobao_codegen/pipeline/phase.rs
1//! Pipeline phase trait.
2
3use eyre::Result;
4
5use super::CompilationContext;
6
7/// Information about a pipeline phase.
8#[derive(Debug, Clone)]
9pub struct PhaseInfo {
10 /// The phase name.
11 pub name: &'static str,
12 /// A human-readable description.
13 pub description: &'static str,
14}
15
16/// A phase in the compilation pipeline.
17///
18/// Phases are executed in order by the pipeline. Each phase can read and
19/// modify the compilation context, adding to the IR, computed data, or
20/// diagnostics.
21///
22/// Built-in phases:
23/// - `ValidatePhase` - validates the manifest and collects diagnostics
24/// - `LowerPhase` - transforms manifest to Application IR
25/// - `AnalyzePhase` - computes shared data from IR
26///
27/// Custom phases can be added to the pipeline for additional processing.
28pub trait Phase: Send + Sync {
29 /// The name of this phase (used in diagnostics and plugin hooks).
30 fn name(&self) -> &'static str;
31
32 /// A human-readable description of what this phase does.
33 fn description(&self) -> &'static str;
34
35 /// Run this phase on the compilation context.
36 ///
37 /// # Errors
38 ///
39 /// Returns an error if the phase fails fatally. Non-fatal issues should
40 /// be recorded as diagnostics instead.
41 fn run(&self, ctx: &mut CompilationContext) -> Result<()>;
42
43 /// Get information about this phase.
44 fn info(&self) -> PhaseInfo {
45 PhaseInfo {
46 name: self.name(),
47 description: self.description(),
48 }
49 }
50}