image.domain\self_evolve\propagation_viz.mbt
97.9% · 47 / 48 points · 143 linesBackground color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.
- 1
///| - 2
/// # 传播 self_evolve/propagation_viz - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 退化传播可视化 — 生成传播链的可视化描述 - 7
// Degradation propagation visualization: generate visual description of propagation chain - 8
// - 9
// Phase 8 v296: 将传播分析从"数据"推向"可视化" — ASCII/Mermaid/Text 三格式。 - 10
- 11
///| - 12
/// 可视化格式。 - 13
/// 描述 Visualization format. - 14
/// `#non_exhaustive` 表示未来可能添加新构造器 - 15
#derive(Eq, @debug.Debug) - 16
#non_exhaustive - 17
pub(all) enum VizFormat { - 18
AsciiViz - 19
MermaidViz - 20
TextViz - 21
} - 22
- 23
///| - 24
pub extend VizFormat with @debug.Debug::{to_repr} - 25
- 26
///| - 27
pub extend VizFormat with Eq::{not_equal, equal} - 28
- 29
///| - 30
/// 传播可视化结果。 - 31
/// 描述 Propagation visualization result. - 32
#derive(Eq, @debug.Debug) - 33
pub(all) struct PropagationViz { - 34
format : VizFormat - 35
content : String - 36
node_count : Int32 - 37
edge_count : Int32 - 38
} - 39
- 40
///| - 41
pub extend PropagationViz with @debug.Debug::{to_repr} - 42
- 43
///| - 44
pub extend PropagationViz with Eq::{not_equal, equal} - 45
- 46
///| - 47
/// 生成 ASCII 格式传播链可视化。 - 48
/// 生成 Generate ASCII format propagation chain visualization. - 49
pub fn visualize_propagation_ascii(pipeline : @imgir.IRPipeline) -> String { - 50●
let ops = pipeline.ops - 51●
let n = ops.length() - 52
let mut result = "=== 退化传播链(ASCII)===\n" - 53
for i in 0..<n { - 54●
let tag = ops[i].tag() - 55●
let degs = detect_degradation(ops[i]) - 56●
let mut line = "[" + i.to_string() + "] " + tag - 57●
if degs.length() > 0 { - 58●
line = line + " ⚠️" - 59
for d in degs { - 60●
line = line + " (" + d.description + ")" - 61
} - 62
} else { - 63●
line = line + " ✅" - 64
} - 65
result = result + line + "\n" - 66
if i + 1 < n { - 67●
let has_prop = degs.length() > 0 - 68●
result = result + (if has_prop { " |⚠️ 传播\n" } else { " |\n" }) - 69
} - 70
} - 71
result - 72
} - 73
- 74
///| - 75
/// 生成 Mermaid 格式传播链可视化。 - 76
/// 生成 Generate Mermaid format propagation chain visualization. - 77
pub fn visualize_propagation_mermaid(pipeline : @imgir.IRPipeline) -> String { - 78●
let ops = pipeline.ops - 79●
let n = ops.length() - 80
let mut result = "graph LR\n" - 81
for i in 0..<n { - 82●
let tag = ops[i].tag() - 83●
let degs = detect_degradation(ops[i]) - 84●
let label = if degs.length() > 0 { tag + "⚠️" } else { tag } - 85●
result = result + " N" + i.to_string() + "[" + label + "]\n" - 86
if i + 1 < n { - 87●
let has_prop = degs.length() > 0 - 88
result = result + - 89
" N" + - 90●
i.to_string() + - 91
" -->" + - 92◐
(if has_prop { "|传播|" } else { "" }) + - 93
" N" + - 94●
(i + 1).to_string() + - 95
"\n" - 96
} - 97
} - 98
result - 99
} - 100
- 101
///| - 102
/// 生成文本格式传播链可视化。 - 103
/// 生成 Generate text format propagation chain visualization. - 104
pub fn visualize_propagation_text(pipeline : @imgir.IRPipeline) -> String { - 105●
let report = analyze_propagation(pipeline) - 106
let ops = pipeline.ops - 107
let mut result = "退化传播分析报告\n" - 108●
result = result + "管道: " + @imgir.ir_describe(pipeline) + "\n" - 109●
result = result + "算子数: " + ops.length().to_string() + "\n" - 110●
result = result + "传播数: " + report.total_propagations.to_string() + "\n" - 111●
result = result + "链长: " + report.chain_length.to_string() + "\n" - 112●
if report.steps.length() > 0 { - 113●
result = result + "传播步骤:\n" - 114
for s in report.steps { - 115●
result = result + " " + s.propagation_desc + "\n" - 116
} - 117
} - 118
result - 119
} - 120
- 121
///| - 122
/// 按指定格式生成传播链可视化。 - 123
/// 生成 Generate propagation chain visualization in specified format. - 124
pub fn visualize_propagation( - 125
pipeline : @imgir.IRPipeline, - 126
format : VizFormat, - 127
) -> PropagationViz { - 128●
let content = match format { - 129●
AsciiViz => visualize_propagation_ascii(pipeline) - 130●
MermaidViz => visualize_propagation_mermaid(pipeline) - 131●
TextViz => visualize_propagation_text(pipeline) - 132
} - 133●
let nodes = pipeline.ops.length() - 134●
let report = analyze_propagation(pipeline) - 135
{ format, content, node_count: nodes, edge_count: report.total_propagations, } - 136
} - 137
- 138
///| - 139
/// 可视化内容是否非空。 - 140
/// 描述 Whether visualization content is non-empty. - 141
pub fn PropagationViz::is_valid(self : PropagationViz) -> Bool { - 142●
self.content.length() > 0 - 143
}