{"record":{"id":"78528b9b1c7c056b","repo":"BoundaryML/baml","slug":"class-field-count-fits-u32","errorCode":null,"errorMessage":"class field count fits u32","messagePattern":"class field count fits u32","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_compiler2_emit/src/lib.rs","lineNumber":1143,"sourceCode":"                        spelling.wire(&qualify_def(db, Definition::Class(class), &class_item.name));\n                    let class_slots = class_field_indices.get(&class_tn.to_string());\n                    declared\n                        .iter()\n                        .map(|iface_field| {\n                            let class_field = block\n                                .field_links\n                                .iter()\n                                .find(|link| link.interface_field == *iface_field)\n                                .map_or(iface_field, |link| &link.class_field);\n                            let slot = class_slots\n                                .and_then(|slots| slots.get(class_field.as_str()))\n                                .copied();\n                            debug_assert!(\n                                slot.is_some(),\n                                \"interface `{iface_tn}` field `{iface_field}` links to \\\n                                 `{class_tn}.{class_field}`, which has no runtime slot\",\n                            );\n                            slot.map(|s| u32::try_from(s).expect(\"class field count fits u32\"))\n                        })\n                        .collect()\n                }\n            };\n            let Some(field_links) = field_links else {\n                continue;\n            };\n            program_packages\n                .entry(spelling.of(pkg_info.root).clone())\n                .or_default()\n                .impl_rules\n                .entry(interface_head)\n                .or_default()\n                .push(ProgramImplRule {\n                    interface_head,\n                    for_ty_pattern,\n                    generic_param_bounds,\n                    interface_args,","sourceCodeStart":1125,"sourceCodeEnd":1161,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_compiler2_emit/src/lib.rs#L1125-L1161","documentation":"While linking interface fields to class fields, the runtime slot index of a linked class field is narrowed to `u32` with `.expect(\"class field count fits u32\")`. The panic means the class field slot index exceeded `u32::MAX`, which the runtime encoding cannot hold — practically indicating a slot-numbering bug rather than a real class with billions of fields.","triggerScenarios":"During `build_packages` field-link construction, `slot.map(|s| u32::try_from(s)...)` receives a slot index > u32::MAX — caused by runaway slot allocation or a corrupted/overflowed class field counter.","commonSituations":"Emitter bugs that increment slot counters without bound; generated classes with enormous field counts from code generation gone wrong; corrupted incremental caches.","solutions":["Check the class field slot allocator for unbounded increments or double-counting","Verify the debug_assert above it: the linked class field must actually have a runtime slot","Clear incremental build caches and rebuild","If huge field counts are legitimate, widen the slot encoding to u64 in VM types"],"exampleFix":"// before\nslot.map(|s| u32::try_from(s).expect(\"class field count fits u32\"))\n// after\nslot.map(|s| u32::try_from(s))\n    .transpose()\n    .map_err(|_| EmitError::TooManyClassFields(class_tn.clone()))?","handlingStrategy":"validation","validationCode":"if let Some(s) = slot {\n    if s > u32::MAX as usize {\n        return Err(CompilerBug::FieldSlotOverflow(class_tn.clone()));\n    }\n}","typeGuard":"fn fits_u32(n: usize) -> Option<u32> {\n    u32::try_from(n).ok()\n}","tryCatchPattern":"std::panic::catch_unwind(|| build_packages(db))\n    .unwrap_or_else(|_| report_compiler_bug(\"class field slot overflow\"));","preventionTips":["Audit the slot allocator for unbounded increments when many classes are emitted","Respect the neighboring debug_assert: a linked interface field must map to a real class slot","Clear incremental caches after changes to field slot numbering"],"tags":["compiler","rust","panic","classes","integer-overflow"],"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"}