Skip to content

Build and lint the LLBC backend with warnings denied in its CI job - #4886

Merged
feliperodri merged 3 commits into
model-checking:mainfrom
feliperodri:llbc-lint-gate
Sep 30, 2026
Merged

feliperodri merged 3 commits into
model-checking:mainfrom
feliperodri:llbc-lint-gate

Conversation

@feliperodri

@feliperodri feliperodri commented Sep 27, 2026 •

Copy link
Copy Markdown
Member

The rest of the Charon stack (#4881, #4882, #4883) has merged, and this is rebased onto main. Three commits: ac73eb722 (the lint gate), 9fafffbb5 (method names, see the end), and 70806c417 (a comment noting that the -D warnings build also covers Charon).

Last step of the Charon plan in #4834: make sure the LLBC backend can't quietly rot again.

Why. Nothing in CI checked the LLBC backend for warnings or lints. The regression script's -D warnings build left out llbc because the old Charon had warnings of its own — its TODO said to revisit once the pin moved — and the clippy job only lints the default features. So the backend had accumulated 13 clippy errors that nobody could see (I found them while doing #4881).

What. Charon now builds warning-free, and #4883 already removed ten of those errors; this fixes the last three. Then kani-llbc-regression.sh — which only the LLBC job runs, and which already builds with llbc — gains a -D warnings build and a clippy -p kani-compiler --features llbc -- -D warnings. The TODO in kani-regression.sh becomes a pointer to it.

The call I'd like checked: I put the gate in the LLBC job rather than the main regression and clippy jobs, so that those don't have to build Charon on every PR. The trade-off is that a PR which breaks only the LLBC lints fails in the LLBC job rather than the clippy one — same signal, different place. Easy to move if you'd rather have it next to the other clippy run.

Verified the gate actually gates: the script runs under errexit, and a planted let_and_return makes it exit 101.

Also: name methods the way Charon does. The last commit replaces the implementing-type suffix on method names (core::num::wrapping_addu8, test::getCounter, getWrapper<T>) with Charon's PathElem::Impl: {u8} / {Wrapper<T>} for inherent impls, and {impl T for A} for trait impls. The trait-impl form refers to a trait impl declaration, which Kani now emits minimally, like trait declarations: the implemented trait and the generics, with no methods, associated items or vtable. The expected output of the four tests with methods changes accordingly, and tests/llbc/impl_paths covers generic inherent and trait impls.

Resolves #4884

@feliperodri
feliperodri requested review from a team as code owners September 27, 2026 19:24
@github-actions github-actions Bot added Z-EndToEndBenchCI Tag a PR to run benchmark CI Z-CompilerBenchCI Tag a PR to run benchmark CI labels Sep 27, 2026
tautschnig added a commit to feliperodri/kani that referenced this pull request Sep 29, 2026
With Charon's type check now running on the translation, several common
signatures made it reject Kani's output ("Found incorrect region var" /
"Found incorrect type var") and the compiler then hit a `todo!()`:

- `fn get(x: Option<&u32>)`, `fn deref2(x: &&u32)`, `fn read(h: Holder<'_>)`:
  only top-level `&T` inputs contributed late-bound regions, so a region
  nested in an ADT or another reference was undeclared. `fn pick<'a>(x: &'a
  u32, y: &'a u32)` declared `'a` twice, once per input.
- `fn f<'a, T: 'a>(x: &'a T)`, `fn rd<'a, T>(x: R<'a, T>)`, methods of an
  `impl<'a>`: parameters were numbered with rustc's index, which counts all
  kinds together (and parent generics first), while Charon numbers each kind
  from zero. Late-bound regions also reused the ids of early-bound ones.
- `FnDef::fn_sig` erases early-bound regions, so `f` above printed
  `x: &'_ T`.
- Function-pointer types declared no regions for their own binder.

Now, as in Charon's translation:

- the late-bound regions are the signature binder's bound variables (all of
  them, each once, wherever they occur), numbered after the early-bound
  regions;
