Skip to main content

lellm_graph/compiler/
context.rs

1//! CompilerContext — 编译上下文。
2
3use crate::state::workflow_state::WorkflowState;
4
5/// 编译上下文 — 包含配置和统计信息。
6pub struct CompilerContext<S: WorkflowState> {
7    /// 最大内联图大小(节点数)
8    pub max_inline_size: usize,
9
10    /// 是否启用调试输出
11    pub debug: bool,
12
13    /// 统计信息
14    pub stats: CompilerStats,
15
16    /// PhantomData
17    _phantom: std::marker::PhantomData<S>,
18}
19
20impl<S: WorkflowState> CompilerContext<S> {
21    /// 创建新的编译上下文。
22    pub fn new() -> Self {
23        Self {
24            max_inline_size: 100, // 默认最大内联图大小
25            debug: false,
26            stats: CompilerStats::default(),
27            _phantom: std::marker::PhantomData,
28        }
29    }
30
31    /// 设置最大内联图大小。
32    pub fn max_inline_size(mut self, max: usize) -> Self {
33        self.max_inline_size = max;
34        self
35    }
36
37    /// 启用调试输出。
38    pub fn debug(mut self, enable: bool) -> Self {
39        self.debug = enable;
40        self
41    }
42}
43
44impl<S: WorkflowState> Default for CompilerContext<S> {
45    fn default() -> Self {
46        Self::new()
47    }
48}
49
50/// 编译统计信息。
51#[derive(Debug, Default, Clone)]
52pub struct CompilerStats {
53    /// Subgraph 总数
54    pub subgraph_count: usize,
55
56    /// 已内联的 Subgraph 数量
57    pub inlined_count: usize,
58
59    /// 未内联的 Subgraph 数量
60    pub not_inlined_count: usize,
61
62    /// 总节点数(优化前)
63    pub total_nodes_before: usize,
64
65    /// 总节点数(优化后)
66    pub total_nodes_after: usize,
67}