image.domain\self_evolve\grill.mbt
93.8% · 75 / 80 points · 289 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/grill - 3
/// - 4
/// 图像处理库子模块 - 5
/// 图像处理库子模块 Image processing library submodule - 6
// grill-me 拷问引擎 — 4.7.4 领域规则可执行化 - 7
// Grill engine: executable 4.7.4 domain rules - 8
// - 9
// 五条拷问规则: - 10
// 1. 数值鲁棒性:除零 / 奇异矩阵 / NaN / Inf / 溢出 - 11
// 2. 退化几何:除零 / 共线点 / 退化三角形 / 零面积 - 12
// 3. 场间断:边界不连续 / 梯度不存在 / 插值外推 - 13
// 4. 时空拓扑:Allen 代数 / 时间区间 / 单调性 - 14
// 5. 四目标兼容:纯 MoonBit 无 C FFI(静态保证) - 15
- 16
///| - 17
/// 拷问规则(对应 4.7.4 五条领域规则)。 - 18
/// 描述 Grill rule (corresponds to 4.7.4 domain rules). - 19
/// `#non_exhaustive` 表示未来可能添加新构造器 - 20
#derive(Eq, @debug.Debug) - 21
#non_exhaustive - 22
pub(all) enum GrillRule { - 23
NumericRobustness // 数值鲁棒性 - 24
DegenerateGeometry // 退化几何 - 25
FieldDiscontinuityRule // 场间断 - 26
SpatiotemporalTopology // 时空拓扑 - 27
MultiTargetCompat // 四目标兼容 - 28
} - 29
- 30
///| - 31
pub extend GrillRule with @debug.Debug::{to_repr} - 32
- 33
///| - 34
pub extend GrillRule with Eq::{not_equal, equal} - 35
- 36
///| - 37
/// 单条拷问结果。 - 38
/// 描述 Single grill result. - 39
#derive(Eq, @debug.Debug) - 40
pub(all) struct GrillResult { - 41
rule : GrillRule - 42
target : String - 43
passed : Bool - 44
reason : String - 45
} - 46
- 47
///| - 48
pub extend GrillResult with @debug.Debug::{to_repr} - 49
- 50
///| - 51
pub extend GrillResult with Eq::{not_equal, equal} - 52
- 53
///| - 54
/// 拷问报告。 - 55
/// 描述 Grill report. - 56
#derive(Eq, @debug.Debug) - 57
pub(all) struct GrillReport { - 58
results : Array[GrillResult] - 59
target_desc : String - 60
} - 61
- 62
///| - 63
pub extend GrillReport with @debug.Debug::{to_repr} - 64
- 65
///| - 66
pub extend GrillReport with Eq::{not_equal, equal} - 67
- 68
///| - 69
/// 全部 5 条拷问规则。 - 70
/// 描述 All 5 grill rules. - 71
pub fn grill_rules() -> Array[GrillRule] { - 72●
[ - 73
NumericRobustness, - 74
DegenerateGeometry, - 75
FieldDiscontinuityRule, - 76
SpatiotemporalTopology, - 77
MultiTargetCompat, - 78
] - 79
} - 80
- 81
///| - 82
/// 规则描述。 - 83
/// 描述 Rule description. - 84
pub fn grill_rule_desc(rule : GrillRule) -> String { - 85●
match rule { - 86●
NumericRobustness => "数值鲁棒性:除零/奇异矩阵/NaN/Inf/溢出" - 87●
DegenerateGeometry => "退化几何:除零/共线点/零面积" - 88
FieldDiscontinuityRule => - 89●
"场间断:边界不连续/梯度不存在/插值外推" - 90
SpatiotemporalTopology => - 91●
"时空拓扑:Allen代数/时间区间/单调性" - 92●
MultiTargetCompat => "四目标兼容:纯MoonBit无CFFI" - 93
} - 94
} - 95
- 96
// 判断退化类型是否数值类 - 97
- 98
///| - 99
fn is_numeric_kind(k : DegradationKind) -> Bool { - 100●
match k { - 101●
DivisionByZero => true - 102○
SingularMatrix => true - 103○
NaNValue => true - 104○
InfValue => true - 105○
Overflow => true - 106●
FieldDiscontinuity => false - 107
} - 108
} - 109
- 110
// 统计数值类退化数 - 111
- 112
///| - 113
fn count_numeric_degradations(degs : Array[DegradationCase]) -> Int32 { - 114●
let mut count = 0 - 115
for d in degs { - 116●
if is_numeric_kind(d.kind) { - 117●
count = count + 1 - 118
} - 119
} - 120
count - 121
} - 122
- 123
// 统计除零退化数(退化几何) - 124
- 125
///| - 126
fn count_divzero_degradations(degs : Array[DegradationCase]) -> Int32 { - 127●
let mut count = 0 - 128
for d in degs { - 129●
if d.kind == DivisionByZero { - 130●
count = count + 1 - 131
} - 132
} - 133
count - 134
} - 135
- 136
// 统计场间断违规数(FieldClamp lo>hi / FieldMask 极端阈值) - 137
- 138
///| - 139
fn count_field_discontinuity(ops : Array[@imgir.IROp]) -> Int32 { - 140●
let mut count = 0 - 141
for op in ops { - 142●
match op { - 143●
FieldClamp(lo, hi) => if lo > hi { count = count + 1 } - 144
FieldMask(threshold) => - 145●
if threshold > 1000000.0F || threshold < -1000000.0F { - 146○
count = count + 1 - 147
} - 148●
_ => () - 149
} - 150
} - 151
count - 152
} - 153
- 154
// 统计时空拓扑违规数(STSnapshot/STInterpolate t 越界 [0,1]) - 155
- 156
///| - 157
fn count_spatiotemporal_violation(ops : Array[@imgir.IROp]) -> Int32 { - 158●
let mut count = 0 - 159
for op in ops { - 160●
match op { - 161●
STSnapshot(t) => if t < 0.0F || t > 1.0F { count = count + 1 } - 162●
STInterpolate(t) => if t < 0.0F || t > 1.0F { count = count + 1 } - 163●
_ => () - 164
} - 165
} - 166
count - 167
} - 168
- 169
///| - 170
/// 对管道执行 5 条拷问规则检查。 - 171
/// 运行 Run 5 grill rules on a pipeline. - 172
pub fn run_grill_check(pipeline : @imgir.IRPipeline) -> GrillReport { - 173●
let ops = pipeline.ops - 174●
let degs = scan_degradations(ops) - 175●
let desc = @imgir.ir_describe(pipeline) - 176
let results : Array[GrillResult] = [] - 177
// 规则 1: 数值鲁棒性 - 178●
let numeric_fail = count_numeric_degradations(degs) - 179●
results.push({ - 180
rule: NumericRobustness, - 181
target: desc, - 182
passed: numeric_fail == 0, - 183
reason: if numeric_fail == 0 { - 184●
"无数值退化" - 185
} else { - 186●
"发现 " + - 187●
numeric_fail.to_string() + - 188
" 处数值退化(除零/奇异/NaN/Inf/溢出)" - 189
}, - 190
}) - 191
// 规则 2: 退化几何 - 192●
let geom_fail = count_divzero_degradations(degs) - 193●
results.push({ - 194
rule: DegenerateGeometry, - 195
target: desc, - 196
passed: geom_fail == 0, - 197
reason: if geom_fail == 0 { - 198●
"无退化几何" - 199
} else { - 200●
"发现 " + - 201●
geom_fail.to_string() + - 202
" 处退化几何(除零/零面积)" - 203
}, - 204
}) - 205
// 规则 3: 场间断 - 206●
let field_fail = count_field_discontinuity(ops) - 207●
results.push({ - 208
rule: FieldDiscontinuityRule, - 209
target: desc, - 210
passed: field_fail == 0, - 211
reason: if field_fail == 0 { - 212●
"无场间断" - 213
} else { - 214●
"发现 " + - 215●
field_fail.to_string() + - 216
" 处场间断(边界不连续/插值外推)" - 217
}, - 218
}) - 219
// 规则 4: 时空拓扑 - 220●
let st_fail = count_spatiotemporal_violation(ops) - 221●
results.push({ - 222
rule: SpatiotemporalTopology, - 223
target: desc, - 224
passed: st_fail == 0, - 225
reason: if st_fail == 0 { - 226●
"时空拓扑一致" - 227
} else { - 228●
"发现 " + - 229●
st_fail.to_string() + - 230
" 处时空拓扑违规(t 越界 [0,1])" - 231
}, - 232
}) - 233
// 规则 5: 四目标兼容(静态保证) - 234●
results.push({ - 235
rule: MultiTargetCompat, - 236
target: desc, - 237
passed: true, - 238
reason: "纯 MoonBit 无 C FFI,四目标共用代码", - 239
}) - 240
{ results, target_desc: desc, } - 241
} - 242
- 243
///| - 244
/// 对全部 19 种算子执行拷问。 - 245
/// 运行 Run grill on all 19 op variants. - 246
pub fn run_grill_all() -> GrillReport { - 247●
let results : Array[GrillResult] = [] - 248●
for op in all_ops() { - 249●
let pipe = @imgir.IRPipeline::new().add(op) - 250●
let report = run_grill_check(pipe) - 251
for r in report.results { - 252●
results.push(r) - 253
} - 254
} - 255
{ results, target_desc: "全部 19 种算子", } - 256
} - 257
- 258
///| - 259
/// 全部规则是否通过。 - 260
/// 描述 Whether all rules passed. - 261
pub fn GrillReport::all_passed(self : GrillReport) -> Bool { - 262●
let mut ok = true - 263
for r in self.results { - 264●
if !r.passed { - 265●
ok = false - 266
} - 267
} - 268
ok - 269
} - 270
- 271
///| - 272
/// 失败规则数。 - 273
/// 描述 Number of failed rules. - 274
pub fn GrillReport::failed_count(self : GrillReport) -> Int32 { - 275●
let mut count = 0 - 276
for r in self.results { - 277●
if !r.passed { - 278●
count = count + 1 - 279
} - 280
} - 281
count - 282
} - 283
- 284
///| - 285
/// 通过规则数。 - 286
/// 描述 Number of passed rules. - 287
pub fn GrillReport::passed_count(self : GrillReport) -> Int32 { - 288●
self.results.length() - self.failed_count() - 289
}