Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 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
1,790 changes: 900 additions & 890 deletions src/v3/compiler/src/bootstrap_generated.rs

Large diffs are not rendered by default.

1,616 changes: 813 additions & 803 deletions src/v3/compiler/src/bootstrap_generated_without_parse_surface.rs

Large diffs are not rendered by default.

49 changes: 49 additions & 0 deletions src/v3/compiler/tests/boundary/m1_4_emit_python_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::path::{Path, PathBuf};
use std::process::{Command, Stdio};
use std::sync::atomic::{AtomicUsize, Ordering};

use crate::common::determinism_fixtures::PROGRAM_FIXTURES;
use v3_compiler::compile_to_dag;
use v3_compiler::dag::{
Behavior, BindNode, BranchNode, LoopBound, LoopNode, Path as DagPath, Port, TransformNode,
Expand Down Expand Up @@ -48,6 +49,37 @@ fn emit_python_module_from_source(source: &str, file_name: &str) -> String {
emit_python_module(&dag).expect("emit python module")
}

fn python_stdout(source: &str, file_name: &str) -> String {
let dag = compile_to_dag(source, file_name).expect("compiled python program source");
let rendered = emit_python_text(&dag).expect("emit python program");
let tmp_dir = next_roundtrip_dir();
std::fs::create_dir_all(&tmp_dir).expect("create tmp dir");
let src_path = tmp_dir.join("main.py");
std::fs::File::create(&src_path)
.and_then(|mut f| f.write_all(rendered.as_bytes()))
.expect("write emitted python source");

let run = Command::new("python3")
.arg(&src_path)
.output()
.expect("run python3");
assert!(
run.status.success(),
"python3 failed on emitted source:\n{}\nstderr:\n{}",
rendered,
String::from_utf8_lossy(&run.stderr)
);
String::from_utf8_lossy(&run.stdout).trim().to_string()
}

fn program_fixture_source(name: &str) -> &'static str {
PROGRAM_FIXTURES
.iter()
.find(|fixture| fixture.name == name)
.unwrap_or_else(|| panic!("missing program fixture `{name}`"))
.source
}

#[test]
fn emit_python_bool_logical_ops_use_keyword_carriers() {
let src = "fn f(a: Bool, b: Bool, c: Bool) -> Bool = a && b || c\n";
Expand Down Expand Up @@ -118,6 +150,23 @@ fn emit_python_uses_only_shared_schema_surface() {
}
}

#[test]
fn emitted_python_admitted_list_fixtures_execute_under_cpython() {
let fixtures = [
("list_map_then_fold_twelve", "12"),
("list_filter_then_fold_seven", "7"),
("nested_list_builtins_inside_lambda_six", "6"),
];

for (name, expected) in fixtures {
let actual = python_stdout(program_fixture_source(name), "python_admitted_fixture.v3");
assert_eq!(
actual, expected,
"emitted Python fixture `{name}` diverged from Rust-canonical expected stdout"
);
}
}

fn next_roundtrip_dir() -> PathBuf {
let id = ROUNDTRIP_ID.fetch_add(1, Ordering::Relaxed);
std::env::temp_dir().join(format!(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,4 @@ pub const GO_EMIT_EXCLUDE: &[&str] = &["recursive_function_call_six"];
/// Program fixtures excluded from Python 5× determinism — `MissingOperatorRealization`,
/// unsupported `Behavior::Loop`, etc., until Python spec/emitter parity matches the
/// Rust matrix (`m1_3_emit_rust_test` is Rust-canonical).
pub const PYTHON_EMIT_EXCLUDE: &[&str] = &[
"list_map_then_fold_twelve",
"list_filter_then_fold_seven",
"nested_list_builtins_inside_lambda_six",
"recursive_function_call_six",
];
pub const PYTHON_EMIT_EXCLUDE: &[&str] = &["recursive_function_call_six"];
80 changes: 80 additions & 0 deletions src/v3/spec/python.dag
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,22 @@ data python_int_sub: OperatorRealization = {
cost: 1
}

data python_int_mul: OperatorRealization = {
language: python_language
target: Int
op: OrderedRing.mul
carrier: "*"
cost: 1
}

data python_int_div: OperatorRealization = {
language: python_language
target: Int
op: OrderedRing.div
carrier: "//"
cost: 1
}

data python_int_eq: OperatorRealization = {
language: python_language

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: carrier "//" realizes OrderedRing.div with Python floor division, which diverges from the Rust/Go Int division realizations for negative operands and violates DB-8 cross-target deterministic emission.

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.

Verified against current head 8b4c4719d: the unsafe Python division realization has been removed. src/v3/spec/python.dag no longer contains python_int_div, OrderedRing.div, or carrier "//", and the regenerated bootstrap snapshots were updated in the same commit. This PR now intentionally omits Python OrderedRing.div until a faithful helper-based realization exists.

target: Int
Expand Down Expand Up @@ -494,6 +510,70 @@ data python_declaration_id_eq: OperatorRealization = {
cost: 1
}

data python_int_ne: OperatorRealization = {
language: python_language
target: Int
op: OrderedRing.ne
carrier: "!="
cost: 1
}

data python_node_id_ne: OperatorRealization = {
language: python_language
target: NodeId
op: OrderedRing.ne
carrier: "!="
cost: 1
}

data python_port_id_ne: OperatorRealization = {
language: python_language
target: PortId
op: OrderedRing.ne
carrier: "!="
cost: 1
}

data python_declaration_id_ne: OperatorRealization = {
language: python_language
target: DeclarationId
op: OrderedRing.ne
carrier: "!="
cost: 1
}

data python_int_lt: OperatorRealization = {
language: python_language
target: Int
op: OrderedRing.lt
carrier: "<"
cost: 1
}

data python_int_le: OperatorRealization = {
language: python_language
target: Int
op: OrderedRing.le
carrier: "<="
cost: 1
}

data python_int_gt: OperatorRealization = {
language: python_language
target: Int
op: OrderedRing.gt
carrier: ">"
cost: 1
}

data python_int_ge: OperatorRealization = {
language: python_language
target: Int
op: OrderedRing.ge
carrier: ">="
cost: 1
}

data python_bool_meet: OperatorRealization = {
language: python_language
target: Bool
Expand Down