Commit 7a126c2
Carolyn Zech
Fix cargo invocations to only use
## Summary
When we invoke `cargo rustc` in `kani-driver`, we have some options in a
`pkg_args` variable, and some in `kani_compiler_flags`. This PR removes
a couple of uses of `pkg_args` that should have really been
`kani_compiler_flags`, and provides documentation about the difference.
## Explanation
Hopefully the documentation in the code is sufficient to understand the
difference (please suggest changes if it's not!), but here's a longer
explanation:
`cargo kani` invokes [cargo
rustc](https://doc.rust-lang.org/cargo/commands/cargo-rustc.html),
described as follows:
> cargo rustc [options] [-- args]
> The specified target for the current package (or package specified by
-p if provided) will be compiled along with all of its dependencies. The
specified args will all be passed to the final compiler invocation, not
any of the dependencies.
Our `pkg_args` variable is what we provide for `-- args`, i.e., the
arguments that we want to provide to kani-compiler when it compiles the
package under verification, but *not its dependencies.*
The docs then say:
> To pass flags to all compiler processes spawned by Cargo, use the
RUSTFLAGS [environment
variable](https://doc.rust-lang.org/cargo/reference/environment-variables.html)
We use the `RUSTFLAGS` environment variable to provide the
`kani_compiler_flags` that should be passed when we invoke
`kani-compiler` on the package to verify *and its dependencies.*
So we should use `kani_compiler_flags` when the dependencies of the
target package should receive the flag, and `pkg_args` when it
shouldn't. I concluded that the only argument that it makes sense to
provide in `pkg_args` is `--reachability`, because when `--reachability`
isn't provided it defaults to `None`, which is the behavior we want.
(Otherwise, we'd run Kani harnesses that we find in dependencies, or if
autoharness is running, generate automatic harnesses for functions in
dependencies, neither of which we want). Dependencies can get all of the
other compiler arguments, since they don't do anything with them when
`--reachability=None` anyway.
## Commit by Commit
- `--no-assert-contracts` is already provided in `kani_compiler_flags`,
and never should have been in `pkg_args` in the first place.
- Having `--backend=llbc` as a `pkg_arg` means that it doesn't get
provided to dependencies, so that when we run Kani's compiler on
dependencies, we'd actually enter the cprover compiler interface. Move
it to compiler args so that it gets passed to the target crate and its
dependencies.
- Autoharness should also use `kani_compiler_flags`, but that involves a
larger refactor than I want to do this close to a release, so added a
TODO for now.
- Add documentation explaining the difference between `pkg_args` and
`kani_compiler_flags`.
By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 and MIT licenses.pkg_args where appropriate (#3984)1 parent 2cfe4dc commit 7a126c2
File tree
6 files changed
+27
-21
lines changed- kani-compiler/src
- kani-driver/src
- autoharness
6 files changed
+27
-21
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
111 | 111 | | |
112 | 112 | | |
113 | 113 | | |
| 114 | + | |
114 | 115 | | |
115 | 116 | | |
116 | 117 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
72 | 72 | | |
73 | 73 | | |
74 | 74 | | |
75 | | - | |
| 75 | + | |
76 | 76 | | |
77 | | - | |
78 | 77 | | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
79 | 84 | | |
80 | 85 | | |
81 | 86 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
154 | 154 | | |
155 | 155 | | |
156 | 156 | | |
| 157 | + | |
| 158 | + | |
157 | 159 | | |
158 | 160 | | |
159 | 161 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
182 | 182 | | |
183 | 183 | | |
184 | 184 | | |
185 | | - | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
186 | 197 | | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | 198 | | |
194 | 199 | | |
195 | 200 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | 56 | | |
60 | 57 | | |
61 | 58 | | |
| |||
100 | 97 | | |
101 | 98 | | |
102 | 99 | | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | 100 | | |
112 | 101 | | |
113 | 102 | | |
| |||
150 | 139 | | |
151 | 140 | | |
152 | 141 | | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
153 | 146 | | |
154 | 147 | | |
155 | 148 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
| |||
0 commit comments