Skip to content

Commit 91a608d

Browse files
authored
Update Kani to Rust nightly-2022-10-11 (rust-lang#1788)
1 parent 06130c7 commit 91a608d

File tree

13 files changed

+82
-56
lines changed

13 files changed

+82
-56
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,11 @@ impl<'tcx> GotocCtx<'tcx> {
404404
}};
405405
}
406406

407-
if let Some(stripped) = intrinsic.strip_prefix("simd_shuffle") {
408-
let _n: u64 = stripped.parse().unwrap();
407+
if let Some(_stripped) = intrinsic.strip_prefix("simd_shuffle") {
408+
// TODO: can be empty now (i.e. `simd_shuffle` instead of `simd_shuffle8`)
409+
// `parse` fails on empty, so comment that bit of code out.
410+
// To re-enable this we'll need to investigate how size is computed now.
411+
// let n: u64 = stripped.parse().unwrap();
409412
return unstable_codegen!(self.codegen_intrinsic_simd_shuffle(
410413
fargs,
411414
p,

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

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_ast::ast::Mutability;
99
use rustc_middle::mir::interpret::{
1010
read_target_uint, AllocId, Allocation, ConstValue, GlobalAlloc, Scalar,
1111
};
12-
use rustc_middle::mir::{Constant, ConstantKind, Operand};
12+
use rustc_middle::mir::{Constant, ConstantKind, Operand, UnevaluatedConst};
1313
use rustc_middle::ty::layout::LayoutOf;
1414
use rustc_middle::ty::{self, Const, ConstKind, FloatTy, Instance, IntTy, Ty, Uint, UintTy};
1515
use rustc_span::def_id::DefId;
@@ -47,28 +47,37 @@ impl<'tcx> GotocCtx<'tcx> {
4747

4848
fn codegen_constant(&mut self, c: &Constant<'tcx>) -> Expr {
4949
trace!(constant=?c, "codegen_constant");
50-
let const_ = match self.monomorphize(c.literal) {
51-
ConstantKind::Ty(ct) => ct,
52-
ConstantKind::Val(val, ty) => return self.codegen_const_value(val, ty, Some(&c.span)),
53-
};
50+
let span = Some(&c.span);
51+
match self.monomorphize(c.literal) {
52+
ConstantKind::Ty(ct) => self.codegen_const(ct, span),
53+
ConstantKind::Val(val, ty) => self.codegen_const_value(val, ty, span),
54+
ConstantKind::Unevaluated(unevaluated, ty) => {
55+
self.codegen_const_unevaluated(unevaluated, ty, span)
56+
}
57+
}
58+
}
5459

55-
self.codegen_const(const_, Some(&c.span))
60+
fn codegen_const_unevaluated(
61+
&mut self,
62+
unevaluated: UnevaluatedConst<'tcx>,
63+
ty: Ty<'tcx>,
64+
span: Option<&Span>,
65+
) -> Expr {
66+
debug!(?unevaluated, "codegen_const_unevaluated");
67+
let const_val =
68+
self.tcx.const_eval_resolve(ty::ParamEnv::reveal_all(), unevaluated, None).unwrap();
69+
self.codegen_const_value(const_val, ty, span)
5670
}
5771

5872
pub fn codegen_const(&mut self, lit: Const<'tcx>, span: Option<&Span>) -> Expr {
5973
debug!("found literal: {:?}", lit);
6074
let lit = self.monomorphize(lit);
6175

6276
match lit.kind() {
63-
// evaluate constant if it has no been evaluated yet
64-
ConstKind::Unevaluated(unevaluated) => {
65-
debug!("The literal was a Unevaluated");
66-
let const_val = self
67-
.tcx
68-
.const_eval_resolve(ty::ParamEnv::reveal_all(), unevaluated, None)
69-
.unwrap();
70-
self.codegen_const_value(const_val, lit.ty(), span)
71-
}
77+
// A `ConstantKind::Ty(ConstKind::Unevaluated)` should no longer show up
78+
// and should be a `ConstantKind::Unevaluated` instead (and thus handled
79+
// at the level of `codegen_constant` instead of `codegen_const`.)
80+
ConstKind::Unevaluated(_) => unreachable!(),
7281

7382
ConstKind::Value(valtree) => {
7483
let value = self.tcx.valtree_to_const_val((lit.ty(), valtree));

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,13 @@ impl<'tcx> GotocCtx<'tcx> {
547547
self,
548548
)
549549
}
550+
ProjectionElem::OpaqueCast(ty) => ProjectedPlace::try_new(
551+
before.goto_expr.cast_to(self.codegen_ty(ty)),
552+
TypeOrVariant::Type(ty),
553+
before.fat_ptr_goto_expr,
554+
before.fat_ptr_mir_typ,
555+
self,
556+
),
550557
}
551558
}
552559

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,12 @@ impl<'tcx> GotocCtx<'tcx> {
402402
// Rust has begun distinguishing "ptr -> num" and "num -> ptr" (providence-relevant casts) but we do not yet:
403403
// Should we? Tracking ticket: https://github.com/model-checking/kani/issues/1274
404404
Rvalue::Cast(
405-
CastKind::Misc
405+
CastKind::IntToInt
406+
| CastKind::FloatToFloat
407+
| CastKind::FloatToInt
408+
| CastKind::IntToFloat
409+
| CastKind::FnPtrToPtr
410+
| CastKind::PtrToPtr
406411
| CastKind::PointerExposeAddress
407412
| CastKind::PointerFromExposedAddress,
408413
e,
@@ -411,6 +416,15 @@ impl<'tcx> GotocCtx<'tcx> {
411416
let t = self.monomorphize(*t);
412417
self.codegen_misc_cast(e, t)
413418
}
419+
Rvalue::Cast(CastKind::DynStar, _, _) => {
420+
let ty = self.codegen_ty(res_ty);
421+
self.codegen_unimplemented_expr(
422+
"CastKind::DynStar",
423+
ty,
424+
loc,
425+
"https://github.com/model-checking/kani/issues/1784",
426+
)
427+
}
414428
Rvalue::Cast(CastKind::Pointer(k), e, t) => {
415429
let t = self.monomorphize(*t);
416430
self.codegen_pointer_cast(k, e, t, loc)
@@ -636,7 +650,7 @@ impl<'tcx> GotocCtx<'tcx> {
636650
// this is a noop in the case dst_subt is a Projection or Opaque type
637651
dst_subt = self.tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), dst_subt);
638652
match dst_subt.kind() {
639-
ty::Slice(_) | ty::Str | ty::Dynamic(_, _) => {
653+
ty::Slice(_) | ty::Str | ty::Dynamic(_, _, _) => {
640654
//TODO: this does the wrong thing on Strings/fixme_boxed_str.rs
641655
// if we cast to slice or string, then we know the source is also a slice or string,
642656
// so there shouldn't be anything to do

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ impl<'tcx> GotocCtx<'tcx> {
555555
/// We follow the order from the `TyCtxt::COMMON_VTABLE_ENTRIES`.
556556
fn trait_vtable_field_types(&mut self, t: ty::Ty<'tcx>) -> Vec<DatatypeComponent> {
557557
let mut vtable_base = common_vtable_fields(self.trait_vtable_drop_type(t));
558-
if let ty::Dynamic(binder, _region) = t.kind() {
558+
if let ty::Dynamic(binder, _, _) = t.kind() {
559559
// The virtual methods on the trait ref. Some auto traits have no methods.
560560
if let Some(principal) = binder.principal() {
561561
let poly = principal.with_self_ty(self.tcx, t);
@@ -710,7 +710,7 @@ impl<'tcx> GotocCtx<'tcx> {
710710
/// codegen for types. it finds a C type which corresponds to a rust type.
711711
/// that means [ty] has to be monomorphized before calling this function.
712712
///
713-
/// check [rustc_middle::ty::layout::LayoutCx::layout_of_uncached] for LLVM codegen
713+
/// check `rustc_ty_utils::layout::layout_of_uncached` for LLVM codegen
714714
///
715715
/// also c.f. <https://www.ralfj.de/blog/2020/04/04/layout-debugging.html>
716716
/// c.f. <https://rust-lang.github.io/unsafe-code-guidelines/introduction.html>

kani-compiler/src/codegen_cprover_gotoc/reachability.rs

Lines changed: 19 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ use rustc_middle::ty::adjustment::CustomCoerceUnsized;
2929
use rustc_middle::ty::adjustment::PointerCast;
3030
use rustc_middle::ty::TypeAndMut;
3131
use rustc_middle::ty::{
32-
self, Closure, ClosureKind, Const, ConstKind, Instance, InstanceDef, ParamEnv, TraitRef, Ty,
33-
TyCtxt, TyKind, TypeFoldable, VtblEntry,
32+
self, Closure, ClosureKind, ConstKind, Instance, InstanceDef, ParamEnv, TraitRef, Ty, TyCtxt,
33+
TyKind, TypeFoldable, VtblEntry,
3434
};
3535
use rustc_span::def_id::DefId;
3636
use tracing::{debug, debug_span, trace, warn};
@@ -337,22 +337,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MonoItemsFnCollector<'a, 'tcx> {
337337
ConstantKind::Val(const_val, _) => const_val,
338338
ConstantKind::Ty(ct) => match ct.kind() {
339339
ConstKind::Value(v) => self.tcx.valtree_to_const_val((ct.ty(), v)),
340-
ConstKind::Unevaluated(un_eval) => {
341-
// Thread local fall into this category.
342-
match self.tcx.const_eval_resolve(ParamEnv::reveal_all(), un_eval, None) {
343-
// The `monomorphize` call should have evaluated that constant already.
344-
Ok(const_val) => const_val,
345-
Err(ErrorHandled::TooGeneric) => span_bug!(
346-
self.body.source_info(location).span,
347-
"Unexpected polymorphic constant: {:?}",
348-
literal
349-
),
350-
Err(error) => {
351-
warn!(?error, "Error already reported");
352-
return;
353-
}
354-
}
355-
}
340+
ConstKind::Unevaluated(_) => unreachable!(),
356341
// Nothing to do
357342
ConstKind::Param(..) | ConstKind::Infer(..) | ConstKind::Error(..) => return,
358343

@@ -361,15 +346,26 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MonoItemsFnCollector<'a, 'tcx> {
361346
unreachable!("Unexpected constant type {:?} ({:?})", ct, ct.kind())
362347
}
363348
},
349+
ConstantKind::Unevaluated(un_eval, _) => {
350+
// Thread local fall into this category.
351+
match self.tcx.const_eval_resolve(ParamEnv::reveal_all(), un_eval, None) {
352+
// The `monomorphize` call should have evaluated that constant already.
353+
Ok(const_val) => const_val,
354+
Err(ErrorHandled::TooGeneric) => span_bug!(
355+
self.body.source_info(location).span,
356+
"Unexpected polymorphic constant: {:?}",
357+
literal
358+
),
359+
Err(error) => {
360+
warn!(?error, "Error already reported");
361+
return;
362+
}
363+
}
364+
}
364365
};
365366
self.collect_const_value(val);
366367
}
367368

368-
fn visit_const(&mut self, constant: Const<'tcx>, location: Location) {
369-
trace!(?constant, ?location, "visit_const");
370-
self.super_const(constant);
371-
}
372-
373369
/// Collect function calls.
374370
fn visit_terminator(&mut self, terminator: &Terminator<'tcx>, location: Location) {
375371
trace!(?terminator, ?location, "visit_terminator");

kani_metadata/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ use serde::{Deserialize, Serialize};
1212
/// The structure of `.kani-metadata.json` files, which are emitted for each crate
1313
#[derive(Debug, Clone, Serialize, Deserialize)]
1414
pub struct KaniMetadata {
15-
/// The proof harnesses (#[kani::proof]) found in this crate.
15+
/// The proof harnesses (`#[kani::proof]`) found in this crate.
1616
pub proof_harnesses: Vec<HarnessMetadata>,
1717
/// The features found in this crate that Kani does not support.
1818
/// (These general translate to `assert(false)` so we can still attempt verification.)

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-2022-09-13"
5+
channel = "nightly-2022-10-11"
66
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]

tests/kani/Intrinsics/Assert/uninit_valid_panic.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
#![feature(core_intrinsics)]
66
use std::intrinsics;
77

8-
// The code below attempts to leave type `bool` uninitialized, causing the
8+
// The code below attempts to leave type `&u32` uninitialized, causing the
99
// intrinsic `assert_uninit_valid` to generate a panic during compilation.
1010
#[kani::proof]
1111
fn main() {
1212
let _var: () = unsafe {
13-
intrinsics::assert_uninit_valid::<bool>();
13+
intrinsics::assert_uninit_valid::<&u32>();
1414
};
1515
}

tests/kani/ProjectionElem/OpaqueCast/check_opaque_cast.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,6 @@
22
//
33
// Modifications Copyright Kani Contributors
44
// See GitHub history for details.
5-
//
6-
// NOTE: The initial fix for this has been reverted from rustc. I'm keeping this test here so we
7-
// will know when it has been reverted back.
8-
// kani-check-fail
95

106
//! Tests that check handling of opaque casts. Tests were adapted from the rustc repository.
117

tests/ui/code-location/expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module/mod.rs:10:5 in function module::not_empty
22
main.rs:13:5 in function same_file
33
/toolchains/
4-
alloc/src/vec/mod.rs:2921:81 in function <std::vec::Vec<i32> as std::ops::Drop>::drop
4+
alloc/src/vec/mod.rs:3031:81 in function <std::vec::Vec<i32> as std::ops::Drop>::drop
55

66
VERIFICATION:- SUCCESSFUL

tools/bookrunner/librustdoc/lib.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#![feature(box_patterns)]
1313
#![feature(control_flow_enum)]
1414
#![feature(box_syntax)]
15-
#![feature(let_else)]
1615
#![feature(test)]
1716
#![feature(never_type)]
1817
#![feature(once_cell)]
@@ -62,7 +61,6 @@ extern crate rustc_session;
6261
extern crate rustc_span;
6362
extern crate rustc_target;
6463
extern crate rustc_trait_selection;
65-
extern crate rustc_typeck;
6664
extern crate test;
6765

6866
pub mod doctest;

tools/compiletest/src/main.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -511,5 +511,8 @@ fn make_test_closure(
511511
let config = config.clone();
512512
let testpaths = testpaths.clone();
513513
let revision = revision.cloned();
514-
test::DynTestFn(Box::new(move || runtest::run(config, &testpaths, revision.as_deref())))
514+
test::DynTestFn(Box::new(move || {
515+
runtest::run(config, &testpaths, revision.as_deref());
516+
Ok(())
517+
}))
515518
}

0 commit comments

Comments
 (0)