image.domain\self_evolve\cross_module.mbt

94.4% · 34 / 36 points · 240 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/cross_module
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 跨模块演化协同 — 跨模块协同演化
  7. 7// Cross-module evolution coordination: coordinate evolution across modules
  8. 8//
  9. 9// Phase 11 v312: 将演化从"知识图谱"推向"跨模块协同" — 多模块协同演化。
  10. 10
  11. 11///|
  12. 12/// 模块依赖类型。
  13. 13/// 描述 Module dependency kind.
  14. 14/// `#non_exhaustive` 表示未来可能添加新构造器
  15. 15#derive(Eq, @debug.Debug)
  16. 16#non_exhaustive
  17. 17pub(all) enum ModuleDepKind {
  18. 18 Uses // 使用
  19. 19 Extends // 扩展
  20. 20 Composes // 组合
  21. 21}
  22. 22
  23. 23///|
  24. 24pub extend ModuleDepKind with @debug.Debug::{to_repr}
  25. 25
  26. 26///|
  27. 27pub extend ModuleDepKind with Eq::{not_equal, equal}
  28. 28
  29. 29///|
  30. 30/// 模块依赖关系。
  31. 31/// 描述 Module dependency.
  32. 32#derive(Eq, @debug.Debug)
  33. 33pub(all) struct ModuleDep {
  34. 34 source : String
  35. 35 target : String
  36. 36 kind : ModuleDepKind
  37. 37}
  38. 38
  39. 39///|
  40. 40pub extend ModuleDep with @debug.Debug::{to_repr}
  41. 41
  42. 42///|
  43. 43pub extend ModuleDep with Eq::{not_equal, equal}
  44. 44
  45. 45///|
  46. 46/// 协同演化动作类型。
  47. 47/// 描述 Co-evolution action kind.
  48. 48/// `#non_exhaustive` 表示未来可能添加新构造器
  49. 49#derive(Eq, @debug.Debug)
  50. 50#non_exhaustive
  51. 51pub(all) enum CoEvolveActionKind {
  52. 52 SyncEvolve // 同步演化
  53. 53 CascadeEvolve // 级联演化
  54. 54 IndependentEvolve // 独立演化
  55. 55}
  56. 56
  57. 57///|
  58. 58pub extend CoEvolveActionKind with @debug.Debug::{to_repr}
  59. 59
  60. 60///|
  61. 61pub extend CoEvolveActionKind with Eq::{not_equal, equal}
  62. 62
  63. 63///|
  64. 64/// 协同演化动作。
  65. 65/// 描述 Co-evolution action.
  66. 66#derive(Eq, @debug.Debug)
  67. 67pub(all) struct CoEvolveAction {
  68. 68 action_kind : CoEvolveActionKind
  69. 69 source_module : String
  70. 70 target_module : String
  71. 71 description : String
  72. 72}
  73. 73
  74. 74///|
  75. 75pub extend CoEvolveAction with @debug.Debug::{to_repr}
  76. 76
  77. 77///|
  78. 78pub extend CoEvolveAction with Eq::{not_equal, equal}
  79. 79
  80. 80///|
  81. 81/// 协同演化报告。
  82. 82/// 描述 Co-evolution report.
  83. 83#derive(Eq, @debug.Debug)
  84. 84pub(all) struct CoEvolveReport {
  85. 85 actions : Array[CoEvolveAction]
  86. 86 total_modules : Int32
  87. 87 sync_count : Int32
  88. 88 cascade_count : Int32
  89. 89 summary : String
  90. 90}
  91. 91
  92. 92///|
  93. 93pub extend CoEvolveReport with @debug.Debug::{to_repr}
  94. 94
  95. 95///|
  96. 96pub extend CoEvolveReport with Eq::{not_equal, equal}
  97. 97
  98. 98///|
  99. 99/// 构建 self_evolve 内部模块依赖图。
  100. 100/// 构建 Build module dependency graph for self_evolve internal modules.
  101. 101pub fn build_module_deps() -> Array[ModuleDep] {
  102. 102● [
  103. 103 { source: "degrade_detect", target: "evolve_types", kind: Uses, },
  104. 104 { source: "test_gen", target: "evolve_types", kind: Uses, },
  105. 105 { source: "optimize", target: "equiv_check", kind: Uses, },
  106. 106 { source: "optimize", target: "evolve_types", kind: Uses, },
  107. 107 { source: "equiv_check", target: "evolve_types", kind: Uses, },
  108. 108 { source: "evolve", target: "degrade_detect", kind: Composes, },
  109. 109 { source: "evolve", target: "test_gen", kind: Composes, },
  110. 110 { source: "evolve", target: "optimize", kind: Composes, },
  111. 111 { source: "schedule", target: "evolve", kind: Extends, },
  112. 112 { source: "auto_decide", target: "predict", kind: Uses, },
  113. 113 { source: "strategy_combo", target: "degrade_detect", kind: Uses, },
  114. 114 { source: "param_tune", target: "evolve_types", kind: Uses, },
  115. 115 { source: "evolve_loop_full", target: "auto_decide", kind: Composes, },
  116. 116 { source: "evolve_loop_full", target: "strategy_combo", kind: Composes, },
  117. 117 { source: "evolve_loop_full", target: "param_tune", kind: Composes, },
  118. 118 { source: "knowledge_graph", target: "degrade_detect", kind: Uses, },
  119. 119 { source: "knowledge_graph", target: "smart_priority", kind: Uses, },
  120. 120 ]
  121. 121}
  122. 122
  123. 123///|
  124. 124/// 为单个算子分析跨模块协同演化。
  125. 125/// 描述 Analyze cross-module co-evolution for a single op.
  126. 126pub fn co_evolve_op(op : @imgir.IROp) -> CoEvolveReport {
  127. 127● let tag = op.tag()
  128. 128 let actions : Array[CoEvolveAction] = []
  129. 129 let mut sync_count = 0
  130. 130 let mut cascade_count = 0
  131. 131● let degs = detect_degradation(op)
  132. 132● if degs.length() > 0 {
  133. 133● actions.push({
  134. 134 action_kind: SyncEvolve,
  135. 135 source_module: "degrade_detect",
  136. 136 target_module: "test_gen",
  137. 137 description: tag + ": 退化检测→测试生成 同步演化",
  138. 138 })
  139. 139 sync_count = sync_count + 1
  140. 140● actions.push({
  141. 141 action_kind: CascadeEvolve,
  142. 142 source_module: "equiv_check",
  143. 143 target_module: "optimize",
  144. 144 description: tag + ": 等价性→优化 级联演化",
  145. 145 })
  146. 146 cascade_count = cascade_count + 1
  147. 147● actions.push({
  148. 148 action_kind: SyncEvolve,
  149. 149 source_module: "degrade_detect",
  150. 150 target_module: "knowledge_graph",
  151. 151 description: tag + ": 退化→知识图谱 同步更新",
  152. 152 })
  153. 153 sync_count = sync_count + 1
  154. 154 }
  155. 155● let cov = coverage_percentage(op)
  156. 156 if cov < 80 {
  157. 157● actions.push({
  158. 158 action_kind: IndependentEvolve,
  159. 159 source_module: "test_gen",
  160. 160 target_module: "test_gen",
  161. 161● description: tag + ": 覆盖率 " + cov.to_string() + "% → 补充测试",
  162. 162 })
  163. 163 }
  164. 164● let score = score_op(op)
  165. 165 if score.score > 50 {
  166. 166○ actions.push({
  167. 167 action_kind: CascadeEvolve,
  168. 168 source_module: "optimize",
  169. 169 target_module: "equiv_check",
  170. 170 description: tag + ": 优化→等价性验证 级联演化",
  171. 171 })
  172. 172 cascade_count = cascade_count + 1
  173. 173 }
  174. 174● if actions.length() == 0 {
  175. 175● actions.push({
  176. 176 action_kind: IndependentEvolve,
  177. 177 source_module: "optimize",
  178. 178 target_module: "optimize",
  179. 179 description: tag + ": 无需协同,独立优化",
  180. 180 })
  181. 181 }
  182. 182 let total_modules = 5
  183. 183 let summary = "跨模块协同[" +
  184. 184 tag +
  185. 185 "]: " +
  186. 186● actions.length().to_string() +
  187. 187 " 动作, " +
  188. 188● sync_count.to_string() +
  189. 189 " 同步, " +
  190. 190● cascade_count.to_string() +
  191. 191 " 级联"
  192. 192 { actions, total_modules, sync_count, cascade_count, summary, }
  193. 193}
  194. 194
  195. 195///|
  196. 196/// 为所有算子分析跨模块协同演化。
  197. 197/// 描述 Analyze cross-module co-evolution for all ops.
  198. 198pub fn co_evolve_all() -> CoEvolveReport {
  199. 199● let all_actions : Array[CoEvolveAction] = []
  200. 200 let mut total_sync = 0
  201. 201 let mut total_cascade = 0
  202. 202 let mut total_modules = 0
  203. 203● for op in all_ops() {
  204. 204● let report = co_evolve_op(op)
  205. 205 for a in report.actions {
  206. 206● all_actions.push(a)
  207. 207 }
  208. 208 total_sync = total_sync + report.sync_count
  209. 209 total_cascade = total_cascade + report.cascade_count
  210. 210 total_modules = total_modules + report.total_modules
  211. 211 }
  212. 212 let summary = "全量跨模块协同: " +
  213. 213● all_actions.length().to_string() +
  214. 214 " 动作, " +
  215. 215● total_sync.to_string() +
  216. 216 " 同步, " +
  217. 217● total_cascade.to_string() +
  218. 218 " 级联"
  219. 219 {
  220. 220 actions: all_actions,
  221. 221 total_modules,
  222. 222 sync_count: total_sync,
  223. 223 cascade_count: total_cascade,
  224. 224 summary,
  225. 225 }
  226. 226}
  227. 227
  228. 228///|
  229. 229/// 协同演化报告是否有级联演化。
  230. 230/// 描述 Whether co-evolution report has cascade actions.
  231. 231pub fn CoEvolveReport::has_cascade(self : CoEvolveReport) -> Bool {
  232. 232● self.cascade_count > 0
  233. 233}
  234. 234
  235. 235///|
  236. 236/// 协同演化报告总动作数。
  237. 237/// 描述 Total action count.
  238. 238pub fn CoEvolveReport::total_actions(self : CoEvolveReport) -> Int32 {
  239. 239● self.actions.length()
  240. 240}