Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 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
4 changes: 3 additions & 1 deletion ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ backends.
- [~] **TLC-1: Call syntax / reference distinction.** Zero-arg fn calls
render as `name()` via `is_zero_arg_callable_ref` (FunctionValueBinding +
Callable node with empty params). Dispatched in emit_var_ref and
emit_typed_expr_base. **Partial:** emitter-side guardrail only —
emit_typed_expr_base. `is_zero_arg_callable_ref` moved to shared
05_emit.dag; Go/Python emit_expr_var now consult it (PR #324).
**Partial:** emitter-side guardrail only —
`rt.name == "Callable"` is an L1 violation. Upstream concept modeling
(Tier 2.6) dissolves this. Imported zero-arg function refs untested.
- [ ] **TLC-2: Runtime bridge signature derivation.** Runtime helper
Expand Down
29 changes: 29 additions & 0 deletions dsl/std/types.dag
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,35 @@ fn container_expected_arity(name: String) -> Int? {
map_get(container_type_arity, name)
}

// Container → algebra mapping: mirrors the type alias declarations below.
// Co-located with the declarations it describes (List = FreeMonoid, etc.).
// Includes surface names, snake_case variants, and algebra self-mappings
// so that any naming convention resolves to the canonical algebra identity.
// TODO: derive programmatically from type alias declarations once M4
// structural identity provides a reflection mechanism.
data container_to_algebra: Map<String, String> = {

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: container_to_algebra re-states the List/Set/Map to algebra facts as a hand-maintained Map<String, String>, creating a duplicate string-keyed authority instead of deriving from the alias declarations, which violates No duplicate representations and the Modeling Faithfulness invariant.

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 duplicate (was in coercion.dag, moved to std/types.dag for co-location). The table already has a TODO: "derive programmatically from type alias declarations once M4 structural identity provides a reflection mechanism." The .dag language currently has no reflection/introspection capability to read type alias bodies at the data-declaration level.


Generated by Claude Code

"List": "FreeMonoid",
"list": "FreeMonoid",
"NonEmptyList": "FreeMonoid",
"non_empty_list": "FreeMonoid",
"FreeMonoid": "FreeMonoid",
"free_monoid": "FreeMonoid",
"Set": "BooleanAlgebra",
"set": "BooleanAlgebra",
"NonEmptySet": "BooleanAlgebra",
"non_empty_set": "BooleanAlgebra",
"BooleanAlgebra": "BooleanAlgebra",
"boolean_algebra": "BooleanAlgebra",
"Map": "PartialFunction",
"map": "PartialFunction",
"PartialFunction": "PartialFunction",
"partial_function": "PartialFunction"
}

fn container_to_algebra_name(name: String) -> String? {
map_get(container_to_algebra, name)
}

// Bool: two-valued coproduct. Structurally: Disj + 2 unit variants.
// Target: Bool = BooleanAlgebra over {True, False}.
type Bool = True | False
Expand Down
73 changes: 19 additions & 54 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 @@ -118,16 +119,6 @@ type TcoReassignInput {
depth: Int
}

type TypedItemKind
= TypedItemTypeDef
| TypedItemTypeAlias
| TypedItemTypeDecl
| TypedItemFunction
| TypedItemDataDef
| TypedItemServiceDef
| TypedItemResourceDef
| TypedItemUnhandled


// =========================================================================
// Backend capability contract -- what each backend declares it can handle.
Expand Down Expand Up @@ -1340,50 +1331,6 @@ fn classify_transport(t: Node) -> TransportKind {
else { LocalKind }
}

// =========================================================================
// Shared classification functions -- target-agnostic item/type/transport
// dispatch. Each backend calls these to determine WHAT kind of thing it's
// looking at, then applies its own rendering for HOW to emit it.
//
// Sustainability invariant: "No duplicate representations."
// These classifiers are the single authority for item/type/transport kind.
// =========================================================================

// Classify a typed item into one of the structural categories.
// Returns: "type_def", "type_alias", "type_decl", "function", "data_def",
// "service_def", "resource_def", "extern_func", or "unhandled".
// For "function", callers must further check item.uses to distinguish fn vs func.
fn classify_typed_item(item: Node) -> TypedItemKind {
let item_has_structure = item.connective != NoConnective
let is_bare_leaf = item_has_structure == false && item.body == none && item.params |> count == 0 && item.transport == none && item.children |> count == 0
let kind = if is_bare_leaf && is_type_alias_return_node(n: rt_type(n: item)) {
TypedItemTypeAlias
} else if is_bare_leaf && !is_type_alias_return_node(n: rt_type(n: item)) {
// Bare leaf declarations with no alias body (e.g., `type Bool`, `type Unit`).
// These are type-system declarations handled by the type map — emitting a
// definition would duplicate what the type map already provides.
TypedItemTypeDecl
} else if item_has_structure && item.transport == none {
TypedItemTypeDef
} else if item.body != none && item.type_annotation == none {
TypedItemFunction
} else if item.body != none && item.type_annotation != none {
TypedItemDataDef
} else if item.transport != none && item.children |> count > 0 {
TypedItemServiceDef
} else if (item.transport == none && item.children |> count > 0) || (item.transport == none && item.children |> count == 0 && item.properties |> count > 0 && item.body == none) {
// Resources: either with capabilities (children > 0) or without (have properties but no body/transport/children).
// Note: inferred may be Some { value: Unit } because the reconciler defaults pass-through items to Unit.
TypedItemResourceDef
} else if item.params |> count > 0 && item.body == none && item.transport == none && item.children |> count == 0 {
// Bare parameterized type declaration (e.g., type List<element>).
// These are type-system declarations and intentionally emit no runtime code.
TypedItemTypeDecl
} else {
TypedItemUnhandled
}
kind
}


// =========================================================================
Expand Down Expand Up @@ -1752,6 +1699,24 @@ 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.
//
// L1 VIOLATION: name-proxy check on resolved type (boundary sufficiency).
// Inference should encode "this is a call" in the IR (ExprCall
// normalization), not leave emit to re-derive it from type-name + arity.
// Dissolves with M4/Tier 2.6: model function application upstream.
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
42 changes: 26 additions & 16 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 @@ -90,11 +91,9 @@ import v2.compiler.infer {

import v2.compiler.emit {
EmitResult, BlockEmitState, InterpPart, TestProjection, TcoFrame, TcoReassignInput,
TypedItemKind, TypedItemTypeDef, TypedItemTypeAlias, TypedItemTypeDecl, TypedItemFunction,
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 All @@ -111,7 +110,7 @@ import v2.compiler.emit {
has_nested_records_node,
is_service_item,
typed_named_arg_matches, order_typed_call_args,
classify_typed_item,
is_type_alias_return_node,
extract_test_projections,
is_tco_eligible, emit_shared_tco_expr,
tco_reassign_core,
Expand Down Expand Up @@ -327,8 +326,8 @@ fn go_package_name(module_name: String) -> String {

fn emit_go_imports(items: List<Node>, imports: List<Node>) -> String {
let has_services = items |> any(item => is_service_item(item: item))
let has_types = items |> any(item => classify_typed_item(item: item) == TypedItemTypeDef)
let has_functions = items |> any(item => classify_typed_item(item: item) == TypedItemFunction)
let has_types = items |> any(item => item.connective != NoConnective && item.transport == none)
let has_functions = items |> any(item => item.body != none && item.type_annotation == none)
let std_imports = collect_go_std_imports(has_services: has_services, has_types: has_types, has_functions: has_functions)
let pkg_imports = imports |> map(imp =>
let mod_name = module_to_filename(name: imp.name)
Expand Down Expand Up @@ -360,24 +359,26 @@ fn collect_go_std_imports(has_services: Bool, has_types: Bool, has_functions: Bo
fn emit_go_typed_item(item: Node, registry: Map<String, ItemInfo>, scope: InferScope) -> String {
let env = scope.type_env
let item_text = authored_name(env: env, node: item)
let kind = classify_typed_item(item: item)
if (kind == TypedItemTypeDef) {
// Structural dispatch on Node fields directly (CM: no shared taxonomy).
let item_has_structure = item.connective != NoConnective
let is_bare_leaf = !item_has_structure && item.body == none && item.params |> count == 0 && item.transport == none && item.children |> count == 0
if item_has_structure && item.transport == none {
emit_go_type_def_from_connective(item: item, env: env)
} else if (kind == TypedItemTypeAlias) {
} else if is_bare_leaf && is_type_alias_return_node(n: rt_type(n: item)) {
emit_go_type_alias(name: item_text, base: rt_type(n: item))
} else if (kind == TypedItemTypeDecl) {
} else if is_bare_leaf || (item.params |> count > 0 && item.body == none && item.transport == none && item.children |> count == 0) {
""
} else if (kind == TypedItemFunction) {
} else if item.body != none && item.type_annotation == none {
if item.uses |> count > 0 {
emit_go_func_def(name: item_text, params: item.params, inferred: rt_type(n: item), uses: item.uses, body: item.body.value, registry: registry, scope: scope)
} else {
emit_go_fn_def(name: item_text, params: item.params, inferred: rt_type(n: item), body: item.body.value, registry: registry, scope: scope)
}
} else if (kind == TypedItemDataDef) {
} else if item.body != none && item.type_annotation != none {
emit_go_data_def(name: item_text, type_node: item.type_annotation.value, value: item.body.value, registry: registry, scope: scope)
} else if (kind == TypedItemServiceDef) {
} else if item.transport != none && item.children |> count > 0 {
emit_go_service_def(item: item, registry: registry, env: env)
} else if (kind == TypedItemResourceDef) {
} else if (item.transport == none && item.children |> count > 0) || (item.transport == none && item.children |> count == 0 && item.properties |> count > 0 && item.body == none) {
emit_go_resource_def(item: item, env: env)
} else {
concat("func init() { panic(\"EMIT BUG: unhandled item: ", item_text, "\") }")
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" { concat(prefix, emit_keyword(key: "null", target: Go)) }
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
42 changes: 26 additions & 16 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 @@ -80,11 +81,9 @@ import v2.compiler.infer {

import v2.compiler.emit {
EmitResult, BlockEmitState, InterpPart, TestProjection, TcoFrame, TcoReassignInput,
TypedItemKind, TypedItemTypeDef, TypedItemTypeAlias, TypedItemTypeDecl, TypedItemFunction,
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 All @@ -101,7 +100,7 @@ import v2.compiler.emit {
language_spec,
is_null_coalesce, emit_null_coalesce, is_type_alias_return_node,
is_service_item, has_service_items,
classify_typed_item,
is_type_alias_return_node,
extract_test_projections,
is_tco_eligible, emit_shared_tco_expr,
tco_reassign_core,
Expand Down Expand Up @@ -332,8 +331,8 @@ fn emit_py_imports(imports: List<Node>) -> String {

fn emit_py_prelude(typed_module: TypedModule) -> String {
let items = typed_module.items
let has_structs = items |> any(item => classify_typed_item(item: item) == TypedItemTypeDef && item.connective == Conj)
let has_enums = items |> any(item => classify_typed_item(item: item) == TypedItemTypeDef && item.connective == Disj)
let has_structs = items |> any(item => item.connective == Conj && item.transport == none)
let has_enums = items |> any(item => item.connective == Disj && item.transport == none)
let has_services = items |> any(item => is_service_item(item: item))

let future_import = "from __future__ import annotations\n"
Expand All @@ -352,24 +351,26 @@ fn emit_py_prelude(typed_module: TypedModule) -> String {
fn emit_py_typed_item(item: Node, registry: Map<String, ItemInfo>, scope: InferScope) -> String {
let env = scope.type_env
let item_text = authored_name(env: env, node: item)
let kind = classify_typed_item(item: item)
if (kind == TypedItemTypeDef) {
// Structural dispatch on Node fields directly (CM: no shared taxonomy).
let item_has_structure = item.connective != NoConnective
let is_bare_leaf = !item_has_structure && item.body == none && item.params |> count == 0 && item.transport == none && item.children |> count == 0
if item_has_structure && item.transport == none {
emit_py_type_def_from_connective(item: item, env: env)
} else if (kind == TypedItemTypeAlias) {
} else if is_bare_leaf && is_type_alias_return_node(n: rt_type(n: item)) {
concat(item_text, " = ", emit_node_type(n: rt_type(n: item), target: Python))
} else if (kind == TypedItemTypeDecl) {
} else if is_bare_leaf || (item.params |> count > 0 && item.body == none && item.transport == none && item.children |> count == 0) {
""
} else if (kind == TypedItemFunction) {
} else if item.body != none && item.type_annotation == none {
if item.uses |> count > 0 {
emit_py_func_def(name: item_text, params: item.params, inferred: rt_type(n: item), uses: item.uses, body: item.body.value, registry: registry, scope: scope)
} else {
emit_py_fn_def(name: item_text, params: item.params, inferred: rt_type(n: item), body: item.body.value, registry: registry, scope: scope)
}
} else if (kind == TypedItemDataDef) {
} else if item.body != none && item.type_annotation != none {
emit_py_data_def(name: item_text, type_node: item.type_annotation.value, value: item.body.value, registry: registry, scope: scope)
} else if (kind == TypedItemServiceDef) {
} else if item.transport != none && item.children |> count > 0 {
emit_py_service_def(item: item, registry: registry, env: env)
} else if (kind == TypedItemResourceDef) {
} else if (item.transport == none && item.children |> count > 0) || (item.transport == none && item.children |> count == 0 && item.properties |> count > 0 && item.body == none) {
emit_py_resource_def(item: item, env: env)
} else {
concat("# unhandled node: ", item_text)
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" { 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
Loading
Loading