From 361a6cc341a0b4cb5f04ab940b22a4a3c5a98876 Mon Sep 17 00:00:00 2001 From: cflmy Date: Sat, 21 Nov 2026 15:39:29 +0800 Subject: [PATCH] refactor(ir): drop the dead call-statement representation The pre-RFC link-form block-quote call was removed by RFC-LANG-0002, but the IR still carried Stmt::Call, CallSite and CallTarget with matching branches in the runtime, infer, call validation, loader, analysis projection and JSON output. No mapper produces that variant any more, so it was a second call representation that could never be reached. - remove Stmt::Call, CallSite and CallTarget from marqdo-ir - remove the runtime exec_call_site path and every exhaustive match arm - remove the 'call_site' Analysis node and its JSON helpers - state in spec/analysis-v2.md that calls are expressions; keep v1 as history with a note that call_site is not produced by the current language Verified: cargo clippy --workspace --all-targets -D warnings clean and cargo test --workspace --locked green (62 targets). --- crates/cli/src/analysis.rs | 29 +-------------- crates/cli/src/loader.rs | 1 - crates/marqdo-frontend/src/calls.rs | 5 --- crates/marqdo-frontend/src/infer.rs | 6 ---- crates/marqdo-ir/src/lib.rs | 46 +----------------------- crates/marqdo-runtime/src/interpreter.rs | 35 +----------------- spec/analysis-v1.md | 3 +- spec/analysis-v2.md | 8 +++-- 8 files changed, 10 insertions(+), 123 deletions(-) diff --git a/crates/cli/src/analysis.rs b/crates/cli/src/analysis.rs index 106adf4..a1cfac6 100644 --- a/crates/cli/src/analysis.rs +++ b/crates/cli/src/analysis.rs @@ -8,9 +8,7 @@ use std::path::Path; use marqdo_expression::{BinaryOp, Expr, UnaryOp}; -use marqdo_ir::{ - CallTarget, Function, Module, ModuleId, PlaceTarget, Resource, SignatureKind, Stmt, UnitKind, -}; +use marqdo_ir::{Function, Module, ModuleId, PlaceTarget, Resource, SignatureKind, Stmt, UnitKind}; use marqdo_span::Span; use serde_json::{json, Value}; use sha2::{Digest, Sha256}; @@ -273,12 +271,6 @@ fn stmt_json(stmt: &Stmt) -> Value { "value": expr_json(expr), "span": span_json(*span), }), - Stmt::Call { call, span } => json!({ - "kind": "call_site", - "target": call_target_json(&call.target), - "args": call.args.iter().map(arg_json).collect::>(), - "span": span_json(*span), - }), Stmt::Branch { arms, span } => json!({ "kind": "branch", "arms": arms.iter().map(|arm| json!({ @@ -378,19 +370,6 @@ fn arg_json(arg: &marqdo_expression::Arg) -> Value { }) } -fn call_target_json(target: &CallTarget) -> Value { - match target { - CallTarget::Function { name } => json!({"kind":"function","name":name}), - CallTarget::Qualified { - module_alias, - function, - } => json!({"kind":"qualified","module_alias":module_alias,"function":function}), - CallTarget::Resolved { module, function } => { - json!({"kind":"resolved","module":module.to_string(),"function":function}) - } - } -} - fn reference_edges(project: &LoadedProject, module_id: &marqdo_ir::ModuleId) -> Vec { let Some(file) = project.files.get(module_id) else { return Vec::new(); @@ -532,12 +511,6 @@ fn collect_calls( } Stmt::Eval { expr: value, .. } => expr_calls(project, module, function, value, calls), Stmt::Return { value, .. } => expr_calls(project, module, function, value, calls), - Stmt::Call { call, span } => calls.push(json!({ - "function": function.id.to_string(), - "span": span_json(*span), - "callee": call_target_json(&call.target), - "state": "resolved", - })), Stmt::Branch { arms, .. } => { for arm in arms { expr_calls(project, module, function, &arm.condition, calls); diff --git a/crates/cli/src/loader.rs b/crates/cli/src/loader.rs index cfea324..6a13a88 100644 --- a/crates/cli/src/loader.rs +++ b/crates/cli/src/loader.rs @@ -540,7 +540,6 @@ fn stmts_use_print(stmts: &[Stmt]) -> bool { target_uses || expr_uses_print(value) } Stmt::Eval { expr, .. } | Stmt::Return { value: expr, .. } => expr_uses_print(expr), - Stmt::Call { call, .. } => call.args.iter().any(|arg| expr_uses_print(&arg.value)), Stmt::Branch { arms, .. } => arms .iter() .any(|arm| expr_uses_print(&arm.condition) || stmts_use_print(&arm.body)), diff --git a/crates/marqdo-frontend/src/calls.rs b/crates/marqdo-frontend/src/calls.rs index b7defd3..4252849 100644 --- a/crates/marqdo-frontend/src/calls.rs +++ b/crates/marqdo-frontend/src/calls.rs @@ -151,11 +151,6 @@ impl<'a> CallChecker<'a> { Stmt::Eval { expr: value, .. } | Stmt::Return { value, .. } => { self.expr(value); } - Stmt::Call { call, .. } => { - for Arg { value, .. } in &call.args { - self.expr(value); - } - } Stmt::Branch { arms, .. } => { for arm in arms { self.expr(&arm.condition); diff --git a/crates/marqdo-frontend/src/infer.rs b/crates/marqdo-frontend/src/infer.rs index 8785555..07463e4 100644 --- a/crates/marqdo-frontend/src/infer.rs +++ b/crates/marqdo-frontend/src/infer.rs @@ -202,12 +202,6 @@ impl<'a> Analyzer<'a> { self.read_expr(expr, &state); state } - Stmt::Call { call, .. } => { - for Arg { value, .. } in &call.args { - self.read_expr(value, &state); - } - state - } Stmt::Return { value, .. } => { self.read_expr(value, &state); state diff --git a/crates/marqdo-ir/src/lib.rs b/crates/marqdo-ir/src/lib.rs index a5adab8..20829dd 100644 --- a/crates/marqdo-ir/src/lib.rs +++ b/crates/marqdo-ir/src/lib.rs @@ -12,7 +12,7 @@ use std::collections::BTreeMap; use std::fmt; -use marqdo_expression::{Arg, Expr}; +use marqdo_expression::Expr; use marqdo_span::Span; use serde::{Deserialize, Serialize}; @@ -283,13 +283,6 @@ pub enum Stmt { /// Span of the whole statement. span: Span, }, - /// Markdown-link call form from a block quote. - Call { - /// Resolved call site. - call: CallSite, - /// Span of the whole statement. - span: Span, - }, /// Ordered list: first matching condition wins. Branch { /// Arms in AST order. @@ -323,7 +316,6 @@ impl Stmt { match self { Stmt::Assign { span, .. } | Stmt::Eval { span, .. } - | Stmt::Call { span, .. } | Stmt::Branch { span, .. } | Stmt::Loop { span, .. } | Stmt::Return { span, .. } => *span, @@ -344,42 +336,6 @@ pub struct BranchArm { pub span: Span, } -/// Target of a call statement. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -#[serde(tag = "target", rename_all = "snake_case")] -pub enum CallTarget { - /// Unqualified function in the current module. - Function { - /// Canonical function name. - name: String, - }, - /// Function reached through an imported module alias. - Qualified { - /// Local import alias. - module_alias: String, - /// Canonical function name. - function: String, - }, - /// Function resolved from a Markdown link target. - Resolved { - /// Canonical module identity. - module: ModuleId, - /// Canonical function name. - function: String, - }, -} - -/// A call statement with evaluated arguments. -#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)] -pub struct CallSite { - /// Callee target. - pub target: CallTarget, - /// Arguments in source order. - pub args: Vec, - /// Span of the call. - pub span: Span, -} - /// One explicit import declared in front matter. #[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)] pub struct ImportDecl { diff --git a/crates/marqdo-runtime/src/interpreter.rs b/crates/marqdo-runtime/src/interpreter.rs index e9d837e..bc5172b 100644 --- a/crates/marqdo-runtime/src/interpreter.rs +++ b/crates/marqdo-runtime/src/interpreter.rs @@ -4,7 +4,7 @@ use std::collections::BTreeMap; use marqdo_expression::{BinaryOp, Expr, RecordEntry}; use marqdo_host::{ExecutionContext, Host, HostOp, ResourceRead}; -use marqdo_ir::{builtins, CallTarget, Function, FunctionId, ModuleId, PlaceTarget, Program, Stmt}; +use marqdo_ir::{builtins, Function, FunctionId, ModuleId, PlaceTarget, Program, Stmt}; use marqdo_span::Span; use marqdo_value::{ErrorCategory, ResourceHandle, RuntimeError, Value}; @@ -344,9 +344,6 @@ impl<'a> Interpreter<'a> { Stmt::Eval { expr, .. } => { self.eval_expr(expr, frame)?; } - Stmt::Call { call, span } => { - self.exec_call_site(program, call, *span, frame)?; - } Stmt::Return { value, span } => { let value = self.eval_expr(value, frame)?; let module = frame.function.module.canonical(); @@ -424,36 +421,6 @@ impl<'a> Interpreter<'a> { Ok(Flow::Next) } - fn exec_call_site( - &mut self, - program: &'a Program, - call: &'a marqdo_ir::CallSite, - span: Span, - frame: &mut Frame, - ) -> Result { - let args = self.eval_args(&call.args, frame)?; - let (module, name) = match &call.target { - CallTarget::Function { name } => (frame.function.module.clone(), name.clone()), - CallTarget::Qualified { - module_alias, - function, - } => { - let Some(target) = program.resolve_import(&frame.function.module, module_alias) - else { - return Err(RuntimeError::new( - ErrorCategory::UnknownSymbol, - Some(span), - format!("unknown imported module alias `{module_alias}`"), - )); - }; - (target.clone(), function.clone()) - } - CallTarget::Resolved { module, function } => (module.clone(), function.clone()), - }; - let caller = frame.function.module.clone(); - self.call_by_name_from(&module, &name, args, Some(span), Some(&caller)) - } - /// Commit one byte into an addressable region after all operand checks. /// /// The three operands are already evaluated, so a rejected value never diff --git a/spec/analysis-v1.md b/spec/analysis-v1.md index 88f11d2..c1bb405 100644 --- a/spec/analysis-v1.md +++ b/spec/analysis-v1.md @@ -95,7 +95,8 @@ Body nodes use a small stable language, never internal IR serialization: `le`, `gt`, `ge`, `add`, `sub`, `mul`, `div`, `floor_div`, `mod`, `pow`); * `call` with `callee` and `args`; * `assign`, `expression`, `call_site`, `branch` (ordered arms), `loop`, - `return`. + `return`. (`call_site` existed for the pre-RFC link-form block-quote call and + is not produced by the current language; this document is historical.) Every node carries a byte `span`. Nodes outside the supported public subset must be marked `unsupported` (future extension), never silently given invented diff --git a/spec/analysis-v2.md b/spec/analysis-v2.md index 0ca7bda..3ed6dd6 100644 --- a/spec/analysis-v2.md +++ b/spec/analysis-v2.md @@ -87,9 +87,11 @@ The module object is unchanged from Analysis v1 except for `resources`: ``` Modules are sorted by `id`; functions, units and calls keep document order and -the v1 semantic node shapes (`assign`, `expression`, `call_site`, `branch`, -`loop`, `return`; literals, variables, lists, records, unary/binary, member, -index, call). `imports`, `references` and `calls` remain static facts; a +the v1 semantic node shapes (`assign`, `expression`, `branch`, `loop`, +`return`; literals, variables, lists, records, unary/binary, member, index, +call). The v1 `call_site` node was retired with RFC-LANG-0002: calls are +`call` expressions inside an `assign`/`expression`/`return`/condition body, not +a separate statement. `imports`, `references` and `calls` remain static facts; a Markdown reference is not a call. `effects` remains `["unknown"]` (a conservative summary, not a purity proof).