behavior-contracts 0.11.16 → 0.11.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generator/emit-shared-typescript-typed.d.ts.map +1 -1
- package/dist/generator/emit-shared-typescript-typed.js +10 -2
- package/dist/generator/emit-shared-typescript-typed.js.map +1 -1
- package/dist/generator/emit-typed-native-go.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-go.js +33 -1
- package/dist/generator/emit-typed-native-go.js.map +1 -1
- package/dist/generator/emit-typed-native-rust.d.ts.map +1 -1
- package/dist/generator/emit-typed-native-rust.js +206 -49
- package/dist/generator/emit-typed-native-rust.js.map +1 -1
- package/dist/generator/native-expr.d.ts +26 -3
- package/dist/generator/native-expr.d.ts.map +1 -1
- package/dist/generator/native-expr.js +35 -19
- package/dist/generator/native-expr.js.map +1 -1
- package/dist/generator/typed.d.ts +16 -0
- package/dist/generator/typed.d.ts.map +1 -1
- package/dist/generator/typed.js +50 -0
- package/dist/generator/typed.js.map +1 -1
- package/package.json +1 -1
|
@@ -72,11 +72,23 @@ pub struct BehaviorError {
|
|
|
72
72
|
|
|
73
73
|
impl BehaviorError {
|
|
74
74
|
pub fn new(code: impl Into<String>, message: impl Into<String>) -> Self {
|
|
75
|
-
BehaviorError {
|
|
75
|
+
BehaviorError {
|
|
76
|
+
code: code.into(),
|
|
77
|
+
message: message.into(),
|
|
78
|
+
detail: None,
|
|
79
|
+
}
|
|
76
80
|
}
|
|
77
81
|
/// The same failure carrying the leaf's structured Error Value.
|
|
78
|
-
pub fn with_detail(
|
|
79
|
-
|
|
82
|
+
pub fn with_detail(
|
|
83
|
+
code: impl Into<String>,
|
|
84
|
+
message: impl Into<String>,
|
|
85
|
+
detail: ErrorDetail,
|
|
86
|
+
) -> Self {
|
|
87
|
+
BehaviorError {
|
|
88
|
+
code: code.into(),
|
|
89
|
+
message: message.into(),
|
|
90
|
+
detail: Some(Box::new(detail)),
|
|
91
|
+
}
|
|
80
92
|
}
|
|
81
93
|
/// The stable failure code (byte-equal to run_behavior) WITHOUT a bc-runtime type.
|
|
82
94
|
pub fn code(&self) -> &str {
|
|
@@ -106,10 +118,17 @@ function emitErrorHelpers() {
|
|
|
106
118
|
fn op_failed(node: &str, policy: &str, e: BehaviorError) -> BehaviorError {
|
|
107
119
|
// The Kind names itself, and 'retry' says it gave up — the attempts are Runtime-owned (scp-error.md:
|
|
108
120
|
// tuning never enters the IR), so what the plan reports is the exhausted retry.
|
|
109
|
-
let exhausted = if policy == "retry" {
|
|
121
|
+
let exhausted = if policy == "retry" {
|
|
122
|
+
" (exhausted)"
|
|
123
|
+
} else {
|
|
124
|
+
""
|
|
125
|
+
};
|
|
110
126
|
BehaviorError {
|
|
111
127
|
code: "OP_FAILED".to_string(),
|
|
112
|
-
message: format!(
|
|
128
|
+
message: format!(
|
|
129
|
+
"operation '{node}' failed under '{policy}' policy{exhausted}: {}",
|
|
130
|
+
e.message
|
|
131
|
+
),
|
|
113
132
|
detail: e.detail,
|
|
114
133
|
}
|
|
115
134
|
}
|
|
@@ -119,7 +138,13 @@ fn op_failed(node: &str, policy: &str, e: BehaviorError) -> BehaviorError {
|
|
|
119
138
|
// (TYPE_MISMATCH / MISSING_PROP) so the covered read stays equivalent to run_behavior; detail.kind
|
|
120
139
|
// distinguishes typeMismatch / missingField.
|
|
121
140
|
#[allow(dead_code)]
|
|
122
|
-
fn de_type_mismatch(
|
|
141
|
+
fn de_type_mismatch(
|
|
142
|
+
model: &str,
|
|
143
|
+
field: &str,
|
|
144
|
+
expected: &str,
|
|
145
|
+
actual_wire: &str,
|
|
146
|
+
raw: Cow<'static, str>,
|
|
147
|
+
) -> BehaviorError {
|
|
123
148
|
BehaviorError::with_detail(
|
|
124
149
|
"TYPE_MISMATCH",
|
|
125
150
|
format!("node '{model}': {field}: expected {expected}, got {actual_wire}"),
|
|
@@ -231,8 +256,14 @@ function emitRustProbeWireTypes(clone) {
|
|
|
231
256
|
// of the result set and is not forbidden.
|
|
232
257
|
pub enum Probe<T> {
|
|
233
258
|
Got(T),
|
|
234
|
-
Wrong {
|
|
235
|
-
|
|
259
|
+
Wrong {
|
|
260
|
+
actual_wire_type: &'static str,
|
|
261
|
+
raw_value: Cow<'static, str>,
|
|
262
|
+
},
|
|
263
|
+
Null {
|
|
264
|
+
actual_wire_type: &'static str,
|
|
265
|
+
raw_value: Cow<'static, str>,
|
|
266
|
+
},
|
|
236
267
|
Absent,
|
|
237
268
|
}
|
|
238
269
|
|
|
@@ -305,7 +336,10 @@ impl WireRow {
|
|
|
305
336
|
// from being copied: the String travels from the wire into the typed struct without a heap copy.
|
|
306
337
|
// Undeclared extras are simply left behind with the row.
|
|
307
338
|
pub fn take(&mut self, field: &str) -> Option<WireValue> {
|
|
308
|
-
self.entries
|
|
339
|
+
self.entries
|
|
340
|
+
.iter()
|
|
341
|
+
.position(|(k, _)| k == field)
|
|
342
|
+
.map(|i| self.entries.swap_remove(i).1)
|
|
309
343
|
}
|
|
310
344
|
}
|
|
311
345
|
|
|
@@ -316,8 +350,14 @@ pub fn probe_string_at(v: Option<WireValue>) -> Probe<Cow<'static, str>> {
|
|
|
316
350
|
match v {
|
|
317
351
|
None => Probe::Absent,
|
|
318
352
|
Some(WireValue::Str(s)) => Probe::Got(s),
|
|
319
|
-
Some(WireValue::Null) => Probe::Null {
|
|
320
|
-
|
|
353
|
+
Some(WireValue::Null) => Probe::Null {
|
|
354
|
+
actual_wire_type: "NULL",
|
|
355
|
+
raw_value: Cow::Borrowed("null"),
|
|
356
|
+
},
|
|
357
|
+
Some(o) => Probe::Wrong {
|
|
358
|
+
actual_wire_type: o.tag(),
|
|
359
|
+
raw_value: o.into_raw(),
|
|
360
|
+
},
|
|
321
361
|
}
|
|
322
362
|
}
|
|
323
363
|
pub fn probe_int_at(v: Option<WireValue>) -> Probe<i64> {
|
|
@@ -328,9 +368,19 @@ pub fn probe_int_at(v: Option<WireValue>) -> Probe<i64> {
|
|
|
328
368
|
// below. A wire numeric type that spells the same attribute 1 or 1.0 leaves the producer no way to
|
|
329
369
|
// pick the variant. Non-integral, or beyond i64, stays LOUD (an exact conversion with a
|
|
330
370
|
// fail-closed boundary, not a fallback).
|
|
331
|
-
Some(WireValue::Float(f))
|
|
332
|
-
|
|
333
|
-
|
|
371
|
+
Some(WireValue::Float(f))
|
|
372
|
+
if (-9223372036854775808.0..9223372036854775808.0).contains(&f) && f == f.trunc() =>
|
|
373
|
+
{
|
|
374
|
+
Probe::Got(f as i64)
|
|
375
|
+
}
|
|
376
|
+
Some(WireValue::Null) => Probe::Null {
|
|
377
|
+
actual_wire_type: "NULL",
|
|
378
|
+
raw_value: Cow::Borrowed("null"),
|
|
379
|
+
},
|
|
380
|
+
Some(o) => Probe::Wrong {
|
|
381
|
+
actual_wire_type: o.tag(),
|
|
382
|
+
raw_value: o.into_raw(),
|
|
383
|
+
},
|
|
334
384
|
}
|
|
335
385
|
}
|
|
336
386
|
// a float position accepts an int and widens it — the same widening the interpreter's outType check does,
|
|
@@ -340,32 +390,56 @@ pub fn probe_float_at(v: Option<WireValue>) -> Probe<f64> {
|
|
|
340
390
|
None => Probe::Absent,
|
|
341
391
|
Some(WireValue::Float(f)) => Probe::Got(f),
|
|
342
392
|
Some(WireValue::Int(n)) => Probe::Got(n as f64),
|
|
343
|
-
Some(WireValue::Null) => Probe::Null {
|
|
344
|
-
|
|
393
|
+
Some(WireValue::Null) => Probe::Null {
|
|
394
|
+
actual_wire_type: "NULL",
|
|
395
|
+
raw_value: Cow::Borrowed("null"),
|
|
396
|
+
},
|
|
397
|
+
Some(o) => Probe::Wrong {
|
|
398
|
+
actual_wire_type: o.tag(),
|
|
399
|
+
raw_value: o.into_raw(),
|
|
400
|
+
},
|
|
345
401
|
}
|
|
346
402
|
}
|
|
347
403
|
pub fn probe_bool_at(v: Option<WireValue>) -> Probe<bool> {
|
|
348
404
|
match v {
|
|
349
405
|
None => Probe::Absent,
|
|
350
406
|
Some(WireValue::Bool(b)) => Probe::Got(b),
|
|
351
|
-
Some(WireValue::Null) => Probe::Null {
|
|
352
|
-
|
|
407
|
+
Some(WireValue::Null) => Probe::Null {
|
|
408
|
+
actual_wire_type: "NULL",
|
|
409
|
+
raw_value: Cow::Borrowed("null"),
|
|
410
|
+
},
|
|
411
|
+
Some(o) => Probe::Wrong {
|
|
412
|
+
actual_wire_type: o.tag(),
|
|
413
|
+
raw_value: o.into_raw(),
|
|
414
|
+
},
|
|
353
415
|
}
|
|
354
416
|
}
|
|
355
417
|
pub fn probe_row_at(v: Option<WireValue>) -> Probe<WireRow> {
|
|
356
418
|
match v {
|
|
357
419
|
None => Probe::Absent,
|
|
358
420
|
Some(WireValue::Row(r)) => Probe::Got(r),
|
|
359
|
-
Some(WireValue::Null) => Probe::Null {
|
|
360
|
-
|
|
421
|
+
Some(WireValue::Null) => Probe::Null {
|
|
422
|
+
actual_wire_type: "NULL",
|
|
423
|
+
raw_value: Cow::Borrowed("null"),
|
|
424
|
+
},
|
|
425
|
+
Some(o) => Probe::Wrong {
|
|
426
|
+
actual_wire_type: o.tag(),
|
|
427
|
+
raw_value: o.into_raw(),
|
|
428
|
+
},
|
|
361
429
|
}
|
|
362
430
|
}
|
|
363
431
|
pub fn probe_list_at(v: Option<WireValue>) -> Probe<WireList> {
|
|
364
432
|
match v {
|
|
365
433
|
None => Probe::Absent,
|
|
366
434
|
Some(WireValue::List(l)) => Probe::Got(l),
|
|
367
|
-
Some(WireValue::Null) => Probe::Null {
|
|
368
|
-
|
|
435
|
+
Some(WireValue::Null) => Probe::Null {
|
|
436
|
+
actual_wire_type: "NULL",
|
|
437
|
+
raw_value: Cow::Borrowed("null"),
|
|
438
|
+
},
|
|
439
|
+
Some(o) => Probe::Wrong {
|
|
440
|
+
actual_wire_type: o.tag(),
|
|
441
|
+
raw_value: o.into_raw(),
|
|
442
|
+
},
|
|
369
443
|
}
|
|
370
444
|
}`;
|
|
371
445
|
}
|
|
@@ -842,6 +916,14 @@ function makeRustExprBackend(resolveHead, plan, breakLabel) {
|
|
|
842
916
|
// Safe by construction: the gated child / guarded element only runs when the ref is non-null (the None
|
|
843
917
|
// arm is statically unreachable in the proven scope). NOT a default — there is no fallback value.
|
|
844
918
|
narrowUnwrap: (optExpr, _innerRef) => `${optExpr}.unwrap()`,
|
|
919
|
+
// #275: wrap a present inner value in SOME — the pure `Some(<inner>)` (Rust opt is Option<T>). The write
|
|
920
|
+
// twin of optNone; no hoisted stmts (Rust needs no address-of temp, unlike Go's `&_optN`).
|
|
921
|
+
optSome: (innerExpr, _innerTy) => ({ stmts: [], expr: `Some(${innerExpr})` }),
|
|
922
|
+
// #275: carry an opt<S> (Option<S>) through into opt<value> (Option<WireValue>) via `.map`, boxing the
|
|
923
|
+
// PRESENT inner with the ONE box SSoT (renderRustWireBox — the SAME call shape as wireBox) and keeping
|
|
924
|
+
// absent None (absent stays absent — NOT WireValue::Null, which is the required-`value` collapse). `.map`
|
|
925
|
+
// consumes the owned Option (the port access clones/moves it, like narrowUnwrap's `.unwrap()`).
|
|
926
|
+
optMapWireBox: (optExpr, innerRef) => `${optExpr}.map(|__ov| ${renderRustWireBox(buildWirePlan(innerRef, { from: "top" }, { model: "port", field: "port", plan }, "in"), "__ov")})`,
|
|
845
927
|
ternary: (cond, t, e, _ty) => `(if ${rustStripOuterParens(cond)} { ${rustStripOuterParens(t)} } else { ${rustStripOuterParens(e)} })`,
|
|
846
928
|
shortCircuitBool: (op, temp, left, rStmts, rExpr) => {
|
|
847
929
|
// and: let temp = if left { <rStmts> rExpr } else { false }; or: if left { true } else { <rStmts> rExpr }.
|
|
@@ -892,53 +974,84 @@ function rustFloatLitExpr(n) {
|
|
|
892
974
|
* are the LOCAL BehaviorError with the SAME code strings as run_behavior.
|
|
893
975
|
*/
|
|
894
976
|
function emitExprHelpersRust() {
|
|
977
|
+
// rustfmt-canonical (genuine clean, NOT skipped): this helper library is STATIC — its content is fixed and
|
|
978
|
+
// IR-width-INDEPENDENT (byte-equal to expr-eval.ts core), so it is written in the exact form rustfmt
|
|
979
|
+
// produces (verified by running `cargo fmt` to a zero diff). Same treatment as the shared wire seam; the
|
|
980
|
+
// #[rustfmt::skip] surface is reserved for IR-width-dependent items that no fixed template can match.
|
|
895
981
|
return `// ── native-expr runtime-free helper library (#108) — byte-equal to expr-eval.ts core ──
|
|
896
982
|
#[allow(dead_code)]
|
|
897
983
|
fn bc_expr_add_i64(a: i64, b: i64) -> Result<i64, BehaviorError> {
|
|
898
|
-
a.checked_add(b)
|
|
984
|
+
a.checked_add(b)
|
|
985
|
+
.ok_or_else(|| BehaviorError::new("INT_OVERFLOW", "i64 overflow"))
|
|
899
986
|
}
|
|
900
987
|
#[allow(dead_code)]
|
|
901
988
|
fn bc_expr_sub_i64(a: i64, b: i64) -> Result<i64, BehaviorError> {
|
|
902
|
-
a.checked_sub(b)
|
|
989
|
+
a.checked_sub(b)
|
|
990
|
+
.ok_or_else(|| BehaviorError::new("INT_OVERFLOW", "i64 overflow"))
|
|
903
991
|
}
|
|
904
992
|
#[allow(dead_code)]
|
|
905
993
|
fn bc_expr_mul_i64(a: i64, b: i64) -> Result<i64, BehaviorError> {
|
|
906
|
-
a.checked_mul(b)
|
|
994
|
+
a.checked_mul(b)
|
|
995
|
+
.ok_or_else(|| BehaviorError::new("INT_OVERFLOW", "i64 overflow"))
|
|
907
996
|
}
|
|
908
997
|
#[allow(dead_code)]
|
|
909
998
|
fn bc_expr_neg_i64(a: i64) -> Result<i64, BehaviorError> {
|
|
910
|
-
a.checked_neg()
|
|
999
|
+
a.checked_neg()
|
|
1000
|
+
.ok_or_else(|| BehaviorError::new("INT_OVERFLOW", "i64 overflow"))
|
|
911
1001
|
}
|
|
912
1002
|
#[allow(dead_code)]
|
|
913
1003
|
fn bc_expr_check_finite(v: f64) -> Result<f64, BehaviorError> {
|
|
914
|
-
if v.is_finite() {
|
|
1004
|
+
if v.is_finite() {
|
|
1005
|
+
Ok(v)
|
|
1006
|
+
} else {
|
|
1007
|
+
Err(BehaviorError::new("NAN_OR_INF", "non-finite float"))
|
|
1008
|
+
}
|
|
915
1009
|
}
|
|
916
1010
|
#[allow(dead_code)]
|
|
917
|
-
fn bc_expr_add_f(a: f64, b: f64) -> Result<f64, BehaviorError> {
|
|
1011
|
+
fn bc_expr_add_f(a: f64, b: f64) -> Result<f64, BehaviorError> {
|
|
1012
|
+
bc_expr_check_finite(a + b)
|
|
1013
|
+
}
|
|
918
1014
|
#[allow(dead_code)]
|
|
919
|
-
fn bc_expr_sub_f(a: f64, b: f64) -> Result<f64, BehaviorError> {
|
|
1015
|
+
fn bc_expr_sub_f(a: f64, b: f64) -> Result<f64, BehaviorError> {
|
|
1016
|
+
bc_expr_check_finite(a - b)
|
|
1017
|
+
}
|
|
920
1018
|
#[allow(dead_code)]
|
|
921
|
-
fn bc_expr_mul_f(a: f64, b: f64) -> Result<f64, BehaviorError> {
|
|
1019
|
+
fn bc_expr_mul_f(a: f64, b: f64) -> Result<f64, BehaviorError> {
|
|
1020
|
+
bc_expr_check_finite(a * b)
|
|
1021
|
+
}
|
|
922
1022
|
#[allow(dead_code)]
|
|
923
|
-
fn bc_expr_neg_f(a: f64) -> Result<f64, BehaviorError> {
|
|
1023
|
+
fn bc_expr_neg_f(a: f64) -> Result<f64, BehaviorError> {
|
|
1024
|
+
bc_expr_check_finite(-a)
|
|
1025
|
+
}
|
|
924
1026
|
#[allow(dead_code)]
|
|
925
|
-
fn bc_expr_mod_f(a: f64, b: f64) -> Result<f64, BehaviorError> {
|
|
1027
|
+
fn bc_expr_mod_f(a: f64, b: f64) -> Result<f64, BehaviorError> {
|
|
1028
|
+
bc_expr_check_finite(a % b)
|
|
1029
|
+
}
|
|
926
1030
|
#[allow(dead_code)]
|
|
927
1031
|
fn bc_expr_mod_i64(a: i64, b: i64) -> Result<i64, BehaviorError> {
|
|
928
|
-
if b == 0 {
|
|
1032
|
+
if b == 0 {
|
|
1033
|
+
return Err(BehaviorError::new("MOD_ZERO", "int mod by zero"));
|
|
1034
|
+
}
|
|
929
1035
|
// Rust % is truncated (sign of dividend) — matches modCore. MIN % -1 would panic; guard it.
|
|
930
|
-
if a == i64::MIN && b == -1 {
|
|
1036
|
+
if a == i64::MIN && b == -1 {
|
|
1037
|
+
return Ok(0);
|
|
1038
|
+
}
|
|
931
1039
|
Ok(a % b)
|
|
932
1040
|
}
|
|
933
1041
|
#[allow(dead_code)]
|
|
934
1042
|
fn bc_expr_widen_i64f(a: i64) -> Result<f64, BehaviorError> {
|
|
935
1043
|
if !(-9007199254740992..=9007199254740992).contains(&a) {
|
|
936
|
-
return Err(BehaviorError::new(
|
|
1044
|
+
return Err(BehaviorError::new(
|
|
1045
|
+
"PRECISION_LOSS",
|
|
1046
|
+
"int exceeds exact float range (±2^53)",
|
|
1047
|
+
));
|
|
937
1048
|
}
|
|
938
1049
|
Ok(a as f64)
|
|
939
1050
|
}
|
|
940
1051
|
#[allow(dead_code)]
|
|
941
|
-
fn bc_expr_div_f(a: f64, b: f64) -> Result<f64, BehaviorError> {
|
|
1052
|
+
fn bc_expr_div_f(a: f64, b: f64) -> Result<f64, BehaviorError> {
|
|
1053
|
+
bc_expr_check_finite(a / b)
|
|
1054
|
+
}
|
|
942
1055
|
#[allow(dead_code)]
|
|
943
1056
|
fn bc_expr_len_arr<T>(a: &[T]) -> Result<i64, BehaviorError> {
|
|
944
1057
|
i64::try_from(a.len()).map_err(|_| BehaviorError::new("INT_OVERFLOW", "i64 overflow"))
|
|
@@ -955,20 +1068,32 @@ fn bc_expr_cmp_cp(a: &str, b: &str) -> std::cmp::Ordering {
|
|
|
955
1068
|
(Some(_), None) => return std::cmp::Ordering::Greater,
|
|
956
1069
|
(Some(ca), Some(cb)) => {
|
|
957
1070
|
if ca != cb {
|
|
958
|
-
return if (ca as u32) < (cb as u32) {
|
|
1071
|
+
return if (ca as u32) < (cb as u32) {
|
|
1072
|
+
std::cmp::Ordering::Less
|
|
1073
|
+
} else {
|
|
1074
|
+
std::cmp::Ordering::Greater
|
|
1075
|
+
};
|
|
959
1076
|
}
|
|
960
1077
|
}
|
|
961
1078
|
}
|
|
962
1079
|
}
|
|
963
1080
|
}
|
|
964
1081
|
#[allow(dead_code)]
|
|
965
|
-
fn bc_expr_str_lt(a: &str, b: &str) -> bool {
|
|
1082
|
+
fn bc_expr_str_lt(a: &str, b: &str) -> bool {
|
|
1083
|
+
bc_expr_cmp_cp(a, b) == std::cmp::Ordering::Less
|
|
1084
|
+
}
|
|
966
1085
|
#[allow(dead_code)]
|
|
967
|
-
fn bc_expr_str_le(a: &str, b: &str) -> bool {
|
|
1086
|
+
fn bc_expr_str_le(a: &str, b: &str) -> bool {
|
|
1087
|
+
bc_expr_cmp_cp(a, b) != std::cmp::Ordering::Greater
|
|
1088
|
+
}
|
|
968
1089
|
#[allow(dead_code)]
|
|
969
|
-
fn bc_expr_str_gt(a: &str, b: &str) -> bool {
|
|
1090
|
+
fn bc_expr_str_gt(a: &str, b: &str) -> bool {
|
|
1091
|
+
bc_expr_cmp_cp(a, b) == std::cmp::Ordering::Greater
|
|
1092
|
+
}
|
|
970
1093
|
#[allow(dead_code)]
|
|
971
|
-
fn bc_expr_str_ge(a: &str, b: &str) -> bool {
|
|
1094
|
+
fn bc_expr_str_ge(a: &str, b: &str) -> bool {
|
|
1095
|
+
bc_expr_cmp_cp(a, b) != std::cmp::Ordering::Less
|
|
1096
|
+
}`;
|
|
972
1097
|
}
|
|
973
1098
|
/**
|
|
974
1099
|
* boundRustType (change #3 — typed `bound`) — the CONCRETE Rust type of a covered node's `bound` handler
|
|
@@ -2608,7 +2733,10 @@ pub const COMPONENT_NAMES_NATIVE_RAW: [&str; ${names.length}] = [${names.join(",
|
|
|
2608
2733
|
// ── unknown_component helper (self-contained; the module carries no straight-line body) ──
|
|
2609
2734
|
const UNKNOWN_COMPONENT_HELPER = `#[allow(dead_code)]
|
|
2610
2735
|
fn unknown_component(component: &str) -> BehaviorError {
|
|
2611
|
-
BehaviorError::new(
|
|
2736
|
+
BehaviorError::new(
|
|
2737
|
+
"UNKNOWN_COMPONENT",
|
|
2738
|
+
format!("component '{component}' has no handler (fail-closed)"),
|
|
2739
|
+
)
|
|
2612
2740
|
}
|
|
2613
2741
|
|
|
2614
2742
|
// leaf_failure — a failure the LEAF reports (test glue): the runner assigns the node's failure code
|
|
@@ -2645,6 +2773,30 @@ ${emitErrorTypeDefs()}
|
|
|
2645
2773
|
${emitRustProbeWireTypes(true)}
|
|
2646
2774
|
`;
|
|
2647
2775
|
}
|
|
2776
|
+
// #275: BC OWNS the formatting of the covered module. The IR-shaped items — the outType struct decls (their
|
|
2777
|
+
// trailing field comments align width-dependently), their Default impls, the map elem-materializers, the
|
|
2778
|
+
// combined-read runners (payload literals + de-box match arms wrap by width), and the component-names const
|
|
2779
|
+
// (a width-wrapping array) — are assembled from the IR (SQL text, field names, port/entry counts, nesting),
|
|
2780
|
+
// so rustfmt's inline-vs-wrapped choice is width-dependent: there is NO content-independent template form
|
|
2781
|
+
// that is byte-identical to rustfmt for every IR (matching would reimplement rustfmt's line-wrapper), while
|
|
2782
|
+
// `bc check` drift-gates the emitted bytes byte-identical, so a post-hoc rustfmt pass is impossible. The
|
|
2783
|
+
// generator therefore declares `#[rustfmt::skip]` on each such top-level item: `cargo fmt --check` passes on
|
|
2784
|
+
// the bytes as emitted, and clippy stays FULLY enforced (rustfmt::skip is rustfmt-only). It is an OUTER
|
|
2785
|
+
// per-item attribute, NOT the module-level inner `#![rustfmt::skip]`, because the inner form is unstable on
|
|
2786
|
+
// stable rust (E0658 custom_inner_attributes → the covered crate would not compile). The STATIC items (the
|
|
2787
|
+
// wire seam + error type shared byte-for-byte with the genuinely-clean shared wire module, and the fixed
|
|
2788
|
+
// helpers) are NOT skipped — they are byte-fixed and emitted rustfmt-clean, keeping the wire.rs gate real.
|
|
2789
|
+
//
|
|
2790
|
+
// Items in a covered-module section are top-level and blank-line ("\n\n") separated (no runner/decl body
|
|
2791
|
+
// carries an interior blank line — verified across the whole golden corpus), so prepending the attribute to
|
|
2792
|
+
// each blank-line-separated block lands it above that item (any leading doc-comment sits between the
|
|
2793
|
+
// attribute and the item, which rust allows). op-agnostic: every item is covered, not a per-op subset.
|
|
2794
|
+
function withRustfmtSkip(section) {
|
|
2795
|
+
return section
|
|
2796
|
+
.split("\n\n")
|
|
2797
|
+
.map((item) => `#[rustfmt::skip]\n${item}`)
|
|
2798
|
+
.join("\n\n");
|
|
2799
|
+
}
|
|
2648
2800
|
function emit(ctx) {
|
|
2649
2801
|
// bc#97 (increment 2): the SSoT language-agnostic propagation pass derives, PER COMPONENT + PER NODE,
|
|
2650
2802
|
// which handler-call boundaries must be awaited (bottom-up over the declared async terminal handlers).
|
|
@@ -2672,7 +2824,7 @@ function emit(ctx) {
|
|
|
2672
2824
|
// an empty native surface (no covered read) carries no runner and no failure — nothing references
|
|
2673
2825
|
// bc-runtime, so it stays runtime-free (bc#90) with only the component-names const.
|
|
2674
2826
|
return `#![allow(dead_code, unused_imports)]
|
|
2675
|
-
${emitStructSurface([])}
|
|
2827
|
+
${withRustfmtSkip(emitStructSurface([]))}
|
|
2676
2828
|
`;
|
|
2677
2829
|
}
|
|
2678
2830
|
const plan = buildTypePlan(ctx.ir);
|
|
@@ -2783,7 +2935,12 @@ use std::borrow::Cow;
|
|
|
2783
2935
|
use std::cell::RefCell;`;
|
|
2784
2936
|
const sections = [
|
|
2785
2937
|
banner,
|
|
2786
|
-
|
|
2938
|
+
// #275: the leaf-transport `use <mod>::{…}` import is width-variable — its symbol set (and so its line
|
|
2939
|
+
// width) depends on the consumer's leaves, so rustfmt wraps it past max_width and no fixed template is
|
|
2940
|
+
// byte-identical for every consumer. Same class as the IR-shaped covered items → generator-owned
|
|
2941
|
+
// #[rustfmt::skip] (verified valid + warning-free on a `use` item on stable rust). sharedImportBlock is a
|
|
2942
|
+
// single fixed-width glob `use <path>::*;` → always clean, not skipped.
|
|
2943
|
+
importBlock ? withRustfmtSkip(importBlock) : undefined,
|
|
2787
2944
|
sharedImportBlock,
|
|
2788
2945
|
// #165: cross-package puts the concrete failure TYPE in the shared crate (imported via the glob above),
|
|
2789
2946
|
// so the transport crate returns `Result<WireValue, BehaviorError>` without importing the covered crate;
|
|
@@ -2792,8 +2949,8 @@ use std::cell::RefCell;`;
|
|
|
2792
2949
|
crossPackage
|
|
2793
2950
|
? `// De-box / op-failure constructors (produce the shared BehaviorError, imported above). Runtime-free.\n${emitErrorHelpers()}`
|
|
2794
2951
|
: `// Local concrete failure type (runtime-free) — a covered runner returns Result<T, BehaviorError> over\n// THIS local type instead of a bc-runtime failure, so the fully-covered module imports ZERO bc runtime.\n${emitBehaviorErrorType()}`,
|
|
2795
|
-
decls
|
|
2796
|
-
defaults
|
|
2952
|
+
decls ? withRustfmtSkip(decls) : undefined,
|
|
2953
|
+
defaults ? withRustfmtSkip(defaults) : undefined,
|
|
2797
2954
|
UNKNOWN_COMPONENT_HELPER,
|
|
2798
2955
|
rustExprUsed.helpers
|
|
2799
2956
|
? `// #108 native-expr helper library (runtime-free; byte-equal to expr-eval.ts core) — used by\n// cond / map-guard checked arithmetic. NO bc-runtime reference (failures use the LOCAL BehaviorError).\n${emitExprHelpersRust()}`
|
|
@@ -2803,10 +2960,10 @@ use std::cell::RefCell;`;
|
|
|
2803
2960
|
? `// strict de-box wire seam — the BC-OWNED, BC-GENERATED concrete WireValue (+ WireRow/WireList): the\n// consumer's single transport takes a WireRow payload + builds + returns a WireValue, implements NOTHING over\n// it. The generated INLINE de-box classifies it against the STATICALLY declared type and owns strictness\n// (required/optional, present/absent, error assembly, fail-closed). Self-contained concrete types.\n${emitRustProbeWireTypes(true)}`
|
|
2804
2961
|
: undefined,
|
|
2805
2962
|
elemMaterializers.length
|
|
2806
|
-
? `// map augmented-element copiers (pure struct field assignment — no dynamic value read).\n${elemMaterializers.join("\n\n")}`
|
|
2963
|
+
? `// map augmented-element copiers (pure struct field assignment — no dynamic value read).\n${withRustfmtSkip(elemMaterializers.join("\n\n"))}`
|
|
2807
2964
|
: undefined,
|
|
2808
|
-
`// Combined read runners (STRUCT-returning — the fully de-plumbed CONCRETE path).\n${runners}`,
|
|
2809
|
-
structSurface,
|
|
2965
|
+
`// Combined read runners (STRUCT-returning — the fully de-plumbed CONCRETE path).\n${withRustfmtSkip(runners)}`,
|
|
2966
|
+
withRustfmtSkip(structSurface),
|
|
2810
2967
|
];
|
|
2811
2968
|
return `${sections.filter((x) => !!x).join("\n\n")}\n`;
|
|
2812
2969
|
}
|