Skip to content

Commit f5f1e94

Browse files
adpaco-awscelinval
andauthored
Upgrade Rust toolchain to nightly-2024-03-21 (#3102)
Upgrades the Rust toolchain to `nightly-2024-03-21`. The relevant changes in Rust are: * rust-lang/rust#122480 * rust-lang/rust#122748 * rust-lang/cargo#12783 I wasn't confident that our regression testing could detect differences in the file paths being generated with the new logic, so I added code similar to the following just to check they were equivalent: ```rust let base_filename = tcx.output_filenames(()).output_path(OutputType::Object); + let binding = tcx.output_filenames(()).path(OutputType::Object); + let base_filename2 = binding.as_path(); + assert_eq!(base_filename, base_filename2); ``` Note that this was done for each instance where we used `output_path`, and completed regression testing with the previous toolchain version. I also checked manually the instance where we generate a `.dot` graph for debug purposes following the instructions [here](https://model-checking.github.io/kani/cheat-sheets.html?highlight=dot#debug) (a `libmain.dot` file was generated for the `main.rs` in one of my projects). --------- Co-authored-by: Celina G. Val <[email protected]>
1 parent 1c3d0f3 commit f5f1e94

File tree

9 files changed

+41
-13
lines changed

9 files changed

+41
-13
lines changed

kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,8 @@ impl CodegenBackend for GotocCodegenBackend {
228228
// - Tests: Generate one model per test harnesses.
229229
// - PubFns: Generate code for all reachable logic starting from the local public functions.
230230
// - None: Don't generate code. This is used to compile dependencies.
231-
let base_filename = tcx.output_filenames(()).output_path(OutputType::Object);
231+
let base_filepath = tcx.output_filenames(()).path(OutputType::Object);
232+
let base_filename = base_filepath.as_path();
232233
let reachability = queries.args().reachability_analysis;
233234
let mut transformer = BodyTransformation::new(&queries, tcx);
234235
let mut results = GotoCodegenResults::new(tcx, reachability);
@@ -412,7 +413,8 @@ impl CodegenBackend for GotocCodegenBackend {
412413
builder.build(&out_path);
413414
} else {
414415
// Write the location of the kani metadata file in the requested compiler output file.
415-
let base_filename = outputs.output_path(OutputType::Object);
416+
let base_filepath = outputs.path(OutputType::Object);
417+
let base_filename = base_filepath.as_path();
416418
let content_stub = CompilerArtifactStub {
417419
metadata_path: base_filename.with_extension(ArtifactType::Metadata),
418420
};

kani-compiler/src/kani_compiler.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,8 @@ impl KaniCompiler {
304304
};
305305
if self.queries.lock().unwrap().args().reachability_analysis == ReachabilityType::Harnesses
306306
{
307-
let base_filename = tcx.output_filenames(()).output_path(OutputType::Object);
307+
let base_filepath = tcx.output_filenames(()).path(OutputType::Object);
308+
let base_filename = base_filepath.as_path();
308309
let harnesses = filter_crate_items(tcx, |_, instance| is_proof_harness(tcx, instance));
309310
let all_harnesses = harnesses
310311
.into_iter()
@@ -376,7 +377,7 @@ impl KaniCompiler {
376377

377378
/// Write the metadata to a file
378379
fn store_metadata(&self, metadata: &KaniMetadata, filename: &Path) {
379-
debug!(?filename, "write_metadata");
380+
debug!(?filename, "store_metadata");
380381
let out_file = File::create(filename).unwrap();
381382
let writer = BufWriter::new(out_file);
382383
if self.queries.lock().unwrap().args().output_pretty_json {
@@ -457,9 +458,9 @@ fn generate_metadata(
457458

458459
/// Extract the filename for the metadata file.
459460
fn metadata_output_path(tcx: TyCtxt) -> PathBuf {
460-
let mut filename = tcx.output_filenames(()).output_path(OutputType::Object);
461-
filename.set_extension(ArtifactType::Metadata);
462-
filename
461+
let filepath = tcx.output_filenames(()).path(OutputType::Object);
462+
let filename = filepath.as_path();
463+
filename.with_extension(ArtifactType::Metadata).to_path_buf()
463464
}
464465

465466
#[cfg(test)]

kani-compiler/src/kani_middle/reachability.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,8 @@ mod debug {
584584
if let Ok(target) = std::env::var("KANI_REACH_DEBUG") {
585585
debug!(?target, "dump_dot");
586586
let outputs = tcx.output_filenames(());
587-
let path = outputs.output_path(OutputType::Metadata).with_extension("dot");
587+
let base_path = outputs.path(OutputType::Metadata);
588+
let path = base_path.as_path().with_extension("dot");
588589
let out_file = File::create(path)?;
589590
let mut writer = BufWriter::new(out_file);
590591
writeln!(writer, "digraph ReachabilityGraph {{")?;

kani-compiler/src/kani_middle/stubbing/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
mod annotations;
66
mod transform;
77

8+
use rustc_span::DUMMY_SP;
89
use std::collections::BTreeMap;
910
use tracing::{debug, trace};
1011

@@ -93,7 +94,7 @@ impl<'tcx> MirVisitor for StubConstChecker<'tcx> {
9394
Const::Val(..) | Const::Ty(..) => {}
9495
Const::Unevaluated(un_eval, _) => {
9596
// Thread local fall into this category.
96-
if self.tcx.const_eval_resolve(ParamEnv::reveal_all(), un_eval, None).is_err() {
97+
if self.tcx.const_eval_resolve(ParamEnv::reveal_all(), un_eval, DUMMY_SP).is_err() {
9798
// The `monomorphize` call should have evaluated that constant already.
9899
let tcx = self.tcx;
99100
let mono_const = &un_eval;

kani-compiler/src/kani_middle/transform/check_values.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -807,7 +807,7 @@ fn ty_validity_per_offset(
807807
Ok(result)
808808
}
809809
FieldsShape::Arbitrary { ref offsets } => {
810-
match ty.kind().rigid().unwrap() {
810+
match ty.kind().rigid().expect(&format!("unexpected type: {ty:?}")) {
811811
RigidTy::Adt(def, args) => {
812812
match def.kind() {
813813
AdtKind::Enum => {

kani-driver/src/call_cargo.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,27 @@ impl KaniSession {
211211
}
212212
},
213213
Message::CompilerArtifact(rustc_artifact) => {
214-
if rustc_artifact.target == *target {
214+
/// Compares two targets, and falls back to a weaker
215+
/// comparison where we avoid dashes in their names.
216+
fn same_target(t1: &Target, t2: &Target) -> bool {
217+
(t1 == t2)
218+
|| (t1.name.replace('-', "_") == t2.name.replace('-', "_")
219+
&& t1.kind == t2.kind
220+
&& t1.src_path == t2.src_path
221+
&& t1.edition == t2.edition
222+
&& t1.doctest == t2.doctest
223+
&& t1.test == t2.test
224+
&& t1.doc == t2.doc)
225+
}
226+
// This used to be `rustc_artifact == *target`, but it
227+
// started to fail after the `cargo` change in
228+
// <https://github.com/rust-lang/cargo/pull/12783>
229+
//
230+
// We should revisit this check after a while to see if
231+
// it's not needed anymore or it can be restricted to
232+
// certain cases.
233+
// TODO: <https://github.com/model-checking/kani/issues/3111>
234+
if same_target(&rustc_artifact.target, target) {
215235
debug_assert!(
216236
artifact.is_none(),
217237
"expected only one artifact for `{target:?}`",

rust-toolchain.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33

44
[toolchain]
5-
channel = "nightly-2024-03-15"
5+
channel = "nightly-2024-03-21"
66
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]

tests/cargo-ui/assess-error/expected

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
error: Failed to compile lib `compilation-error`
1+
error: Failed to compile lib `compilation_error`
22
error: Failed to assess project: Failed to build all targets

tests/kani/ValidValues/write_invalid.rs renamed to tests/kani/ValidValues/write_invalid_fixme.rs

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//! Writing invalid bytes is not UB as long as the incorrect value is not read.
77
//! However, we over-approximate for sake of simplicity and performance.
88
9+
// Note: We're getting an unexpected compilation error because the type returned
10+
// from StableMIR is `Alias`: https://github.com/model-checking/kani/issues/3113
11+
912
use std::num::NonZeroU8;
1013

1114
#[kani::proof]

0 commit comments

Comments
 (0)