{"record":{"id":"a688fdb296e21b39","repo":"BoundaryML/baml","slug":"generic-arity-fits-u32","errorCode":null,"errorMessage":"generic arity fits u32","messagePattern":"generic arity fits u32","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/baml_compiler2_emit/src/lib.rs","lineNumber":1050,"sourceCode":"                _ => unreachable!(\"split_interface matched an interface\"),\n            };\n            complete_interface_assoc(\n                &mut interface_assoc,\n                &iface_tn,\n                &iface_arg_tys,\n                &for_ty,\n                &impl_params,\n                resolved,\n            );\n            // The constraint set was lowered (and fail-closed gated) inside\n            // `impl_rule_target`, so the bake, the decompose attribution,\n            // and the rule's `ImplCoherenceKey` all carry the identical\n            // canonicalized bounds.\n            // A block's own method is compiled against the owner frame — the\n            // impl's declared generics, which for an in-class block ARE the\n            // class's.\n            let impl_frame: Vec<bex_vm_types::TyTemplate> = (0..u32::try_from(impl_params.len())\n                .expect(\"generic arity fits u32\"))\n                .map(bex_vm_types::TyTemplate::TypeArgRef)\n                .collect();\n            let Some(interface_head) = interface_indices\n                .get(&iface_tn)\n                .copied()\n                .map(ObjectIndex::from_raw)\n            else {\n                continue;\n            };\n            let mut methods = indexmap::IndexMap::new();\n            for &m in &block.methods {\n                let method_name = function_data(db, m).name.clone();\n                // An unindexed body has a `$compiler_intrinsic` /\n                // `$await_any` body Pass 4 never pools — drop just that\n                // method (losing a dispatch, never adding a wrong one). The\n                // stdlib only uses those bodies on free functions, so this is\n                // unreachable today; the debug_assert pins the convention.\n                // TODO: reject intrinsic/await-any bodies inside impl blocks","sourceCodeStart":1032,"sourceCodeEnd":1068,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/baml_compiler2_emit/src/lib.rs#L1032-L1068","documentation":"When building an impl frame, the compiler converts the impl's declared generic parameter count to `u32` with `.expect(\"generic arity fits u32\")` to generate `TyTemplate::TypeArgRef` slots. The panic means an impl block declares more than `u32::MAX` generic parameters — practically only reachable via an arity-computation bug, since real declarations cannot have 4 billion generics.","triggerScenarios":"`impl_params.len()` overflowing u32 during `build_packages` frame construction — caused by duplicated or recursively expanded parameter lists rather than a genuine huge arity.","commonSituations":"Lowering bugs that duplicate generic parameters when merging class and impl generics; pathological generated code; infinite recursion in parameter collection that inflated the list.","solutions":["Audit how `impl_params` is collected for duplication or runaway expansion","Deduplicate the generic parameter list before frame construction","If genuinely large arities are expected, widen the field or cap with a proper diagnostic"],"exampleFix":"// before\nu32::try_from(impl_params.len()).expect(\"generic arity fits u32\")\n// after\nu32::try_from(impl_params.len())\n    .map_err(|_| EmitError::TooManyGenerics(impl_params.len()))?","handlingStrategy":"validation","validationCode":"if impl_params.len() > u32::MAX as usize {\n    return Err(CompilerBug::GenericArityOverflow(impl_params.len()));\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(\"generic arity overflow\"));","preventionTips":["Deduplicate impl_params before frame construction to catch collection bugs","Cap declared generic arity at parse time","Add a test that merging class and impl generics does not duplicate parameters"],"tags":["compiler","rust","panic","generics","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"}