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).
This commit is contained in:
1 parent
b38b769932
commit
361a6cc341
8 files changed
+10
-123
No files matched your search
@@ -8,9 +8,7 @@
|
|||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
|
|
||||||
use marqdo_expression::{BinaryOp, Expr, UnaryOp};
|
use marqdo_expression::{BinaryOp, Expr, UnaryOp};
|
||||||
use marqdo_ir::{
|
use marqdo_ir::{Function, Module, ModuleId, PlaceTarget, Resource, SignatureKind, Stmt, UnitKind};
|
||||||
CallTarget, Function, Module, ModuleId, PlaceTarget, Resource, SignatureKind, Stmt, UnitKind,
|
|
||||||
};
|
|
||||||
use marqdo_span::Span;
|
use marqdo_span::Span;
|
||||||
use serde_json::{json, Value};
|
use serde_json::{json, Value};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
@@ -273,12 +271,6 @@ fn stmt_json(stmt: &Stmt) -> Value {
|
|||||||
"value": expr_json(expr),
|
"value": expr_json(expr),
|
||||||
"span": span_json(*span),
|
"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::<Vec<_>>(),
|
|
||||||
"span": span_json(*span),
|
|
||||||
}),
|
|
||||||
Stmt::Branch { arms, span } => json!({
|
Stmt::Branch { arms, span } => json!({
|
||||||
"kind": "branch",
|
"kind": "branch",
|
||||||
"arms": arms.iter().map(|arm| json!({
|
"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<Value> {
|
fn reference_edges(project: &LoadedProject, module_id: &marqdo_ir::ModuleId) -> Vec<Value> {
|
||||||
let Some(file) = project.files.get(module_id) else {
|
let Some(file) = project.files.get(module_id) else {
|
||||||
return Vec::new();
|
return Vec::new();
|
||||||
@@ -532,12 +511,6 @@ fn collect_calls(
|
|||||||
}
|
}
|
||||||
Stmt::Eval { expr: value, .. } => expr_calls(project, module, function, value, calls),
|
Stmt::Eval { expr: value, .. } => expr_calls(project, module, function, value, calls),
|
||||||
Stmt::Return { 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, .. } => {
|
Stmt::Branch { arms, .. } => {
|
||||||
for arm in arms {
|
for arm in arms {
|
||||||
expr_calls(project, module, function, &arm.condition, calls);
|
expr_calls(project, module, function, &arm.condition, calls);
|
||||||
|
|||||||
@@ -540,7 +540,6 @@ fn stmts_use_print(stmts: &[Stmt]) -> bool {
|
|||||||
target_uses || expr_uses_print(value)
|
target_uses || expr_uses_print(value)
|
||||||
}
|
}
|
||||||
Stmt::Eval { expr, .. } | Stmt::Return { value: expr, .. } => expr_uses_print(expr),
|
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
|
Stmt::Branch { arms, .. } => arms
|
||||||
.iter()
|
.iter()
|
||||||
.any(|arm| expr_uses_print(&arm.condition) || stmts_use_print(&arm.body)),
|
.any(|arm| expr_uses_print(&arm.condition) || stmts_use_print(&arm.body)),
|
||||||
|
|||||||
@@ -151,11 +151,6 @@ impl<'a> CallChecker<'a> {
|
|||||||
Stmt::Eval { expr: value, .. } | Stmt::Return { value, .. } => {
|
Stmt::Eval { expr: value, .. } | Stmt::Return { value, .. } => {
|
||||||
self.expr(value);
|
self.expr(value);
|
||||||
}
|
}
|
||||||
Stmt::Call { call, .. } => {
|
|
||||||
for Arg { value, .. } in &call.args {
|
|
||||||
self.expr(value);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Stmt::Branch { arms, .. } => {
|
Stmt::Branch { arms, .. } => {
|
||||||
for arm in arms {
|
for arm in arms {
|
||||||
self.expr(&arm.condition);
|
self.expr(&arm.condition);
|
||||||
|
|||||||
@@ -202,12 +202,6 @@ impl<'a> Analyzer<'a> {
|
|||||||
self.read_expr(expr, &state);
|
self.read_expr(expr, &state);
|
||||||
state
|
state
|
||||||
}
|
}
|
||||||
Stmt::Call { call, .. } => {
|
|
||||||
for Arg { value, .. } in &call.args {
|
|
||||||
self.read_expr(value, &state);
|
|
||||||
}
|
|
||||||
state
|
|
||||||
}
|
|
||||||
Stmt::Return { value, .. } => {
|
Stmt::Return { value, .. } => {
|
||||||
self.read_expr(value, &state);
|
self.read_expr(value, &state);
|
||||||
state
|
state
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use marqdo_expression::{Arg, Expr};
|
use marqdo_expression::Expr;
|
||||||
use marqdo_span::Span;
|
use marqdo_span::Span;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
@@ -283,13 +283,6 @@ pub enum Stmt {
|
|||||||
/// Span of the whole statement.
|
/// Span of the whole statement.
|
||||||
span: Span,
|
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.
|
/// Ordered list: first matching condition wins.
|
||||||
Branch {
|
Branch {
|
||||||
/// Arms in AST order.
|
/// Arms in AST order.
|
||||||
@@ -323,7 +316,6 @@ impl Stmt {
|
|||||||
match self {
|
match self {
|
||||||
Stmt::Assign { span, .. }
|
Stmt::Assign { span, .. }
|
||||||
| Stmt::Eval { span, .. }
|
| Stmt::Eval { span, .. }
|
||||||
| Stmt::Call { span, .. }
|
|
||||||
| Stmt::Branch { span, .. }
|
| Stmt::Branch { span, .. }
|
||||||
| Stmt::Loop { span, .. }
|
| Stmt::Loop { span, .. }
|
||||||
| Stmt::Return { span, .. } => *span,
|
| Stmt::Return { span, .. } => *span,
|
||||||
@@ -344,42 +336,6 @@ pub struct BranchArm {
|
|||||||
pub span: Span,
|
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<Arg>,
|
|
||||||
/// Span of the call.
|
|
||||||
pub span: Span,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// One explicit import declared in front matter.
|
/// One explicit import declared in front matter.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
|
||||||
pub struct ImportDecl {
|
pub struct ImportDecl {
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use std::collections::BTreeMap;
|
|||||||
|
|
||||||
use marqdo_expression::{BinaryOp, Expr, RecordEntry};
|
use marqdo_expression::{BinaryOp, Expr, RecordEntry};
|
||||||
use marqdo_host::{ExecutionContext, Host, HostOp, ResourceRead};
|
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_span::Span;
|
||||||
use marqdo_value::{ErrorCategory, ResourceHandle, RuntimeError, Value};
|
use marqdo_value::{ErrorCategory, ResourceHandle, RuntimeError, Value};
|
||||||
|
|
||||||
@@ -344,9 +344,6 @@ impl<'a> Interpreter<'a> {
|
|||||||
Stmt::Eval { expr, .. } => {
|
Stmt::Eval { expr, .. } => {
|
||||||
self.eval_expr(expr, frame)?;
|
self.eval_expr(expr, frame)?;
|
||||||
}
|
}
|
||||||
Stmt::Call { call, span } => {
|
|
||||||
self.exec_call_site(program, call, *span, frame)?;
|
|
||||||
}
|
|
||||||
Stmt::Return { value, span } => {
|
Stmt::Return { value, span } => {
|
||||||
let value = self.eval_expr(value, frame)?;
|
let value = self.eval_expr(value, frame)?;
|
||||||
let module = frame.function.module.canonical();
|
let module = frame.function.module.canonical();
|
||||||
@@ -424,36 +421,6 @@ impl<'a> Interpreter<'a> {
|
|||||||
Ok(Flow::Next)
|
Ok(Flow::Next)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec_call_site(
|
|
||||||
&mut self,
|
|
||||||
program: &'a Program,
|
|
||||||
call: &'a marqdo_ir::CallSite,
|
|
||||||
span: Span,
|
|
||||||
frame: &mut Frame,
|
|
||||||
) -> Result<Value, RuntimeError> {
|
|
||||||
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.
|
/// Commit one byte into an addressable region after all operand checks.
|
||||||
///
|
///
|
||||||
/// The three operands are already evaluated, so a rejected value never
|
/// The three operands are already evaluated, so a rejected value never
|
||||||
|
|||||||
+2
-1
@@ -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`);
|
`le`, `gt`, `ge`, `add`, `sub`, `mul`, `div`, `floor_div`, `mod`, `pow`);
|
||||||
* `call` with `callee` and `args`;
|
* `call` with `callee` and `args`;
|
||||||
* `assign`, `expression`, `call_site`, `branch` (ordered arms), `loop`,
|
* `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
|
Every node carries a byte `span`. Nodes outside the supported public subset
|
||||||
must be marked `unsupported` (future extension), never silently given invented
|
must be marked `unsupported` (future extension), never silently given invented
|
||||||
|
|||||||
+5
-3
@@ -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
|
Modules are sorted by `id`; functions, units and calls keep document order and
|
||||||
the v1 semantic node shapes (`assign`, `expression`, `call_site`, `branch`,
|
the v1 semantic node shapes (`assign`, `expression`, `branch`, `loop`,
|
||||||
`loop`, `return`; literals, variables, lists, records, unary/binary, member,
|
`return`; literals, variables, lists, records, unary/binary, member, index,
|
||||||
index, call). `imports`, `references` and `calls` remain static facts; a
|
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
|
Markdown reference is not a call. `effects` remains `["unknown"]` (a
|
||||||
conservative summary, not a purity proof).
|
conservative summary, not a purity proof).
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user