Skip to content

Commit 46bdb75

Browse files
authored
Upgrade Rust toolchain to nightly-2024-02-25 (#3048)
Upgrades the Rust toolchain to `nightly-2024-02-25`. The Rust compiler PRs that triggered changes in this upgrades are: * rust-lang/rust#121209 * rust-lang/rust#121309 * rust-lang/rust#120863 * rust-lang/rust#117772 * rust-lang/rust#117658 With rust-lang/rust#121309 some intrinsics became inlineable so their names became qualified. This made our `match` on the intrinsic name to fail in those cases, leaving them as unsupported constructs as in this example: ``` warning: Found the following unsupported constructs: - _RNvNtCscyGW2MM2t5j_4core10intrinsics8unlikelyCs1eohKeNmpdS_5arith (3) - caller_location (1) - foreign function (1) Verification will fail if one or more of these constructs is reachable. See https://model-checking.github.io/kani/rust-feature-support.html for more details. [...] Failed Checks: _RNvNtCscyGW2MM2t5j_4core10intrinsics8unlikelyCs1eohKeNmpdS_5arith is not currently supported by Kani. Please post your example at https://github.com/model-checking/kani/issues/new/choose File: "/home/ubuntu/.rustup/toolchains/nightly-2024-02-18-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/num/mod.rs", line 25, in core::num::<impl i8>::checked_add ``` We use `trimmed_name()` to work around this, but that may include type arguments if the intrinsic is defined on generics. So in those cases, we just take the first part of the name so we can keep the rest as before. Resolves #3044
1 parent 73b4c47 commit 46bdb75

File tree

18 files changed

+34
-24
lines changed

18 files changed

+34
-24
lines changed

cprover_bindings/src/goto_program/location.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// Copyright Kani Contributors
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33
use crate::cbmc_string::{InternStringOption, InternedString};
4-
use std::convert::TryInto;
54
use std::fmt::Debug;
65

76
/// A `Location` represents a source location.

cprover_bindings/src/goto_program/typ.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ use super::super::MachineModel;
77
use super::{Expr, SymbolTable};
88
use crate::cbmc_string::InternedString;
99
use std::collections::BTreeMap;
10-
use std::convert::TryInto;
1110
use std::fmt::Debug;
1211

1312
///////////////////////////////////////////////////////////////////////////////////////////////

kani-compiler/src/codegen_cprover_gotoc/codegen/assert.rs

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use crate::codegen_cprover_gotoc::GotocCtx;
2222
use cbmc::goto_program::{Expr, Location, Stmt, Type};
2323
use cbmc::InternedString;
2424
use stable_mir::ty::Span as SpanStable;
25-
use std::convert::AsRef;
2625
use strum_macros::{AsRefStr, EnumString};
2726
use tracing::debug;
2827

kani-compiler/src/codegen_cprover_gotoc/codegen/function.rs

-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ use stable_mir::mir::{Body, Local};
1212
use stable_mir::ty::{RigidTy, TyKind};
1313
use stable_mir::CrateDef;
1414
use std::collections::BTreeMap;
15-
use std::iter::FromIterator;
1615
use tracing::{debug, debug_span};
1716

1817
/// Codegen MIR functions into gotoc

kani-compiler/src/codegen_cprover_gotoc/codegen/intrinsic.rs

+18-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ impl<'tcx> GotocCtx<'tcx> {
112112
place: &Place,
113113
span: Span,
114114
) -> Stmt {
115-
let intrinsic_sym = instance.mangled_name();
115+
let intrinsic_sym = instance.trimmed_name();
116116
let intrinsic = intrinsic_sym.as_str();
117117
let loc = self.codegen_span_stable(span);
118118
debug!(?instance, "codegen_intrinsic");
@@ -288,6 +288,23 @@ impl<'tcx> GotocCtx<'tcx> {
288288
}};
289289
}
290290

291+
/// Gets the basename of an intrinsic given its trimmed name.
292+
///
293+
/// For example, given `arith_offset::<u8>` this returns `arith_offset`.
294+
fn intrinsic_basename(name: &str) -> &str {
295+
let scope_sep_count = name.matches("::").count();
296+
// We expect at most one `::` separator from trimmed intrinsic names
297+
debug_assert!(
298+
scope_sep_count < 2,
299+
"expected at most one `::` in intrinsic name, but found {scope_sep_count} in `{name}`"
300+
);
301+
let name_split = name.split_once("::");
302+
if let Some((base_name, _type_args)) = name_split { base_name } else { name }
303+
}
304+
// The trimmed name includes type arguments if the intrinsic was defined
305+
// on generic types, but we only need the basename for the match below.
306+
let intrinsic = intrinsic_basename(intrinsic);
307+
291308
if let Some(stripped) = intrinsic.strip_prefix("simd_shuffle") {
292309
assert!(fargs.len() == 3, "`simd_shuffle` had unexpected arguments {fargs:?}");
293310
let n: u64 = self.simd_shuffle_length(stripped, farg_types, span);

kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ use std::ffi::OsString;
5353
use std::fmt::Write;
5454
use std::fs::File;
5555
use std::io::BufWriter;
56-
use std::iter::FromIterator;
5756
use std::path::{Path, PathBuf};
5857
use std::process::Command;
5958
use std::sync::{Arc, Mutex};
@@ -353,10 +352,10 @@ impl CodegenBackend for GotocCodegenBackend {
353352
ongoing_codegen: Box<dyn Any>,
354353
_sess: &Session,
355354
_filenames: &OutputFilenames,
356-
) -> Result<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>), ErrorGuaranteed> {
355+
) -> (CodegenResults, FxIndexMap<WorkProductId, WorkProduct>) {
357356
match ongoing_codegen.downcast::<(CodegenResults, FxIndexMap<WorkProductId, WorkProduct>)>()
358357
{
359-
Ok(val) => Ok(*val),
358+
Ok(val) => *val,
360359
Err(val) => panic!("unexpected error: {:?}", (*val).type_id()),
361360
}
362361
}

