image.domain\self_evolve\propagation_viz.mbt

97.9% · 47 / 48 points · 143 lines

Background color reports the state of each line. Underlined characters mark exact instrumented byte offsets; hover them to inspect the visit count.

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