Skip to content

Commit e922d73

Browse files
authored
Update the rust toolchain to nightly-2024-06-11 (rust-lang#3225)
Changes required due to: - rust-lang/rust@a34c26e7ec Make body_owned_by return the body directly. - rust-lang/rust@333458c2cb Uplift TypeRelation and Relate - rust-lang/rust@459ce3f6bb Add an intrinsic for `ptr::metadata` - rust-lang/rust@7e08f80b34 Split smir `Const` into `TyConst` and `MirConst` - rust-lang/rust@eb584a23bf offset_of: allow (unstably) taking the offset of slice tail fields - rust-lang/rust@16e8803579 Update cargo Resolves: rust-lang#3218
1 parent eeb5fe7 commit e922d73

File tree

17 files changed

+150
-46
lines changed

17 files changed

+150
-46
lines changed

Cargo.lock

+4-4
Original file line numberDiff line numberDiff line change
@@ -390,9 +390,9 @@ checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
390390

391391
[[package]]
392392
name = "itertools"
393-
version = "0.12.1"
393+
version = "0.13.0"
394394
source = "registry+https://github.com/rust-lang/crates.io-index"
395-
checksum = "ba291022dbbd398a455acf126c1e341954079855bc60dfdda641363bd6922569"
395+
checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
396396
dependencies = [
397397
"either",
398398
]
@@ -999,9 +999,9 @@ dependencies = [
999999

10001000
[[package]]
10011001
name = "string-interner"
1002-
version = "0.15.0"
1002+
version = "0.17.0"
10031003
source = "registry+https://github.com/rust-lang/crates.io-index"
1004-
checksum = "07f9fdfdd31a0ff38b59deb401be81b73913d76c9cc5b1aed4e1330a223420b9"
1004+
checksum = "1c6a0d765f5807e98a091107bae0a56ea3799f66a5de47b2c84c94a39c09974e"
10051005
dependencies = [
10061006
"cfg-if",
10071007
"hashbrown",

cprover_bindings/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ lazy_static = "1.4.0"
1717
num = "0.4.0"
1818
num-traits = "0.2"
1919
serde = {version = "1", features = ["derive"]}
20-
string-interner = "0.15.0"
20+
string-interner = "0.17.0"
2121
tracing = "0.1"
2222
linear-map = {version = "1.2", features = ["serde_impl"]}
2323

kani-compiler/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ publish = false
1212
cbmc = { path = "../cprover_bindings", package = "cprover_bindings", optional = true }
1313
clap = { version = "4.4.11", features = ["derive", "cargo"] }
1414
home = "0.5"
15-
itertools = "0.12"
15+
itertools = "0.13"
1616
kani_metadata = {path = "../kani_metadata"}
1717
lazy_static = "1.4.0"
1818
num = { version = "0.4.0", optional = true }

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

+33-5
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use stable_mir::mir::alloc::{AllocId, GlobalAlloc};
1111
use stable_mir::mir::mono::{Instance, StaticDef};
1212
use stable_mir::mir::Operand;
1313
use stable_mir::ty::{
14-
Allocation, Const, ConstantKind, FloatTy, FnDef, GenericArgs, IntTy, RigidTy, Size, Span, Ty,
15-
TyKind, UintTy,
14+
Allocation, ConstantKind, FloatTy, FnDef, GenericArgs, IntTy, MirConst, RigidTy, Size, Span,
15+
Ty, TyConst, TyConstKind, TyKind, UintTy,
1616
};
1717
use stable_mir::{CrateDef, CrateItem};
1818
use tracing::{debug, trace};
@@ -63,17 +63,17 @@ impl<'tcx> GotocCtx<'tcx> {
6363
) -> Expr {
6464
let stable_const = rustc_internal::stable(constant);
6565
let stable_span = rustc_internal::stable(span);
66-
self.codegen_const(&stable_const, stable_span)
66+
self.codegen_const_ty(&stable_const, stable_span)
6767
}
6868

69-
/// Generate a goto expression that represents a constant.
69+
/// Generate a goto expression that represents a MIR-level constant.
7070
///
7171
/// There are two possible constants included in the body of an instance:
7272
/// - Allocated: It will have its byte representation already defined. We try to eagerly
7373
/// generate code for it as simple literals or constants if possible. Otherwise, we create
7474
/// a memory allocation for them and access them indirectly.
7575
/// - ZeroSized: These are ZST constants and they just need to match the right type.
76-
pub fn codegen_const(&mut self, constant: &Const, span: Option<Span>) -> Expr {
76+
pub fn codegen_const(&mut self, constant: &MirConst, span: Option<Span>) -> Expr {
7777
trace!(?constant, "codegen_constant");
7878
match constant.kind() {
7979
ConstantKind::Allocated(alloc) => self.codegen_allocation(alloc, constant.ty(), span),
@@ -90,6 +90,34 @@ impl<'tcx> GotocCtx<'tcx> {
9090
ConstantKind::Param(..) | ConstantKind::Unevaluated(..) => {
9191
unreachable!()
9292
}
93+
ConstantKind::Ty(t) => self.codegen_const_ty(t, span),
94+
}
95+
}
96+
97+
/// Generate a goto expression that represents a type-level constant.
98+
///
99+
/// There are two possible constants included in the body of an instance:
100+
/// - Allocated: It will have its byte representation already defined. We try to eagerly
101+
/// generate code for it as simple literals or constants if possible. Otherwise, we create
102+
/// a memory allocation for them and access them indirectly.
103+
/// - ZeroSized: These are ZST constants and they just need to match the right type.
104+
pub fn codegen_const_ty(&mut self, constant: &TyConst, span: Option<Span>) -> Expr {
105+
trace!(?constant, "codegen_constant");
106+
match constant.kind() {
107+
TyConstKind::ZSTValue(lit_ty) => {
108+
match lit_ty.kind() {
109+
// Rust "function items" (not closures, not function pointers, see `codegen_fndef`)
110+
TyKind::RigidTy(RigidTy::FnDef(def, args)) => {
111+
self.codegen_fndef(def, &args, span)
112+
}
113+
_ => Expr::init_unit(self.codegen_ty_stable(*lit_ty), &self.symbol_table),
114+
}
115+
}
116+
TyConstKind::Value(ty, alloc) => self.codegen_allocation(alloc, *ty, span),
117+
TyConstKind::Bound(..) => unreachable!(),
118+
TyConstKind::Param(..) | TyConstKind::Unevaluated(..) => {
119+
unreachable!()
120+
}
93121
}
94122
}
95123

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

+53-7
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@ use cbmc::goto_program::{
1818
use cbmc::MachineModel;
1919
use cbmc::{btree_string_map, InternString, InternedString};
2020
use num::bigint::BigInt;
21-
use rustc_middle::ty::{TyCtxt, VtblEntry};
21+
use rustc_middle::ty::{ParamEnv, TyCtxt, VtblEntry};
2222
use rustc_smir::rustc_internal;
2323
use rustc_target::abi::{FieldsShape, TagEncoding, Variants};
2424
use stable_mir::abi::{Primitive, Scalar, ValueAbi};
2525
use stable_mir::mir::mono::Instance;
2626
use stable_mir::mir::{
2727
AggregateKind, BinOp, CastKind, NullOp, Operand, Place, PointerCoercion, Rvalue, UnOp,
2828
};
29-
use stable_mir::ty::{ClosureKind, Const, IntTy, RigidTy, Size, Ty, TyKind, UintTy, VariantIdx};
29+
use stable_mir::ty::{ClosureKind, IntTy, RigidTy, Size, Ty, TyConst, TyKind, UintTy, VariantIdx};
3030
use std::collections::BTreeMap;
3131
use tracing::{debug, trace, warn};
3232

@@ -161,7 +161,7 @@ impl<'tcx> GotocCtx<'tcx> {
161161
}
162162

163163
/// Codegens expressions of the type `let a = [4u8; 6];`
164-
fn codegen_rvalue_repeat(&mut self, op: &Operand, sz: &Const, loc: Location) -> Expr {
164+
fn codegen_rvalue_repeat(&mut self, op: &Operand, sz: &TyConst, loc: Location) -> Expr {
165165
let op_expr = self.codegen_operand_stable(op);
166166
let width = sz.eval_target_usize().unwrap();
167167
op_expr.array_constant(width).with_location(loc)
@@ -170,7 +170,7 @@ impl<'tcx> GotocCtx<'tcx> {
170170
fn codegen_rvalue_len(&mut self, p: &Place) -> Expr {
171171
let pt = self.place_ty_stable(p);
172172
match pt.kind() {
173-
TyKind::RigidTy(RigidTy::Array(_, sz)) => self.codegen_const(&sz, None),
173+
TyKind::RigidTy(RigidTy::Array(_, sz)) => self.codegen_const_ty(&sz, None),
174174
TyKind::RigidTy(RigidTy::Slice(_)) => {
175175
unwrap_or_return_codegen_unimplemented!(self, self.codegen_place_stable(p))
176176
.fat_ptr_goto_expr
@@ -779,9 +779,10 @@ impl<'tcx> GotocCtx<'tcx> {
779779
.with_size_of_annotation(self.codegen_ty_stable(*t)),
780780
NullOp::AlignOf => Expr::int_constant(layout.align.abi.bytes(), Type::size_t()),
781781
NullOp::OffsetOf(fields) => Expr::int_constant(
782-
layout
782+
self.tcx
783783
.offset_of_subfield(
784-
self,
784+
ParamEnv::reveal_all(),
785+
layout,
785786
fields.iter().map(|(var_idx, field_idx)| {
786787
(
787788
rustc_internal::internal(self.tcx, var_idx),
@@ -814,6 +815,51 @@ impl<'tcx> GotocCtx<'tcx> {
814815
}
815816
}
816817
UnOp::Neg => self.codegen_operand_stable(e).neg(),
818+
UnOp::PtrMetadata => {
819+
let src_goto_expr = self.codegen_operand_stable(e);
820+
let dst_goto_typ = self.codegen_ty_stable(res_ty);
821+
debug!(
822+
"PtrMetadata |{:?}| with result type |{:?}|",
823+
src_goto_expr, dst_goto_typ
824+
);
825+
if let Some(_vtable_typ) =
826+
src_goto_expr.typ().lookup_field_type("vtable", &self.symbol_table)
827+
{
828+
let vtable_expr = src_goto_expr.member("vtable", &self.symbol_table);
829+
let dst_components =
830+
dst_goto_typ.lookup_components(&self.symbol_table).unwrap();
831+
assert_eq!(dst_components.len(), 2);
832+
assert_eq!(dst_components[0].name(), "_vtable_ptr");
833+
assert!(dst_components[0].typ().is_pointer());
834+
assert_eq!(dst_components[1].name(), "_phantom");
835+
self.assert_is_rust_phantom_data_like(&dst_components[1].typ());
836+
Expr::struct_expr(
837+
dst_goto_typ,
838+
btree_string_map![
839+
("_vtable_ptr", vtable_expr.cast_to(dst_components[0].typ())),
840+
(
841+
"_phantom",
842+
Expr::struct_expr(
843+
dst_components[1].typ(),
844+
[].into(),
845+
&self.symbol_table
846+
)
847+
)
848+
],
849+
&self.symbol_table,
850+
)
851+
} else if let Some(len_typ) =
852+
src_goto_expr.typ().lookup_field_type("len", &self.symbol_table)
853+
{
854+
assert_eq!(len_typ, dst_goto_typ);
855+
src_goto_expr.member("len", &self.symbol_table)
856+
} else {
857+
unreachable!(
858+
"fat pointer with neither vtable nor len: {:?}",
859+
src_goto_expr
860+
);
861+
}
862+
}
817863
},
818864
Rvalue::Discriminant(p) => {
819865
let place =
@@ -1453,7 +1499,7 @@ impl<'tcx> GotocCtx<'tcx> {
14531499
) => {
14541500
// Cast to a slice fat pointer.
14551501
assert_eq!(src_elt_type, dst_elt_type);
1456-
let dst_goto_len = self.codegen_const(&src_elt_count, None);
1502+
let dst_goto_len = self.codegen_const_ty(&src_elt_count, None);
14571503
let src_pointee_ty = pointee_type_stable(coerce_info.src_ty).unwrap();
14581504
let dst_data_expr = if src_pointee_ty.kind().is_array() {
14591505
src_goto_expr.cast_to(self.codegen_ty_stable(src_elt_type).to_pointer())

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
1111
use rustc_middle::ty::print::FmtPrinter;
1212
use rustc_middle::ty::GenericArgsRef;
1313
use rustc_middle::ty::{
14-
self, AdtDef, Const, CoroutineArgs, FloatTy, Instance, IntTy, PolyFnSig, Ty, TyCtxt, TyKind,
15-
UintTy, VariantDef, VtblEntry,
14+
self, AdtDef, Const, CoroutineArgs, CoroutineArgsExt, FloatTy, Instance, IntTy, PolyFnSig, Ty,
15+
TyCtxt, TyKind, UintTy, VariantDef, VtblEntry,
1616
};
1717
use rustc_middle::ty::{List, TypeFoldable};
1818
use rustc_smir::rustc_internal;

kani-compiler/src/codegen_cprover_gotoc/utils/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl<'tcx> GotocCtx<'tcx> {
125125
}
126126

127127
/// Best effort check if the struct represents a rust `std::marker::PhantomData`
128-
fn assert_is_rust_phantom_data_like(&self, t: &Type) {
128+
pub fn assert_is_rust_phantom_data_like(&self, t: &Type) {
129129
// TODO: A `std::marker::PhantomData` appears to be an empty struct, in the cases we've seen.
130130
// Is there something smarter we can do here?
131131
assert!(t.is_struct_like());

kani-compiler/src/kani_middle/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ fn parse_modify_values<'a>(
633633
TokenTree::Token(token, _) => {
634634
if let TokenKind::Ident(id, _) = &token.kind {
635635
let hir = tcx.hir();
636-
let bid = hir.body_owned_by(local_def_id);
636+
let bid = hir.body_owned_by(local_def_id).id();
637637
Some(
638638
hir.body_param_names(bid)
639639
.zip(mir.args_iter())

kani-compiler/src/kani_middle/reachability.rs

+4
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,10 @@ impl<'a, 'tcx> MirVisitor for MonoItemsFnCollector<'a, 'tcx> {
376376
// Nothing to do here.
377377
return;
378378
}
379+
ConstantKind::Ty(_) => {
380+
// Nothing to do here.
381+
return;
382+
}
379383
};
380384
self.collect_allocation(&allocation);
381385
}

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use crate::kani_middle::find_fn_def;
77
use rustc_middle::ty::TyCtxt;
88
use stable_mir::mir::mono::Instance;
99
use stable_mir::mir::*;
10-
use stable_mir::ty::{Const, GenericArgs, Span, Ty, UintTy};
10+
use stable_mir::ty::{GenericArgs, MirConst, Span, Ty, UintTy};
1111
use std::fmt::Debug;
1212
use std::mem;
1313

@@ -80,12 +80,12 @@ impl MutableBody {
8080
}
8181

8282
pub fn new_str_operand(&mut self, msg: &str, span: Span) -> Operand {
83-
let literal = Const::from_str(msg);
83+
let literal = MirConst::from_str(msg);
8484
Operand::Constant(Constant { span, user_ty: None, literal })
8585
}
8686

8787
pub fn new_const_operand(&mut self, val: u128, uint_ty: UintTy, span: Span) -> Operand {
88-
let literal = Const::try_from_uint(val, uint_ty).unwrap();
88+
let literal = MirConst::try_from_uint(val, uint_ty).unwrap();
8989
Operand::Constant(Constant { span, user_ty: None, literal })
9090
}
9191

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

+15-13
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ use crate::kani_middle::transform::body::{CheckType, MutableBody, SourceInstruct
1818
use crate::kani_middle::transform::check_values::SourceOp::UnsupportedCheck;
1919
use crate::kani_middle::transform::{TransformPass, TransformationType};
2020
use crate::kani_queries::QueryDb;
21-
use rustc_middle::ty::TyCtxt;
21+
use rustc_middle::ty::{Const, TyCtxt};
22+
use rustc_smir::rustc_internal;
2223
use stable_mir::abi::{FieldsShape, Scalar, TagEncoding, ValueAbi, VariantsShape, WrappingRange};
2324
use stable_mir::mir::mono::{Instance, InstanceKind};
2425
use stable_mir::mir::visit::{Location, PlaceContext, PlaceRef};
@@ -28,7 +29,7 @@ use stable_mir::mir::{
2829
Statement, StatementKind, Terminator, TerminatorKind,
2930
};
3031
use stable_mir::target::{MachineInfo, MachineSize};
31-
use stable_mir::ty::{AdtKind, Const, IndexedVal, RigidTy, Ty, TyKind, UintTy};
32+
use stable_mir::ty::{AdtKind, IndexedVal, MirConst, RigidTy, Ty, TyKind, UintTy};
3233
use stable_mir::CrateDef;
3334
use std::fmt::Debug;
3435
use strum_macros::AsRefStr;
@@ -65,7 +66,7 @@ impl TransformPass for ValidValuePass {
6566
// Do not cache body.blocks().len() since it will change as we add new checks.
6667
for bb_idx in 0..new_body.blocks().len() {
6768
let Some(candidate) =
68-
CheckValueVisitor::find_next(&new_body, bb_idx, bb_idx >= orig_len)
69+
CheckValueVisitor::find_next(tcx, &new_body, bb_idx, bb_idx >= orig_len)
6970
else {
7071
continue;
7172
};
@@ -118,7 +119,7 @@ impl ValidValuePass {
118119
) {
119120
let span = source.span(body.blocks());
120121
let rvalue = Rvalue::Use(Operand::Constant(Constant {
121-
literal: Const::from_bool(false),
122+
literal: MirConst::from_bool(false),
122123
span,
123124
user_ty: None,
124125
}));
@@ -262,7 +263,8 @@ struct UnsafeInstruction {
262263
/// - Transmute
263264
/// - MemCopy
264265
/// - Cast
265-
struct CheckValueVisitor<'a> {
266+
struct CheckValueVisitor<'a, 'b> {
267+
tcx: TyCtxt<'b>,
266268
locals: &'a [LocalDecl],
267269
/// Whether we should skip the next instruction, since it might've been instrumented already.
268270
/// When we instrument an instruction, we partition the basic block, and the instruction that
@@ -279,13 +281,15 @@ struct CheckValueVisitor<'a> {
279281
machine: MachineInfo,
280282
}
281283

282-
impl<'a> CheckValueVisitor<'a> {
284+
impl<'a, 'b> CheckValueVisitor<'a, 'b> {
283285
fn find_next(
286+
tcx: TyCtxt<'b>,
284287
body: &'a MutableBody,
285288
bb: BasicBlockIdx,
286289
skip_first: bool,
287290
) -> Option<UnsafeInstruction> {
288291
let mut visitor = CheckValueVisitor {
292+
tcx,
289293
locals: body.locals(),
290294
skip_next: skip_first,
291295
current: SourceInstruction::Statement { idx: 0, bb },
@@ -305,7 +309,7 @@ impl<'a> CheckValueVisitor<'a> {
305309
}
306310
}
307311

308-
impl<'a> MirVisitor for CheckValueVisitor<'a> {
312+
impl<'a, 'b> MirVisitor for CheckValueVisitor<'a, 'b> {
309313
fn visit_statement(&mut self, stmt: &Statement, location: Location) {
310314
if self.skip_next {
311315
self.skip_next = false;
@@ -388,12 +392,10 @@ impl<'a> MirVisitor for CheckValueVisitor<'a> {
388392
match validity {
389393
Ok(ranges) if ranges.is_empty() => {}
390394
Ok(ranges) => {
391-
let sz = Const::try_from_uint(
392-
target_ty.layout().unwrap().shape().size.bytes()
393-
as u128,
394-
UintTy::Usize,
395-
)
396-
.unwrap();
395+
let sz = rustc_internal::stable(Const::from_target_usize(
396+
self.tcx,
397+
target_ty.layout().unwrap().shape().size.bytes() as u64,
398+
));
397399
self.push_target(SourceOp::BytesValidity {
398400
target_ty,
399401
rvalue: Rvalue::Repeat(args[1].clone(), sz),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::TyCtxt;
1111
use rustc_smir::rustc_internal;
1212
use stable_mir::mir::mono::Instance;
1313
use stable_mir::mir::{Body, Constant, Operand, TerminatorKind};
14-
use stable_mir::ty::{Const as MirConst, FnDef, RigidTy, TyKind};
14+
use stable_mir::ty::{FnDef, MirConst, RigidTy, TyKind};
1515
use stable_mir::{CrateDef, DefId};
1616
use std::collections::HashSet;
1717
use std::fmt::Debug;

0 commit comments

Comments
 (0)