diff --git a/kani-compiler/src/codegen_cprover_gotoc/archive.rs b/kani-compiler/src/codegen_cprover_gotoc/archive.rs index 2bf3e2c8380c..3909ca1135b2 100644 --- a/kani-compiler/src/codegen_cprover_gotoc/archive.rs +++ b/kani-compiler/src/codegen_cprover_gotoc/archive.rs @@ -59,8 +59,7 @@ impl<'a> ArchiveBuilder<'a> { let entries = self.entries.iter().map(|(entry_name, file)| { let data = std::fs::read(file).unwrap_or_else(|err| { sess.fatal(&format!( - "error while reading object file during archive building: {}", - err + "error while reading object file during archive building: {err}" )); }); (entry_name, data) diff --git a/kani-compiler/src/codegen_cprover_gotoc/codegen/statement.rs b/kani-compiler/src/codegen_cprover_gotoc/codegen/statement.rs index ab8d250dbe73..75ee1a0e65f7 100644 --- a/kani-compiler/src/codegen_cprover_gotoc/codegen/statement.rs +++ b/kani-compiler/src/codegen_cprover_gotoc/codegen/statement.rs @@ -164,8 +164,8 @@ impl<'tcx> GotocCtx<'tcx> { TerminatorKind::Goto { target } => { Stmt::goto(self.current_fn().find_label(target), loc) } - TerminatorKind::SwitchInt { discr, switch_ty, targets } => { - self.codegen_switch_int(discr, *switch_ty, targets, loc) + TerminatorKind::SwitchInt { discr, targets } => { + self.codegen_switch_int(discr, targets, loc) } // The following two use `codegen_mimic_unimplemented` // because we don't want to raise the warning during compilation. @@ -365,23 +365,21 @@ impl<'tcx> GotocCtx<'tcx> { fn codegen_switch_int( &mut self, discr: &Operand<'tcx>, - switch_ty: Ty<'tcx>, targets: &SwitchTargets, loc: Location, ) -> Stmt { let v = self.codegen_operand(discr); - let switch_ty = self.monomorphize(switch_ty); + let switch_ty = v.typ().clone(); if targets.all_targets().len() == 1 { // Translate to a guarded goto let first_target = targets.iter().next().unwrap(); Stmt::block( vec![ - v.eq(Expr::int_constant(first_target.0, self.codegen_ty(switch_ty))) - .if_then_else( - Stmt::goto(self.current_fn().find_label(&first_target.1), loc), - None, - loc, - ), + v.eq(Expr::int_constant(first_target.0, switch_ty)).if_then_else( + Stmt::goto(self.current_fn().find_label(&first_target.1), loc), + None, + loc, + ), Stmt::goto(self.current_fn().find_label(&targets.otherwise()), loc), ], loc, @@ -392,7 +390,7 @@ impl<'tcx> GotocCtx<'tcx> { let cases = targets .iter() .map(|(c, bb)| { - Expr::int_constant(c, self.codegen_ty(switch_ty)) + Expr::int_constant(c, switch_ty.clone()) .switch_case(Stmt::goto(self.current_fn().find_label(&bb), loc)) }) .collect(); diff --git a/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs b/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs index fcf4d935b7c5..f315e1795fa9 100644 --- a/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs +++ b/kani-compiler/src/codegen_cprover_gotoc/codegen/typ.rs @@ -20,7 +20,7 @@ use rustc_middle::ty::{ use rustc_middle::ty::{List, TypeFoldable}; use rustc_span::def_id::DefId; use rustc_target::abi::{ - Abi::Vector, FieldsShape, Integer, Layout, Primitive, Size, TagEncoding, TyAndLayout, + Abi::Vector, FieldsShape, Integer, LayoutS, Primitive, Size, TagEncoding, TyAndLayout, VariantIdx, Variants, }; use rustc_target::spec::abi::Abi; @@ -327,10 +327,12 @@ impl<'tcx> GotocCtx<'tcx> { self.sig_with_untupled_args(sig) } - // Adapted from `fn_sig_for_fn_abi` in compiler/rustc_middle/src/ty/layout.rs + // Adapted from `fn_sig_for_fn_abi` in + // https://github.com/rust-lang/rust/blob/739d68a76e35b22341d9930bb6338bf202ba05ba/compiler/rustc_ty_utils/src/abi.rs#L88 // Code duplication tracked here: https://github.com/model-checking/kani/issues/1365 fn generator_sig( &self, + did: &DefId, ty: Ty<'tcx>, substs: ty::subst::SubstsRef<'tcx>, ) -> ty::PolyFnSig<'tcx> { @@ -352,10 +354,21 @@ impl<'tcx> GotocCtx<'tcx> { let env_ty = self.tcx.mk_adt(pin_adt_ref, pin_substs); let sig = sig.skip_binder(); - let state_did = self.tcx.require_lang_item(LangItem::GeneratorState, None); - let state_adt_ref = self.tcx.adt_def(state_did); - let state_substs = self.tcx.intern_substs(&[sig.yield_ty.into(), sig.return_ty.into()]); - let ret_ty = self.tcx.mk_adt(state_adt_ref, state_substs); + // The `FnSig` and the `ret_ty` here is for a generators main + // `Generator::resume(...) -> GeneratorState` function in case we + // have an ordinary generator, or the `Future::poll(...) -> Poll` + // function in case this is a special generator backing an async construct. + let ret_ty = if self.tcx.generator_is_async(*did) { + let state_did = self.tcx.require_lang_item(LangItem::Poll, None); + let state_adt_ref = self.tcx.adt_def(state_did); + let state_substs = self.tcx.intern_substs(&[sig.return_ty.into()]); + self.tcx.mk_adt(state_adt_ref, state_substs) + } else { + let state_did = self.tcx.require_lang_item(LangItem::GeneratorState, None); + let state_adt_ref = self.tcx.adt_def(state_did); + let state_substs = self.tcx.intern_substs(&[sig.yield_ty.into(), sig.return_ty.into()]); + self.tcx.mk_adt(state_adt_ref, state_substs) + }; ty::Binder::bind_with_vars( self.tcx.mk_fn_sig( [env_ty, sig.resume_ty].iter(), @@ -380,7 +393,7 @@ impl<'tcx> GotocCtx<'tcx> { } sig } - ty::Generator(_, substs, _) => self.generator_sig(fntyp, substs), + ty::Generator(did, substs, _) => self.generator_sig(did, fntyp, substs), _ => unreachable!("Can't get function signature of type: {:?}", fntyp), }) } @@ -865,10 +878,10 @@ impl<'tcx> GotocCtx<'tcx> { fn codegen_alignment_padding( &self, size: Size, - layout: &Layout, + layout: &LayoutS, idx: usize, ) -> Option { - let align = Size::from_bits(layout.align().abi.bits()); + let align = Size::from_bits(layout.align.abi.bits()); let overhang = Size::from_bits(size.bits() % align.bits()); if overhang != Size::ZERO { self.codegen_struct_padding(size, size + align - overhang, idx) @@ -890,16 +903,16 @@ impl<'tcx> GotocCtx<'tcx> { fn codegen_struct_fields( &mut self, flds: Vec<(String, Ty<'tcx>)>, - layout: &Layout, + layout: &LayoutS, initial_offset: Size, ) -> Vec { - match &layout.fields() { + match &layout.fields { FieldsShape::Arbitrary { offsets, memory_index } => { assert_eq!(flds.len(), offsets.len()); assert_eq!(offsets.len(), memory_index.len()); let mut final_fields = Vec::with_capacity(flds.len()); let mut offset = initial_offset; - for idx in layout.fields().index_by_increasing_offset() { + for idx in layout.fields.index_by_increasing_offset() { let fld_offset = offsets[idx]; let (fld_name, fld_ty) = &flds[idx]; if let Some(padding) = @@ -922,7 +935,7 @@ impl<'tcx> GotocCtx<'tcx> { } // Primitives, such as NEVER, have no fields FieldsShape::Primitive => vec![], - _ => unreachable!("{}\n{:?}", self.current_fn().readable_name(), layout.fields()), + _ => unreachable!("{}\n{:?}", self.current_fn().readable_name(), layout.fields), } } @@ -931,7 +944,7 @@ impl<'tcx> GotocCtx<'tcx> { let flds: Vec<_> = tys.iter().enumerate().map(|(i, t)| (GotocCtx::tuple_fld_name(i), *t)).collect(); // tuple cannot have other initial offset - self.codegen_struct_fields(flds, &layout.layout, Size::ZERO) + self.codegen_struct_fields(flds, &layout.layout.0, Size::ZERO) } /// A closure / some shims in Rust MIR takes two arguments: @@ -1136,7 +1149,7 @@ impl<'tcx> GotocCtx<'tcx> { } fields.extend(ctx.codegen_alignment_padding( offset, - &type_and_layout.layout, + &type_and_layout.layout.0, fields.len(), )); fields @@ -1338,7 +1351,7 @@ impl<'tcx> GotocCtx<'tcx> { self.ensure_struct(self.ty_mangled_name(ty), self.ty_pretty_name(ty), |ctx, _| { let variant = &def.variants().raw[0]; let layout = ctx.layout_of(ty); - ctx.codegen_variant_struct_fields(variant, subst, &layout.layout, Size::ZERO) + ctx.codegen_variant_struct_fields(variant, subst, &layout.layout.0, Size::ZERO) }) } @@ -1347,7 +1360,7 @@ impl<'tcx> GotocCtx<'tcx> { &mut self, variant: &VariantDef, subst: &'tcx InternalSubsts<'tcx>, - layout: &Layout, + layout: &LayoutS, initial_offset: Size, ) -> Vec { let flds: Vec<_> = @@ -1430,7 +1443,7 @@ impl<'tcx> GotocCtx<'tcx> { Some(variant) => { // a single enum is pretty much like a struct let layout = gcx.layout_of(ty).layout; - gcx.codegen_variant_struct_fields(variant, subst, &layout, Size::ZERO) + gcx.codegen_variant_struct_fields(variant, subst, &layout.0, Size::ZERO) } } }) @@ -1516,9 +1529,9 @@ impl<'tcx> GotocCtx<'tcx> { ty: Ty<'tcx>, adtdef: &'tcx AdtDef, subst: &'tcx InternalSubsts<'tcx>, - variants: &IndexVec, + variants: &IndexVec>, ) -> Type { - let non_zst_count = variants.iter().filter(|layout| layout.size().bytes() > 0).count(); + let non_zst_count = variants.iter().filter(|layout| layout.size.bytes() > 0).count(); let mangled_name = self.ty_mangled_name(ty); let pretty_name = self.ty_pretty_name(ty); tracing::trace!(?pretty_name, ?variants, ?subst, ?non_zst_count, "codegen_enum: Niche"); @@ -1535,12 +1548,12 @@ impl<'tcx> GotocCtx<'tcx> { pub(crate) fn variant_min_offset( &self, - variants: &IndexVec, + variants: &IndexVec>, ) -> Option { variants .iter() .filter_map(|lo| { - if lo.fields().count() == 0 { + if lo.fields.count() == 0 { None } else { // get the offset of the leftmost field, which is the one @@ -1548,10 +1561,7 @@ impl<'tcx> GotocCtx<'tcx> { // in the order of increasing offsets. Note that this is not // necessarily the 0th field since the compiler may reorder // fields. - Some( - lo.fields() - .offset(lo.fields().index_by_increasing_offset().next().unwrap()), - ) + Some(lo.fields.offset(lo.fields.index_by_increasing_offset().next().unwrap())) } }) .min() @@ -1622,7 +1632,7 @@ impl<'tcx> GotocCtx<'tcx> { pretty_name: InternedString, def: &'tcx AdtDef, subst: &'tcx InternalSubsts<'tcx>, - layouts: &IndexVec, + layouts: &IndexVec>, initial_offset: Size, ) -> Vec { def.variants() @@ -1654,7 +1664,7 @@ impl<'tcx> GotocCtx<'tcx> { pretty_name: InternedString, case: &VariantDef, subst: &'tcx InternalSubsts<'tcx>, - variant: &Layout, + variant: &LayoutS, initial_offset: Size, ) -> Type { let case_name = format!("{name}::{}", case.name); diff --git a/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs b/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs index 4d91eecf7a01..406a92e587ea 100644 --- a/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs +++ b/kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs @@ -229,7 +229,7 @@ impl CodegenBackend for GotocCodegenBackend { sess, CrateType::Rlib, outputs, - codegen_results.crate_info.local_crate_name.as_str(), + codegen_results.crate_info.local_crate_name, ); builder.build(&rlib); Ok(()) diff --git a/kani-compiler/src/kani_middle/attributes.rs b/kani-compiler/src/kani_middle/attributes.rs index b850b590a344..45748b873753 100644 --- a/kani-compiler/src/kani_middle/attributes.rs +++ b/kani-compiler/src/kani_middle/attributes.rs @@ -33,7 +33,7 @@ pub fn extract_integer_argument(attr: &Attribute) -> Option { let attr_args = attr.meta_item_list()?; // Only extracts one integer value as argument if attr_args.len() == 1 { - let x = attr_args[0].literal()?; + let x = attr_args[0].lit()?; match x.kind { LitKind::Int(y, ..) => Some(y), _ => None, diff --git a/kani-compiler/src/kani_middle/coercion.rs b/kani-compiler/src/kani_middle/coercion.rs index a92c2f366ae9..799ba3b4766c 100644 --- a/kani-compiler/src/kani_middle/coercion.rs +++ b/kani-compiler/src/kani_middle/coercion.rs @@ -215,7 +215,7 @@ fn custom_coerce_unsize_info<'tcx>( let trait_ref = ty::Binder::dummy(TraitRef { def_id, - substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]), + substs: tcx.mk_substs_trait(source_ty, [target_ty.into()]), }); match tcx.codegen_select_candidate((ParamEnv::reveal_all(), trait_ref)) { diff --git a/kani-compiler/src/kani_middle/reachability.rs b/kani-compiler/src/kani_middle/reachability.rs index 4a035d3be223..7845f4bab4ca 100644 --- a/kani-compiler/src/kani_middle/reachability.rs +++ b/kani-compiler/src/kani_middle/reachability.rs @@ -402,7 +402,10 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MonoItemsFnCollector<'a, 'tcx> { ConstKind::Value(v) => self.tcx.valtree_to_const_val((ct.ty(), v)), ConstKind::Unevaluated(_) => unreachable!(), // Nothing to do - ConstKind::Param(..) | ConstKind::Infer(..) | ConstKind::Error(..) => return, + ConstKind::Param(..) + | ConstKind::Infer(..) + | ConstKind::Error(..) + | ConstKind::Expr(..) => return, // Shouldn't happen ConstKind::Placeholder(..) | ConstKind::Bound(..) => { diff --git a/kani-compiler/src/kani_middle/resolve.rs b/kani-compiler/src/kani_middle/resolve.rs index ab76fbcc16df..514a73510031 100644 --- a/kani-compiler/src/kani_middle/resolve.rs +++ b/kani-compiler/src/kani_middle/resolve.rs @@ -305,8 +305,8 @@ fn resolve_in_module(tcx: TyCtxt, current_module: DefId, segments: Segments) -> } /// Resolves a path by exploring a non-glob use statement. -fn resolve_in_use(tcx: TyCtxt, use_path: &rustc_hir::Path, segments: Segments) -> Option { - if let Res::Def(def_kind, def_id) = use_path.res { +fn resolve_in_use(tcx: TyCtxt, use_path: &rustc_hir::UsePath, segments: Segments) -> Option { + if let Res::Def(def_kind, def_id) = use_path.res[0] { tracing::debug!( "Resolving `{}` via `use` import of `{}`", segments_to_string(&segments), @@ -340,7 +340,7 @@ fn resolve_in_use(tcx: TyCtxt, use_path: &rustc_hir::Path, segments: Segments) - fn resolve_in_glob_uses( tcx: TyCtxt, current_module: LocalDefId, - glob_imports: Vec<&rustc_hir::Path>, + glob_imports: Vec<&rustc_hir::UsePath>, segments: &Segments, ) -> Option { let glob_resolves = glob_imports @@ -377,10 +377,10 @@ fn resolve_in_glob_uses( /// Resolves a path by exploring a glob use statement. fn resolve_in_glob_use( tcx: TyCtxt, - use_path: &rustc_hir::Path, + use_path: &rustc_hir::UsePath, segments: Segments, ) -> Option { - if let Res::Def(DefKind::Mod, def_id) = use_path.res { + if let Res::Def(DefKind::Mod, def_id) = use_path.res[0] { resolve_in_module(tcx, def_id, segments) } else { None diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 0fb3d8fbb64a..aa6a41cddcbb 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -2,5 +2,5 @@ # SPDX-License-Identifier: Apache-2.0 OR MIT [toolchain] -channel = "nightly-2022-11-20" +channel = "nightly-2022-12-11" components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"] diff --git a/tests/kani/ConstEval/limit_fixme.rs b/tests/kani/ConstEval/limit.rs similarity index 100% rename from tests/kani/ConstEval/limit_fixme.rs rename to tests/kani/ConstEval/limit.rs diff --git a/tests/ui/code-location/expected b/tests/ui/code-location/expected index e7be32d314db..20d7f40879bc 100644 --- a/tests/ui/code-location/expected +++ b/tests/ui/code-location/expected @@ -1,6 +1,6 @@ module/mod.rs:10:5 in function module::not_empty main.rs:13:5 in function same_file /toolchains/ -alloc/src/vec/mod.rs:3029:81 in function as std::ops::Drop>::drop +alloc/src/vec/mod.rs:3054:81 in function as std::ops::Drop>::drop VERIFICATION:- SUCCESSFUL diff --git a/tools/compiletest/src/main.rs b/tools/compiletest/src/main.rs index 08953bdd69c5..eb268436c23f 100644 --- a/tools/compiletest/src/main.rs +++ b/tools/compiletest/src/main.rs @@ -285,6 +285,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts { list: false, options: test::Options::new(), time_options: None, + fail_fast: true, force_run_in_process: false, } } @@ -565,7 +566,7 @@ fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn { /// Print a message and error out without panicking fn fatal_error(message: &str) { - println!("error: {}", message); + println!("error: {message}"); // Use resume_unwind instead of panic!() to prevent a panic message + backtrace from // compiletest, which is unnecessary noise. std::panic::resume_unwind(Box::new(()));