image.domain\self_evolve\evolve_loop.mbt
91.7% · 33 / 36 points · 118 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/evolve_loop - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// 自演化闭环 — 串联 test_gen + degrade + optimize + perf - 7
// Evolution loop: full cycle connecting all self_evolve capabilities - 8
- 9
///| - 10
/// 自演化闭环报告。 - 11
/// 描述 Evolution cycle report. - 12
#derive(Eq, @debug.Debug) - 13
pub(all) struct EvolveCycleReport { - 14
pipeline_desc : String - 15
original_op_count : Int32 - 16
optimized_op_count : Int32 - 17
generated_tests : Array[TestCase] - 18
found_degradations : Array[DegradationCase] - 19
optimization_report : OptimizationReport - 20
perf_regression : PerfRegression - 21
cycle_summary : String - 22
} - 23
- 24
///| - 25
pub extend EvolveCycleReport with @debug.Debug::{to_repr} - 26
- 27
///| - 28
pub extend EvolveCycleReport with Eq::{not_equal, equal} - 29
- 30
///| - 31
/// 完整自演化闭环:退化发现 → 测试生成 → 管道优化 → 性能回归 → 综合报告。 - 32
/// 描述 Full evolution cycle: degradation → test gen → optimize → perf → report. - 33
pub fn evolve_full_cycle(pipeline : @imgir.IRPipeline) -> EvolveCycleReport { - 34●
let ops = pipeline.ops - 35
// 1. 退化发现 - 36●
let degradations = scan_degradations(ops) - 37
// 2. 测试生成 - 38●
let tests = evolve_test_suite(ops) - 39
// 3. 管道优化 - 40●
let opt_report = optimize_all(pipeline) - 41
// 4. 性能回归 - 42●
let perf = perf_optimize_check(pipeline) - 43
// 5. 综合报告 - 44
let summary = "管道 '" + - 45●
@imgir.ir_describe(pipeline) + - 46
"': " + - 47●
ops.length().to_string() + - 48
" 算子 → " + - 49●
opt_report.optimized_length.to_string() + - 50
" 优化后, " + - 51●
tests.length().to_string() + - 52
" 测试, " + - 53●
degradations.length().to_string() + - 54
" 退化, 成本变化 " + - 55●
perf.delta.to_string() - 56
{ - 57●
pipeline_desc: @imgir.ir_describe(pipeline), - 58●
original_op_count: ops.length(), - 59
optimized_op_count: opt_report.optimized_length, - 60
generated_tests: tests, - 61
found_degradations: degradations, - 62
optimization_report: opt_report, - 63
perf_regression: perf, - 64
cycle_summary: summary, - 65
} - 66
} - 67
- 68
///| - 69
/// 对全部 19 种算子执行自演化闭环。 - 70
/// 运行 Run evolution cycle on all 19 op variants. - 71
pub fn evolve_cycle_all() -> Array[EvolveCycleReport] { - 72●
let reports : Array[EvolveCycleReport] = [] - 73●
for op in all_ops() { - 74●
let pipe = @imgir.IRPipeline::new().add(op) - 75●
reports.push(evolve_full_cycle(pipe)) - 76
} - 77
reports - 78
} - 79
- 80
///| - 81
/// 闭环是否改善了管道(算子减少且成本降低)。 - 82
/// 描述 Whether cycle improved the pipeline (fewer ops and lower cost). - 83
pub fn EvolveCycleReport::is_improved(self : EvolveCycleReport) -> Bool { - 84●
self.optimized_op_count < self.original_op_count && - 85●
self.perf_regression.is_improvement() - 86
} - 87
- 88
///| - 89
/// 闭环是否有退化风险。 - 90
/// 描述 Whether cycle has degradation risk. - 91
pub fn EvolveCycleReport::has_degradation_risk( - 92
self : EvolveCycleReport, - 93
) -> Bool { - 94●
self.found_degradations.length() > 0 - 95
} - 96
- 97
///| - 98
/// 闭环安全度(0-100,越高越安全)。 - 99
/// 描述 Cycle safety score (0-100, higher is safer). - 100
pub fn EvolveCycleReport::safety_score(self : EvolveCycleReport) -> Int32 { - 101●
let deg_penalty = self.found_degradations.length() * 10 - 102
- 103
let mut severe_count = 0 - 104
for d in self.found_degradations { - 105●
match d.severity { - 106○
Warning => () - 107○
Critical => severe_count = severe_count + 1 - 108●
Fatal => severe_count = severe_count + 1 - 109
} - 110
} - 111
let severe_penalty = severe_count * 20 - 112
let score = 100 - deg_penalty - severe_penalty - 113
if score < 0 { - 114○
0 - 115
} else { - 116●
score - 117
} - 118
}