{"record":{"id":"9c3baeac5d726827","repo":"BoundaryML/baml","slug":"what-item","errorCode":null,"errorMessage":"{what}: {item}","messagePattern":"\\{what\\}: \\{item\\}","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_compiler2_emit/src/emit.rs","lineNumber":2066,"sourceCode":"            return Some(slot);\n        }\n        let rendered = item.to_string();\n        let slot = self.globals.get(&rendered).copied();\n        if slot.is_some() {\n            self.references.record(&rendered);\n        }\n        slot\n    }\n\n    /// [`Self::try_function_global_index`], panicking with `what` when the\n    /// item does not resolve.\n    fn function_global_index(\n        &mut self,\n        item: &baml_compiler2_mir::ItemRef<'ctx>,\n        what: &str,\n    ) -> usize {\n        self.try_function_global_index(item)\n            .unwrap_or_else(|| panic!(\"{what}: {item}\"))\n    }\n\n    /// Push a function reference as a value: a pooled, interned\n    /// `Object::GenericFunction` wrapper over the function's global slot\n    /// (empty `type_args` for a plain reference). Interning by\n    /// (function, `type_args`) over the shared object pool makes identical\n    /// references share ONE pooled object → pointer-stable identity\n    /// (`greet === greet`, `foo<int> === foo<int>`).\n    ///\n    /// Serial emit scans the whole program pool here, so wrappers minted by\n    /// EARLIER functions are reused too. Parallel emit scans only this\n    /// worker's fragment; the serial merge replays the cross-function dedup\n    /// in original function order (see `merge_function_fragment`),\n    /// reproducing the exact serial candidate set and pool layout.\n    fn emit_pooled_function_value(\n        &mut self,\n        item: &baml_compiler2_mir::ItemRef<'ctx>,\n        type_args: &[baml_type::RealizedTy],","sourceCodeStart":2048,"sourceCodeEnd":2084,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_compiler2_emit/src/emit.rs#L2048-L2084","documentation":"`function_global_index` is the panicking wrapper around `try_function_global_index`: when a function item does not resolve to a Pass-1 global slot (it is missing from the `globals` map by its rendered name), the compiler aborts with the caller-supplied `what` context (e.g. \"undefined function\"). The code documents that a `None` from `try_function_global_index` normally means the callee is not statically addressable and callers should fall back to an indirect call; this wrapper is used on paths where resolution is required.","triggerScenarios":"Emitting a function value or direct call to a function name absent from the `globals` slot map — e.g. calling a function defined in a package not registered in this compilation context, referencing a function that was deleted/renamed while stale incremental state persists, or a `Constant::Function`/`GenericFunction` whose item was never slotted by Pass 1.","commonSituations":"Cross-package BAML references to functions that aren't compiled into the current unit; renamed functions with stale caches; typos at the MIR level after a refactor of the function-name rendering (`ItemRef::to_string`) so the lookup key no longer matches the Pass-1 key.","solutions":["Verify the referenced function exists and is part of the compiled package set; add the missing package/module to the compilation","Clean incremental caches and rebuild so Pass 1 re-slots all current functions","Check whether the function was renamed; update the reference at the BAML source level","If the callee can legitimately be unresolvable, switch the call site to the indirect-call fallback via `try_function_global_index` instead of the panicking wrapper"],"exampleFix":"// before\nlet global_idx = self.function_global_index(item, \"undefined function\");\n// after\nmatch self.try_function_global_index(item) {\n    Some(global_idx) => { /* direct reference */ }\n    None => { /* fall back to indirect call */ }\n}","handlingStrategy":"validation","validationCode":"// pre-flight: confirm every referenced function resolves in this compilation unit\nlet unresolved: Vec<_> = referenced_functions\n    .iter()\n    .filter(|f| !globals.contains_key(&f.to_string()))\n    .collect();\nif !unresolved.is_empty() {\n    return Err(format!(\"unresolved functions: {:?}\", unresolved));\n}","typeGuard":null,"tryCatchPattern":"match std::panic::catch_unwind(|| emit_function(item)) {\n    Ok(_) => /* direct emit */,\n    Err(_) => /* fall back to indirect call via try_function_global_index */,\n}","preventionTips":["Keep all referenced packages in the compilation unit","Rebuild from scratch after renaming or moving functions","Verify cross-package exports before referencing remote functions","Use try_function_global_index with a fallback on non-critical paths"],"tags":["compiler","undefined-function","emit","global-resolution"],"backgroundTag":"resource-not-found","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"}