Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 70 additions & 47 deletions src/v3/compiler/src/test_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,6 @@ pub const R1_CANONICAL_COMPLEXITY_LENS: &str = include_str!(concat!(
"/../lenses/complexity.dag"
));

/// Bind whose `value` port receives structural `cost_of` for `LensOutputEquals` / `DifferentialEquals`.
///
/// Today the runner keys this on `TestClaim.file_name` until `DeclarationRef` can name the bind
/// directly (M1(2.8) — same story as `r1_lens_output_input_from_program`). **Process ratchet:** do
/// not extend this `match` without a linked issue toward that dissolution (api-review #764).
fn cost_bind_for_claim_file(file_name: &str) -> Option<&'static str> {
match file_name {
"r1_merge_sort_pair.v3" => Some("merge_sort_out"),
"r1_lane_e_differential_witness.v3" => Some("lane_e_diff_out"),
"fixture_compiler_nerd_canonical_complexity.v3" => Some("complexity_demo_out"),
"fixture_compiler_nerd_canonical_parallelism.v3" => Some("total"),
_ => None,
}
}

/// Host-written forward fold for structural depth costs (see `src/v3/lenses/complexity.dag`).
///
/// T-LaneE `DifferentialEquals` compares this receipt to [`crate::lens_cost::cost_of`] (emit output
Expand Down Expand Up @@ -1351,6 +1336,10 @@ pub struct TestRunner<'a> {
dag: &'a Dag,
}

struct ProgramInputRole {
output_bind_name: String,
}

