{"record":{"id":"49ec042d55284e99","repo":"BoundaryML/baml","slug":"int-ilog-invariants-self-0-base-2-already-enforced","errorCode":null,"errorMessage":"int.ilog: invariants self > 0 && base >= 2 already enforced","messagePattern":"int\\.ilog: invariants self > 0 && base >= 2 already enforced","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"baml_language/crates/bex_vm/src/package_baml/int.rs","lineNumber":130,"sourceCode":"            .unwrap_or_else(|_| unreachable!(\"int._random_in_range: offset is below upper - lower\"))\n    }\n\n    fn ilog(int: i64, base: i64) -> Result<i64, VmRustFnError> {\n        if int <= 0 {\n            return Err(VmBamlError::InvalidArgument {\n                message: format!(\"int.ilog: undefined for non-positive input (self = {int})\"),\n            }\n            .into());\n        }\n        if base < 2 {\n            return Err(VmBamlError::InvalidArgument {\n                message: format!(\"int.ilog: base must be >= 2, got {base}\"),\n            }\n            .into());\n        }\n        // Both invariants hold above, so checked_ilog cannot return None.\n        Ok(i64::from(int.checked_ilog(base).unwrap_or_else(|| {\n            unreachable!(\"int.ilog: invariants self > 0 && base >= 2 already enforced\")\n        })))\n    }\n\n    // ── Bit operations ────────────────────────────────────────────────────────\n\n    fn leading_zeros(int: i64) -> i64 {\n        i64::from(int.leading_zeros())\n    }\n\n    fn leading_ones(int: i64) -> i64 {\n        i64::from(int.leading_ones())\n    }\n\n    fn trailing_zeros(int: i64) -> i64 {\n        i64::from(int.trailing_zeros())\n    }\n\n    fn trailing_ones(int: i64) -> i64 {","sourceCodeStart":112,"sourceCodeEnd":148,"githubUrl":"https://github.com/BoundaryML/baml/blob/bd85ce9dee1463ff04d27efd20531013a4ff46c1/baml_language/crates/bex_vm/src/package_baml/int.rs#L112-L148","documentation":"Internal invariant panic in `int.ilog`. The function first validates `int > 0` and `base >= 2`, returning `VmBamlError::InvalidArgument` otherwise (that user-facing path is error 401's sibling). Because both invariants are enforced before the call, `checked_ilog` cannot return None, so the `unreachable!` only fires if that pre-validation was bypassed — a VM bug, not a user-facing condition.","triggerScenarios":"Calling `int.ilog(base)` on a BAML int with self <= 0 or base < 2 produces the normal InvalidArgument error, not this panic; this panic occurs only if the validation code path is skipped or checked_ilog returns None despite valid inputs (should be impossible).","commonSituations":"Seen only when hacking on the VM's native int package, or if a patched build altered the guard conditions above the checked_ilog call. BAML developers calling ilog with 0/negative values or base 1 get the regular 'base must be >= 2' error instead.","solutions":["If you actually passed self <= 0 or base < 2, you should be seeing InvalidArgument, not this panic — verify you are on an unmodified bex_vm build.","Rebuild/upgrade bex_vm; this is an internal invariant failure in the ilog implementation.","Report the exact (int, base) inputs to the baml_language maintainers."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"fn valid_ilog_args(int: i64, base: i64) -> bool {\n    int > 0 && base >= 2\n}","typeGuard":null,"tryCatchPattern":"// Guard in BAML/Rust before calling ilog; the panic path is unreachable for valid input.\nif !(int > 0 && base >= 2) { return Err(/* InvalidArgument */); }","preventionTips":["Check int > 0 and base >= 2 before calling int.ilog.","Expect the normal InvalidArgument error (not a panic) for bad inputs on unmodified builds.","Never patch out the pre-validation guards in int.rs."],"tags":["rust","internal-invariant","math","panic"],"backgroundTag":"internal-invariant-violation","analyzedSha":"bd85ce9dee1463ff04d27efd20531013a4ff46c1","analyzedAt":"2026-09-12T03:38:25.718Z","contentChangedAt":"2026-09-12T03:38:25.718Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}