Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
30 changes: 17 additions & 13 deletions src/v3/compiler/tests/boundary/m1_3_emit_rust_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use std::sync::OnceLock;
use v3_compiler::compile_to_dag;
use v3_compiler::emit::{emit as shared_emit, emit_module as shared_emit_module, EmitTarget};
use v3_compiler::emit_rust::{emit_rust, emit_rust_module};
use v3_compiler::test_runner::TestClaimValue;

use crate::common::determinism_fixtures::PROGRAM_FIXTURES;
use crate::common::{HarnessLinkMode, RustcHarness};
Expand All @@ -43,6 +44,20 @@ fn emit_module(source: &str) -> String {
emit_rust_module(&dag).expect("emits module")
}

fn r1_gate_claim_source(claim_name: &str) -> String {
let gate_path = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/fixtures/r1_gates.dag");
let gate_source = std::fs::read_to_string(&gate_path)
.unwrap_or_else(|err| panic!("read {gate_path:?}: {err}"));
let gate_dag = compile_to_dag(&gate_source, "src/v3/compiler/tests/fixtures/r1_gates.dag")
.expect("r1_gates.dag compiles");
let claim = gate_dag
.declaration_by_name(claim_name)
.unwrap_or_else(|| panic!("claim `{claim_name}` not found"));
TestClaimValue::from_declaration(claim)
.unwrap_or_else(|reason| panic!("claim `{claim_name}` should lower structurally: {reason}"))
.source
}

#[test]
fn emit_rust_bool_logical_ops_use_spec_carriers() {
let src = "let x: Bool = true && false || true\n";
Expand Down Expand Up @@ -427,18 +442,6 @@ let zero: Int = 0",
assert!(out.contains("BoxedInt::Empty => 0,"), "got: {out}");
}

const SUB_MATCH_OVER_USER_SUM_SOURCE: &str = r#"
type Choice = Number(Int) | Missing

fn score(choice: Choice) -> Int =
match choice {
Number(value) => value
Missing => 0
}

let result: Bool = score(Number(7)) == 7 && score(Missing) == 0
"#;

/// Day-1 T-Sub receipt gate for `sub_match_over_user_sum`.
///
/// Audit result: the first-class implementation path already exists on `main`.
Expand All @@ -453,7 +456,8 @@ let result: Bool = score(Number(7)) == 7 && score(Missing) == 0
/// parse -> lower -> infer -> Rust emit -> rustc link -> runtime execution.
#[test]
fn sub_match_over_user_sum_links_and_runs() {
assert_eq!(roundtrip_stdout(SUB_MATCH_OVER_USER_SUM_SOURCE), "true");
let source = r1_gate_claim_source("sub_match_over_user_sum");
assert_eq!(roundtrip_stdout(&source), "true");
}

#[test]
Expand Down
17 changes: 16 additions & 1 deletion src/v3/compiler/tests/fixtures/r1_gates.dag
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,25 @@
//
// Lives under `src/v3/compiler/tests/fixtures/` so it is **not** auto-staged
// into `Dag::new()` bootstrap (`src/v3/std/*.dag` is build-script enumerated).
// `sub_match_over_user_sum_links_and_runs` also extracts this claim source for
// the rustc boundary receipt, so the named T-Sub gate has one program witness.

module std.r1_gates

import std.verification { TestClaim, TestSuite }
import std.verification { Compiles, TestClaim, TestSuite }

data sub_match_over_user_sum: TestClaim = {
name: "sub_match_over_user_sum",
source: "type Choice = Number(Int) | Missing\n\nfn score(choice: Choice) -> Int =\n match choice {\n Number(value) => value\n Missing => 0\n }\n\nlet result: Bool = score(Number(7)) == 7 && score(Missing) == 0\n",
file_name: "r1_sub_match_over_user_sum.v3",
predicate: Compiles,
requires: []
}

data sub_match_over_user_sum_gate: TestSuite = {
name: "sub_match_over_user_sum_gate",
claims: [sub_match_over_user_sum]
}

data user_authored_lens_compiles_gate: TestClaim = {
name: "user_authored_lens_compiles",
Expand Down
14 changes: 14 additions & 0 deletions src/v3/compiler/tests/integration/test_runner_test.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! **Layer:** integration

use std::path::PathBuf;

use v3_compiler::dag::{FieldValue, LiteralBits};
use v3_compiler::test_runner::TestClaimValue;
use v3_compiler::test_runner::{ClaimResult, TestRunner};
Expand Down Expand Up @@ -299,3 +301,15 @@ data suite: TestSuite = {
assert_eq!(results.len(), 1);
assert_eq!(results[0].result, ClaimResult::NotYetImplemented);
}

#[test]
fn test_runner_runs_sub_match_over_user_sum_gate() {
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
let gate = manifest_dir.join("tests/fixtures/r1_gates.dag");
let source =
std::fs::read_to_string(&gate).unwrap_or_else(|err| panic!("read {gate:?}: {err}"));
let dag = compile_clean(&source, "src/v3/compiler/tests/fixtures/r1_gates.dag");
let results = TestRunner::new(&dag).run_suite("sub_match_over_user_sum_gate");

assert_all_pass(&results);
}
Loading