Skip to content

Commit 7bf5a6d

Browse files
authored
Update Rust toolchain to 2023-09-23 (rust-lang#2806)
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: rust-lang#2784
1 parent fece7ee commit 7bf5a6d

File tree

5 files changed

+30
-37
lines changed

5 files changed

+30
-37
lines changed

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

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,8 @@ use crate::unwrap_or_return_codegen_unimplemented;
66
use cbmc::btree_string_map;
77
use cbmc::goto_program::{DatatypeComponent, Expr, ExprValue, Location, Stmt, Symbol, Type};
88
use rustc_ast::ast::Mutability;
9-
use rustc_middle::mir::interpret::{
10-
read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, Scalar,
11-
};
12-
use rustc_middle::mir::{Constant, ConstantKind, Operand, UnevaluatedConst};
9+
use rustc_middle::mir::interpret::{read_target_uint, AllocId, Allocation, GlobalAlloc, Scalar};
10+
use rustc_middle::mir::{Const as mirConst, ConstOperand, ConstValue, Operand, UnevaluatedConst};
1311
use rustc_middle::ty::layout::LayoutOf;
1412
use rustc_middle::ty::{self, Const, ConstKind, FloatTy, Instance, IntTy, Ty, Uint, UintTy};
1513
use rustc_span::def_id::DefId;
@@ -56,13 +54,13 @@ impl<'tcx> GotocCtx<'tcx> {
5654
/// 1. `Ty` means e.g. that it's a const generic parameter. (See `codegen_const`)
5755
/// 2. `Val` means it's a constant value of various kinds. (See `codegen_const_value`)
5856
/// 3. `Unevaluated` means we need to run the interpreter, to get a `ConstValue`. (See `codegen_const_unevaluated`)
59-
fn codegen_constant(&mut self, c: &Constant<'tcx>) -> Expr {
57+
fn codegen_constant(&mut self, c: &ConstOperand<'tcx>) -> Expr {
6058
trace!(constant=?c, "codegen_constant");
6159
let span = Some(&c.span);
62-
match self.monomorphize(c.literal) {
63-
ConstantKind::Ty(ct) => self.codegen_const(ct, span),
64-
ConstantKind::Val(val, ty) => self.codegen_const_value(val, ty, span),
65-
ConstantKind::Unevaluated(unevaluated, ty) => {
60+
match self.monomorphize(c.const_) {
61+
mirConst::Ty(ct) => self.codegen_const(ct, span),
62+
mirConst::Val(val, ty) => self.codegen_const_value(val, ty, span),
63+
mirConst::Unevaluated(unevaluated, ty) => {
6664
self.codegen_const_unevaluated(unevaluated, ty, span)
6765
}
6866
}
@@ -125,8 +123,8 @@ impl<'tcx> GotocCtx<'tcx> {
125123
trace!(val=?v, ?lit_ty, "codegen_const_value");
126124
match v {
127125
ConstValue::Scalar(s) => self.codegen_scalar(s, lit_ty, span),
128-
ConstValue::Slice { data, start, end } => {
129-
self.codegen_slice_value(v, lit_ty, span, data.inner(), start, end)
126+
ConstValue::Slice { data, meta } => {
127+
self.codegen_slice_value(v, lit_ty, span, data.inner(), meta.try_into().unwrap())
130128
}
131129
ConstValue::Indirect { alloc_id, offset } => {
132130
let alloc = self.tcx.global_alloc(alloc_id).unwrap_memory();
@@ -155,15 +153,12 @@ impl<'tcx> GotocCtx<'tcx> {
155153
lit_ty: Ty<'tcx>,
156154
span: Option<&Span>,
157155
data: &'tcx Allocation,
158-
start: usize,
159-
end: usize,
156+
size: usize,
160157
) -> Expr {
161158
if let ty::Ref(_, ref_ty, _) = lit_ty.kind() {
162159
match ref_ty.kind() {
163160
ty::Str => {
164161
// a string literal
165-
// These seem to always start at 0
166-
assert_eq!(start, 0);
167162
// Create a static variable that holds its value
168163
let mem_var = self.codegen_const_allocation(data, None);
169164

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

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

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

188183
// Codegen as a fat pointer
189184
let data_expr = mem_var.cast_to(Type::unsigned_int(8).to_pointer());
190-
let len_expr = Expr::int_constant(end - start, Type::size_t());
185+
let len_expr = Expr::int_constant(size, Type::size_t());
191186
return slice_fat_ptr(
192187
self.codegen_ty(lit_ty),
193188
data_expr,
@@ -198,8 +193,7 @@ impl<'tcx> GotocCtx<'tcx> {
198193
ty::Slice(slice_ty) => {
199194
if let Uint(UintTy::U8) = slice_ty.kind() {
200195
let mem_var = self.codegen_const_allocation(data, None);
201-
let slice =
202-
data.inspect_with_uninit_and_ptr_outside_interpreter(start..end);
196+
let slice = data.inspect_with_uninit_and_ptr_outside_interpreter(0..size);
203197
let len = slice.len();
204198
let data_expr = mem_var.cast_to(Type::unsigned_int(8).to_pointer());
205199
let len_expr = Expr::int_constant(len, Type::size_t());

kani-compiler/src/kani_middle/intrinsics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//! This module contains a MIR pass that replaces some intrinsics by rust intrinsics models as
44
//! well as validation logic that can only be added during monomorphization.
55
use rustc_index::IndexVec;
6-
use rustc_middle::mir::{interpret::ConstValue, Body, ConstantKind, Operand, TerminatorKind};
6+
use rustc_middle::mir::{Body, Const as mirConst, ConstValue, Operand, TerminatorKind};
77
use rustc_middle::mir::{Local, LocalDecl};
88
use rustc_middle::ty::{self, Ty, TyCtxt};
99
use rustc_middle::ty::{Const, GenericArgsRef};
@@ -69,7 +69,7 @@ impl<'tcx> ModelIntrinsics<'tcx> {
6969
new_gen_args.push(len.into());
7070

7171
let Operand::Constant(fn_def) = func else { unreachable!() };
72-
fn_def.literal = ConstantKind::from_value(
72+
fn_def.const_ = mirConst::from_value(
7373
ConstValue::ZeroSized,
7474
tcx.type_of(stub_id).instantiate(tcx, &new_gen_args),
7575
);

kani-compiler/src/kani_middle/reachability.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
2222
use rustc_hir::def::DefKind;
2323
use rustc_hir::def_id::DefId;
2424
use rustc_hir::ItemId;
25-
use rustc_middle::mir::interpret::{AllocId, ConstValue, ErrorHandled, GlobalAlloc, Scalar};
25+
use rustc_middle::mir::interpret::{AllocId, ErrorHandled, GlobalAlloc, Scalar};
2626
use rustc_middle::mir::mono::MonoItem;
2727
use rustc_middle::mir::visit::Visitor as MirVisitor;
2828
use rustc_middle::mir::{
29-
Body, CastKind, Constant, ConstantKind, Location, Rvalue, Terminator, TerminatorKind,
29+
Body, CastKind, Const, ConstOperand, ConstValue, Location, Rvalue, Terminator, TerminatorKind,
3030
UnevaluatedConst,
3131
};
3232
use rustc_middle::span_bug;
@@ -322,7 +322,7 @@ impl<'a, 'tcx> MonoItemsFnCollector<'a, 'tcx> {
322322
ConstValue::Scalar(Scalar::Ptr(ptr, _size)) => {
323323
self.collected.extend(collect_alloc_items(self.tcx, ptr.provenance).iter());
324324
}
325-
ConstValue::Slice { data: alloc, start: _, end: _ } => {
325+
ConstValue::Slice { data: alloc, .. } => {
326326
for id in alloc.inner().provenance().provenances() {
327327
self.collected.extend(collect_alloc_items(self.tcx, id).iter())
328328
}
@@ -435,12 +435,12 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MonoItemsFnCollector<'a, 'tcx> {
435435
}
436436

437437
/// Collect constants that are represented as static variables.
438-
fn visit_constant(&mut self, constant: &Constant<'tcx>, location: Location) {
439-
let literal = self.monomorphize(constant.literal);
440-
debug!(?constant, ?location, ?literal, "visit_constant");
441-
let val = match literal {
442-
ConstantKind::Val(const_val, _) => const_val,
443-
ConstantKind::Ty(ct) => match ct.kind() {
438+
fn visit_constant(&mut self, constant: &ConstOperand<'tcx>, location: Location) {
439+
let const_ = self.monomorphize(constant.const_);
440+
debug!(?constant, ?location, ?const_, "visit_constant");
441+
let val = match const_ {
442+
Const::Val(const_val, _) => const_val,
443+
Const::Ty(ct) => match ct.kind() {
444444
ConstKind::Value(v) => self.tcx.valtree_to_const_val((ct.ty(), v)),
445445
ConstKind::Unevaluated(_) => unreachable!(),
446446
// Nothing to do
@@ -454,7 +454,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MonoItemsFnCollector<'a, 'tcx> {
454454
unreachable!("Unexpected constant type {:?} ({:?})", ct, ct.kind())
455455
}
456456
},
457-
ConstantKind::Unevaluated(un_eval, _) => {
457+
Const::Unevaluated(un_eval, _) => {
458458
// Thread local fall into this category.
459459
match self.tcx.const_eval_resolve(ParamEnv::reveal_all(), un_eval, None) {
460460
// The `monomorphize` call should have evaluated that constant already.
@@ -473,8 +473,8 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MonoItemsFnCollector<'a, 'tcx> {
473473
span_bug!(
474474
span,
475475
"Unexpected polymorphic constant: {:?} {:?}",
476-
literal,
477-
constant.literal
476+
const_,
477+
constant.const_
478478
)
479479
}
480480
}

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
1414
use rustc_hir::{def_id::DefId, definitions::DefPathHash};
1515
use rustc_index::IndexVec;
1616
use rustc_middle::mir::{
17-
interpret::ConstValue, visit::MutVisitor, Body, ConstantKind, Local, LocalDecl, Location,
18-
Operand,
17+
visit::MutVisitor, Body, Const, ConstValue, Local, LocalDecl, Location, Operand,
1918
};
2019
use rustc_middle::ty::{self, TyCtxt};
2120

@@ -79,7 +78,7 @@ impl<'tcx> MutVisitor<'tcx> for ForeignFunctionTransformer<'tcx> {
7978
let Operand::Constant(function_definition) = operand else {
8079
return;
8180
};
82-
function_definition.literal = ConstantKind::from_value(
81+
function_definition.const_ = Const::from_value(
8382
ConstValue::ZeroSized,
8483
self.tcx.type_of(stub).instantiate(self.tcx, arguments),
8584
);

rust-toolchain.toml

Lines changed: 1 addition & 1 deletion
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-2023-09-19"
5+
channel = "nightly-2023-09-23"
66
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]

0 commit comments

Comments
 (0)