Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an LLBC backend #3514

Merged
merged 24 commits into from
Oct 8, 2024
Merged

Add an LLBC backend #3514

merged 24 commits into from
Oct 8, 2024

Conversation

zhassan-aws
Copy link
Contributor

@zhassan-aws zhassan-aws commented Sep 14, 2024

This PR adds a new codegen backend that generates low-level borrow calculus (LLBC), which is the format defined by Charon and Aeneas.

The backend can be invoked using -Zaeneas, and will generate a .llbc file. This file can then be passed to Aeneas to generate Lean for example. Currently, Aeneas needs to be manually run on the generated LLBC.

The PR translates stable MIR to unstructured LLBC (ULLBC) and then uses the Charon library to apply transformations that reconstruct the control flow to regain some of the high-level structure (loops, if statements, etc.).

In this PR, very few MIR constructs are handled, but the PR is already pretty big. More support to come in subsequent PRs.

Call-outs:

  • Charon is currently not released on crates.io, so the library is added as a dependency through GitHub with a particular commit.
  • The Kani driver is currenty heavily tailored towards CBMC, so currently it's expecting a goto file, and thus errors out when the Aeneas backend is invoked.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 and MIT licenses.

@zhassan-aws zhassan-aws requested a review from a team as a code owner September 14, 2024 00:12
@github-actions github-actions bot added the Z-BenchCI Tag a PR to run benchmark CI label Sep 14, 2024
Copy link
Member

@tautschnig tautschnig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with the following understanding:

  1. Some cleanup is needed as indicated by the comments.
  2. The codegen for Aeneas does need further work, but this doesn't impact any existing user who continues to use the cprover back-end.

kani-driver/src/call_single_file.rs Outdated Show resolved Hide resolved
kani-compiler/src/kani_compiler.rs Outdated Show resolved Hide resolved
kani-compiler/src/kani_compiler.rs Outdated Show resolved Hide resolved
kani-compiler/Cargo.toml Outdated Show resolved Hide resolved
.gitignore Show resolved Hide resolved
kani-compiler/src/codegen_aeneas_llbc/mir_to_ullbc/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't reviewed the backend code yet, but I'm curious about how this affects our released software. Are we shipping the new backend?

kani-compiler/src/args.rs Outdated Show resolved Hide resolved
kani-compiler/src/args.rs Show resolved Hide resolved
Copy link
Contributor Author

@zhassan-aws zhassan-aws left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't reviewed the backend code yet, but I'm curious about how this affects our released software. Are we shipping the new backend?

That was the plan (it's under an unstable feature). If we prefer to not include it in the release at this point, we can disable the feature by default and have a separate set of regressions for this feature.

kani-compiler/src/args.rs Show resolved Hide resolved
kani-compiler/src/args.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few more comments

kani-compiler/src/args.rs Show resolved Hide resolved
kani-driver/src/args/mod.rs Outdated Show resolved Hide resolved
kani-driver/src/call_single_file.rs Show resolved Hide resolved
kani-compiler/src/args.rs Outdated Show resolved Hide resolved
kani-compiler/src/codegen_aeneas_llbc/mir_to_ullbc/mod.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be great if we could eventually simplify the naming schema, and remove the name generation code. This seems fairly fragile, hard to maintain and I worry that this will not work (or even be unsound) if 2+ crates have the same name. That said, I think it is out of scope of this PR since you are only trying to match Aeneas name schema.

The handling of monomorphic vs generic code also need some improvement. To unblock this PR, can we add an error if we encounter generic code? I think none of your tests depend on generic code.

Copy link
Contributor

@celinval celinval left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet! I this is a great first step. Thanks @zhassan-aws

@zhassan-aws zhassan-aws added this pull request to the merge queue Oct 8, 2024
Merged via the queue into model-checking:main with commit e7ab090 Oct 8, 2024
27 checks passed
@zhassan-aws zhassan-aws deleted the llbc4 branch October 8, 2024 19:05
github-merge-queue bot pushed a commit that referenced this pull request Oct 12, 2024
@celinval pointed out that `cargo update` will attempt to update the
`charon` submodule as well.

Exclude the `charon` submodule from the workspace so that it's not
considered when running `cargo update`, `cargo deny`, `cargo clippy`,
and `cargo fmt`. The PR also reverts some of the configuration changes
made in #3514.

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
github-merge-queue bot pushed a commit that referenced this pull request Oct 18, 2024
In #3514, the LLBC does not
keep the variable names from the Rust source. This PR extracts the names
of variables from MIR and carries it over to the LLBC.

For instance, for `tests/expected/llbc/basic1` which has the following
Rust:
```rust
fn select(s: bool, x: i32, y: i32) -> i32 {
    if s { x } else { y }
}
```
without this PR, running Aeneas on the output LLBC produces:
```lean
def select (b : Bool) (i : I32) (i1 : I32) : Result I32 :=
  if b
  then Result.ok i
  else Result.ok i1
```
but with this PR, it produces:
```lean
def select (s : Bool) (x : I32) (y : I32) : Result I32 :=
  if s
  then Result.ok x
  else Result.ok y
```

This should not be merged before #3514, so keeping it as a draft for the
time being.

The actual diff on top of #3514 can be viewed here:
zhassan-aws/kani@llbc4...zhassan-aws:kani:llbc-names

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
github-merge-queue bot pushed a commit that referenced this pull request Oct 23, 2024
This is a follow-up on #3514. As @celinval suggested
([here](#3514 (comment))),
renaming all user-facing options from "Aeneas" to Lean.

Inside the Kani compiler which is only concerned with producing LLBC
(and doesn't know about Lean/Aeneas), I'm renaming the relevant feature
from `aeneas` to `llbc`, and the backend is now called the LLBC backend
as opposed to the Aeneas backend.

Towards #3585 

By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Z-BenchCI Tag a PR to run benchmark CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants