Skip to content

Commit

Permalink
Update Rust toolchain to 2023-09-23
Browse files Browse the repository at this point in the history
Source changes required by the following upstream commits:

* rust-lang/rust@5a0a1ff0cd move ConstValue into mir
* rust-lang/rust@ea22adbabd adjust constValue::Slice to work for arbitrary slice types
* rust-lang/rust@c94410c145 rename mir::Constant -> mir::ConstOperand, mir::ConstKind -> mir::Const

Fixes: model-checking#2784
  • Loading branch information
tautschnig committed Oct 4, 2023
1 parent 62f136c commit 27cb922
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 37 deletions.
32 changes: 13 additions & 19 deletions kani-compiler/src/codegen_cprover_gotoc/codegen/operand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ use crate::unwrap_or_return_codegen_unimplemented;
use cbmc::btree_string_map;
use cbmc::goto_program::{DatatypeComponent, Expr, ExprValue, Location, Stmt, Symbol, Type};
use rustc_ast::ast::Mutability;
use rustc_middle::mir::interpret::{
read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, Scalar,
};
use rustc_middle::mir::{Constant, ConstantKind, Operand, UnevaluatedConst};
use rustc_middle::mir::interpret::{read_target_uint, AllocId, Allocation, GlobalAlloc, Scalar};
use rustc_middle::mir::{Const as mirConst, ConstOperand, ConstValue, Operand, UnevaluatedConst};
use rustc_middle::ty::layout::LayoutOf;
use rustc_middle::ty::{self, Const, ConstKind, FloatTy, Instance, IntTy, Ty, Uint, UintTy};
use rustc_span::def_id::DefId;
Expand Down Expand Up @@ -56,13 +54,13 @@ impl<'tcx> GotocCtx<'tcx> {
/// 1. `Ty` means e.g. that it's a const generic parameter. (See `codegen_const`)
/// 2. `Val` means it's a constant value of various kinds. (See `codegen_const_value`)
/// 3. `Unevaluated` means we need to run the interpreter, to get a `ConstValue`. (See `codegen_const_unevaluated`)
fn codegen_constant(&mut self, c: &Constant<'tcx>) -> Expr {
fn codegen_constant(&mut self, c: &ConstOperand<'tcx>) -> Expr {
trace!(constant=?c, "codegen_constant");
let span = Some(&c.span);
match self.monomorphize(c.literal) {
ConstantKind::Ty(ct) => self.codegen_const(ct, span),
ConstantKind::Val(val, ty) => self.codegen_const_value(val, ty, span),
ConstantKind::Unevaluated(unevaluated, ty) => {
match self.monomorphize(c.const_) {
mirConst::Ty(ct) => self.codegen_const(ct, span),
mirConst::Val(val, ty) => self.codegen_const_value(val, ty, span),
mirConst::Unevaluated(unevaluated, ty) => {
self.codegen_const_unevaluated(unevaluated, ty, span)
}
}
Expand Down Expand Up @@ -125,8 +123,8 @@ impl<'tcx> GotocCtx<'tcx> {
trace!(val=?v, ?lit_ty, "codegen_const_value");
match v {
ConstValue::Scalar(s) => self.codegen_scalar(s, lit_ty, span),
ConstValue::Slice { data, start, end } => {
self.codegen_slice_value(v, lit_ty, span, data.inner(), start, end)
ConstValue::Slice { data, meta } => {
self.codegen_slice_value(v, lit_ty, span, data.inner(), meta.try_into().unwrap())
}
ConstValue::Indirect { alloc_id, offset } => {
let alloc = self.tcx.global_alloc(alloc_id).unwrap_memory();
Expand Down Expand Up @@ -155,15 +153,12 @@ impl<'tcx> GotocCtx<'tcx> {
lit_ty: Ty<'tcx>,
span: Option<&Span>,
data: &'tcx Allocation,
start: usize,
end: usize,
size: usize,
) -> Expr {
if let ty::Ref(_, ref_ty, _) = lit_ty.kind() {
match ref_ty.kind() {
ty::Str => {
// a string literal
// These seem to always start at 0
assert_eq!(start, 0);
// Create a static variable that holds its value
let mem_var = self.codegen_const_allocation(data, None);

Expand All @@ -179,15 +174,15 @@ impl<'tcx> GotocCtx<'tcx> {
};

// Extract the actual string literal
let slice = data.inspect_with_uninit_and_ptr_outside_interpreter(start..end);
let slice = data.inspect_with_uninit_and_ptr_outside_interpreter(0..size);
let s = ::std::str::from_utf8(slice).expect("non utf8 str from miri");

// Store the identifier to the string literal in the goto context
self.str_literals.insert(*ident, s.into());

// Codegen as a fat pointer
let data_expr = mem_var.cast_to(Type::unsigned_int(8).to_pointer());
let len_expr = Expr::int_constant(end - start, Type::size_t());
let len_expr = Expr::int_constant(size, Type::size_t());
return slice_fat_ptr(
self.codegen_ty(lit_ty),
data_expr,
Expand All @@ -198,8 +193,7 @@ impl<'tcx> GotocCtx<'tcx> {
ty::Slice(slice_ty) => {
if let Uint(UintTy::U8) = slice_ty.kind() {
let mem_var = self.codegen_const_allocation(data, None);
let slice =
data.inspect_with_uninit_and_ptr_outside_interpreter(start..end);
let slice = data.inspect_with_uninit_and_ptr_outside_interpreter(0..size);
let len = slice.len();
let data_expr = mem_var.cast_to(Type::unsigned_int(8).to_pointer());
let len_expr = Expr::int_constant(len, Type::size_t());
Expand Down
4 changes: 2 additions & 2 deletions kani-compiler/src/kani_middle/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
//! This module contains a MIR pass that replaces some intrinsics by rust intrinsics models as
//! well as validation logic that can only be added during monomorphization.
use rustc_index::IndexVec;
use rustc_middle::mir::{interpret::ConstValue, Body, ConstantKind, Operand, TerminatorKind};
use rustc_middle::mir::{Body, Const as mirConst, ConstValue, Operand, TerminatorKind};
use rustc_middle::mir::{Local, LocalDecl};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::ty::{Const, GenericArgsRef};
Expand Down Expand Up @@ -69,7 +69,7 @@ impl<'tcx> ModelIntrinsics<'tcx> {
new_gen_args.push(len.into());

let Operand::Constant(fn_def) = func else { unreachable!() };
fn_def.literal = ConstantKind::from_value(
fn_def.const_ = mirConst::from_value(
ConstValue::ZeroSized,
tcx.type_of(stub_id).instantiate(tcx, &new_gen_args),
);
Expand Down
24 changes: 12 additions & 12 deletions kani-compiler/src/kani_middle/reachability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::def::DefKind;
use rustc_hir::def_id::DefId;
use rustc_hir::ItemId;
use rustc_middle::mir::interpret::{AllocId, ConstValue, ErrorHandled, GlobalAlloc, Scalar};
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, GlobalAlloc, Scalar};
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::mir::visit::Visitor as MirVisitor;
use rustc_middle::mir::{
Body, CastKind, Constant, ConstantKind, Location, Rvalue, Terminator, TerminatorKind,
Body, CastKind, Const, ConstOperand, ConstValue, Location, Rvalue, Terminator, TerminatorKind,
UnevaluatedConst,
};
use rustc_middle::span_bug;
Expand Down Expand Up @@ -322,7 +322,7 @@ impl<'a, 'tcx> MonoItemsFnCollector<'a, 'tcx> {
ConstValue::Scalar(Scalar::Ptr(ptr, _size)) => {
self.collected.extend(collect_alloc_items(self.tcx, ptr.provenance).iter());
}
ConstValue::Slice { data: alloc, start: _, end: _ } => {
ConstValue::Slice { data: alloc, .. } => {
for id in alloc.inner().provenance().provenances() {
self.collected.extend(collect_alloc_items(self.tcx, id).iter())
}
Expand Down Expand Up @@ -435,12 +435,12 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MonoItemsFnCollector<'a, 'tcx> {
}

/// Collect constants that are represented as static variables.
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
let literal = self.monomorphize(constant.literal);
debug!(?constant, ?location, ?literal, "visit_constant");
let val = match literal {
ConstantKind::Val(const_val, _) => const_val,
ConstantKind::Ty(ct) => match ct.kind() {
fn visit_constant(&mut self, constant: &ConstOperand<'tcx>, location: Location) {
let const_ = self.monomorphize(constant.const_);
debug!(?constant, ?location, ?const_, "visit_constant");
let val = match const_ {
Const::Val(const_val, _) => const_val,
Const::Ty(ct) => match ct.kind() {
ConstKind::Value(v) => self.tcx.valtree_to_const_val((ct.ty(), v)),
ConstKind::Unevaluated(_) => unreachable!(),
// Nothing to do
Expand All @@ -454,7 +454,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MonoItemsFnCollector<'a, 'tcx> {
unreachable!("Unexpected constant type {:?} ({:?})", ct, ct.kind())
}
},
ConstantKind::Unevaluated(un_eval, _) => {
Const::Unevaluated(un_eval, _) => {
// Thread local fall into this category.
match self.tcx.const_eval_resolve(ParamEnv::reveal_all(), un_eval, None) {
// The `monomorphize` call should have evaluated that constant already.
Expand All @@ -473,8 +473,8 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MonoItemsFnCollector<'a, 'tcx> {
span_bug!(
span,
"Unexpected polymorphic constant: {:?} {:?}",
literal,
constant.literal
const_,
constant.const_
)
}
}
Expand Down
5 changes: 2 additions & 3 deletions kani-compiler/src/kani_middle/stubbing/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
use rustc_hir::{def_id::DefId, definitions::DefPathHash};
use rustc_index::IndexVec;
use rustc_middle::mir::{
interpret::ConstValue, visit::MutVisitor, Body, ConstantKind, Local, LocalDecl, Location,
Operand,
visit::MutVisitor, Body, Const, ConstValue, Local, LocalDecl, Location, Operand,
};
use rustc_middle::ty::{self, TyCtxt};

Expand Down Expand Up @@ -79,7 +78,7 @@ impl<'tcx> MutVisitor<'tcx> for ForeignFunctionTransformer<'tcx> {
let Operand::Constant(function_definition) = operand else {
return;
};
function_definition.literal = ConstantKind::from_value(
function_definition.const_ = Const::from_value(
ConstValue::ZeroSized,
self.tcx.type_of(stub).instantiate(self.tcx, arguments),
);
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
# SPDX-License-Identifier: Apache-2.0 OR MIT

[toolchain]
channel = "nightly-2023-09-19"
channel = "nightly-2023-09-23"
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]

0 comments on commit 27cb922

Please sign in to comment.