Skip to content

Commit 32999cc

Browse files
committed
Make compute dispatch language-agnostic via builtin alias
1 parent 9badd2e commit 32999cc

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

crates/compiler/src/ssa.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ use zyntax_typed_ast::{
1919
ConstValue, InternedString, Type,
2020
};
2121

22+
/// Internal alias used when lowering `compute(...) { ... }` expressions.
23+
/// This must not collide with user code.
24+
const INTERNAL_COMPUTE_ALIAS: &str = "__internal_compute_dispatch";
25+
2226
/// SSA builder state
2327
pub struct SsaBuilder {
2428
/// Current function being built
@@ -1752,11 +1756,9 @@ impl SsaBuilder {
17521756
if name_str == "Some" || name_str == "Ok" || name_str == "Err" {
17531757
return self
17541758
.translate_enum_constructor(block_id, &name_str, args, &expr.ty);
1755-
}
1756-
1757-
// Check if this is an external runtime symbol (e.g., "$haxe$trace$int")
1758-
// External symbols start with '$' and are resolved at link time
1759-
if name_str.starts_with('$') {
1759+
} else if name_str.starts_with('$') {
1760+
// Check if this is an external runtime symbol (e.g., "$haxe$trace$int")
1761+
// External symbols start with '$' and are resolved at link time
17601762
(crate::hir::HirCallable::Symbol(name_str), None)
17611763
} else if let Some(&func_id) = self.function_symbols.get(func_name) {
17621764
// Direct function call to known function
@@ -1851,7 +1853,7 @@ impl SsaBuilder {
18511853
TypedExpression::Compute(compute) => {
18521854
// Lower compute expressions through the existing call pipeline for now.
18531855
// This preserves call-based execution while keeping typed compute structure.
1854-
let compute_name = InternedString::new_global("compute");
1856+
let compute_name = InternedString::new_global(INTERNAL_COMPUTE_ALIAS);
18551857
let lowered = zyntax_typed_ast::typed_ast::TypedCall {
18561858
callee: Box::new(zyntax_typed_ast::typed_node(
18571859
TypedExpression::Variable(compute_name),

crates/zynml/ml.zyn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@
2929
// ============================================================================
3030

3131
@builtin {
32+
// Internal dispatch aliases (language-level constructs lowered to plugin calls)
33+
__internal_compute_dispatch: "$ZynML$compute",
34+
3235
// === Tensor Operations (zrtl_tensor) ===
3336
tensor: "tensor_from_array", // tensor([1.0, 2.0]) -> tensor_from_array([1.0, 2.0])
3437
tensor_from_array: "$Tensor$from_array_f32",

0 commit comments

Comments
 (0)