{"record":{"id":"e0aec6b636672add","repo":"BoundaryML/baml","slug":"type-alias-offset-fits-u32","errorCode":null,"errorMessage":"type-alias offset fits u32","messagePattern":"type-alias offset fits u32","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_compiler2_emit/src/lib.rs","lineNumber":2450,"sourceCode":"            PoolObjKind::Class => {\n                let off = units[u].classes.len();\n                units[u].classes.push(obj);\n                LocalRef::Class(u32::try_from(off).expect(\"class offset fits u32\"))\n            }\n            PoolObjKind::Enum => {\n                let off = units[u].enums.len();\n                units[u].enums.push(obj);\n                LocalRef::Enum(u32::try_from(off).expect(\"enum offset fits u32\"))\n            }\n            PoolObjKind::Interface => {\n                let off = units[u].interfaces.len();\n                units[u].interfaces.push(obj);\n                LocalRef::Interface(u32::try_from(off).expect(\"interface offset fits u32\"))\n            }\n            PoolObjKind::TypeAlias => {\n                let off = units[u].type_alias_objects.len();\n                units[u].type_alias_objects.push(obj);\n                LocalRef::TypeAlias(u32::try_from(off).expect(\"type-alias offset fits u32\"))\n            }\n            PoolObjKind::NamedFn(_) | PoolObjKind::CodeAnon => {\n                let off = units[u].code.len();\n                units[u].code.push(obj);\n                LocalRef::Code(u32::try_from(off).expect(\"code offset fits u32\"))\n            }\n        };\n        obj_localref.push(local_ref);\n    }\n\n    // ---- Global slot -> owner + local flat index ----------------------------\n    // slot -> fq name (functions, interface bodies, and lets).\n    let mut slot_to_name: Vec<Option<String>> = vec![None; program.globals.len()];\n    for (name, &slot) in &program.function_global_indices {\n        slot_to_name[slot] = Some(name.clone());\n    }\n    for (slot, name) in &interface_body_slot_names {\n        slot_to_name[*slot] = Some(name.clone());","sourceCodeStart":2432,"sourceCodeEnd":2468,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_compiler2_emit/src/lib.rs#L2432-L2468","documentation":"This is a Rust panic raised by `u32::try_from(off).expect(\"type-alias offset fits u32\")` in baml_compiler2_emit's object-pool emitter. When a new TypeAlias pool object is pushed into a compilation unit's `type_alias_objects` vector, its index is converted to u32 for the emitted `LocalRef::TypeAlias`. The panic fires only if the number of type-alias objects in one unit exceeds u32::MAX (about 4.29 billion), which would make the emitted u32 offset unable to address the object. It is an internal invariant guard, not a user-facing validation error.","triggerScenarios":"Compiling a single compilation unit whose `type_alias_objects` pool grows beyond 4,294,967,295 entries — i.e. a BAML source containing (or a code generator emitting) more than u32::MAX type-alias definitions in one unit.","commonSituations":"Practically never hit by hand-written BAML code; would require runaway code generation, a bug in a macro/expansion layer that duplicates type-alias definitions in a loop, or a corrupted/huge generated source. Also seen by contributors running fuzzers with artificially crafted giant inputs.","solutions":["Check the input for runaway or duplicated type-alias definitions — a generator loop may be emitting the same type alias millions of times; fix the generator.","Split the compilation unit: move type aliases into separate units/files so no single unit exceeds u32::MAX objects.","Reduce total type-alias count in the offending source by deduplicating aliases that resolve to the same underlying type.","If this occurs on normal-sized input, report it as a compiler bug: the pool indexing may be looping and re-pushing objects; file an issue with the reproducing source."],"exampleFix":"// before: emitting one alias object per textual occurrence\nfor alias in all_aliases_everywhere {\n    units[u].type_alias_objects.push(obj);\n}\n// after: deduplicate aliases before pooling\nlet seen = &mut HashSet::new();\nfor alias in all_aliases_everywhere.into_iter().filter(|a| seen.insert(a.key())) {\n    units[u].type_alias_objects.push(obj);\n}","handlingStrategy":"validation","validationCode":"assert!(\n    units[u].type_alias_objects.len() < u32::MAX as usize,\n    \"compilation unit has too many type-alias objects for u32 offsets\"\n);","typeGuard":null,"tryCatchPattern":"// Rust panics cannot be caught with catch_unwind safely across FFI; validate before emitting:\nlet result = std::panic::catch_unwind(|| emit_pool(units));\nmatch result {\n    Ok(pool) => pool,\n    Err(_) => fallback_to_diagnostic_error(\"pool overflow\"),\n}","preventionTips":["Deduplicate type-alias definitions before pooling so no unit grows unboundedly.","Split very large generated sources across multiple compilation units.","Add a compile-time (early) diagnostic when a unit's object counts approach u32::MAX instead of panicking mid-emit.","When generating BAML programmatically, assert emitted alias counts per unit stay far below 2^32."],"tags":["rust","compiler","panic","overflow","internal-invariant"],"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"}