diff --git a/dag/std/compiler_entry.dag b/dag/std/compiler_entry.dag index 0ff5539baa2..d9f5f5ff78e 100644 --- a/dag/std/compiler_entry.dag +++ b/dag/std/compiler_entry.dag @@ -49,12 +49,14 @@ import std.measure { // executes; its contract is that every universe member reaches exactly one terminal observation, // never a silent remainder. The process re-derives its own exclusive wall partition on stderr // as `[native-cost-partition]` (same receipt shape as claim_batch `[cost-partition]`: exclusive -// load / context / prepare / eval over parent_span_nanos) plus one `[native-prepare]` line per -// unique module and one `[native-prepare-split]` line that partitions prepare into resolve vs -// infer (the two halves native_test_resolve_module / native_test_infer_resolved). The +// load / context / prepare / eval over parent_span_nanos) plus one `[native-prepare-split]` +// line per unique module that partitions prepare into resolve vs infer (the two halves +// native_test_resolve_module / native_test_infer_resolved) and carries decls=. The // `[native-cost-partition]` verdict is native_driver_cost_account over NativeDriverExclusiveRows, -// not a second copy of the reconcile law. Re-run the emitted binary over a universe file to -// re-derive the numbers. +// not a second copy of the reconcile law: remainder_nanos is that fold's residual, and +// OverAttributed carries no remainder field (underflow is not a number). A non-Reconciled +// arm is a process refusal, not a printed string with exit 0. Re-run the emitted binary over +// a universe file to re-derive the numbers. type CompilerEntryDriver = RetainedHostCliKernel @@ -118,3 +120,40 @@ fn native_driver_cost_account( } } } + +// DECLARED FRONTIER (DESIGN §3c) — not a live bind on this head. +// native_driver_cost_row_standing has no executing consumer here: planted witnesses +// prove the fold; they do not exercise the spawn. Consumer: native_lane_runner +// run_native_binary. Route: after the child exits, that spawn reads the relayed +// stderr into NativeDriverChildExited and folds native_driver_cost_row_standing, +// refusing NativeDriverCostRowsUnobserved. Trigger (DESIGN §4b(3) capability, not +// an artifact): the host relays the child's stderr on successful exit +// (native_lane_runner run_native_binary as changed by #10940). Kill condition: if +// that relay lands and this standing is still unread, the row is dangling. Until +// the capability holds, this PR stays off native_lane_runner (deep-cat-655 owns +// it). Observed is [native-cost-partition] after exit; Unobserved is exited +// without that tag; Pending is the child still running. On main, Command::output +// drops the pipe on success (eager-raven-113 #11060 universe receipt: 15508s +// admitted, 3536 verdict rows, zero partition tags in host-captured stderr). The +// relay is exit-gated, not streamed. + +type NativeDriverChildStanding + = NativeDriverChildExited { stderr: String } + | NativeDriverChildStillRunning + +type NativeDriverCostRowStanding + = NativeDriverCostRowsObserved + | NativeDriverCostRowsUnobserved + | NativeDriverCostRowsPending + +fn native_driver_cost_row_standing(child: NativeDriverChildStanding) -> NativeDriverCostRowStanding { + match child { + NativeDriverChildStillRunning => NativeDriverCostRowsPending + NativeDriverChildExited { stderr } => + if string_contains(s: stderr, pattern: "[native-cost-partition] ") { + NativeDriverCostRowsObserved + } else { + NativeDriverCostRowsUnobserved + } + } +} diff --git a/dag/test/claim/native_driver_cost_partition_witness_test.dag b/dag/test/claim/native_driver_cost_partition_witness_test.dag index 156de571022..e13a6971825 100644 --- a/dag/test/claim/native_driver_cost_partition_witness_test.dag +++ b/dag/test/claim/native_driver_cost_partition_witness_test.dag @@ -8,6 +8,12 @@ import std.compiler_entry { NativeDriverCostRemainderExceedsTolerance, native_driver_cost_account, native_driver_cost_remainder_tolerance_nanos, + native_driver_cost_row_standing, + NativeDriverChildExited, + NativeDriverChildStillRunning, + NativeDriverCostRowsObserved, + NativeDriverCostRowsUnobserved, + NativeDriverCostRowsPending, native_driver_exclusive_sum } @@ -75,3 +81,31 @@ test fn a_remainder_past_tolerance_is_not_a_partition() -> Bool { NativeDriverCostOverAttributed { sum_exclusive: _, parent_span: _ } => false } } + +test fn a_completed_capture_with_no_cost_rows_is_unobserved() -> Bool { + match native_driver_cost_row_standing(child: NativeDriverChildExited { stderr: "" }) { + NativeDriverCostRowsUnobserved => true + NativeDriverCostRowsObserved => false + NativeDriverCostRowsPending => false + } +} + +test fn a_planted_partition_line_is_observed() -> Bool { + match native_driver_cost_row_standing( + child: NativeDriverChildExited { + stderr: "[native-cost-partition] {\"verdict\":\"NativeDriverCostReconciled\"}\n" + } + ) { + NativeDriverCostRowsObserved => true + NativeDriverCostRowsUnobserved => false + NativeDriverCostRowsPending => false + } +} + +test fn a_child_that_has_not_exited_is_pending_not_unobserved() -> Bool { + match native_driver_cost_row_standing(child: NativeDriverChildStillRunning) { + NativeDriverCostRowsPending => true + NativeDriverCostRowsObserved => false + NativeDriverCostRowsUnobserved => false + } +} diff --git a/src/v1/05_emit_rust.dag b/src/v1/05_emit_rust.dag index d54c7a3bbd9..5fb2342f6bb 100644 --- a/src/v1/05_emit_rust.dag +++ b/src/v1/05_emit_rust.dag @@ -16971,8 +16971,7 @@ fn emit_source_root_eval_driver_main_rs(crate_name: String, pipeline_module: Str " prepare_infer_nanos += this_infer;\n", " prepare_samples.push(this_prepare);\n", " prepare_ok += 1;\n", - " eprintln!(\"[native-prepare] module=\{dotted\} nanos=\{this_prepare\} decls=\{\} outcome=accepted\", declarations.len());\n", - " eprintln!(\"[native-prepare-split] module=\{dotted\} resolve_nanos=\{this_resolve\} infer_nanos=\{this_infer\} prepare_nanos=\{this_prepare\} outcome=accepted\");\n", + " eprintln!(\"[native-prepare-split] module=\{dotted\} resolve_nanos=\{this_resolve\} infer_nanos=\{this_infer\} prepare_nanos=\{this_prepare\} decls=\{\} outcome=accepted\", declarations.len());\n", " for declaration in declarations {\n", " let eval_start = Instant::now();\n", " let observation = native_test_eval_one(prepared.clone(), declaration.clone());\n", @@ -16991,8 +16990,7 @@ fn emit_source_root_eval_driver_main_rs(crate_name: String, pipeline_module: Str " prepare_infer_nanos += this_infer;\n", " prepare_samples.push(this_prepare);\n", " prepare_refused += 1;\n", - " eprintln!(\"[native-prepare] module=\{dotted\} nanos=\{this_prepare\} decls=\{\} outcome=refused\", declarations.len());\n", - " eprintln!(\"[native-prepare-split] module=\{dotted\} resolve_nanos=\{this_resolve\} infer_nanos=\{this_infer\} prepare_nanos=\{this_prepare\} outcome=infer_refused\");\n", + " eprintln!(\"[native-prepare-split] module=\{dotted\} resolve_nanos=\{this_resolve\} infer_nanos=\{this_infer\} prepare_nanos=\{this_prepare\} decls=\{\} outcome=infer_refused\", declarations.len());\n", " let reason = diagnostics.tail.last().map(|d| d.reason.clone()).unwrap_or_else(|| diagnostics.head.reason.clone());\n", " for declaration in declarations {\n", " let observation = NativeTestObservation {\n", @@ -17016,8 +17014,7 @@ fn emit_source_root_eval_driver_main_rs(crate_name: String, pipeline_module: Str " prepare_resolve_nanos += this_resolve;\n", " prepare_samples.push(this_prepare);\n", " prepare_refused += 1;\n", - " eprintln!(\"[native-prepare] module=\{dotted\} nanos=\{this_prepare\} decls=\{\} outcome=refused\", declarations.len());\n", - " eprintln!(\"[native-prepare-split] module=\{dotted\} resolve_nanos=\{this_resolve\} infer_nanos=0 prepare_nanos=\{this_prepare\} outcome=resolve_refused\");\n", + " eprintln!(\"[native-prepare-split] module=\{dotted\} resolve_nanos=\{this_resolve\} infer_nanos=0 prepare_nanos=\{this_prepare\} decls=\{\} outcome=resolve_refused\", declarations.len());\n", " let reason = diagnostics.tail.last().map(|d| d.reason.clone()).unwrap_or_else(|| diagnostics.head.reason.clone());\n", " for declaration in declarations {\n", " let observation = NativeTestObservation {\n", @@ -17048,7 +17045,6 @@ fn emit_source_root_eval_driver_main_rs(crate_name: String, pipeline_module: Str " eval: nanosecond(native_cost_i64(eval_nanos)),\n", " });\n", " let exclusive_sum = nanosecond_count(native_driver_exclusive_sum(exclusive.clone())) as u128;\n", - " let remainder_nanos = parent_span_nanos.saturating_sub(exclusive_sum);\n", " let shared_nanos = load_nanos + context_nanos;\n", " let shared_per_identity = if identities == 0 { 0 } else { shared_nanos / identities as u128 };\n", " let eval_mean = if eval_samples.is_empty() { 0 } else { eval_nanos / eval_samples.len() as u128 };\n", @@ -17061,14 +17057,14 @@ fn emit_source_root_eval_driver_main_rs(crate_name: String, pipeline_module: Str " nanosecond(native_cost_i64(parent_span_nanos)),\n", " exclusive,\n", " native_driver_cost_remainder_tolerance_nanos(),\n", - " );\n", + " );\n let remainder_nanos = match accounting.as_ref() { NativeDriverCostAccounting::NativeDriverCostOverAttributed \{ .. \} => None, NativeDriverCostAccounting::NativeDriverCostReconciled \{ residual, .. \} | NativeDriverCostAccounting::NativeDriverCostRemainderExceedsTolerance \{ residual, .. \} => Some(nanosecond_count(residual.clone()) as u128) };\n", " let verdict = match accounting.as_ref() {\n", " NativeDriverCostAccounting::NativeDriverCostOverAttributed \{ .. \} => r#\"NativeDriverCostOverAttributed\"#,\n", " NativeDriverCostAccounting::NativeDriverCostRemainderExceedsTolerance \{ .. \} => r#\"NativeDriverCostRemainderExceedsTolerance\"#,\n", " NativeDriverCostAccounting::NativeDriverCostReconciled \{ .. \} => r#\"NativeDriverCostReconciled\"#,\n", " };\n", - " eprintln!(\"[native-cost-partition] {}\", serde_json::json!(\{ \"basis\": \"native_driver_wall\", \"basis_note\": \"single-threaded SourceRootEvalDriver wall; exclusive rows partition parent_span_nanos\", \"producer\": \"std.compiler_entry.SourceRootEvalDriver\", \"verdict\": verdict, \"tolerance_nanos\": tolerance_nanos, \"parent_span_nanos\": parent_span_nanos, \"exclusive\": \{ \"load\": load_nanos, \"context\": context_nanos, \"prepare\": prepare_nanos, \"eval\": eval_nanos \}, \"sum_exclusive_nanos\": exclusive_sum, \"remainder_nanos\": remainder_nanos, \"source_files\": source_files, \"identities\": identities, \"unique_modules\": unique_modules, \"file_refusals\": file_refusals, \"prepare_ok\": prepare_ok, \"prepare_refused\": prepare_refused, \"shared_nanos\": shared_nanos, \"shared_per_identity_nanos\": shared_per_identity, \"prepare_mean_nanos\": prepare_mean, \"prepare_p50_nanos\": native_cost_quantile_nanos(&prepare_samples, 1, 2), \"prepare_p95_nanos\": native_cost_quantile_nanos(&prepare_samples, 19, 20), \"prepare_max_nanos\": prepare_samples.last().copied().unwrap_or(0), \"eval_mean_nanos\": eval_mean, \"eval_p50_nanos\": native_cost_quantile_nanos(&eval_samples, 1, 2), \"eval_p95_nanos\": native_cost_quantile_nanos(&eval_samples, 19, 20), \"eval_max_nanos\": eval_samples.last().copied().unwrap_or(0), \"prepare_share_per_identity_nanos\": prepare_share_per_identity, \"floor_per_identity_nanos\": floor_per_identity, \"mean_decls_per_module\": decls_per_module, \"prepare_resolve_nanos\": prepare_resolve_nanos, \"prepare_infer_nanos\": prepare_infer_nanos \}));\n", - "}\n") + " let mut partition = serde_json::json!(\{ \"basis\": \"native_driver_wall\", \"basis_note\": \"single-threaded SourceRootEvalDriver wall; exclusive rows partition parent_span_nanos\", \"producer\": \"std.compiler_entry.SourceRootEvalDriver\", \"verdict\": verdict, \"tolerance_nanos\": tolerance_nanos, \"parent_span_nanos\": parent_span_nanos, \"exclusive\": \{ \"load\": load_nanos, \"context\": context_nanos, \"prepare\": prepare_nanos, \"eval\": eval_nanos \}, \"sum_exclusive_nanos\": exclusive_sum, \"source_files\": source_files, \"identities\": identities, \"unique_modules\": unique_modules, \"file_refusals\": file_refusals, \"prepare_ok\": prepare_ok, \"prepare_refused\": prepare_refused, \"shared_nanos\": shared_nanos, \"shared_per_identity_nanos\": shared_per_identity, \"prepare_mean_nanos\": prepare_mean, \"prepare_p50_nanos\": native_cost_quantile_nanos(&prepare_samples, 1, 2), \"prepare_p95_nanos\": native_cost_quantile_nanos(&prepare_samples, 19, 20), \"prepare_max_nanos\": prepare_samples.last().copied().unwrap_or(0), \"eval_mean_nanos\": eval_mean, \"eval_p50_nanos\": native_cost_quantile_nanos(&eval_samples, 1, 2), \"eval_p95_nanos\": native_cost_quantile_nanos(&eval_samples, 19, 20), \"eval_max_nanos\": eval_samples.last().copied().unwrap_or(0), \"prepare_share_per_identity_nanos\": prepare_share_per_identity, \"floor_per_identity_nanos\": floor_per_identity, \"mean_decls_per_module\": decls_per_module, \"prepare_resolve_nanos\": prepare_resolve_nanos, \"prepare_infer_nanos\": prepare_infer_nanos \});\n if let Some(r) = remainder_nanos { partition[\"remainder_nanos\"] = serde_json::json!(r); }\n eprintln!(\"[native-cost-partition] {}\", partition);\n", + " match accounting.as_ref() { NativeDriverCostAccounting::NativeDriverCostOverAttributed \{ sum_exclusive, parent_span \} => { eprintln!(\"REFUSED: native driver cost OverAttributed \{\{ sum_exclusive_nanos: \{\}, parent_span_nanos: \{\} \}\}\", nanosecond_count(sum_exclusive.clone()) as u128, nanosecond_count(parent_span.clone()) as u128); std::process::exit(1); } NativeDriverCostAccounting::NativeDriverCostRemainderExceedsTolerance \{ residual, tolerance \} => { eprintln!(\"REFUSED: native driver cost RemainderExceedsTolerance \{\{ residual_nanos: \{\}, tolerance_nanos: \{\} \}\}\", nanosecond_count(residual.clone()) as u128, nanosecond_count(tolerance.clone()) as u128); std::process::exit(1); } NativeDriverCostAccounting::NativeDriverCostReconciled \{ .. \} => {} }\n}\n") } } diff --git a/src/v1/stage0/src/std_compiler_entry.rs b/src/v1/stage0/src/std_compiler_entry.rs index 6a125389d19..1606c68b7f0 100644 --- a/src/v1/stage0/src/std_compiler_entry.rs +++ b/src/v1/stage0/src/std_compiler_entry.rs @@ -2,7 +2,9 @@ // Source module: std.compiler_entry use self::CompilerEntryDriver::*; +use self::NativeDriverChildStanding::*; use self::NativeDriverCostAccounting::*; +use self::NativeDriverCostRowStanding::*; pub use crate::std_measure::Nanosecond; pub use crate::std_measure::{ millisecond, millisecond_to_nanosecond, nanosecond, nanosecond_count, @@ -107,9 +109,61 @@ pub fn native_driver_cost_account( } } +#[derive(Debug, Clone, PartialEq, serde::Serialize, serde::Deserialize)] +#[serde(tag = "_variant")] +pub enum NativeDriverChildStanding { + NativeDriverChildExited { stderr: String }, + NativeDriverChildStillRunning, +} +impl NativeDriverChildStanding { + pub fn stderr(&self) -> String { + match self { + NativeDriverChildStanding::NativeDriverChildExited { stderr: __val, .. } => { + __val.clone() + } + NativeDriverChildStanding::NativeDriverChildStillRunning => { + panic!("no stderr on unit variant") + } + } + } +} + +#[derive( + Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize, +)] +#[serde(tag = "_variant")] +pub enum NativeDriverCostRowStanding { + NativeDriverCostRowsObserved, + NativeDriverCostRowsUnobserved, + NativeDriverCostRowsPending, +} + +pub fn native_driver_cost_row_standing( + child: Rc, +) -> NativeDriverCostRowStanding { + match (*child.clone()).clone() { + NativeDriverChildStanding::NativeDriverChildStillRunning => { + NativeDriverCostRowStanding::NativeDriverCostRowsPending + } + NativeDriverChildStanding::NativeDriverChildExited { stderr: stderr, .. } => { + if v1_rt::string_contains(&stderr, "[native-cost-partition] ".to_string()) { + NativeDriverCostRowStanding::NativeDriverCostRowsObserved + } else { + NativeDriverCostRowStanding::NativeDriverCostRowsUnobserved + } + } + } +} + #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct RetainedHostCliKernel; #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct DirectIngestDriver; #[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] pub struct SourceRootEvalDriver; +#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct NativeDriverCostRowsObserved; +#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct NativeDriverCostRowsUnobserved; +#[derive(Debug, Clone, Copy, PartialEq, Eq, serde::Serialize, serde::Deserialize)] +pub struct NativeDriverCostRowsPending; diff --git a/src/v1/stage0/src/v1_compiler_emit_rust.rs b/src/v1/stage0/src/v1_compiler_emit_rust.rs index 4af53fd3307..4522a9a8d91 100644 --- a/src/v1/stage0/src/v1_compiler_emit_rust.rs +++ b/src/v1/stage0/src/v1_compiler_emit_rust.rs @@ -39236,7 +39236,7 @@ pub fn emit_source_root_eval_driver_main_rs( crate::v1_compiler_emit_core_support::module_to_filename(pipeline_module.clone()); Rc::new(TextFile { path: v1_rt::concat(v1_rt::concat(rust_source_root(), "main".to_string()), rust_source_ext()), - content: v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat("// Generated by v1 compiler -- do not edit.\n\n".to_string(), "#![allow(unused_parens, clippy::all, clippy::disallowed_macros)]\n\n".to_string()), "use std::rc::Rc;\n".to_string()), "use std::time::Instant;\n\n".to_string()), "use ".to_string()), crate_name.clone()), "::extdeps_communication_medium::{DecodeFidelity, Medium};\n".to_string()), "use ".to_string()), crate_name.clone()), "::".to_string()), pipeline_mod.clone()), "::{\n".to_string()), " native_test_context_from_ingest, native_test_eval_one, native_test_infer_resolved,\n".to_string()), " native_test_resolve_module,\n".to_string()), " NativeTestObservation, NativeTestStage, NativeTestVerdict,\n".to_string()), "};\n".to_string()), "use ".to_string()), crate_name.clone()), "::v2_compiler_source_authority::{source_root_for_storage_path, DagSourceReadWitness};\n".to_string()), "use ".to_string()), crate_name.clone()), "::v2_std_artifact::{Artifact, ArtifactKind};\n".to_string()), "use ".to_string()), crate_name.clone()), "::v2_std_diagnostic::Outcome;\n".to_string()), "use ".to_string()), crate_name.clone()), "::std_compiler_entry::{\n".to_string()), " native_driver_cost_account, native_driver_cost_remainder_tolerance_nanos, native_driver_exclusive_sum,\n".to_string()), " NativeDriverCostAccounting, NativeDriverExclusiveRows,\n".to_string()), "};\n".to_string()), "use ".to_string()), crate_name.clone()), "::std_measure::{nanosecond, nanosecond_count};\n".to_string()), "\n".to_string()), "fn collect_dag_paths(dir: &std::path::Path, out: &mut Vec) -> Result<(), String> {\n".to_string()), " let entries = match std::fs::read_dir(dir) {\n".to_string()), " Ok(entries) => entries,\n".to_string()), " Err(cause) => return Err(format!(\"could not walk source root {}: {cause}\", dir.display())),\n".to_string()), " };\n".to_string()), " for entry in entries {\n".to_string()), " let entry = match entry {\n".to_string()), " Ok(entry) => entry,\n".to_string()), " Err(cause) => return Err(format!(\"could not read entry under {}: {cause}\", dir.display())),\n".to_string()), " };\n".to_string()), " let path = entry.path();\n".to_string()), " if path.is_dir() {\n".to_string()), " collect_dag_paths(&path, out)?;\n".to_string()), " } else if path.extension().map(|ext| ext == \"dag\").unwrap_or(false) {\n".to_string()), " out.push(path.to_string_lossy().into_owned());\n".to_string()), " }\n".to_string()), " }\n".to_string()), " Ok(())\n".to_string()), "}\n".to_string()), "\n".to_string()), "fn native_cost_quantile_nanos(sorted: &[u128], numer: usize, denom: usize) -> u128 {\n".to_string()), " if sorted.is_empty() { return 0; }\n".to_string()), " let idx = (sorted.len() - 1) * numer / denom;\n".to_string()), " sorted[idx]\n".to_string()), "}\n".to_string()), "\n".to_string()), "fn native_cost_i64(n: u128) -> i64 {\n".to_string()), " i64::try_from(n).unwrap_or(i64::MAX)\n".to_string()), "}\n".to_string()), "\n".to_string()), "fn main() {\n".to_string()), " let driver_start = Instant::now();\n".to_string()), " let mut args = std::env::args().skip(1);\n".to_string()), " let universe_path = match args.next() {\n".to_string()), " Some(path) => path,\n".to_string()), " None => {\n".to_string()), " eprintln!(\"REFUSED: no universe file given -- usage: ".to_string()), crate_name.clone()), " ...\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " };\n".to_string()), " let source_roots: Vec = args.collect();\n".to_string()), " if source_roots.is_empty() {\n".to_string()), " eprintln!(\"REFUSED: no source roots given -- usage: ".to_string()), crate_name.clone()), " ...\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " let universe_text = match std::fs::read_to_string(&universe_path) {\n".to_string()), " Ok(text) => text,\n".to_string()), " Err(cause) => {\n".to_string()), " eprintln!(\"REFUSED: could not read universe file {universe_path}: {cause}\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " };\n".to_string()), " let mut universe: Vec<(Rc>, String)> = Vec::new();\n".to_string()), " let mut seen: std::collections::HashSet = std::collections::HashSet::new();\n".to_string()), " for line in universe_text.lines() {\n".to_string()), " if line.is_empty() || line.starts_with('#') {\n".to_string()), " continue;\n".to_string()), " }\n".to_string()), " match line.split_once('\\t') {\n".to_string()), " Some((module, declaration)) if !module.is_empty() && !declaration.is_empty() => {\n".to_string()), " if !seen.insert(line.to_string()) {\n".to_string()), " eprintln!(\"REFUSED: duplicate universe line: {line}\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " universe.push((\n".to_string()), " Rc::new(module.split('.').map(|segment| segment.to_string()).collect::>()),\n".to_string()), " declaration.to_string(),\n".to_string()), " ));\n".to_string()), " }\n".to_string()), " _ => {\n".to_string()), " eprintln!(\"REFUSED: malformed universe line (expected moduledeclaration): {line}\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " }\n".to_string()), " }\n".to_string()), " if universe.is_empty() {\n".to_string()), " eprintln!(\"REFUSED: universe file {universe_path} carried no test identities\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " let load_start = Instant::now();\n".to_string()), " let mut paths: Vec = Vec::new();\n".to_string()), " for root in &source_roots {\n".to_string()), " if let Err(cause) = collect_dag_paths(std::path::Path::new(root), &mut paths) {\n".to_string()), " eprintln!(\"REFUSED: {cause}\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " }\n".to_string()), " paths.sort();\n".to_string()), " let mut reads: Vec> = Vec::new();\n".to_string()), " for path in &paths {\n".to_string()), " let text = match std::fs::read_to_string(path) {\n".to_string()), " Ok(text) => text,\n".to_string()), " Err(cause) => {\n".to_string()), " eprintln!(\"REFUSED: could not read {path}: {cause}\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " };\n".to_string()), " reads.push(Rc::new(DagSourceReadWitness {\n".to_string()), " source: Rc::new(Medium {\n".to_string()), " carried: text,\n".to_string()), " fidelity: DecodeFidelity::Lossless,\n".to_string()), " _phantom: std::marker::PhantomData,\n".to_string()), " }),\n".to_string()), " artifact: Rc::new(Artifact {\n".to_string()), " kind: ArtifactKind::SourceFile,\n".to_string()), " id: path.clone(),\n".to_string()), " file_path: path.clone(),\n".to_string()), " }),\n".to_string()), " compilation_unit: path.clone(),\n".to_string()), " source_root: source_root_for_storage_path(path.clone()),\n".to_string()), " }));\n".to_string()), " }\n".to_string()), " let source_files = paths.len() as u64;\n".to_string()), " let load_nanos = load_start.elapsed().as_nanos();\n".to_string()), " let context_start = Instant::now();\n".to_string()), " let context = match &*native_test_context_from_ingest(Rc::new(reads.into())) {\n".to_string()), " Outcome::Accepted { value, .. } => value.clone(),\n".to_string()), " Outcome::Rejected { diagnostics } => {\n".to_string()), " eprintln!(\"CONTEXT-REFUSED: {diagnostics:#?}\");\n".to_string()), " std::process::exit(1);\n".to_string()), " }\n".to_string()), " };\n".to_string()), " let context_nanos = context_start.elapsed().as_nanos();\n".to_string()), " eprintln!(\"[native-cost-shared] {}\", serde_json::json!({ \"producer\": \"std.compiler_entry.SourceRootEvalDriver\", \"source_files\": source_files, \"load_nanos\": load_nanos, \"context_nanos\": context_nanos, \"file_refusals\": context.file_refusals.len() }));\n".to_string()), " for refusal in context.file_refusals.iter() {\n".to_string()), " println!(\"{}\", serde_json::json!({ \"file_refusal\": refusal }));\n".to_string()), " }\n".to_string()), " let mut module_order: Vec<(String, Rc>)> = Vec::new();\n".to_string()), " let mut module_decls: std::collections::HashMap> = std::collections::HashMap::new();\n".to_string()), " for (qn, declaration) in &universe {\n".to_string()), " let dotted = qn.iter().cloned().collect::>().join(\".\");\n".to_string()), " if !module_decls.contains_key(&dotted) {\n".to_string()), " module_order.push((dotted.clone(), qn.clone()));\n".to_string()), " module_decls.insert(dotted.clone(), Vec::new());\n".to_string()), " }\n".to_string()), " module_decls.get_mut(&dotted).unwrap().push(declaration.clone());\n".to_string()), " }\n".to_string()), " let mut rows: u64 = 0;\n".to_string()), " let mut prepare_nanos: u128 = 0;\n".to_string()), " let mut eval_nanos: u128 = 0;\n".to_string()), " let mut prepare_ok: u64 = 0;\n".to_string()), " let mut prepare_refused: u64 = 0;\n".to_string()), " let mut prepare_samples: Vec = Vec::new();\n".to_string()), " let mut eval_samples: Vec = Vec::new();\n".to_string()), " let mut prepare_resolve_nanos: u128 = 0;\n".to_string()), " let mut prepare_infer_nanos: u128 = 0;\n".to_string()), " for (dotted, qn) in &module_order {\n".to_string()), " let declarations = &module_decls[dotted];\n".to_string()), " let prepare_start = Instant::now();\n".to_string()), " let resolve_start = Instant::now();\n".to_string()), " match &*native_test_resolve_module(context.clone(), qn.clone()) {\n".to_string()), " Outcome::Accepted { value: resolved, .. } => {\n".to_string()), " let this_resolve = resolve_start.elapsed().as_nanos();\n".to_string()), " let infer_start = Instant::now();\n".to_string()), " match &*native_test_infer_resolved(qn.clone(), resolved.clone()) {\n".to_string()), " Outcome::Accepted { value: prepared, .. } => {\n".to_string()), " let this_infer = infer_start.elapsed().as_nanos();\n".to_string()), " let this_prepare = prepare_start.elapsed().as_nanos();\n".to_string()), " prepare_nanos += this_prepare;\n".to_string()), " prepare_resolve_nanos += this_resolve;\n".to_string()), " prepare_infer_nanos += this_infer;\n".to_string()), " prepare_samples.push(this_prepare);\n".to_string()), " prepare_ok += 1;\n".to_string()), " eprintln!(\"[native-prepare] module={dotted} nanos={this_prepare} decls={} outcome=accepted\", declarations.len());\n".to_string()), " eprintln!(\"[native-prepare-split] module={dotted} resolve_nanos={this_resolve} infer_nanos={this_infer} prepare_nanos={this_prepare} outcome=accepted\");\n".to_string()), " for declaration in declarations {\n".to_string()), " let eval_start = Instant::now();\n".to_string()), " let observation = native_test_eval_one(prepared.clone(), declaration.clone());\n".to_string()), " let this_eval = eval_start.elapsed().as_nanos();\n".to_string()), " eval_nanos += this_eval;\n".to_string()), " eval_samples.push(this_eval);\n".to_string()), " println!(\"{}\", serde_json::to_string(&observation).unwrap());\n".to_string()), " rows += 1;\n".to_string()), " }\n".to_string()), " }\n".to_string()), " Outcome::Rejected { diagnostics } => {\n".to_string()), " let this_infer = infer_start.elapsed().as_nanos();\n".to_string()), " let this_prepare = prepare_start.elapsed().as_nanos();\n".to_string()), " prepare_nanos += this_prepare;\n".to_string()), " prepare_resolve_nanos += this_resolve;\n".to_string()), " prepare_infer_nanos += this_infer;\n".to_string()), " prepare_samples.push(this_prepare);\n".to_string()), " prepare_refused += 1;\n".to_string()), " eprintln!(\"[native-prepare] module={dotted} nanos={this_prepare} decls={} outcome=refused\", declarations.len());\n".to_string()), " eprintln!(\"[native-prepare-split] module={dotted} resolve_nanos={this_resolve} infer_nanos={this_infer} prepare_nanos={this_prepare} outcome=infer_refused\");\n".to_string()), " let reason = diagnostics.tail.last().map(|d| d.reason.clone()).unwrap_or_else(|| diagnostics.head.reason.clone());\n".to_string()), " for declaration in declarations {\n".to_string()), " let observation = NativeTestObservation {\n".to_string()), " module: qn.clone(),\n".to_string()), " declaration: declaration.clone(),\n".to_string()), " verdict: Rc::new(NativeTestVerdict::NativeTestRefused {\n".to_string()), " stage: NativeTestStage::NativeTestStagePrepare,\n".to_string()), " reason: reason.clone(),\n".to_string()), " }),\n".to_string()), " };\n".to_string()), " println!(\"{}\", serde_json::to_string(&observation).unwrap());\n".to_string()), " rows += 1;\n".to_string()), " }\n".to_string()), " }\n".to_string()), " }\n".to_string()), " }\n".to_string()), " Outcome::Rejected { diagnostics } => {\n".to_string()), " let this_resolve = resolve_start.elapsed().as_nanos();\n".to_string()), " let this_prepare = prepare_start.elapsed().as_nanos();\n".to_string()), " prepare_nanos += this_prepare;\n".to_string()), " prepare_resolve_nanos += this_resolve;\n".to_string()), " prepare_samples.push(this_prepare);\n".to_string()), " prepare_refused += 1;\n".to_string()), " eprintln!(\"[native-prepare] module={dotted} nanos={this_prepare} decls={} outcome=refused\", declarations.len());\n".to_string()), " eprintln!(\"[native-prepare-split] module={dotted} resolve_nanos={this_resolve} infer_nanos=0 prepare_nanos={this_prepare} outcome=resolve_refused\");\n".to_string()), " let reason = diagnostics.tail.last().map(|d| d.reason.clone()).unwrap_or_else(|| diagnostics.head.reason.clone());\n".to_string()), " for declaration in declarations {\n".to_string()), " let observation = NativeTestObservation {\n".to_string()), " module: qn.clone(),\n".to_string()), " declaration: declaration.clone(),\n".to_string()), " verdict: Rc::new(NativeTestVerdict::NativeTestRefused {\n".to_string()), " stage: NativeTestStage::NativeTestStagePrepare,\n".to_string()), " reason: reason.clone(),\n".to_string()), " }),\n".to_string()), " };\n".to_string()), " println!(\"{}\", serde_json::to_string(&observation).unwrap());\n".to_string()), " rows += 1;\n".to_string()), " }\n".to_string()), " }\n".to_string()), " }\n".to_string()), " }\n".to_string()), " println!(\"{}\", serde_json::json!({ \"_terminal\": \"complete\", \"rows\": rows, \"file_refusals\": context.file_refusals.len() }));\n".to_string()), " let file_refusals = context.file_refusals.len() as u64;\n".to_string()), " prepare_samples.sort_unstable();\n".to_string()), " eval_samples.sort_unstable();\n".to_string()), " let parent_span_nanos = driver_start.elapsed().as_nanos();\n".to_string()), " let identities = universe.len() as u64;\n".to_string()), " let unique_modules = module_order.len() as u64;\n".to_string()), " let exclusive = Rc::new(NativeDriverExclusiveRows {\n".to_string()), " load: nanosecond(native_cost_i64(load_nanos)),\n".to_string()), " context: nanosecond(native_cost_i64(context_nanos)),\n".to_string()), " prepare: nanosecond(native_cost_i64(prepare_nanos)),\n".to_string()), " eval: nanosecond(native_cost_i64(eval_nanos)),\n".to_string()), " });\n".to_string()), " let exclusive_sum = nanosecond_count(native_driver_exclusive_sum(exclusive.clone())) as u128;\n".to_string()), " let remainder_nanos = parent_span_nanos.saturating_sub(exclusive_sum);\n".to_string()), " let shared_nanos = load_nanos + context_nanos;\n".to_string()), " let shared_per_identity = if identities == 0 { 0 } else { shared_nanos / identities as u128 };\n".to_string()), " let eval_mean = if eval_samples.is_empty() { 0 } else { eval_nanos / eval_samples.len() as u128 };\n".to_string()), " let prepare_mean = if prepare_samples.is_empty() { 0 } else { prepare_nanos / prepare_samples.len() as u128 };\n".to_string()), " let decls_per_module = if unique_modules == 0 { 0 } else { identities / unique_modules };\n".to_string()), " let prepare_share_per_identity = if identities == 0 { 0 } else { prepare_nanos / identities as u128 };\n".to_string()), " let floor_per_identity = eval_mean + prepare_share_per_identity;\n".to_string()), " let tolerance_nanos = nanosecond_count(native_driver_cost_remainder_tolerance_nanos()) as u128;\n".to_string()), " let accounting = native_driver_cost_account(\n".to_string()), " nanosecond(native_cost_i64(parent_span_nanos)),\n".to_string()), " exclusive,\n".to_string()), " native_driver_cost_remainder_tolerance_nanos(),\n".to_string()), " );\n".to_string()), " let verdict = match accounting.as_ref() {\n".to_string()), " NativeDriverCostAccounting::NativeDriverCostOverAttributed { .. } => r#\"NativeDriverCostOverAttributed\"#,\n".to_string()), " NativeDriverCostAccounting::NativeDriverCostRemainderExceedsTolerance { .. } => r#\"NativeDriverCostRemainderExceedsTolerance\"#,\n".to_string()), " NativeDriverCostAccounting::NativeDriverCostReconciled { .. } => r#\"NativeDriverCostReconciled\"#,\n".to_string()), " };\n".to_string()), " eprintln!(\"[native-cost-partition] {}\", serde_json::json!({ \"basis\": \"native_driver_wall\", \"basis_note\": \"single-threaded SourceRootEvalDriver wall; exclusive rows partition parent_span_nanos\", \"producer\": \"std.compiler_entry.SourceRootEvalDriver\", \"verdict\": verdict, \"tolerance_nanos\": tolerance_nanos, \"parent_span_nanos\": parent_span_nanos, \"exclusive\": { \"load\": load_nanos, \"context\": context_nanos, \"prepare\": prepare_nanos, \"eval\": eval_nanos }, \"sum_exclusive_nanos\": exclusive_sum, \"remainder_nanos\": remainder_nanos, \"source_files\": source_files, \"identities\": identities, \"unique_modules\": unique_modules, \"file_refusals\": file_refusals, \"prepare_ok\": prepare_ok, \"prepare_refused\": prepare_refused, \"shared_nanos\": shared_nanos, \"shared_per_identity_nanos\": shared_per_identity, \"prepare_mean_nanos\": prepare_mean, \"prepare_p50_nanos\": native_cost_quantile_nanos(&prepare_samples, 1, 2), \"prepare_p95_nanos\": native_cost_quantile_nanos(&prepare_samples, 19, 20), \"prepare_max_nanos\": prepare_samples.last().copied().unwrap_or(0), \"eval_mean_nanos\": eval_mean, \"eval_p50_nanos\": native_cost_quantile_nanos(&eval_samples, 1, 2), \"eval_p95_nanos\": native_cost_quantile_nanos(&eval_samples, 19, 20), \"eval_max_nanos\": eval_samples.last().copied().unwrap_or(0), \"prepare_share_per_identity_nanos\": prepare_share_per_identity, \"floor_per_identity_nanos\": floor_per_identity, \"mean_decls_per_module\": decls_per_module, \"prepare_resolve_nanos\": prepare_resolve_nanos, \"prepare_infer_nanos\": prepare_infer_nanos }));\n".to_string()), "}\n".to_string()), + content: v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat(v1_rt::concat("// Generated by v1 compiler -- do not edit.\n\n".to_string(), "#![allow(unused_parens, clippy::all, clippy::disallowed_macros)]\n\n".to_string()), "use std::rc::Rc;\n".to_string()), "use std::time::Instant;\n\n".to_string()), "use ".to_string()), crate_name.clone()), "::extdeps_communication_medium::{DecodeFidelity, Medium};\n".to_string()), "use ".to_string()), crate_name.clone()), "::".to_string()), pipeline_mod.clone()), "::{\n".to_string()), " native_test_context_from_ingest, native_test_eval_one, native_test_infer_resolved,\n".to_string()), " native_test_resolve_module,\n".to_string()), " NativeTestObservation, NativeTestStage, NativeTestVerdict,\n".to_string()), "};\n".to_string()), "use ".to_string()), crate_name.clone()), "::v2_compiler_source_authority::{source_root_for_storage_path, DagSourceReadWitness};\n".to_string()), "use ".to_string()), crate_name.clone()), "::v2_std_artifact::{Artifact, ArtifactKind};\n".to_string()), "use ".to_string()), crate_name.clone()), "::v2_std_diagnostic::Outcome;\n".to_string()), "use ".to_string()), crate_name.clone()), "::std_compiler_entry::{\n".to_string()), " native_driver_cost_account, native_driver_cost_remainder_tolerance_nanos, native_driver_exclusive_sum,\n".to_string()), " NativeDriverCostAccounting, NativeDriverExclusiveRows,\n".to_string()), "};\n".to_string()), "use ".to_string()), crate_name.clone()), "::std_measure::{nanosecond, nanosecond_count};\n".to_string()), "\n".to_string()), "fn collect_dag_paths(dir: &std::path::Path, out: &mut Vec) -> Result<(), String> {\n".to_string()), " let entries = match std::fs::read_dir(dir) {\n".to_string()), " Ok(entries) => entries,\n".to_string()), " Err(cause) => return Err(format!(\"could not walk source root {}: {cause}\", dir.display())),\n".to_string()), " };\n".to_string()), " for entry in entries {\n".to_string()), " let entry = match entry {\n".to_string()), " Ok(entry) => entry,\n".to_string()), " Err(cause) => return Err(format!(\"could not read entry under {}: {cause}\", dir.display())),\n".to_string()), " };\n".to_string()), " let path = entry.path();\n".to_string()), " if path.is_dir() {\n".to_string()), " collect_dag_paths(&path, out)?;\n".to_string()), " } else if path.extension().map(|ext| ext == \"dag\").unwrap_or(false) {\n".to_string()), " out.push(path.to_string_lossy().into_owned());\n".to_string()), " }\n".to_string()), " }\n".to_string()), " Ok(())\n".to_string()), "}\n".to_string()), "\n".to_string()), "fn native_cost_quantile_nanos(sorted: &[u128], numer: usize, denom: usize) -> u128 {\n".to_string()), " if sorted.is_empty() { return 0; }\n".to_string()), " let idx = (sorted.len() - 1) * numer / denom;\n".to_string()), " sorted[idx]\n".to_string()), "}\n".to_string()), "\n".to_string()), "fn native_cost_i64(n: u128) -> i64 {\n".to_string()), " i64::try_from(n).unwrap_or(i64::MAX)\n".to_string()), "}\n".to_string()), "\n".to_string()), "fn main() {\n".to_string()), " let driver_start = Instant::now();\n".to_string()), " let mut args = std::env::args().skip(1);\n".to_string()), " let universe_path = match args.next() {\n".to_string()), " Some(path) => path,\n".to_string()), " None => {\n".to_string()), " eprintln!(\"REFUSED: no universe file given -- usage: ".to_string()), crate_name.clone()), " ...\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " };\n".to_string()), " let source_roots: Vec = args.collect();\n".to_string()), " if source_roots.is_empty() {\n".to_string()), " eprintln!(\"REFUSED: no source roots given -- usage: ".to_string()), crate_name.clone()), " ...\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " let universe_text = match std::fs::read_to_string(&universe_path) {\n".to_string()), " Ok(text) => text,\n".to_string()), " Err(cause) => {\n".to_string()), " eprintln!(\"REFUSED: could not read universe file {universe_path}: {cause}\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " };\n".to_string()), " let mut universe: Vec<(Rc>, String)> = Vec::new();\n".to_string()), " let mut seen: std::collections::HashSet = std::collections::HashSet::new();\n".to_string()), " for line in universe_text.lines() {\n".to_string()), " if line.is_empty() || line.starts_with('#') {\n".to_string()), " continue;\n".to_string()), " }\n".to_string()), " match line.split_once('\\t') {\n".to_string()), " Some((module, declaration)) if !module.is_empty() && !declaration.is_empty() => {\n".to_string()), " if !seen.insert(line.to_string()) {\n".to_string()), " eprintln!(\"REFUSED: duplicate universe line: {line}\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " universe.push((\n".to_string()), " Rc::new(module.split('.').map(|segment| segment.to_string()).collect::>()),\n".to_string()), " declaration.to_string(),\n".to_string()), " ));\n".to_string()), " }\n".to_string()), " _ => {\n".to_string()), " eprintln!(\"REFUSED: malformed universe line (expected moduledeclaration): {line}\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " }\n".to_string()), " }\n".to_string()), " if universe.is_empty() {\n".to_string()), " eprintln!(\"REFUSED: universe file {universe_path} carried no test identities\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " let load_start = Instant::now();\n".to_string()), " let mut paths: Vec = Vec::new();\n".to_string()), " for root in &source_roots {\n".to_string()), " if let Err(cause) = collect_dag_paths(std::path::Path::new(root), &mut paths) {\n".to_string()), " eprintln!(\"REFUSED: {cause}\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " }\n".to_string()), " paths.sort();\n".to_string()), " let mut reads: Vec> = Vec::new();\n".to_string()), " for path in &paths {\n".to_string()), " let text = match std::fs::read_to_string(path) {\n".to_string()), " Ok(text) => text,\n".to_string()), " Err(cause) => {\n".to_string()), " eprintln!(\"REFUSED: could not read {path}: {cause}\");\n".to_string()), " std::process::exit(2);\n".to_string()), " }\n".to_string()), " };\n".to_string()), " reads.push(Rc::new(DagSourceReadWitness {\n".to_string()), " source: Rc::new(Medium {\n".to_string()), " carried: text,\n".to_string()), " fidelity: DecodeFidelity::Lossless,\n".to_string()), " _phantom: std::marker::PhantomData,\n".to_string()), " }),\n".to_string()), " artifact: Rc::new(Artifact {\n".to_string()), " kind: ArtifactKind::SourceFile,\n".to_string()), " id: path.clone(),\n".to_string()), " file_path: path.clone(),\n".to_string()), " }),\n".to_string()), " compilation_unit: path.clone(),\n".to_string()), " source_root: source_root_for_storage_path(path.clone()),\n".to_string()), " }));\n".to_string()), " }\n".to_string()), " let source_files = paths.len() as u64;\n".to_string()), " let load_nanos = load_start.elapsed().as_nanos();\n".to_string()), " let context_start = Instant::now();\n".to_string()), " let context = match &*native_test_context_from_ingest(Rc::new(reads.into())) {\n".to_string()), " Outcome::Accepted { value, .. } => value.clone(),\n".to_string()), " Outcome::Rejected { diagnostics } => {\n".to_string()), " eprintln!(\"CONTEXT-REFUSED: {diagnostics:#?}\");\n".to_string()), " std::process::exit(1);\n".to_string()), " }\n".to_string()), " };\n".to_string()), " let context_nanos = context_start.elapsed().as_nanos();\n".to_string()), " eprintln!(\"[native-cost-shared] {}\", serde_json::json!({ \"producer\": \"std.compiler_entry.SourceRootEvalDriver\", \"source_files\": source_files, \"load_nanos\": load_nanos, \"context_nanos\": context_nanos, \"file_refusals\": context.file_refusals.len() }));\n".to_string()), " for refusal in context.file_refusals.iter() {\n".to_string()), " println!(\"{}\", serde_json::json!({ \"file_refusal\": refusal }));\n".to_string()), " }\n".to_string()), " let mut module_order: Vec<(String, Rc>)> = Vec::new();\n".to_string()), " let mut module_decls: std::collections::HashMap> = std::collections::HashMap::new();\n".to_string()), " for (qn, declaration) in &universe {\n".to_string()), " let dotted = qn.iter().cloned().collect::>().join(\".\");\n".to_string()), " if !module_decls.contains_key(&dotted) {\n".to_string()), " module_order.push((dotted.clone(), qn.clone()));\n".to_string()), " module_decls.insert(dotted.clone(), Vec::new());\n".to_string()), " }\n".to_string()), " module_decls.get_mut(&dotted).unwrap().push(declaration.clone());\n".to_string()), " }\n".to_string()), " let mut rows: u64 = 0;\n".to_string()), " let mut prepare_nanos: u128 = 0;\n".to_string()), " let mut eval_nanos: u128 = 0;\n".to_string()), " let mut prepare_ok: u64 = 0;\n".to_string()), " let mut prepare_refused: u64 = 0;\n".to_string()), " let mut prepare_samples: Vec = Vec::new();\n".to_string()), " let mut eval_samples: Vec = Vec::new();\n".to_string()), " let mut prepare_resolve_nanos: u128 = 0;\n".to_string()), " let mut prepare_infer_nanos: u128 = 0;\n".to_string()), " for (dotted, qn) in &module_order {\n".to_string()), " let declarations = &module_decls[dotted];\n".to_string()), " let prepare_start = Instant::now();\n".to_string()), " let resolve_start = Instant::now();\n".to_string()), " match &*native_test_resolve_module(context.clone(), qn.clone()) {\n".to_string()), " Outcome::Accepted { value: resolved, .. } => {\n".to_string()), " let this_resolve = resolve_start.elapsed().as_nanos();\n".to_string()), " let infer_start = Instant::now();\n".to_string()), " match &*native_test_infer_resolved(qn.clone(), resolved.clone()) {\n".to_string()), " Outcome::Accepted { value: prepared, .. } => {\n".to_string()), " let this_infer = infer_start.elapsed().as_nanos();\n".to_string()), " let this_prepare = prepare_start.elapsed().as_nanos();\n".to_string()), " prepare_nanos += this_prepare;\n".to_string()), " prepare_resolve_nanos += this_resolve;\n".to_string()), " prepare_infer_nanos += this_infer;\n".to_string()), " prepare_samples.push(this_prepare);\n".to_string()), " prepare_ok += 1;\n".to_string()), " eprintln!(\"[native-prepare-split] module={dotted} resolve_nanos={this_resolve} infer_nanos={this_infer} prepare_nanos={this_prepare} decls={} outcome=accepted\", declarations.len());\n".to_string()), " for declaration in declarations {\n".to_string()), " let eval_start = Instant::now();\n".to_string()), " let observation = native_test_eval_one(prepared.clone(), declaration.clone());\n".to_string()), " let this_eval = eval_start.elapsed().as_nanos();\n".to_string()), " eval_nanos += this_eval;\n".to_string()), " eval_samples.push(this_eval);\n".to_string()), " println!(\"{}\", serde_json::to_string(&observation).unwrap());\n".to_string()), " rows += 1;\n".to_string()), " }\n".to_string()), " }\n".to_string()), " Outcome::Rejected { diagnostics } => {\n".to_string()), " let this_infer = infer_start.elapsed().as_nanos();\n".to_string()), " let this_prepare = prepare_start.elapsed().as_nanos();\n".to_string()), " prepare_nanos += this_prepare;\n".to_string()), " prepare_resolve_nanos += this_resolve;\n".to_string()), " prepare_infer_nanos += this_infer;\n".to_string()), " prepare_samples.push(this_prepare);\n".to_string()), " prepare_refused += 1;\n".to_string()), " eprintln!(\"[native-prepare-split] module={dotted} resolve_nanos={this_resolve} infer_nanos={this_infer} prepare_nanos={this_prepare} decls={} outcome=infer_refused\", declarations.len());\n".to_string()), " let reason = diagnostics.tail.last().map(|d| d.reason.clone()).unwrap_or_else(|| diagnostics.head.reason.clone());\n".to_string()), " for declaration in declarations {\n".to_string()), " let observation = NativeTestObservation {\n".to_string()), " module: qn.clone(),\n".to_string()), " declaration: declaration.clone(),\n".to_string()), " verdict: Rc::new(NativeTestVerdict::NativeTestRefused {\n".to_string()), " stage: NativeTestStage::NativeTestStagePrepare,\n".to_string()), " reason: reason.clone(),\n".to_string()), " }),\n".to_string()), " };\n".to_string()), " println!(\"{}\", serde_json::to_string(&observation).unwrap());\n".to_string()), " rows += 1;\n".to_string()), " }\n".to_string()), " }\n".to_string()), " }\n".to_string()), " }\n".to_string()), " Outcome::Rejected { diagnostics } => {\n".to_string()), " let this_resolve = resolve_start.elapsed().as_nanos();\n".to_string()), " let this_prepare = prepare_start.elapsed().as_nanos();\n".to_string()), " prepare_nanos += this_prepare;\n".to_string()), " prepare_resolve_nanos += this_resolve;\n".to_string()), " prepare_samples.push(this_prepare);\n".to_string()), " prepare_refused += 1;\n".to_string()), " eprintln!(\"[native-prepare-split] module={dotted} resolve_nanos={this_resolve} infer_nanos=0 prepare_nanos={this_prepare} decls={} outcome=resolve_refused\", declarations.len());\n".to_string()), " let reason = diagnostics.tail.last().map(|d| d.reason.clone()).unwrap_or_else(|| diagnostics.head.reason.clone());\n".to_string()), " for declaration in declarations {\n".to_string()), " let observation = NativeTestObservation {\n".to_string()), " module: qn.clone(),\n".to_string()), " declaration: declaration.clone(),\n".to_string()), " verdict: Rc::new(NativeTestVerdict::NativeTestRefused {\n".to_string()), " stage: NativeTestStage::NativeTestStagePrepare,\n".to_string()), " reason: reason.clone(),\n".to_string()), " }),\n".to_string()), " };\n".to_string()), " println!(\"{}\", serde_json::to_string(&observation).unwrap());\n".to_string()), " rows += 1;\n".to_string()), " }\n".to_string()), " }\n".to_string()), " }\n".to_string()), " }\n".to_string()), " println!(\"{}\", serde_json::json!({ \"_terminal\": \"complete\", \"rows\": rows, \"file_refusals\": context.file_refusals.len() }));\n".to_string()), " let file_refusals = context.file_refusals.len() as u64;\n".to_string()), " prepare_samples.sort_unstable();\n".to_string()), " eval_samples.sort_unstable();\n".to_string()), " let parent_span_nanos = driver_start.elapsed().as_nanos();\n".to_string()), " let identities = universe.len() as u64;\n".to_string()), " let unique_modules = module_order.len() as u64;\n".to_string()), " let exclusive = Rc::new(NativeDriverExclusiveRows {\n".to_string()), " load: nanosecond(native_cost_i64(load_nanos)),\n".to_string()), " context: nanosecond(native_cost_i64(context_nanos)),\n".to_string()), " prepare: nanosecond(native_cost_i64(prepare_nanos)),\n".to_string()), " eval: nanosecond(native_cost_i64(eval_nanos)),\n".to_string()), " });\n".to_string()), " let exclusive_sum = nanosecond_count(native_driver_exclusive_sum(exclusive.clone())) as u128;\n".to_string()), " let shared_nanos = load_nanos + context_nanos;\n".to_string()), " let shared_per_identity = if identities == 0 { 0 } else { shared_nanos / identities as u128 };\n".to_string()), " let eval_mean = if eval_samples.is_empty() { 0 } else { eval_nanos / eval_samples.len() as u128 };\n".to_string()), " let prepare_mean = if prepare_samples.is_empty() { 0 } else { prepare_nanos / prepare_samples.len() as u128 };\n".to_string()), " let decls_per_module = if unique_modules == 0 { 0 } else { identities / unique_modules };\n".to_string()), " let prepare_share_per_identity = if identities == 0 { 0 } else { prepare_nanos / identities as u128 };\n".to_string()), " let floor_per_identity = eval_mean + prepare_share_per_identity;\n".to_string()), " let tolerance_nanos = nanosecond_count(native_driver_cost_remainder_tolerance_nanos()) as u128;\n".to_string()), " let accounting = native_driver_cost_account(\n".to_string()), " nanosecond(native_cost_i64(parent_span_nanos)),\n".to_string()), " exclusive,\n".to_string()), " native_driver_cost_remainder_tolerance_nanos(),\n".to_string()), " );\n let remainder_nanos = match accounting.as_ref() { NativeDriverCostAccounting::NativeDriverCostOverAttributed { .. } => None, NativeDriverCostAccounting::NativeDriverCostReconciled { residual, .. } | NativeDriverCostAccounting::NativeDriverCostRemainderExceedsTolerance { residual, .. } => Some(nanosecond_count(residual.clone()) as u128) };\n".to_string()), " let verdict = match accounting.as_ref() {\n".to_string()), " NativeDriverCostAccounting::NativeDriverCostOverAttributed { .. } => r#\"NativeDriverCostOverAttributed\"#,\n".to_string()), " NativeDriverCostAccounting::NativeDriverCostRemainderExceedsTolerance { .. } => r#\"NativeDriverCostRemainderExceedsTolerance\"#,\n".to_string()), " NativeDriverCostAccounting::NativeDriverCostReconciled { .. } => r#\"NativeDriverCostReconciled\"#,\n".to_string()), " };\n".to_string()), " let mut partition = serde_json::json!({ \"basis\": \"native_driver_wall\", \"basis_note\": \"single-threaded SourceRootEvalDriver wall; exclusive rows partition parent_span_nanos\", \"producer\": \"std.compiler_entry.SourceRootEvalDriver\", \"verdict\": verdict, \"tolerance_nanos\": tolerance_nanos, \"parent_span_nanos\": parent_span_nanos, \"exclusive\": { \"load\": load_nanos, \"context\": context_nanos, \"prepare\": prepare_nanos, \"eval\": eval_nanos }, \"sum_exclusive_nanos\": exclusive_sum, \"source_files\": source_files, \"identities\": identities, \"unique_modules\": unique_modules, \"file_refusals\": file_refusals, \"prepare_ok\": prepare_ok, \"prepare_refused\": prepare_refused, \"shared_nanos\": shared_nanos, \"shared_per_identity_nanos\": shared_per_identity, \"prepare_mean_nanos\": prepare_mean, \"prepare_p50_nanos\": native_cost_quantile_nanos(&prepare_samples, 1, 2), \"prepare_p95_nanos\": native_cost_quantile_nanos(&prepare_samples, 19, 20), \"prepare_max_nanos\": prepare_samples.last().copied().unwrap_or(0), \"eval_mean_nanos\": eval_mean, \"eval_p50_nanos\": native_cost_quantile_nanos(&eval_samples, 1, 2), \"eval_p95_nanos\": native_cost_quantile_nanos(&eval_samples, 19, 20), \"eval_max_nanos\": eval_samples.last().copied().unwrap_or(0), \"prepare_share_per_identity_nanos\": prepare_share_per_identity, \"floor_per_identity_nanos\": floor_per_identity, \"mean_decls_per_module\": decls_per_module, \"prepare_resolve_nanos\": prepare_resolve_nanos, \"prepare_infer_nanos\": prepare_infer_nanos });\n if let Some(r) = remainder_nanos { partition[\"remainder_nanos\"] = serde_json::json!(r); }\n eprintln!(\"[native-cost-partition] {}\", partition);\n".to_string()), " match accounting.as_ref() { NativeDriverCostAccounting::NativeDriverCostOverAttributed { sum_exclusive, parent_span } => { eprintln!(\"REFUSED: native driver cost OverAttributed {{ sum_exclusive_nanos: {}, parent_span_nanos: {} }}\", nanosecond_count(sum_exclusive.clone()) as u128, nanosecond_count(parent_span.clone()) as u128); std::process::exit(1); } NativeDriverCostAccounting::NativeDriverCostRemainderExceedsTolerance { residual, tolerance } => { eprintln!(\"REFUSED: native driver cost RemainderExceedsTolerance {{ residual_nanos: {}, tolerance_nanos: {} }}\", nanosecond_count(residual.clone()) as u128, nanosecond_count(tolerance.clone()) as u128); std::process::exit(1); } NativeDriverCostAccounting::NativeDriverCostReconciled { .. } => {} }\n}\n".to_string()), }) } } diff --git a/src/v1/tests/src/lib.rs b/src/v1/tests/src/lib.rs index a909a7b213c..6dab0187e4e 100644 --- a/src/v1/tests/src/lib.rs +++ b/src/v1/tests/src/lib.rs @@ -12,6 +12,9 @@ mod grounded_shared_carrier_wrap_test; #[cfg(test)] mod unknown_pipeline_driver_refusal_test; +#[cfg(test)] +mod native_driver_cost_refusal_test; + #[cfg(test)] mod ambiguous_prefix_infix_newline_test; #[cfg(test)] diff --git a/src/v1/tests/src/native_driver_cost_refusal_test.rs b/src/v1/tests/src/native_driver_cost_refusal_test.rs new file mode 100644 index 00000000000..68a87a34180 --- /dev/null +++ b/src/v1/tests/src/native_driver_cost_refusal_test.rs @@ -0,0 +1,149 @@ +//! Native-driver cost accounting must refuse, not clamp, and must stop the driver. +//! +//! Review 63891: `saturating_sub` printed remainder_nanos 0 on OverAttributed (a fabricated +//! number). The non-Reconciled arms printed a verdict string and exited 0 (an inert law). +//! `[native-prepare]` duplicated `[native-prepare-split]`. +//! +//! The driver source is `v1.compiler.emit_rust` `emit_source_root_eval_driver_main_rs`. +//! The three-verdict law is `std.compiler_entry` `native_driver_cost_account` (also enrolled +//! as dag witnesses). This file executes both: planted over-attribution on the fold, and +//! the emitted main's refusal/exit shape. + +use v1_compiler::std_compiler_entry::{ + native_driver_cost_account, native_driver_cost_remainder_tolerance_nanos, + native_driver_cost_row_standing, NativeDriverChildStanding, NativeDriverCostAccounting, + NativeDriverCostRowStanding, NativeDriverExclusiveRows, +}; +use v1_compiler::std_measure::nanosecond; +use v1_compiler::v1_compiler_emit_rust::emit_source_root_eval_driver_main_rs; + +fn driver_main() -> String { + emit_source_root_eval_driver_main_rs( + "v1_compiled".to_string(), + "v2.compiler.compile".to_string(), + ) + .content + .clone() +} + +#[test] +fn planted_over_attribution_is_over_attributed_not_clamped() { + let account = native_driver_cost_account( + nanosecond(100), + std::rc::Rc::new(NativeDriverExclusiveRows { + load: nanosecond(40), + context: nanosecond(40), + prepare: nanosecond(40), + eval: nanosecond(0), + }), + native_driver_cost_remainder_tolerance_nanos(), + ); + match account.as_ref() { + NativeDriverCostAccounting::NativeDriverCostOverAttributed { + sum_exclusive, + parent_span, + } => { + assert_eq!(sum_exclusive, &nanosecond(120)); + assert_eq!(parent_span, &nanosecond(100)); + } + other => panic!("planted exclusive > parent must be OverAttributed, got {other:?}"), + } +} + +#[test] +fn reconciled_parent_passes() { + let account = native_driver_cost_account( + nanosecond(3439809790856), + std::rc::Rc::new(NativeDriverExclusiveRows { + load: nanosecond(432921485), + context: nanosecond(3380085706753), + prepare: nanosecond(59277814291), + eval: nanosecond(3531894), + }), + native_driver_cost_remainder_tolerance_nanos(), + ); + assert!( + matches!( + account.as_ref(), + NativeDriverCostAccounting::NativeDriverCostReconciled { .. } + ), + "control: a parent covering exclusive rows within tolerance must reconcile, got {account:?}" + ); +} + +#[test] +fn emitted_driver_refuses_over_attribution_instead_of_clamping_and_fails_the_process() { + let main_rs = driver_main(); + assert!( + !main_rs.contains("saturating_sub(exclusive_sum)") && !main_rs.contains("checked_sub("), + "remainder is the fold residual — not a second subtraction that can clamp or fork OverAttributed; emitted:\n{main_rs}" + ); + assert!( + main_rs.contains("NativeDriverCostReconciled { residual, .. }") + || main_rs.contains("NativeDriverCostReconciled { residual, ..}"), + "remainder_nanos must come from native_driver_cost_account residual; emitted:\n{main_rs}" + ); + assert!( + main_rs.contains("std::process::exit(1)") + && main_rs.contains("NativeDriverCostOverAttributed") + && main_rs.contains("NativeDriverCostRemainderExceedsTolerance") + && main_rs.contains("REFUSED: native driver cost OverAttributed") + && main_rs.contains("REFUSED: native driver cost RemainderExceedsTolerance"), + "non-Reconciled arms must refuse and exit 1 so the law is not inert; emitted:\n{main_rs}" + ); + assert!( + !main_rs.contains("[native-prepare] "), + "[native-prepare] is a subset of [native-prepare-split]; one representation" + ); + assert!( + main_rs.contains("[native-prepare-split]") && main_rs.contains("decls={}"), + "the split line must carry decls=; emitted:\n{main_rs}" + ); +} + +#[test] +fn a_completed_capture_with_no_cost_rows_is_unobserved() { + let standing = native_driver_cost_row_standing(std::rc::Rc::new( + NativeDriverChildStanding::NativeDriverChildExited { + stderr: String::new(), + }, + )); + assert!( + matches!( + standing, + NativeDriverCostRowStanding::NativeDriverCostRowsUnobserved + ), + "empty stderr after a completed spawn is unobserved, not a green partition" + ); +} + +#[test] +fn a_planted_partition_line_is_observed() { + let stderr = "[native-cost-partition] {\"verdict\":\"NativeDriverCostReconciled\"}\n"; + let standing = native_driver_cost_row_standing(std::rc::Rc::new( + NativeDriverChildStanding::NativeDriverChildExited { + stderr: stderr.to_string(), + }, + )); + assert!( + matches!( + standing, + NativeDriverCostRowStanding::NativeDriverCostRowsObserved + ), + "the partition tag after exit is Observed" + ); +} + +#[test] +fn a_child_that_has_not_exited_is_pending_not_unobserved() { + let standing = native_driver_cost_row_standing(std::rc::Rc::new( + NativeDriverChildStanding::NativeDriverChildStillRunning, + )); + assert!( + matches!( + standing, + NativeDriverCostRowStanding::NativeDriverCostRowsPending + ), + "Command::output never returns until exit; empty mid-run is pending, not unobserved" + ); +}