Skip to content

Commit 1ee3921

Browse files
authored
Merge branch 'main' into fun-ty
2 parents 8fd74ba + 254fd5a commit 1ee3921

File tree

88 files changed

+3042
-1525
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

88 files changed

+3042
-1525
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Linting for the Rust engine
2+
3+
on:
4+
pull_request:
5+
merge_group:
6+
workflow_dispatch:
7+
push:
8+
branches: [main]
9+
10+
jobs:
11+
clippy:
12+
name: clippy
13+
runs-on: linux
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Run clippy
17+
run: |
18+
cargo clippy -p rust-printer -- --no-deps

Cargo.lock

Lines changed: 32 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ members = [
1515
"engine/names/extract",
1616
"hax-types",
1717
"rust-printer",
18+
"rust-printer/macros",
1819
]
1920
exclude = ["tests", "rustc-coverage-tests", "rust-printer/tests"]
2021
default-members = [

cli/driver/src/exporter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ impl From<ExtractionCallbacks> for hax_frontend_exporter_options::Options {
7171
fn from(opts: ExtractionCallbacks) -> hax_frontend_exporter_options::Options {
7272
hax_frontend_exporter_options::Options {
7373
inline_anon_consts: true,
74+
resolve_drop_bounds: false,
7475
}
7576
}
7677
}

docs/frontend/evaluation.md

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ For the crates that successfully generated ASTs, we compared the time taken by `
119119
- On average, `cargo hax` is about 4–5 times slower than `cargo check`.
120120
- At the **10th decile**, the slowdown is only about 2×, indicating better scaling for larger crates.
121121

122-
## Conclusion
122+
### Conclusion
123123

124124
Our quantitative evaluation shows that the hax frontend successfully extracts ASTs for a large portion of the Rust ecosystem. Nevertheless, a small portion of crates reveal performance bottlenecks or outright failures that require further investigation and optimization.
125125

@@ -131,3 +131,30 @@ These results also highlight a few **limitations** of this initial study:
131131
Overall, the hax frontend demonstrates capabilities for large-scale Rust code verification, but continued refinement is needed to handle edge cases and improve performance.
132132

133133
[^1]: For a given crate, we normalize the times by dividing them by the total time.
134+
135+
## Qualitative evaluation
136+
137+
The qualitative evaluation aims at identifying what Rust patterns the frontend can handle. It also tests whether the information extracted from the frontend describes correctly the input Rust code.
138+
139+
### Rustc coverage test suite
140+
141+
The Rust compiler (rustc) has extensive test suites that describe various expectations of how it should handle Rust input. One of them is the [coverage test suite](https://rustc-dev-guide.rust-lang.org/tests/compiletest.html#coverage-tests) which contains a set of Rust inputs that is supposed to cover a wide range of Rust constructs. This test suite has been adapted to test hax.
142+
143+
We use the following methodology:
144+
- The Rust inputs from the test suite have been copied to `rustc-coverage-tests/src/`, and can be updated using a script.
145+
- A Rust crate structure is built around these source files, to allow hax to handle them. The files that fail `cargo check` are excluded. There are currently 26 excluded (out of 81) tests, mostly because they contain asynchronous code, which requires a runtime file that is missing in our infrastructure.
146+
- To test hax frontend, we run `cargo hax json`. If the command succeeds, the test is considered successful.
147+
148+
These tests aim at increasing the confidence in the ability of hax frontend to handle Rust inputs covering all of the language constructs. As of today, all tests are handled successfully by hax frontend. However we don't test any requirement on the output (see the following section for tests of hax frontend output quality).
149+
150+
### Rust printer testing
151+
152+
This method aims at testing the quality of hax frontend's output. It uses a tool that is under development that we call the Rust printer.
153+
154+
This tool (written in Rust) takes the output of hax frontend (a json file describing the content of a Rust crate), it imports it as an AST (similar to the hax engine AST), and then prints this AST in Rust syntax.
155+
156+
If the Rust code we get out of this tool is equivalent to the Rust code it was given as input, then this means hax frontend correctly extracted the input code without losing or altering any information.
157+
158+
There is no easy way of testing the full input/output equivalence so the methodology here is to test that the resulting code behaves the same as the input code with respect to relevant test cases.
159+
160+
This work is available in the `rust-printer` folder. In the `tests` subfolder, an input file is available with tests for all Rust constructs supported by the printer (currently functions and expressions). For now these tests pass after extracting and printing the file with hax frontend and the Rust printer. This means that for the Rust constructs covered by the printer and the test file, hax frontend's extraction is correct. However this still needs to be extended to test more Rust constructs.

docs/manual/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ manager</a> <i>(with <a href="https://nixos.wiki/wiki/Flakes">flakes</a> enabled
5353
- or following [those steps](https://github.com/mschwaig/howto-install-nix-with-flake-support).
5454

5555
+ **Run hax on a crate directly** to get F\*/Coq/... (assuming you are in the crate's folder):
56-
- `nix run github:hacspec/hax -- into fstar` extracts F*.
56+
- `nix run github:hacspec/hax -- into fstar` extracts F\*.
5757
5858
+ **Install hax**: `nix profile install github:hacspec/hax`, then run `cargo hax --help` anywhere
5959
+ **Note**: in any of the Nix commands above, replace `github:hacspec/hax` by `./dir` to compile a local checkout of hax that lives in `./some-dir`

docs/manual/quick_start/index.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
weight: 0
33
---
44

5-
# Quick start with hax and F*
5+
# Quick start with hax and F\*
66

77
Do you want to try hax out on a Rust crate of yours? This chapter is
88
what you are looking for!
@@ -11,7 +11,7 @@ what you are looking for!
1111

1212
- <input type="checkbox" class="user-checkable"/> [Install the hax toolchain](https://github.com/hacspec/hax?tab=readme-ov-file#installation).
1313
<span style="margin-right:30px;"></span>🪄 Running `cargo hax --version` should print some version info.
14-
- <input type="checkbox" class="user-checkable"/> [Install F*](https://github.com/FStarLang/FStar/blob/master/INSTALL.md) *(optional: only if want to run F\*)*
14+
- <input type="checkbox" class="user-checkable"/> [Install F\*](https://github.com/FStarLang/FStar/blob/master/INSTALL.md) *(optional: only if want to run F\*)*
1515

1616
## Setup the crate you want to verify
1717

@@ -34,7 +34,7 @@ what you are looking for!
3434
specific crate you want to extract.*
3535

3636
Run the command `cargo hax into fstar` to extract every item of your
37-
crate as F* modules in the subfolder `proofs/fstar/extraction`.
37+
crate as F\* modules in the subfolder `proofs/fstar/extraction`.
3838

3939
**What is critical? What is worth verifying?**
4040
Probably, your Rust crate contains mixed kinds of code: some parts are
@@ -68,22 +68,22 @@ about the `-i` flag [in the FAQ](../faq/include-flags.md).
6868

6969

7070

71-
## Start F* verification
71+
## Start F\* verification
7272
After running the hax toolchain on your Rust code, you will end up
73-
with various F* modules in the `proofs/fstar/extraction` folder. The
74-
`Makefile` in `proofs/fstar/extraction` will run F*.
73+
with various F\* modules in the `proofs/fstar/extraction` folder. The
74+
`Makefile` in `proofs/fstar/extraction` will run F\*.
7575

7676
1. **Lax check:** the first step is to run `OTHERFLAGS="--lax" make`,
77-
which will run F* in "lax" mode. The lax mode just makes sure basic
77+
which will run F\* in "lax" mode. The lax mode just makes sure basic
7878
typechecking works: it is not proving anything. This first step is
79-
important because there might be missing libraries. If F* is not
79+
important because there might be missing libraries. If F\* is not
8080
able to find a definition, it is probably a `libcore` issue: you
81-
probably need to edit the F* library, which lives in the
81+
probably need to edit the F\* library, which lives in the
8282
`proofs-libs` directory in the root of the hax repo.
83-
2. **Typecheck:** the second step is to run `make`. This will ask F*
83+
2. **Typecheck:** the second step is to run `make`. This will ask F\*
8484
to typecheck fully your crate. This is very likely that you need to
8585
add preconditions and postconditions at this stage. Indeed, this
86-
second step is about panic freedom: if F* can typecheck your crate,
86+
second step is about panic freedom: if F\* can typecheck your crate,
8787
it means your code *never* panics, which already is an important
8888
property.
8989

docs/manual/tutorial/data-invariants.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ impl Add for F {
9494
}
9595
```
9696

97-
Here, F* is able to prove automatically that (1) the addition doesn't
97+
Here, F\* is able to prove automatically that (1) the addition doesn't
9898
overflow and (2) that the invariant of `F` is preserved. The
99-
definition of type `F` in F* (named `t_F`) very explicitly requires
99+
definition of type `F` in F\* (named `t_F`) very explicitly requires
100100
the invariant as a refinement on `v`.

docs/manual/tutorial/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ programs using the hax toolchain. hax is a tool that translates Rust
99
programs to various formal programming languages.
1010

1111
The formal programming languages we target are called *backends*. Some
12-
of them, e.g. [F*](https://fstar-lang.org/) or
12+
of them, e.g. [F\*](https://fstar-lang.org/) or
1313
[Coq](https://coq.inria.fr/), are general purpose formal programming
1414
languages. Others are specialized tools:
1515
[ProVerif](https://bblanche.gitlabpages.inria.fr/proverif/) is
1616
dedicated to proving properties about protocols.
1717

1818
This tutorial focuses on proving properties with the
19-
[F* programming language](https://fstar-lang.org/).
19+
[F\* programming language](https://fstar-lang.org/).

docs/manual/tutorial/panic-freedom.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ weight: 0
55
# Panic freedom
66

77
Let's start with a simple example: a function that squares a `u8`
8-
integer. To extract this function to F* using hax, we simply need to
8+
integer. To extract this function to F\* using hax, we simply need to
99
run the command `cargo hax into fstar` in the directory of the crate
1010
in which the function `square` is defined.
1111

@@ -18,8 +18,8 @@ fn square(x: u8) -> u8 {
1818
}
1919
```
2020

21-
Though, if we try to verify this function, F* is complaining about a
22-
subtyping issue: F* tells us that it is not able to prove that the
21+
Though, if we try to verify this function, F\* is complaining about a
22+
subtyping issue: F\* tells us that it is not able to prove that the
2323
result of the multiplication `x * x` fits the range of `u8`. The
2424
multiplication `x * x` might indeed be overflowing!
2525

@@ -70,7 +70,7 @@ fn square_option(x: u8) -> Option<u8> {
7070
}
7171
```
7272

73-
Here, F* is able to prove panic-freedom: calling `square` with any
73+
Here, F\* is able to prove panic-freedom: calling `square` with any
7474
input is safe. Though, one may argue that `square`'s input being small
7575
enough should really be an assumption. Having to deal with the
7676
possible integer overflowing whenever squaring is a huge burden. Can
@@ -102,7 +102,7 @@ fn square_requires(x: u8) -> u8 {
102102
}
103103
```
104104

105-
With this precondition, F* is able to prove panic freedom. From now
105+
With this precondition, F\* is able to prove panic freedom. From now
106106
on, it is the responsibility of the clients of `square` to respect the
107107
contact. The next step is thus be to verify, through hax extraction,
108108
that `square` is used correctly at every call site.

0 commit comments

Comments
 (0)