#[derive(Debug, Clone, PartialEq, Eq)]
enum DiagnosticDetailFilter {
Any,
Expand Down Expand Up @@ -1585,15 +1574,12 @@ impl<'a> TestRunner<'a> {
let input_name = decl_display_name(input_id, input_decl);
let expected_name = decl_display_name(expected_id, expected_decl);

// R1 gate sentinel: `Dag` inputs are not yet expressible as structural `data` bodies in the
// fixture DSL; `r1_lens_output_input_from_program` names a typed placeholder while the
// runner reflects `Dag.nodes` from `TestClaim.source` / `file_name`.
// **Dissolution trigger (ROADMAP / INVARIANTS P2):** replace string matching on this name
// with a structural `TestClaim` / `std.verification` coproduct arm (reflection input vs
// literal body) so runners do not key behavior on declaration spellings.
const PROGRAM_INPUT_SENTINEL: &str = "r1_lens_output_input_from_program";
let program_input = match self.program_input_role(input_decl) {
Ok(role) => role,
Err(msg) => return ClaimResult::Fail(format!("LensOutputEquals: {msg}")),
};

if input_decl.value_body.is_none() {
if input_decl.value_body.is_none() && program_input.is_none() {
return ClaimResult::Fail(format!(
"LensOutputEquals: input_ref `{input_name}` has no value body"
));
Expand All @@ -1614,8 +1600,7 @@ impl<'a> TestRunner<'a> {
// **Dissolution trigger (name-keyed bridge):** delete the `lens_decl.name ==
// Some("named_function_count")` arm and this entire parallel authority when
// `DeclarationRef` resolves lens executable identity from `program_dag` (or structured
// `TestClaim` metadata) without fixture-local stub bodies — same upstream fix as retiring
// `PROGRAM_INPUT_SENTINEL` string dispatch above.
// `TestClaim` metadata) without fixture-local stub bodies.
// INVARIANTS P3 / TESTING: `TestClaim.source` must lower cleanly — never ignore
// tokenize/parse failures and fall back to the fixture graph (that would let malformed
// programs `Pass` when inputs/lens resolve only from the fixture).
Expand All @@ -1639,17 +1624,12 @@ impl<'a> TestRunner<'a> {
// T-LaneE (`cost_of`): structural `Lookup<Int>` from the Rust-generated lens on the claim
// program's `merge_sort_out` bind vs a fixture `Lookup<Int>` expected value.
if lens_decl.name.as_deref() == Some("cost_of") {
if input_decl.name.as_deref() != Some(PROGRAM_INPUT_SENTINEL) {
return ClaimResult::Fail(format!(
"LensOutputEquals(cost_of): input_ref must be `{PROGRAM_INPUT_SENTINEL}` sentinel, got `{input_name}`"
));
}
let Some(cost_bind) = cost_bind_for_claim_file(&claim.file_name) else {
let Some(program_input) = program_input.as_ref() else {
return ClaimResult::Fail(format!(
"LensOutputEquals(cost_of): no structural-cost bind mapping for file `{}`",
claim.file_name
"LensOutputEquals(cost_of): input_ref `{input_name}` must inhabit ProgramInput"
));
};
let cost_bind = program_input.output_bind_name.as_str();
let Some(bind) = find_bind(&program_dag, cost_bind, &claim.file_name) else {
return ClaimResult::Fail(format!(
"LensOutputEquals(cost_of): bind `{cost_bind}` not found in `{}`",
Expand Down Expand Up @@ -1706,7 +1686,7 @@ impl<'a> TestRunner<'a> {
None
};

let input_field = if input_decl.name.as_deref() == Some(PROGRAM_INPUT_SENTINEL) {
let input_field = if program_input.is_some() {
// P2: `id_space` must be the same `Dag` `apply_lens_declaration` will use for the lens
// (canonical compile, claim `program_dag`, or merged fixture `self.dag`) so reflected
// `List` / `Behavior` variant `DeclarationId`s are not mixed across graphs.
Expand Down Expand Up @@ -1741,7 +1721,7 @@ impl<'a> TestRunner<'a> {
},
None => {
return ClaimResult::Fail(format!(
"LensOutputEquals: input_ref `{input_name}` has no value body (use `{PROGRAM_INPUT_SENTINEL}` sentinel when the input `Dag` is only available via `TestClaim.source`)"
"LensOutputEquals: input_ref `{input_name}` has no value body (use ProgramInput when the input `Dag` is only available via `TestClaim.source`)"
));
}
}
Expand Down Expand Up @@ -1819,6 +1799,51 @@ impl<'a> TestRunner<'a> {
}
}

fn program_input_role(&self, decl: &Declaration) -> Result<Option<ProgramInputRole>, String> {
let Some(program_input_id) = self.dag.declaration_by_name("ProgramInput").map(|d| d.id)
else {
return Ok(None);
};
if decl.inhabits != Some(program_input_id)
&& decl.meta_tag != Some(program_input_id)
&& !matches!(
&decl.connective,
TypeConnective::Instantiation { template, .. } if *template == program_input_id
)
{
return Ok(None);
}
let Some(ValueBody::Structural { fields }) = decl.value_body.as_ref() else {
return Err(format!(
"ProgramInput `{}` must have a structural data body",
decl_display_name(decl.id, decl)
));
};
let Some(output_ref) = field(fields, "output_ref") else {
return Err(format!(
"ProgramInput `{}` is missing `output_ref`",
decl_display_name(decl.id, decl)
));
};
let output_ref = match output_ref {
FieldValue::Reference(id) => *id,
other => {
return Err(format!(
"ProgramInput `{}` output_ref must be a DeclarationRef edge, got {other:?}",
decl_display_name(decl.id, decl)
));
}
};
let output_decl = self.dag.declaration(output_ref);
let Some(output_bind_name) = output_decl.name.clone() else {
return Err(format!(
"ProgramInput `{}` output_ref must name a declaration",
decl_display_name(decl.id, decl)
));
};
Ok(Some(ProgramInputRole { output_bind_name }))
}

fn eval_differential_equals(
&self,
claim: &TestClaimValue,
Expand Down Expand Up @@ -1852,12 +1877,15 @@ impl<'a> TestRunner<'a> {
let oracle_lineage = decl_display_name(oracle_id, oracle_decl);
let input_name = decl_display_name(input_id, input_decl);

const PROGRAM_INPUT_SENTINEL: &str = "r1_lens_output_input_from_program";
if input_decl.name.as_deref() != Some(PROGRAM_INPUT_SENTINEL) {
return ClaimResult::Fail(format!(
"DifferentialEquals: input_ref must be `{PROGRAM_INPUT_SENTINEL}` sentinel, got `{input_name}`"
));
}
let program_input = match self.program_input_role(input_decl) {
Ok(Some(role)) => role,
Ok(None) => {
return ClaimResult::Fail(format!(
"DifferentialEquals: input_ref `{input_name}` must inhabit ProgramInput"
));
}
Err(msg) => return ClaimResult::Fail(format!("DifferentialEquals: {msg}")),
};

let program_dag = match compile_to_dag(&claim.source, &claim.file_name) {
Ok(dag) => dag,
Expand All @@ -1876,12 +1904,7 @@ impl<'a> TestRunner<'a> {
}
};

let Some(cost_bind) = cost_bind_for_claim_file(&claim.file_name) else {
return ClaimResult::Fail(format!(
"DifferentialEquals: no structural-cost bind mapping for file `{}`",
claim.file_name
));
};
let cost_bind = program_input.output_bind_name.as_str();
let Some(bind) = find_bind(&program_dag, cost_bind, &claim.file_name) else {
return ClaimResult::Fail(format!(
"DifferentialEquals: bind `{cost_bind}` not found in `{}`",
Expand Down
29 changes: 23 additions & 6 deletions src/v3/compiler/tests/fixtures/r1_gates.dag
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import std.verification {
Compiles,
DifferentialEquals,
LensOutputEquals,
ProgramInput,
TestClaim,
TestSuite
}
Expand Down Expand Up @@ -143,9 +144,25 @@ data testgen_structural_coverage_suite: TestSuite = {
claims: [testgen_structural_coverage_gate]
}

// `LensOutputEquals` R1 gate: input `Dag` is reflected from `TestClaim.source` using the
// `r1_lens_output_input_from_program` sentinel (see `test_runner::eval_lens_output_equals`).
data r1_lens_output_input_from_program: Int = 0
// `LensOutputEquals` R1 gate: input `Dag` is reflected from `TestClaim.source` using
// the structural `ProgramInput` role.
data x: Int = 0

data merge_sort_out: Int = 0

data lane_e_diff_out: Int = 0

data r1_lens_output_input_from_program: ProgramInput = {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Regenerate bootstrap artifacts before using ProgramInput

Using ProgramInput in this fixture introduces a hard compile failure because this commit adds the new type in std/verification.dag but does not update the generated/bootstrap std artifacts consumed by compile_to_dag; as a result, cargo test -p v3-compiler test_runner_runs_r1_lane_e_suite fails with ResolveError: unresolved type identifier \ProgramInput`and the affected runner suites never execute. Please regenerate and commit the bootstrap/generated outputs (or defer theseProgramInput`-typed declarations until that is done).

Useful? React with 👍 / 👎.

output_ref: x
}

data r1_merge_sort_program_input: ProgramInput = {
output_ref: merge_sort_out
}

data r1_lane_e_program_input: ProgramInput = {
output_ref: lane_e_diff_out
}

data lens_output_equals_expected: Int = 1

Expand Down Expand Up @@ -178,7 +195,7 @@ data complexity_merge_sort_is_nlogn_gate: TestClaim = {
file_name: "r1_merge_sort_pair.v3",
predicate: LensOutputEquals(
cost_of,
r1_lens_output_input_from_program,
r1_merge_sort_program_input,
complexity_merge_sort_expected_cost
),
requires: []
Expand All @@ -193,7 +210,7 @@ data complexity_merge_sort_v3_matches_v2_oracle_gate: TestClaim = {
predicate: DifferentialEquals(
v3_program_cost,
v2_oracle_cost,
r1_lens_output_input_from_program
r1_merge_sort_program_input
),
requires: []
}
Expand All @@ -209,7 +226,7 @@ data lane_e_bundled_witness_host_emit_parity_gate: TestClaim = {
predicate: DifferentialEquals(
v3_program_cost,
v2_oracle_cost,
r1_lens_output_input_from_program
r1_lane_e_program_input
),
requires: []
}
Expand Down
29 changes: 23 additions & 6 deletions src/v3/compiler/tests/fixtures/r1_gates.template.dag
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import std.verification {
Compiles,
DifferentialEquals,
LensOutputEquals,
ProgramInput,
TestClaim,
TestSuite
}
Expand Down Expand Up @@ -143,9 +144,25 @@ data testgen_structural_coverage_suite: TestSuite = {
claims: [testgen_structural_coverage_gate]
}

// `LensOutputEquals` R1 gate: input `Dag` is reflected from `TestClaim.source` using the
// `r1_lens_output_input_from_program` sentinel (see `test_runner::eval_lens_output_equals`).
data r1_lens_output_input_from_program: Int = 0
// `LensOutputEquals` R1 gate: input `Dag` is reflected from `TestClaim.source` using
// the structural `ProgramInput` role.
data x: Int = 0

data merge_sort_out: Int = 0

data lane_e_diff_out: Int = 0

data r1_lens_output_input_from_program: ProgramInput = {
output_ref: x
}

data r1_merge_sort_program_input: ProgramInput = {
output_ref: merge_sort_out
}

data r1_lane_e_program_input: ProgramInput = {
output_ref: lane_e_diff_out
}

data lens_output_equals_expected: Int = 1

Expand Down Expand Up @@ -178,7 +195,7 @@ data complexity_merge_sort_is_nlogn_gate: TestClaim = {
file_name: "r1_merge_sort_pair.v3",
predicate: LensOutputEquals(
cost_of,
r1_lens_output_input_from_program,
r1_merge_sort_program_input,
complexity_merge_sort_expected_cost
),
requires: []
Expand All @@ -193,7 +210,7 @@ data complexity_merge_sort_v3_matches_v2_oracle_gate: TestClaim = {
predicate: DifferentialEquals(
v3_program_cost,
v2_oracle_cost,
r1_lens_output_input_from_program
r1_merge_sort_program_input
),
requires: []
}
Expand All @@ -209,7 +226,7 @@ data lane_e_bundled_witness_host_emit_parity_gate: TestClaim = {
predicate: DifferentialEquals(
v3_program_cost,
v2_oracle_cost,
r1_lens_output_input_from_program
r1_lane_e_program_input
),
requires: []
}
Expand Down
31 changes: 27 additions & 4 deletions src/v3/compiler/tests/t_demo/t_demo_fixtures.dag
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import std.verification {
FailsWithDiagnostic,
LensOutputEquals,
PortHasState,
ProgramInput,
Resolved,
TestClaim,
TestSuite,
Expand All @@ -40,7 +41,29 @@ fn named_function_count(d: Dag) -> Int =
fn cost_of(d: Dag, port_id: PortId) -> Lookup<Int> =
miss_int_lookup()

data r1_lens_output_input_from_program: Int = 0
data complexity_demo_out: Int = 0

data total: Int = 0

data combine_payload: Int = 0

data upsert_effect: Int = 0

data r1_lens_output_input_from_program: ProgramInput = {
output_ref: combine_payload
}

data t_demo_complexity_program_input: ProgramInput = {
output_ref: complexity_demo_out
}

data t_demo_parallelism_program_input: ProgramInput = {
output_ref: total
}

data t_demo_effects_program_input: ProgramInput = {
output_ref: upsert_effect
}

data t_demo_complexity_cost_expected: Int = 3

Expand Down Expand Up @@ -78,7 +101,7 @@ data compiler_nerd_complexity_lens_output: TestClaim = {
file_name: "fixture_compiler_nerd_canonical_complexity.v3",
predicate: LensOutputEquals(
cost_of,
r1_lens_output_input_from_program,
t_demo_complexity_program_input,
t_demo_complexity_cost_expected
),
requires: []
Expand All @@ -102,7 +125,7 @@ data compiler_nerd_parallelism_lens_output: TestClaim = {
file_name: "fixture_compiler_nerd_canonical_parallelism.v3",
predicate: LensOutputEquals(
cost_of,
r1_lens_output_input_from_program,
t_demo_parallelism_program_input,
t_demo_parallelism_cost_expected
),
requires: []
Expand Down Expand Up @@ -152,7 +175,7 @@ data integration_effects_lens_output: TestClaim = {
file_name: "fixture_integration_canonical_effects.v3",
predicate: LensOutputEquals(
named_function_count,
r1_lens_output_input_from_program,
t_demo_effects_program_input,
t_demo_effects_bind_count_expected
),
requires: []
Expand Down
7 changes: 7 additions & 0 deletions src/v3/std/verification.dag
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ type TestPredicate
lens_ref: DeclarationRef
}

// Structural runner input role for predicates whose input is the compiled
// `TestClaim.source` program. `output_ref` names the bind declaration in that

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BLOCKING: ProgramInput conflates “use the compiled TestClaim.source Dag as input” with “select this output bind,” forcing dummy output_ref declarations for named_function_count-style lenses and making an illegal unused-target state representable (Illegal States Unrepresentable / Minimal information per interface).

// program whose value port is the assertion target for cost/differential lenses.
type ProgramInput {
output_ref: DeclarationRef
}

// `requires` is the **only** place `ResourceReference` edges attach for a claim
// (including mock backends when `predicate` is `MockBackedInvariant`). No parallel
// resource slots on predicate variants — `obligation_for_claim` / materialization
Expand Down
Loading