{"record":{"id":"a3746a6cd66d1626","repo":"BoundaryML/baml","slug":"failed-to-allocate-bigint-field-field-name-p","errorCode":null,"errorMessage":"failed to allocate bigint field `{field_name}`: {p}","messagePattern":"failed to allocate bigint field `(.+?)`: (.+?)","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"baml_language/crates/baml_builtins2_codegen/src/codegen.rs","lineNumber":652,"sourceCode":"        }\n        // `to_value` has no error channel (`fn to_value(self, vm) -> Value`),\n        // so an out-of-i63 native i64 reaches this path only when caller-side\n        // Rust constructed a struct field that violates the i63 BAML\n        // contract. Fail loudly in *both* debug and release rather than\n        // truncating silently via `Value::int`'s `debug_assert`.\n        BamlType::Int => format!(\n            \"bex_vm_types::Value::try_int(self.{field_name}).unwrap_or_else(|| panic!(\\\n                \\\"`{field_name}: int` is outside BAML int range [{{}}, {{}}], got {{}}\\\", \\\n                bex_vm_types::Value::INT_MIN, bex_vm_types::Value::INT_MAX, self.{field_name}))\"\n        ),\n        // Bigints are always heap-allocated, and allocation is fallible (the\n        // value may exceed `MAX_BIGINT_BITS`). `to_value` has no error channel,\n        // so — like the `int` range case above — fail loudly rather than\n        // silently dropping the overflow. The panic reports the bit count from\n        // `VmPanic::AllocFailure` (`{p}`), never the bigint itself, which could\n        // be millions of digits long.\n        BamlType::Bigint => format!(\n            \"vm.try_alloc_bigint(self.{field_name}).unwrap_or_else(|p| panic!(\\\n                \\\"failed to allocate bigint field `{field_name}`: {{p}}\\\"))\"\n        ),\n        BamlType::Float => {\n            format!(\"bex_vm_types::Value::object(vm.alloc_float(self.{field_name}))\")\n        }\n        BamlType::Bool => format!(\"bex_vm_types::Value::bool(self.{field_name})\"),\n        BamlType::Null => \"bex_vm_types::Value::NULL\".to_string(),\n        // String, List, Map, Optional, Generic, Named, Media — already a Value\n        _ => format!(\"self.{field_name}\"),\n    }\n}\n\n// ============================================================================\n// Naming helpers\n// ============================================================================\n\nfn to_pascal_case(s: &str) -> String {\n    let mut chars = s.chars();","sourceCodeStart":634,"sourceCodeEnd":670,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_builtins2_codegen/src/codegen.rs#L634-L670","documentation":"Generated struct-copy code panics when try_alloc_bigint fails while copying a `bigint` field into a VM value. Bigints are heap-allocated and allocation is fallible (the value may exceed MAX_BIGINT_BITS); since `to_value` has no error channel, the failure panics with the VmPanic::AllocFailure report rather than silently dropping the overflow. The panic intentionally prints only the panic reason, never the huge number itself.","triggerScenarios":"emit_copy_struct -> copy_field_to_value generating `vm.try_alloc_bigint(self.field).unwrap_or_else(|p| panic!(...))` for a bigint field whose bit count exceeds MAX_BIGINT_BITS.","commonSituations":"Computing astronomically large exponents/products in Rust and passing them as BAML bigint fields; host memory exhaustion during allocation.","solutions":["Check the bigint's bit length (bits()) against MAX_BIGINT_BITS before constructing the struct.","Truncate or reduce the value's magnitude at the source computation.","Ensure sufficient memory is available if the failure is OOM-driven."],"exampleFix":"// before\nMyStruct { big: giant_bigint }\n// after\nif giant_bigint.bits() > MAX_BIGINT_BITS { /* reduce or reject */ }\nMyStruct { big: giant_bigint }","handlingStrategy":"validation","validationCode":"fn allocatable(v: &BigInt) -> bool { v.bits() <= MAX_BIGINT_BITS }","typeGuard":null,"tryCatchPattern":"// This is a panic, not a Result; check size before constructing\nif !allocatable(&v) { /* reduce magnitude or reject upstream */ }","preventionTips":["Check bit length against MAX_BIGINT_BITS before passing bigints to the VM.","Bound intermediate computations (exponents, factorials, products).","Monitor available memory for allocations of huge values.","Prefer saturating/clamping logic over unbounded growth."],"tags":["panic","allocation","bigint","codegen"],"backgroundTag":"value-out-of-range","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"}