kani-compiler/src/kani_compiler.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -465,10 +465,8 @@ fn metadata_output_path(tcx: TyCtxt) -> PathBuf {
465465
#[cfg(test)]
466466
mod tests {
467467
use super::*;
468-
use kani_metadata::{HarnessAttributes, HarnessMetadata};
468+
use kani_metadata::HarnessAttributes;
469469
use rustc_data_structures::fingerprint::Fingerprint;
470-
use rustc_hir::definitions::DefPathHash;
471-
use std::collections::HashMap;
472470

473471
fn mock_next_harness_id() -> HarnessId {
474472
static mut COUNTER: u64 = 0;

kani-compiler/src/kani_middle/metadata.rs

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! This module handles Kani metadata generation. For example, generating HarnessMetadata for a
44
//! given function.
55
6-
use std::default::Default;
76
use std::path::Path;
87

98
use crate::kani_middle::attributes::test_harness_name;

kani-compiler/src/kani_middle/provide.rs

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ use crate::kani_middle::reachability::{collect_reachable_items, filter_crate_ite
1010
use crate::kani_middle::stubbing;
1111
use crate::kani_queries::QueryDb;
1212
use rustc_hir::def_id::{DefId, LocalDefId};
13-
use rustc_interface;
1413
use rustc_middle::util::Providers;
1514
use rustc_middle::{mir::Body, query::queries, ty::TyCtxt};
1615
use stable_mir::mir::mono::MonoItem;

kani-compiler/src/kani_middle/reachability.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use stable_mir::mir::{
3131
TerminatorKind,
3232
};
3333
use stable_mir::ty::{Allocation, ClosureKind, ConstantKind, RigidTy, Ty, TyKind};
34-
use stable_mir::{self, CrateItem};
34+
use stable_mir::CrateItem;
3535
use stable_mir::{CrateDef, ItemKind};
3636

3737
use crate::kani_middle::coercion;

kani-driver/src/args/playback_args.rs

-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,6 @@ impl ValidateArgs for PlaybackArgs {
100100

101101
#[cfg(test)]
102102
mod tests {
103-
use clap::Parser;
104-
105103
use super::*;
106104

107105
#[test]

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-02-17"
5+
channel = "nightly-2024-02-25"
66
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
Checking harness check_access_length_17...
22

33
Failed Checks: assumption failed\
4-
in std::hint::assert_unchecked
4+
in <usize as std::slice::SliceIndex<[u8]>>::get_unchecked
55

66
Checking harness check_access_length_zero...
77

88
Failed Checks: assumption failed\
9-
in std::hint::assert_unchecked
9+
in <usize as std::slice::SliceIndex<[u8]>>::get_unchecked
1010

1111
Verification failed for - check_access_length_17
1212
Verification failed for - check_access_length_zero
+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Checking harness check_always_out_bounds...
22

33
Failed Checks: assumption failed
4-
in std::hint::assert_unchecked
4+
in <usize as std::slice::SliceIndex<[u8]>>::get_unchecked
55

66
Verification failed for - check_always_out_bounds

tests/kani/Intrinsics/Atomic/Stable/AtomicPtr/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ fn check_fetch_byte_add() {
1818

1919
#[kani::proof]
2020
fn check_fetch_byte_sub() {
21-
let atom = AtomicPtr::<i64>::new(core::ptr::invalid_mut(1));
21+
let atom = AtomicPtr::<i64>::new(core::ptr::without_provenance_mut(1));
2222
assert_eq!(atom.fetch_byte_sub(1, Ordering::Relaxed).addr(), 1);
2323
assert_eq!(atom.load(Ordering::Relaxed).addr(), 0);
2424
}

tests/kani/Intrinsics/Likely/main.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,15 @@ fn check_unlikely(x: i32, y: i32) {
2828
}
2929

3030
#[kani::proof]
31-
fn main() {
31+
fn check_likely_main() {
3232
let x = kani::any();
3333
let y = kani::any();
3434
check_likely(x, y);
35+
}
36+
37+
#[kani::proof]
38+
fn check_unlikely_main() {
39+
let x = kani::any();
40+
let y = kani::any();
3541
check_unlikely(x, y);
3642
}

tools/bookrunner/librustdoc/html/markdown.rs

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
88
use rustc_span::edition::Edition;
99

10-
use std::default::Default;
1110
use std::str;
1211
use std::{borrow::Cow, marker::PhantomData};
1312

tools/compiletest/src/runtest.rs

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use std::process::{Command, ExitStatus, Output, Stdio};
2323
use std::str;
2424

2525
use serde::{Deserialize, Serialize};
26-
use serde_yaml;
2726
use tracing::*;
2827
use wait_timeout::ChildExt;
2928

0 commit comments

Comments
 (0)