- every generic parameter gets its position among parameters of the same
  kind, computed per item from `generics_of`, including parents; an
  `ItemGenerics` scope is active while translating a type, trait or function
  declaration (and a function's generic body, which mentions its
  parameters);
- the declaration's signature comes from `tcx.fn_sig(..).instantiate_identity()`;
- function-pointer types bind their regions, and item parameters inside
  them are referenced one binder further out.

Elided regions (`'_`) stay unnamed, as Charon leaves them.

`tests/llbc/regions` covers each case; it fails without this change.
The llbc suite passes (22/22), and fmt and both CI clippy invocations are
clean. `cargo clippy --features llbc` still reports the three pre-existing
lints that model-checking#4886 fixes.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig added a commit to feliperodri/kani that referenced this pull request Sep 29, 2026
With Charon's type check now running on the translation, several common
signatures made it reject Kani's output ("Found incorrect region var" /
"Found incorrect type var") and the compiler then hit a `todo!()`:

- `fn get(x: Option<&u32>)`, `fn deref2(x: &&u32)`, `fn read(h: Holder<'_>)`:
  only top-level `&T` inputs contributed late-bound regions, so a region
  nested in an ADT or another reference was undeclared. `fn pick<'a>(x: &'a
  u32, y: &'a u32)` declared `'a` twice, once per input.
- `fn f<'a, T: 'a>(x: &'a T)`, `fn rd<'a, T>(x: R<'a, T>)`, methods of an
  `impl<'a>`: parameters were numbered with rustc's index, which counts all
  kinds together (and parent generics first), while Charon numbers each kind
  from zero. Late-bound regions also reused the ids of early-bound ones.
- `FnDef::fn_sig` erases early-bound regions, so `f` above printed
  `x: &'_ T`.
- Function-pointer types declared no regions for their own binder.

Now, as in Charon's translation:

- the late-bound regions are the signature binder's bound variables (all of
  them, each once, wherever they occur), numbered after the early-bound
  regions;
- every generic parameter gets its position among parameters of the same
  kind, computed per item from `generics_of`, including parents; an
  `ItemGenerics` scope is active while translating a type, trait or function
  declaration (and a function's generic body, which mentions its
  parameters);
- the declaration's signature comes from `tcx.fn_sig(..).instantiate_identity()`;
- function-pointer types bind their regions, and item parameters inside
  them are referenced one binder further out.

Elided regions (`'_`) stay unnamed, as Charon leaves them.

