Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
e4eb072
fix(CG): Go/Python emit_expr_var now consults binding_kind for keywor…
claude Apr 6, 2026
1e4a5b8
refactor(CG): remove dead coercion data, derive container kind from a…
claude Apr 6, 2026
20e3ce0
feat(CG/MM-2): surface connective through TypeRendering
claude Apr 6, 2026
19af457
fix(CG): remove uppercase None from null-literal check in Go/Python
claude Apr 6, 2026
6bdb2de
fix(CG): address review — coercion arity covers algebra names, L1 doc…
claude Apr 6, 2026
1365e88
fix(CG): revert speculative TypeRendering.connective, fix Rust-specif…
claude Apr 6, 2026
4218462
refactor(CG): move container_to_algebra + algebra_arity to std/types.dag
claude Apr 6, 2026
69a4cf5
fix(CG): delete wrong algebra_arity table and dead container-kind fun…
claude Apr 6, 2026
e23340c
refactor(CG/MM-1): dissolve classify_typed_item — backends read struc…
claude Apr 6, 2026
c1971b1
docs(CG): update ROADMAP — TLC-3 complete across all backends
briansrls Apr 6, 2026
a3e0936
refactor(CG/MM-1): extract shared item predicates, eliminate parallel…
claude Apr 6, 2026
80e9484
fix(CG): scope is_zero_arg_callable_ref back to Rust-only per review
briansrls Apr 6, 2026
57efa81
docs(CG): fix ROADMAP — revert TLC-3 overclaim, record MM-1 progress
claude Apr 6, 2026
b54dcae
docs(CG): fix MM-1 overclaim — fail-closed boundaries still partial
claude Apr 6, 2026
a8ae883
docs(CG): correct TLC-3 and MM-1 accuracy per review
briansrls Apr 6, 2026
0ff776c
Merge branch 'main' into claude/implement-lane-2-jfNh2
briansrls Apr 6, 2026
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
14 changes: 14 additions & 0 deletions src/v2/05_emit.dag
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import v2.std.core {
authored_name_at, NewlineIndex,
expr_var_name_at, expr_call_func_at, let_binding_name_at,
ExprData, NoExprData,
VarBindingKind, FunctionValueBinding,
ExprLiteral, ExprVar, ExprFieldAccess, ExprCall, ExprMethodCall,
ExprMatch, ExprIf, ExprLet, ExprRecordLit, ExprListLit,
ExprBinOp, ExprUnaryOp, ExprLambda, ExprStringInterp,
Expand Down Expand Up @@ -1752,6 +1753,19 @@ fn emit_null_coalesce(l_str: String, r_str: String, target: RenderTarget) -> Str
}
}

// DAG references to zero-arg functions are calls; all backends need explicit parens.
// Checks FunctionValueBinding + resolved Callable type has no params.
fn is_zero_arg_callable_ref(binding_kind: VarBindingKind?, resolved_type: InferredNode?) -> Bool {
match binding_kind {

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.

Invariant violation: is_zero_arg_callable_ref still makes an emit-time nullary-call decision by testing rt.name == "Callable", which uses a name proxy for missing upstream call structure and violates Boundary sufficiency and Emission is translation, not decision-making.

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.

Acknowledged — this is a pre-existing L1 violation (was in 05_emit_rust.dag, moved to shared 05_emit.dag). Added documentation comment on the function marking the boundary sufficiency violation and noting the dissolution path (M4/Tier 2.6: inference normalizes ExprVar→ExprCall for nullary invocation). ROADMAP TLC-1 updated to record the Go/Python progress and the remaining upstream work. Fixed in 6bdb2de.


Generated by Claude Code

Some { value: FunctionValueBinding } =>
match resolved_type {
Some { value: Resolved { node: rt } } => rt.name == "Callable" && (rt.params |> count) == 0
_ => false
}
_ => false
}
}

// =========================================================================
// emit_shared_expr — full shared ExprData dispatcher (P4.2 step 5)
//
Expand Down
16 changes: 13 additions & 3 deletions src/v2/05_emit_go.dag
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ module v2.compiler.emit_go

