Skip to content

Conversation

carolynzech
Copy link
Contributor

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, 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

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.

Otherwise, dependencies will go into the cprover Kani backend.
Since both backends do nothing in the ReachabilityType::None case, this doesn't impact current functionality,
but still good to fix in case the Lean backend does ever diverge from the cprover one for this case.
@github-actions github-actions bot added the Z-EndToEndBenchCI Tag a PR to run benchmark CI label Apr 3, 2025
@carolynzech carolynzech force-pushed the fix-cargo-invocations branch from 627b58b to ed455a8 Compare April 3, 2025 18:01
@carolynzech carolynzech marked this pull request as ready for review April 3, 2025 18:06
@carolynzech carolynzech requested a review from a team as a code owner April 3, 2025 18:06
Copy link
Contributor

@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.

Thanks for sorting this out @carolynzech!

@carolynzech carolynzech added this pull request to the merge queue Apr 3, 2025
@carolynzech carolynzech removed this pull request from the merge queue due to a manual request Apr 3, 2025
@carolynzech carolynzech enabled auto-merge April 3, 2025 20:05
@carolynzech carolynzech added this pull request to the merge queue Apr 3, 2025
Merged via the queue into model-checking:main with commit 7a126c2 Apr 3, 2025
24 of 25 checks passed
@carolynzech carolynzech deleted the fix-cargo-invocations branch April 3, 2025 22:28
github-merge-queue bot pushed a commit that referenced this pull request Apr 4, 2025
Bump Kani version to 0.61.0.

Github-generated release notes:

## What's Changed
* Fix CHANGELOG of 0.60.0 by @qinheping in
#3925
* Bump tests/perf/s2n-quic from `d88faa4` to `8670e83` by @dependabot in
#3928
* Update toolchain to 2025-03-04 by @qinheping in
#3927
* Install the right toolchain for HEAD and BASE checks in
`verify-std-check.yml` by @remi-delmas-3000 in
#3920
* Automatic cargo update to 2025-03-10 by @github-actions in
#3926
* Automatic toolchain upgrade to nightly-2025-03-05 by @github-actions
in #3929
* Upgrade toolchain to nightly-2025-03-07 by @tautschnig in
#3931
* Upgrade toolchain to nightly-2025-03-12 by @tautschnig in
#3933
* Automatic toolchain upgrade to nightly-2025-03-13 by @github-actions
in #3934
* Update CBMC dependency to 6.5.0 by @tautschnig in
#3936
* Automatic toolchain upgrade to nightly-2025-03-14 by @github-actions
in #3937
* Automatic toolchain upgrade to nightly-2025-03-15 by @github-actions
in #3938
* Automatic toolchain upgrade to nightly-2025-03-16 by @github-actions
in #3939
* Automatic toolchain upgrade to nightly-2025-03-17 by @github-actions
in #3940
* Automatic cargo update to 2025-03-17 by @github-actions in
#3941
* Autoharness: Don't panic on `_` argument and add `_autoharness` suffix
to GOTO files by @carolynzech in
#3942
* Implement `f16` and `f128` cases in `codegen_float_type` by
@carolynzech in #3943
* Support function implementations of known built-ins by @tautschnig in
#3945
* Autoharness: metadata improvements and enable standard library
application by @carolynzech in
#3948
* Autoharness: `--list` option by @carolynzech in
#3952
* Add support for anonymous nested statics by @carolynzech in
#3953
* Automatic cargo update to 2025-03-24 by @github-actions in
#3954
* Bump tests/perf/s2n-quic from `8670e83` to `324cf31` by @dependabot in
#3955
* Document behavior of checked_size_of_raw and is_inbounds by @rajath-mk
in #3956
* Upgrade toolchain to 2025-03-18 by @zhassan-aws in
#3959
* Remove unstable-features from code formatting script by @zhassan-aws
in #3962
* Remove CI job to update features/verify-rust-std by @tautschnig in
#3963
* Make is_inbounds public by @rajath-mk in
#3958
* Enable Kani to work with a stable toolchain by @zhassan-aws in
#3964
* Automatic cargo update to 2025-03-31 by @github-actions in
#3966
* Add support for struct field accessing in loop contracts by
@thanhnguyen-aws in #3970
* Bump tests/perf/s2n-quic from `324cf31` to `d0aff82` by @dependabot in
#3968
* Clarify `is_inbounds` docs by @carolynzech in
#3974
* Upgrade toolchain to 2025-04-01 by @carolynzech in
#3973
* Remove remaining `--enable-unstable` mentions by @carolynzech in
#3978
* Clean up unused dependencies by @zhassan-aws in
#3981
* Automatic toolchain upgrade to nightly-2025-04-02 by @github-actions
in #3983
* Update dependencies per `cargo-outdated` by @carolynzech in
#3982
* Fix `autoharness` termination test & print metadata in alphabetical
order by @carolynzech in
#3971
* Fix cargo invocations to only use `pkg_args` where appropriate by
@carolynzech in #3984


**Full Changelog**:
kani-0.60.0...kani-0.61.0

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 Apr 17, 2025
## Summary
- fda814b: Make the autoharness filter
flags work on the standard library by moving them to
`kani_compiler_flags`, which ensures they're passed to all Kani compiler
invocations.
- c0430ec: Print the crate name in our
output tables.
- 093fc6b: **Breaking Change** to
rename `--include-function` and `--exclude-function` to mention
`pattern`s instead, which makes it clearer that they talk about
substrings of the total paths (e.g., modules). Also implement the
suggestion from
#3922 (comment)
so that the flags are no longer mutually exclusive.
- 9e35fca: Let the above flags filter
on crate names as well.
- 66444e4: Warn if an exclude flag
makes an include flag moot.

## Detail
Some more context on why f933799c54b09210cb267963ff1dc431c7a9385a allows
for both flags to be passed now: I realized as part of
#3984 how when we call `cargo
rustc` for a `cargo kani` invocation, we don't pass `--reachability` to
dependencies to avoid running harnesses in them. The problem is that we
can't do the same for our cargo command to build the standard library,
since that uses `cargo build`, which does not have the same ability to
pass flags only to the final compiler invocation and not the
dependencies. So we end up passing `--reachability=AllFns` to the
dependencies of the standard library as well and generate automatic
harnesses for them. If we can pass both filter flags, we can run
commands like `kani autoharness --std --include-pattern core
--exclude-pattern miniz_oxide`, which will include functions from the
`core` crate while excluding functions in the `miniz_oxide` that just
happen to have the word "core" in them.

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-EndToEndBenchCI Tag a PR to run benchmark CI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants