image.domain\self_evolve\recommend.mbt

91.2% · 31 / 34 points · 159 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/recommend
  3. 3///
  4. 4/// 图像处理库子模块
  5. 5/// 图像处理库子模块 Image processing library submodule
  6. 6// 演化推荐引擎 — 根据当前状态推荐下一步演化
  7. 7// Evolution recommendation engine: recommend next evolution step based on current state
  8. 8//
  9. 9// Phase 8 v298: 将演化从"被动"推向"主动推荐" — 根据覆盖/退化/传播推荐下一步。
  10. 10
  11. 11///|
  12. 12/// 推荐动作类型。
  13. 13/// 描述 Recommendation action type.
  14. 14/// `#non_exhaustive` 表示未来可能添加新构造器
  15. 15#derive(Eq, @debug.Debug)
  16. 16#non_exhaustive
  17. 17pub(all) enum RecommendAction {
  18. 18 AddTests
  19. 19 FixDegradation
  20. 20 AddPropagationTest
  21. 21 OptimizePipeline
  22. 22 NoActionNeeded
  23. 23}
  24. 24
  25. 25///|
  26. 26pub extend RecommendAction with @debug.Debug::{to_repr}
  27. 27
  28. 28///|
  29. 29pub extend RecommendAction with Eq::{not_equal, equal}
  30. 30
  31. 31///|
  32. 32/// 单条演化推荐。
  33. 33/// 描述 Single evolution recommendation.
  34. 34#derive(Eq, @debug.Debug)
  35. 35pub(all) struct Recommendation {
  36. 36 action : RecommendAction
  37. 37 target_op : String
  38. 38 priority : TestPriority
  39. 39 reason : String
  40. 40}
  41. 41
  42. 42///|
  43. 43pub extend Recommendation with @debug.Debug::{to_repr}
  44. 44
  45. 45///|
  46. 46pub extend Recommendation with Eq::{not_equal, equal}
  47. 47
  48. 48///|
  49. 49/// 推荐报告。
  50. 50/// 描述 Recommendation report.
  51. 51#derive(Eq, @debug.Debug)
  52. 52pub(all) struct RecommendationReport {
  53. 53 recommendations : Array[Recommendation]
  54. 54 total : Int32
  55. 55 high_priority_count : Int32
  56. 56 summary : String
  57. 57}
  58. 58
  59. 59///|
  60. 60pub extend RecommendationReport with @debug.Debug::{to_repr}
  61. 61
  62. 62///|
  63. 63pub extend RecommendationReport with Eq::{not_equal, equal}
  64. 64
  65. 65///|
  66. 66/// 推荐单算子下一步演化。
  67. 67/// 描述 Recommend next evolution step for a single op.
  68. 68pub fn recommend_next(op : @imgir.IROp) -> Recommendation {
  69. 69● let tag = op.tag()
  70. 70● let degs = detect_degradation(op)
  71. 71● let cov = coverage_percentage(op)
  72. 72● if degs.length() > 0 {
  73. 73● {
  74. 74 action: FixDegradation,
  75. 75 target_op: tag,
  76. 76 priority: HighPriority,
  77. 77● reason: tag + " 有 " + degs.length().to_string() + " 个退化需修复",
  78. 78 }
  79. 79● } else if cov < 50 {
  80. 80○ {
  81. 81 action: AddTests,
  82. 82 target_op: tag,
  83. 83 priority: MediumPriority,
  84. 84○ reason: tag + " 覆盖率仅 " + cov.to_string() + "%,需增加测试",
  85. 85 }
  86. 86 } else {
  87. 87● {
  88. 88 action: NoActionNeeded,
  89. 89 target_op: tag,
  90. 90 priority: LowPriority,
  91. 91 reason: tag + " 状态良好,无需操作",
  92. 92 }
  93. 93 }
  94. 94}
  95. 95
  96. 96///|
  97. 97/// 推荐全算子演化。
  98. 98/// 描述 Recommend evolution for all ops.
  99. 99pub fn recommend_all() -> RecommendationReport {
  100. 100● let recs : Array[Recommendation] = []
  101. 101 let mut high_count = 0
  102. 102● for op in all_ops() {
  103. 103● let rec = recommend_next(op)
  104. 104 if rec.priority is HighPriority {
  105. 105○ high_count = high_count + 1
  106. 106 }
  107. 107● recs.push(rec)
  108. 108 }
  109. 109● let total = recs.length()
  110. 110 let summary = "演化推荐: " +
  111. 111● total.to_string() +
  112. 112 " 条推荐, " +
  113. 113● high_count.to_string() +
  114. 114 " 条高优先级"
  115. 115 { recommendations: recs, total, high_priority_count: high_count, summary, }
  116. 116}
  117. 117
  118. 118///|
  119. 119/// 推荐管道演化。
  120. 120/// 描述 Recommend evolution for a pipeline.
  121. 121pub fn recommend_for_pipeline(
  122. 122 pipeline : @imgir.IRPipeline,
  123. 123) -> RecommendationReport {
  124. 124● let recs : Array[Recommendation] = []
  125. 125 let mut high_count = 0
  126. 126● let has_prop = has_propagation_risk(pipeline)
  127. 127 if has_prop {
  128. 128● recs.push({
  129. 129 action: AddPropagationTest,
  130. 130 target_op: "pipeline",
  131. 131 priority: HighPriority,
  132. 132 reason: "管道有传播风险,需添加传播测试",
  133. 133 })
  134. 134 high_count = high_count + 1
  135. 135 }
  136. 136 for op in pipeline.ops {
  137. 137● let rec = recommend_next(op)
  138. 138 if rec.priority is HighPriority {
  139. 139● high_count = high_count + 1
  140. 140 }
  141. 141● recs.push(rec)
  142. 142 }
  143. 143● let total = recs.length()
  144. 144 let summary = "管道推荐: " +
  145. 145● total.to_string() +
  146. 146 " 条推荐, " +
  147. 147● high_count.to_string() +
  148. 148 " 条高优先级(管道 " +
  149. 149● @imgir.ir_describe(pipeline) +
  150. 150 ")"
  151. 151 { recommendations: recs, total, high_priority_count: high_count, summary, }
  152. 152}
  153. 153
  154. 154///|
  155. 155/// 推荐报告是否有紧急推荐。
  156. 156/// 描述 Whether recommendation report has urgent items.
  157. 157pub fn RecommendationReport::has_urgent(self : RecommendationReport) -> Bool {
  158. 158● self.high_priority_count > 0
  159. 159}