{"record":{"id":"9757e37b2f90a57b","repo":"BoundaryML/baml","slug":"sys-op-callee-must-resolve-to-a-statically-known-global","errorCode":null,"errorMessage":"sys_op callee must resolve to a statically-known global function: {callee:?}","messagePattern":"sys_op callee must resolve to a statically-known global function: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"baml_language/crates/baml_compiler2_emit/src/emit.rs","lineNumber":2538,"sourceCode":"            Terminator::SysOp {\n                callee,\n                args,\n                runtime_id,\n                destination,\n                target,\n                unwind: _,\n            } => {\n                let callee_item = pull_semantics::resolve_constant_function_item(\n                    callee,\n                    &self.analysis.classifications,\n                    &self.analysis.def_use,\n                );\n                let global_callee = callee_item\n                    .as_ref()\n                    .and_then(|item| self.try_function_global_index(item))\n                    .map(GlobalIndex::from_raw)\n                    .unwrap_or_else(|| {\n                        panic!(\n                            \"sys_op callee must resolve to a statically-known global function: {callee:?}\"\n                        )\n                    });\n\n                unwrap_infallible(pull_semantics::walk_call_direct_args(self, args));\n                if let Some(runtime_id) = runtime_id {\n                    unwrap_infallible(pull_semantics::walk_operand_pull(self, runtime_id));\n                }\n                let inst = if runtime_id.is_some() {\n                    self.emit(Instruction::SysOpWithRuntimeId(global_callee))\n                } else {\n                    self.emit(Instruction::SysOp(global_callee))\n                };\n                if let Some(item) = &callee_item {\n                    self.set_operand(inst, OperandMeta::Callable(item.to_string()));\n                }\n                self.emit_store_place(destination);\n                self.emit_jump_unless_fallthrough(*target);","sourceCodeStart":2520,"sourceCodeEnd":2556,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_compiler2_emit/src/emit.rs#L2520-L2556","documentation":"This is a compiler-internal panic raised while lowering a sys_op call in the baml_compiler2_emit backend. The emitter requires that the callee of a sys_op instruction resolve to a statically-known global function so it can emit a GlobalIndex; if the callee symbol cannot be mapped to a global index, the compiler treats it as a broken internal invariant and panics. It indicates the MIR passed to the emitter contains a call whose target was not registered as a global, which should have been caught in earlier passes.","triggerScenarios":"Compiling BAML source where a sys_op call's callee item fails try_function_global_index(), e.g. the callee is a dynamically-dispatched or unregistered function reference rather than a top-level function definition.","commonSituations":"Encountered during BAML compiler development or when feeding IR from a modified/buggy front-end pass; end users hit it only when the compiler pipeline has a regression (e.g. a new language feature lowering calls differently).","solutions":["Ensure the sys_op callee is a statically-known global function (a top-level fn) rather than a lambda, method value, or dynamic callee.","Check that the front-end/MIR passes registered every called function in the globals map so try_function_global_index can resolve it.","File a bug with the BAML source that reproduces it; this is a compiler invariant violation, not a user-fixable configuration issue.","Bisect compiler/toolchain versions to find the regression and pin to a working baml-cli version."],"exampleFix":"// before: calling a sys_op through a non-global callee\nlet f = some.dynamic_callee;\nsys_op(f, args);\n// after: call the named global function directly\nsys_op(known_global_fn, args);","handlingStrategy":"validation","validationCode":"// ensure sys_op callees are top-level named functions\nfn is_static_global_callee(callee: &Callee) -> bool {\n    matches!(callee, Callee::NamedFunction(name) if registry.contains_global(name))\n}","typeGuard":"fn as_global_index(callee: &Callee) -> Option<GlobalIndex> {\n    match callee {\n        Callee::NamedFunction(name) => globals.get(name).map(|i| GlobalIndex::from_raw(*i)),\n        _ => None,\n    }\n}","tryCatchPattern":"// panics are not catchable; guard the pipeline\nmatch compile(source) {\n    Ok(bytecode) => run(bytecode),\n    Err(e) => log_compiler_bug(e), // include repro source\n}","preventionTips":["Call sys_ops only with statically-known global functions","Keep compiler and runtime versions aligned","Add CI compile tests for every sys_op usage pattern","Fuzz the compiler front-end to catch unresolved callees early"],"tags":["compiler","panic","internal-invariant","rust"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}