`tests/llbc/regions` covers each case; it fails without this change.
The llbc suite passes (22/22), and fmt and both CI clippy invocations are
clean. `cargo clippy --features llbc` still reports the three pre-existing
lints that model-checking#4886 fixes.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig added a commit to feliperodri/kani that referenced this pull request Sep 29, 2026
…name builders (model-checking#4882)

Rebased onto main after model-checking#4881 merged; three commits: `29c3b1eb2`,
`697526953`, and `dfc1b0592` (see below).

Second step toward the Charon bump (model-checking#4834), still on the old pin.

**The bug.** Calling *any* inherent method aborts the compiler with the
LLBC backend. A local type is enough:

```rust
impl Counter { fn get(&self) -> u32 { self.n } }
```
```
expected impl trait, found inherent impl on DefId(0:6 ~ test[4a52]::{impl#0})
```

and so is `x.wrapping_add(y)` from `core`. Method names get the
implementing type appended so methods from different impls don't
collide, and that type was read from the impl's trait ref — which only
trait impls have. It now comes from the impl's self type, which both
kinds have and which prints identically for trait impls: `traitimpl`
(pinned in model-checking#4881) still expects `get_valA` / `get_valB`. Two new tests
cover the local and the `core` case; both crashed before.

**The cleanup.** The path-to-name walk existed three times
(`defid_to_name`, `def_to_name`, `adtdef_to_name`), differing only in
where the span came from — and the ADT copy panicked on an `{impl}` path
element the other two skip. Now there's one. Separately, the
integer-type → scalar-value table was duplicated between constants and
switch targets; it's one function now, so the bump rewrites it in one
place.

**No behaviour change beyond the crash** — that's the point of doing
this before the bump. All 19 expectations from model-checking#4881 are untouched,
including `int_literals` (negatives at every width) and `switch_int`,
which exercise the merged table.

The third commit stops `inherent_core/expected` from pinning the
callee's `@FunN` id: ids follow the fingerprint order in which Kani
reaches items, which changed with nightly-2026-09-24 (`@Fun1` became
`@Fun2`). The callee's name is still checked by its declaration line.

**Where I'd like input:** the suffix scheme itself (`getCounter`,
`core::num::wrapping_addu8`) is kept as-is, because changing it here
would muddy the "nothing changed" signal. Charon's own naming uses a
proper `{impl}` path element instead; I'd rather adopt that in the bump,
where names change anyway. Shout if you'd prefer it now. (Now done on
top of the bump, in model-checking#4886; see model-checking#4884.)

I also dropped a planned "route every redesigned construct through
helpers" step after looking closely: those call sites already sit in
five functions (`translate_ty`, `translate_allocation`,
`translate_switch_targets`, `translate_bin_op`, the trait-decl builder),
so a helper layer would add indirection without making the bump
meaningfully smaller.

`tests/llbc` 21/21, `kani-llbc-regression.sh`, fmt, clippy. Part of the
names item in model-checking#3585.

---------

Co-authored-by: Michael Tautschnig <tautschn@amazon.com>
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
tautschnig added a commit to feliperodri/kani that referenced this pull request Sep 29, 2026
With Charon's type check now running on the translation, several common
signatures made it reject Kani's output ("Found incorrect region var" /
"Found incorrect type var") and the compiler then hit a `todo!()`:

- `fn get(x: Option<&u32>)`, `fn deref2(x: &&u32)`, `fn read(h: Holder<'_>)`:
  only top-level `&T` inputs contributed late-bound regions, so a region
  nested in an ADT or another reference was undeclared. `fn pick<'a>(x: &'a
  u32, y: &'a u32)` declared `'a` twice, once per input.
- `fn f<'a, T: 'a>(x: &'a T)`, `fn rd<'a, T>(x: R<'a, T>)`, methods of an
  `impl<'a>`: parameters were numbered with rustc's index, which counts all
  kinds together (and parent generics first), while Charon numbers each kind
  from zero. Late-bound regions also reused the ids of early-bound ones.
- `FnDef::fn_sig` erases early-bound regions, so `f` above printed
  `x: &'_ T`.
- Function-pointer types declared no regions for their own binder.

Now, as in Charon's translation:

- the late-bound regions are the signature binder's bound variables (all of
  them, each once, wherever they occur), numbered after the early-bound
  regions;
- every generic parameter gets its position among parameters of the same
  kind, computed per item from `generics_of`, including parents; an
  `ItemGenerics` scope is active while translating a type, trait or function
  declaration (and a function's generic body, which mentions its
  parameters);
- the declaration's signature comes from `tcx.fn_sig(..).instantiate_identity()`;
- function-pointer types bind their regions, and item parameters inside
  them are referenced one binder further out.

Elided regions (`'_`) stay unnamed, as Charon leaves them.

`tests/llbc/regions` covers each case; it fails without this change.
The llbc suite passes (22/22), and fmt and both CI clippy invocations are
clean. `cargo clippy --features llbc` still reports the three pre-existing
lints that model-checking#4886 fixes.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
kasimte pushed a commit to kasimte/kani that referenced this pull request Sep 30, 2026
…ecking#4883)

Rebased onto main after model-checking#4881 and model-checking#4882 merged. Nine commits: five for
the bump itself (from `cbd1e83c7`) and four follow-ups (see "Follow-ups"
below). They're split so each can be read on its own.

Resolves model-checking#4834: Charon goes from a commit 2,176 commits old to
`nightly-2026.09.29`, and `scripts/charon-patch.diff`, the CI step that
applied it, and the workspace `[patch]` for its git dependency all go
away. Charon itself builds unpatched on our toolchain.

## Why it's shaped this way

