Repository navigation
Refactor container classification and zero-arg callable detection #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
e4eb072
1e4a5b8
20e3ce0
19af457
6bdb2de
1365e88
4218462
69a4cf5
e23340c
c1971b1
a3e0936
80e9484
57efa81
b54dcae
a8ae883
0ff776c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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, | ||
|
|
@@ -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. | ||
|
|
@@ -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 | ||
| } | ||
|
|
||
|
|
||
| // ========================================================================= | ||
|
|
@@ -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 { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Acknowledged — this is a pre-existing L1 violation (was in 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) | ||
| // | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invariant violation:
container_to_algebrare-states theList/Set/Mapto algebra facts as a hand-maintainedMap<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.There was a problem hiding this comment.
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 tostd/types.dagfor 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