import v2.std.core {
Node, InferredNode, Resolved, CompilerError,
VarBindingKind, FunctionValueBinding,
is_import_node, import_is_all, import_specific_names, module_imports, module_items,
param_node_type_expr,
authored_name_at, NewlineIndex,
Expand Down Expand Up @@ -94,7 +95,7 @@ import v2.compiler.emit {
TypedItemDataDef, TypedItemServiceDef, TypedItemResourceDef,
emit_literal, emit_bin_op_symbol, emit_keyword, emit_primitive_type, emit_container, emit_map_type,
emit_node_type, emit_ident, emit_let_binding, emit_simple_expr,
emit_unary_op, emit_lambda, emit_error_expr, emit_return, emit_lambda_params, emit_list_lit_expr, emit_shared_expr, emit_default_bin_op,
emit_unary_op, emit_lambda, emit_error_expr, emit_return, emit_lambda_params, emit_list_lit_expr, emit_shared_expr, emit_default_bin_op, is_zero_arg_callable_ref,
emit_string_literal, escape_go_interp_text, escape_string_literal_body,
empty_emit_scope, module_emit_scope,
scope_after_expr,
Expand Down Expand Up @@ -594,9 +595,18 @@ fn emit_go_field_access(base: Node, field: String, summary: FieldSummary?, regis
fn emit_go_expr_var(expr: Node, depth: Int, source_index: NewlineIndex?) -> String {
let prefix = make_indent(level: depth)
match expr.expr_data {
ExprVar { binding_kind: _ } =>
ExprVar { binding_kind: binding_kind } =>
let n = expr_var_name_at(texpr: expr, source_index: source_index)
concat(prefix, emit_ident(name: n, target: Go))
if n == "none" || n == "None" { concat(prefix, emit_keyword(key: "null", target: Go)) }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Remove uppercase None from null-literal check

None is not a reserved DAG keyword (dag_keyword_set only marks lowercase none/null), so a user can legally bind an identifier named None and rely on emit_ident to escape it for the target language. This new branch rewrites ExprVar named None to the null literal, so references to that binding are emitted as constants (nil in Go, and similarly in emit_py_expr_var) instead of the variable value, which changes program semantics.

Useful? React with 👍 / 👎.

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.

Good catch — fixed in 19af457. Removed the uppercase None check from both Go and Python emit_expr_var. Only lowercase "none" (the actual DAG keyword) is now mapped to the null literal.

Note: the Rust emitter has the same pre-existing name == "None" check at emit_var_ref (05_emit_rust.dag:1714). That's a known L1 violation to be resolved upstream via resolver normalization, not in this PR.


Generated by Claude Code

else if n == "true" || n == "false" { concat(prefix, emit_keyword(key: n, target: Go)) }
else {
let ident = emit_ident(name: n, target: Go)
if is_zero_arg_callable_ref(binding_kind: binding_kind, resolved_type: expr.inferred) {
concat(prefix, ident, "()")
} else {
concat(prefix, ident)
}
}
_ => concat(prefix, emit_error_expr(message: "emit_go_expr_var expected ExprVar", target: Go))
}
}
Expand Down
16 changes: 13 additions & 3 deletions src/v2/05_emit_python.dag
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module v2.compiler.emit_python

import v2.std.core {
Node, InferredNode, Resolved, CompilerError,
VarBindingKind, FunctionValueBinding,
is_import_node, import_is_all, import_specific_names, module_imports, module_items,
param_node_type_expr,
authored_name_at, NewlineIndex,
Expand Down Expand Up @@ -84,7 +85,7 @@ import v2.compiler.emit {
TypedItemDataDef, TypedItemServiceDef, TypedItemResourceDef,
emit_literal, emit_bin_op_symbol, emit_keyword, emit_primitive_type, emit_container, emit_map_type,
emit_node_type, emit_ident, emit_let_binding, emit_simple_expr,
emit_unary_op, emit_lambda, emit_error_expr, emit_return, emit_lambda_params, emit_list_lit_expr, emit_shared_expr, emit_default_bin_op,
emit_unary_op, emit_lambda, emit_error_expr, emit_return, emit_lambda_params, emit_list_lit_expr, emit_shared_expr, emit_default_bin_op, is_zero_arg_callable_ref,
emit_string_literal, escape_python_interp_text, escape_string_literal_body,
empty_emit_scope, module_emit_scope,
scope_after_expr,
Expand Down Expand Up @@ -575,9 +576,18 @@ fn emit_py_field_access(base: Node, field: String, summary: FieldSummary?, regis

fn emit_py_expr_var(expr: Node, source_index: NewlineIndex?) -> String {
match expr.expr_data {
ExprVar { binding_kind: _ } =>
ExprVar { binding_kind: binding_kind } =>
let n = expr_var_name_at(texpr: expr, source_index: source_index)
emit_ident(name: n, target: Python)
if n == "none" || n == "None" { emit_keyword(key: "null", target: Python) }
else if n == "true" || n == "false" { emit_keyword(key: n, target: Python) }
else {
let ident = emit_ident(name: n, target: Python)
if is_zero_arg_callable_ref(binding_kind: binding_kind, resolved_type: expr.inferred) {
concat(ident, "()")
} else {
ident
}
}
_ => emit_error_expr(message: "emit_py_expr_var expected ExprVar", target: Python)
}
}
Expand Down
15 changes: 1 addition & 14 deletions src/v2/05_emit_rust.dag
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ import v2.compiler.emit {
TypedItemFunction, TypedItemDataDef, TypedItemServiceDef, TypedItemResourceDef,
rust_literal_for_pattern,
emit_literal, emit_bin_op_symbol, emit_keyword, emit_node_type, build_type_rendering, render_type, emit_ident, emit_let_binding, emit_let_binding_annotated, emit_return,
emit_unary_op, emit_lambda, emit_error_expr, emit_lambda_params, emit_null_coalesce, emit_list_lit_expr, emit_shared_expr,
emit_unary_op, emit_lambda, emit_error_expr, emit_lambda_params, emit_null_coalesce, emit_list_lit_expr, emit_shared_expr, is_zero_arg_callable_ref,
emit_string_literal, emit_simple_expr, escape_rust_interp_text, escape_string_literal_body,
module_emit_scope,
scope_after_expr,
Expand Down Expand Up @@ -1710,19 +1710,6 @@ fn effective_variant_parent(name: String, binding_kind: VarBindingKind?, resolve
}
}

// DAG references to zero-arg functions are calls; Rust needs explicit parens.
// Checks FunctionValueBinding + resolved Callable type has no params.
fn is_zero_arg_callable_ref(binding_kind: VarBindingKind?, resolved_type: InferredNode?) -> Bool {
match binding_kind {
Some { value: FunctionValueBinding } =>
match resolved_type {
Some { value: Resolved { node: rt } } => rt.name == "Callable" && (rt.params |> count) == 0
_ => false
}
_ => false
}
}

fn emit_var_ref(name: String, binding_kind: VarBindingKind?, resolved_type: InferredNode?, shared_types: Map<String, Bool>, registry: Map<String, ItemInfo>, emit_info: EmitGraphInfo) -> String {
if name == "none" || name == "None" { emit_keyword(key: "null", target: Rust) }
else if name == "true" || name == "false" { emit_keyword(key: name, target: Rust) }
Expand Down
22 changes: 17 additions & 5 deletions src/v2/coercion.dag
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module v2.compiler.coercion

import v2.compiler.artifact { RenderTarget, Rust, Python, Go, Dag }
import std.coercion { TypeCheckpoint, InhabitantDecl, CallableRepr }
import std.types { container_expected_arity }
import extdeps.languages.rust.types {
rust_type_checkpoints, rust_algebra_inhabitants, rust_callable,
rust_optional_template
Expand Down Expand Up @@ -163,9 +164,20 @@ fn apply_inhabitant_template2(template: String, first: String, second: String) -
replace(replace(template, "\{0\}", first), "\{1\}", second)
}

// =========================================================================
// Container identity constants (hardcoded; should be derived from algebra arity)
// =========================================================================
// Container kind classification: derived from container_type_arity in std/types.dag.
// Keyed containers (arity 2) vs element containers (arity 1).

This comment was marked as resolved.

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.

Fixed in 6bdb2de. Added coercion_container_arity that resolves both surface names (via container_expected_arity) AND algebra names (via container_to_algebra → InhabitantDecl.arity). is_keyed_container("PartialFunction") and is_element_container("FreeMonoid") now return true.


Generated by Claude Code

// These functions replace the hardcoded coercion_keyed_container_names and
// coercion_element_container_names data constants that were never consumed.
fn is_keyed_container(name: String) -> Bool {
match container_expected_arity(name: name) {
Some { value: arity } => arity == 2
None => false
}
}

data coercion_keyed_container_names: List<String> = ["Map", "PartialFunction"]
data coercion_element_container_names: List<String> = ["List", "Set", "NonEmptyList", "NonEmptySet", "FreeMonoid"]
fn is_element_container(name: String) -> Bool {
match container_expected_arity(name: name) {
Some { value: arity } => arity == 1
None => false
}
}
25 changes: 11 additions & 14 deletions src/v2/stage0/src/v2_compiler_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ impl<T: Ord> NonEmptyBTreeSet<T> {
pub use crate::v2_compiler_artifact::{RenderTarget};
use crate::v2_compiler_artifact::RenderTarget::{Rust, Python, Go, Dag};
pub use crate::std_coercion::{TypeCheckpoint, InhabitantDecl, CallableRepr};
pub use crate::std_types::{container_expected_arity};
pub use crate::extdeps_languages_rust_types::{rust_type_checkpoints, rust_algebra_inhabitants, rust_callable, rust_optional_template};
pub use crate::extdeps_languages_python_types::{python_type_checkpoints, python_algebra_inhabitants, python_callable, python_optional_template};
pub use crate::extdeps_languages_go_types::{go_type_checkpoints, go_algebra_inhabitants, go_callable, go_optional_template};
Expand Down Expand Up @@ -164,20 +165,16 @@ pub fn apply_inhabitant_template2(template: String, first: String, second: Strin
v2_rt::replace(v2_rt::replace(template, "{0}".to_string(), first), "{1}".to_string(), second)
}

pub fn coercion_keyed_container_names() -> Rc<Vec<String>> {
thread_local! {
static CACHED: Rc<Vec<String>> = {
Rc::new(vec!["Map".to_string(), "PartialFunction".to_string()])
};
}
CACHED.with(|c| c.clone())
pub fn is_keyed_container(name: String) -> bool {
match container_expected_arity(name) {
Some(arity) => (arity.clone() == 2),
None => false,
}
}

pub fn coercion_element_container_names() -> Rc<Vec<String>> {
thread_local! {
static CACHED: Rc<Vec<String>> = {
Rc::new(vec!["List".to_string(), "Set".to_string(), "NonEmptyList".to_string(), "NonEmptySet".to_string(), "FreeMonoid".to_string()])
};
}
CACHED.with(|c| c.clone())
pub fn is_element_container(name: String) -> bool {
match container_expected_arity(name) {
Some(arity) => (arity.clone() == 1),
None => false,
}
}
13 changes: 12 additions & 1 deletion src/v2/stage0/src/v2_compiler_emit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,10 @@ impl<T: Ord> NonEmptyBTreeSet<T> {
self.0
}
}
pub use crate::v2_std_core::{Node, ErrorNode, InferredNode, is_compiler_error, module_imports, module_items, param_node_name, param_node_type_expr, param_node_default_value, authored_name_at, NewlineIndex, expr_var_name_at, expr_call_func_at, let_binding_name_at, ExprData, StringPart, LiteralValue, TextFile, SourceSpan, BinOp, UnaryOpKind, DeclaredFuncSig, lambda_param_names_at, record_lit_type_name, arm_body, arm_pattern, arm_guard, arg_name, arg_value, field_init_node_name, field_init_node_value, if_condition, if_then_branch, if_else_branch, match_scrutinee, match_arm_nodes, let_value, let_body, field_access_base, method_receiver, lambda_body, cast_expr, return_value, binop_left, binop_right, slice_start, slice_end, unaryop_operand, expr_has_self_call, expr_has_non_tail_self_call, local_transport_node, is_rest_transport, is_shell_transport, is_file_transport, is_local_transport, is_transport_kind, transport_kind_rest, transport_kind_shell, transport_kind_file, transport_has_auth, field_init_operation_modifier, operation_modifier_name, leaf_node, with_required_cardinality, tuple_type_name, Connective, Cardinality};
pub use crate::v2_std_core::{Node, ErrorNode, InferredNode, is_compiler_error, module_imports, module_items, param_node_name, param_node_type_expr, param_node_default_value, authored_name_at, NewlineIndex, expr_var_name_at, expr_call_func_at, let_binding_name_at, ExprData, VarBindingKind, StringPart, LiteralValue, TextFile, SourceSpan, BinOp, UnaryOpKind, DeclaredFuncSig, lambda_param_names_at, record_lit_type_name, arm_body, arm_pattern, arm_guard, arg_name, arg_value, field_init_node_name, field_init_node_value, if_condition, if_then_branch, if_else_branch, match_scrutinee, match_arm_nodes, let_value, let_body, field_access_base, method_receiver, lambda_body, cast_expr, return_value, binop_left, binop_right, slice_start, slice_end, unaryop_operand, expr_has_self_call, expr_has_non_tail_self_call, local_transport_node, is_rest_transport, is_shell_transport, is_file_transport, is_local_transport, is_transport_kind, transport_kind_rest, transport_kind_shell, transport_kind_file, transport_has_auth, field_init_operation_modifier, operation_modifier_name, leaf_node, with_required_cardinality, tuple_type_name, Connective, Cardinality};
use crate::v2_std_core::InferredNode::{Resolved, CompilerError, TypeVariable};
use crate::v2_std_core::ExprData::{NoExprData, ExprLiteral, ExprVar, ExprFieldAccess, ExprCall, ExprMethodCall, ExprMatch, ExprIf, ExprLet, ExprRecordLit, ExprListLit, ExprBinOp, ExprUnaryOp, ExprLambda, ExprStringInterp, ExprBlock, ExprCast, ExprForEach, ExprIndex, ExprSlice, ExprError, ExprReturn};
use crate::v2_std_core::VarBindingKind::{FunctionValueBinding};
use crate::v2_std_core::StringPart::{Text, Interpolation};
use crate::v2_std_core::BinOp::{NullCoalesce};
use crate::v2_std_core::Connective::{Conj, Disj, NoConnective};
Expand Down Expand Up @@ -2159,6 +2160,16 @@ pub fn emit_null_coalesce(l_str: String, r_str: String, target: RenderTarget) ->
}
}

pub fn is_zero_arg_callable_ref(binding_kind: Option<Rc<VarBindingKind>>, resolved_type: Option<Rc<InferredNode>>) -> bool {
match binding_kind.as_deref().cloned() {
Some(VarBindingKind::FunctionValueBinding) => match resolved_type.as_deref().cloned() {
Some(InferredNode::Resolved { node: rt, .. }) => ((rt.name.clone().as_str() == "Callable".to_string().as_str()) && ((rt.params.clone().len() as i64) == 0)),
_ => false,
},
_ => false,
}
}

pub fn emit_shared_expr(texpr: Rc<Node>, target: RenderTarget, source_index: Option<Rc<NewlineIndex>>, wrap_result: impl Fn(String) -> String + Clone, recurse: impl Fn(Rc<Node>) -> String + Clone, emit_var: impl Fn(Rc<Node>) -> String + Clone, emit_field_access: impl Fn(Rc<Node>) -> String + Clone, emit_call: impl Fn(Rc<Node>) -> String + Clone, emit_method_call: impl Fn(Rc<Node>) -> String + Clone, emit_match: impl Fn(Rc<Node>) -> String + Clone, emit_if: impl Fn(Rc<Node>) -> String + Clone, emit_let: impl Fn(Rc<Node>) -> String + Clone, emit_record_lit: impl Fn(Rc<Node>) -> String + Clone, emit_string_interp: impl Fn(Rc<Node>) -> String + Clone, emit_block: impl Fn(Rc<Node>) -> String + Clone, emit_cast: impl Fn(Rc<Node>) -> String + Clone, emit_for_each: impl Fn(Rc<Node>) -> String + Clone, emit_index: impl Fn(Rc<Node>) -> String + Clone, emit_slice: impl Fn(Rc<Node>) -> String + Clone, emit_bin_op: impl Fn(Rc<Node>) -> String + Clone) -> String {
match (*texpr.expr_data.clone()).clone() {
ExprData::ExprLiteral { value: v, .. } => wrap_result(emit_literal(v.clone(), target.clone())),
Expand Down
Loading
Loading