Every past Charon bump broke Kani because we hand-copied Charon's option
defaults and its list of passes. Charon now exposes both, so the LLBC
backend configures Charon exactly as `charon --preset aeneas` does and
runs `run_transformation_passes` after our own MIR-to-ULLBC step. That
deletes about 90 lines, and the next bump should be mostly renames.

For the translation itself, wherever the AST was *redesigned* rather
than renamed, I copied what Charon's own MIR translator emits instead of
inventing a mapping — the arithmetic overflow modes, assert kinds,
switches, builtin types, drops. The commit message lists each one.

## What the review should focus on

The risk the issue called out is a port that compiles but changes
meaning. model-checking#4881 pinned the old output first, and I reviewed every changed
expected file against its old version. The expected-file commit lists
what changed; in short: formatting, names instead of `@Adt0`, and two
deliberate refinements — `unchecked_add` overflow is now `ub.+` rather
than a panic (the old AST couldn't say UB), and drops name their glue
type.

Three things I'd especially like eyes on, because each was a silent bug
waiting to happen:

- **`TypeDeclId::UNIT` must be `()`**. Every tuple points at id 0, and
Charon's driver reserves it before anything else. Kani didn't, so
without that tuples would have silently named whichever ADT got
registered first. The `tuple` and `projection` tests now print `(i32,
i32)` where that would show.
- **Asserts need their `check_kind`**. We dropped the MIR assert
message; the new `reconstruct_fallible_operations` only folds an
overflow check into `panic.+` when it knows which check it is. Without
it, `arith_checked` quietly stops folding.
- **Charon now type-checks the translation**, and it caught a real
mismatch the old pin never checked: calls didn't pass the late-bound
regions the callee declares. Calls now pass them as erased, from the
same helper the declaration uses. A follow-up (`f5c3d5139`) makes the
declarations themselves match Charon's numbering; see below.

## Things I'd like input on

- `deny.toml` (its own commit): swap four stale MPL exceptions for
`ustr` (BSD-2-Clause-Patent), and **ignore two "unmaintained"
advisories** (`paste`, `atomic-polyfill`) that only Charon pulls in.
They're not vulnerabilities and the LLBC backend isn't in releases, but
ignoring advisories is a policy call — happy to handle it differently.
- Drops point at the glue `Instance::resolve_drop_in_place` returns, the
`core::ptr::drop_glue` instance that `drop_in_place::<T>` wraps.
Upstream reaches the glue through a proof for a synthetic
`Destruct::drop_glue` method, which Kani doesn't model. If Aeneas
specifically wants the trait form, that's a bigger follow-up.

## Not in this PR

- **Charon's `{impl}` path naming** (model-checking#4884): it isn't needed for model-checking#4834
and renames every method, so it is in model-checking#4886 instead.
- Arrays, slices, `str` literals, `Box`, casts, const generics,
supertraits and associated consts still stop at Kani's own `todo!()`s —
same as before, independent of Charon. Listed with reproducers in model-checking#4885.
- Trait-clause proofs stay placeholders, as they were. `both_none`'s
output also shows model-checking#3585's generic-vs-monomorphized mismatch more visibly
now (a generic signature over a monomorphic body) — pre-existing, not
introduced here.

## Follow-ups

- `f5c3d5139` declares generic parameters and regions the way Charon
numbers them. Signatures with a reference that isn't a top-level `&T`
input (`Option<&u32>`, `&&u32`, `Holder<'_>`), with a region used twice
(`pick<'a>(x: &'a u32, y: &'a u32)`), with an early-bound region before
a type parameter (`fn f<'a, T: 'a>`), or in an `impl<'a>` failed
Charon's type check. Now all late-bound regions of the signature binder
are declared once, after the early-bound ones; every parameter gets its
per-kind position; the declared signature keeps its early-bound regions;
and fn-pointer types bind their own regions. New test
`tests/llbc/regions`.
- `817c2aa1f` stops with an error ("Charon reported N error(s) while
translating to LLBC") instead of the `todo!()` when Charon reports
errors.
- `3a07dcfc0` fixes the drop-glue comment and removes an unused
parameter.
- `c00ab4007` moves the pin to `nightly-2026.09.29`, which differs from
`nightly-2026.09.26` only in using the published
`serde_state_perfect_derive` (AeneasVerif/charon#1486), so `deny.toml`
no longer allows the `serde_state` git source.

`tests/llbc` 22/22, `kani-llbc-regression.sh`, kani 613, expected 478,
ui 152, cargo-kani 71, unit tests with and without `llbc`, `cargo deny
--all-features`, fmt, clippy.

---------

Co-authored-by: Michael Tautschnig <tautschn@amazon.com>
Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@feliperodri feliperodri self-assigned this Sep 30, 2026
feliperodri and others added 2 commits September 30, 2026 07:12
Nothing in CI checked the LLBC backend for warnings or lints: the regression
script's `-D warnings` build left out the `llbc` feature because the old
Charon had warnings of its own (the TODO said to revisit once the pin moved),
and the clippy job only lints the default features. Thirteen clippy errors had
accumulated in the backend as a result.

Charon now builds warning-free, and the port removed ten of those errors; fix
the remaining three. Rather than make the main regression job build Charon, add
a `-D warnings` build and a clippy run to `kani-llbc-regression.sh`, which only
the LLBC job runs and which already builds with `llbc`. Verified that a planted
lint fails the script.
… suffix

The name builder dropped the `{impl}` element of a method's path and
appended the implementing type to the method name instead:
`core::num::wrapping_addu8`, `test::getCounter`, `test::get_valA`, and for a
generic impl `test::getWrapper<T>` (the rendered type, generics included).
Charon's own translation keeps the impl in the path, which Aeneas and
Charon's name matching and short-name computation expect.

Build the element as Charon does:

- an inherent impl is `PathElem::Impl(ImplElem::Ty(..))`: its self type,
  bound by the impl's generics (`{Wrapper<T>}`, `{u8}`);
- a trait impl is `PathElem::Impl(ImplElem::Trait(id))`, which refers to a
  trait impl declaration. Kani now declares trait impls the way it declares
  trait decls: the implemented trait and the generics, with no associated
  items, methods or vtable (`VTableDecl::Unknown`). The declaration is
  created the first time the impl is named; its id is registered before its
  own name (which contains the impl) is computed.

So `u8::wrapping_add` is `core::num::{u8}::wrapping_add`, `Counter::get` is
`test::{Counter}::get`, and `<A as T>::get_val` is
`test::{impl T for A}::get_val` (printed with Charon's short name
`impl_T_for_A::get_val`). The expected output of the four tests with
methods changes accordingly; in `regions`, the inherent method and the free
function are both named `get` now, so Charon prints both by full path.
`tests/llbc/impl_paths` covers generic inherent and trait impls and a trait
impl for a reference type.

The llbc suite passes (23/23); `kani-llbc-regression.sh` (with the
`-D warnings` build and llbc clippy), fmt and both CI clippy invocations
pass.

Resolves model-checking#4884

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
`RUSTFLAGS="-D warnings"` reaches Charon because it is a path dependency:
cargo only caps lints (`--cap-lints allow`) for registry and git
dependencies. So a Charon pin that introduces a warning fails this job,
while the clippy line lints `kani-compiler` only. Say so in the comment,
which read as if both lines were about Kani's backend only.

Co-authored-by: Kiro <kiro-agent@users.noreply.github.com>
@feliperodri
feliperodri added this pull request to the merge queue Sep 30, 2026
Merged via the queue into model-checking:main with commit 358baf8 Sep 30, 2026
32 of 34 checks passed
@feliperodri
feliperodri deleted the llbc-lint-gate branch September 30, 2026 08:48
@feliperodri feliperodri added this to the Charon front end (LLBC) milestone Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Z-CompilerBenchCI Tag a PR to run benchmark CI Z-EndToEndBenchCI Tag a PR to run benchmark CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

LLBC: name methods with Charon's impl path elements instead of a type suffix

2 participants