Skip to content

Commit 47014e6

Browse files
Update rust toolchain to 2022-12-11 (rust-lang#2045)
Co-authored-by: Adrian Palacios <[email protected]>
1 parent b558eff commit 47014e6

File tree

12 files changed

+64
-53
lines changed

12 files changed

+64
-53
lines changed

kani-compiler/src/codegen_cprover_gotoc/archive.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ impl<'a> ArchiveBuilder<'a> {
5959
let entries = self.entries.iter().map(|(entry_name, file)| {
6060
let data = std::fs::read(file).unwrap_or_else(|err| {
6161
sess.fatal(&format!(
62-
"error while reading object file during archive building: {}",
63-
err
62+
"error while reading object file during archive building: {err}"
6463
));
6564
});
6665
(entry_name, data)

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

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,8 @@ impl<'tcx> GotocCtx<'tcx> {
164164
TerminatorKind::Goto { target } => {
165165
Stmt::goto(self.current_fn().find_label(target), loc)
166166
}
167-
TerminatorKind::SwitchInt { discr, switch_ty, targets } => {
168-
self.codegen_switch_int(discr, *switch_ty, targets, loc)
167+
TerminatorKind::SwitchInt { discr, targets } => {
168+
self.codegen_switch_int(discr, targets, loc)
169169
}
170170
// The following two use `codegen_mimic_unimplemented`
171171
// because we don't want to raise the warning during compilation.
@@ -365,23 +365,21 @@ impl<'tcx> GotocCtx<'tcx> {
365365
fn codegen_switch_int(
366366
&mut self,
367367
discr: &Operand<'tcx>,
368-
switch_ty: Ty<'tcx>,
369368
targets: &SwitchTargets,
370369
loc: Location,
371370
) -> Stmt {
372371
let v = self.codegen_operand(discr);
373-
let switch_ty = self.monomorphize(switch_ty);
372+
let switch_ty = v.typ().clone();
374373
if targets.all_targets().len() == 1 {
375374
// Translate to a guarded goto
376375
let first_target = targets.iter().next().unwrap();
377376
Stmt::block(
378377
vec![
379-
v.eq(Expr::int_constant(first_target.0, self.codegen_ty(switch_ty)))
380-
.if_then_else(
381-
Stmt::goto(self.current_fn().find_label(&first_target.1), loc),
382-
None,
383-
loc,
384-
),
378+
v.eq(Expr::int_constant(first_target.0, switch_ty)).if_then_else(
379+
Stmt::goto(self.current_fn().find_label(&first_target.1), loc),
380+
None,
381+
loc,
382+
),
385383
Stmt::goto(self.current_fn().find_label(&targets.otherwise()), loc),
386384
],
387385
loc,
@@ -392,7 +390,7 @@ impl<'tcx> GotocCtx<'tcx> {
392390
let cases = targets
393391
.iter()
394392
.map(|(c, bb)| {
395-
Expr::int_constant(c, self.codegen_ty(switch_ty))
393+
Expr::int_constant(c, switch_ty.clone())
396394
.switch_case(Stmt::goto(self.current_fn().find_label(&bb), loc))
397395
})
398396
.collect();

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

Lines changed: 38 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::ty::{
2020
use rustc_middle::ty::{List, TypeFoldable};
2121
use rustc_span::def_id::DefId;
2222
use rustc_target::abi::{
23-
Abi::Vector, FieldsShape, Integer, Layout, Primitive, Size, TagEncoding, TyAndLayout,
23+
Abi::Vector, FieldsShape, Integer, LayoutS, Primitive, Size, TagEncoding, TyAndLayout,
2424
VariantIdx, Variants,
2525
};
2626
use rustc_target::spec::abi::Abi;
@@ -327,10 +327,12 @@ impl<'tcx> GotocCtx<'tcx> {
327327
self.sig_with_untupled_args(sig)
328328
}
329329

330-
// Adapted from `fn_sig_for_fn_abi` in compiler/rustc_middle/src/ty/layout.rs
330+
// Adapted from `fn_sig_for_fn_abi` in
331+
// https://github.com/rust-lang/rust/blob/739d68a76e35b22341d9930bb6338bf202ba05ba/compiler/rustc_ty_utils/src/abi.rs#L88
331332
// Code duplication tracked here: https://github.com/model-checking/kani/issues/1365
332333
fn generator_sig(
333334
&self,
335+
did: &DefId,
334336
ty: Ty<'tcx>,
335337
substs: ty::subst::SubstsRef<'tcx>,
336338
) -> ty::PolyFnSig<'tcx> {
@@ -352,10 +354,21 @@ impl<'tcx> GotocCtx<'tcx> {
352354
let env_ty = self.tcx.mk_adt(pin_adt_ref, pin_substs);
353355

354356
let sig = sig.skip_binder();
355-
let state_did = self.tcx.require_lang_item(LangItem::GeneratorState, None);
356-
let state_adt_ref = self.tcx.adt_def(state_did);
357-
let state_substs = self.tcx.intern_substs(&[sig.yield_ty.into(), sig.return_ty.into()]);
358-
let ret_ty = self.tcx.mk_adt(state_adt_ref, state_substs);
357+
// The `FnSig` and the `ret_ty` here is for a generators main
358+
// `Generator::resume(...) -> GeneratorState` function in case we
359+
// have an ordinary generator, or the `Future::poll(...) -> Poll`
360+
// function in case this is a special generator backing an async construct.
361+
let ret_ty = if self.tcx.generator_is_async(*did) {
362+
let state_did = self.tcx.require_lang_item(LangItem::Poll, None);
363+
let state_adt_ref = self.tcx.adt_def(state_did);
364+
let state_substs = self.tcx.intern_substs(&[sig.return_ty.into()]);
365+
self.tcx.mk_adt(state_adt_ref, state_substs)
366+
} else {
367+
let state_did = self.tcx.require_lang_item(LangItem::GeneratorState, None);
368+
let state_adt_ref = self.tcx.adt_def(state_did);
369+
let state_substs = self.tcx.intern_substs(&[sig.yield_ty.into(), sig.return_ty.into()]);
370+
self.tcx.mk_adt(state_adt_ref, state_substs)
371+
};
359372
ty::Binder::bind_with_vars(
360373
self.tcx.mk_fn_sig(
361374
[env_ty, sig.resume_ty].iter(),
@@ -380,7 +393,7 @@ impl<'tcx> GotocCtx<'tcx> {
380393
}
381394
sig
382395
}
383-
ty::Generator(_, substs, _) => self.generator_sig(fntyp, substs),
396+
ty::Generator(did, substs, _) => self.generator_sig(did, fntyp, substs),
384397
_ => unreachable!("Can't get function signature of type: {:?}", fntyp),
385398
})
386399
}
@@ -865,10 +878,10 @@ impl<'tcx> GotocCtx<'tcx> {
865878
fn codegen_alignment_padding(
866879
&self,
867880
size: Size,
868-
layout: &Layout,
881+
layout: &LayoutS<VariantIdx>,
869882
idx: usize,
870883
) -> Option<DatatypeComponent> {
871-
let align = Size::from_bits(layout.align().abi.bits());
884+
let align = Size::from_bits(layout.align.abi.bits());
872885
let overhang = Size::from_bits(size.bits() % align.bits());
873886
if overhang != Size::ZERO {
874887
self.codegen_struct_padding(size, size + align - overhang, idx)
@@ -890,16 +903,16 @@ impl<'tcx> GotocCtx<'tcx> {
890903
fn codegen_struct_fields(
891904
&mut self,
892905
flds: Vec<(String, Ty<'tcx>)>,
893-
layout: &Layout,
906+
layout: &LayoutS<VariantIdx>,
894907
initial_offset: Size,
895908
) -> Vec<DatatypeComponent> {
896-
match &layout.fields() {
909+
match &layout.fields {
897910
FieldsShape::Arbitrary { offsets, memory_index } => {
898911
assert_eq!(flds.len(), offsets.len());
899912
assert_eq!(offsets.len(), memory_index.len());
900913
let mut final_fields = Vec::with_capacity(flds.len());
901914
let mut offset = initial_offset;
902-
for idx in layout.fields().index_by_increasing_offset() {
915+
for idx in layout.fields.index_by_increasing_offset() {
903916
let fld_offset = offsets[idx];
904917
let (fld_name, fld_ty) = &flds[idx];
905918
if let Some(padding) =
@@ -922,7 +935,7 @@ impl<'tcx> GotocCtx<'tcx> {
922935
}
923936
// Primitives, such as NEVER, have no fields
924937
FieldsShape::Primitive => vec![],
925-
_ => unreachable!("{}\n{:?}", self.current_fn().readable_name(), layout.fields()),
938+
_ => unreachable!("{}\n{:?}", self.current_fn().readable_name(), layout.fields),
926939
}
927940
}
928941

@@ -931,7 +944,7 @@ impl<'tcx> GotocCtx<'tcx> {
931944
let flds: Vec<_> =
932945
tys.iter().enumerate().map(|(i, t)| (GotocCtx::tuple_fld_name(i), *t)).collect();
933946
// tuple cannot have other initial offset
934-
self.codegen_struct_fields(flds, &layout.layout, Size::ZERO)
947+
self.codegen_struct_fields(flds, &layout.layout.0, Size::ZERO)
935948
}
936949

937950
/// A closure / some shims in Rust MIR takes two arguments:
@@ -1136,7 +1149,7 @@ impl<'tcx> GotocCtx<'tcx> {
11361149
}
11371150
fields.extend(ctx.codegen_alignment_padding(
11381151
offset,
1139-
&type_and_layout.layout,
1152+
&type_and_layout.layout.0,
11401153
fields.len(),
11411154
));
11421155
fields
@@ -1338,7 +1351,7 @@ impl<'tcx> GotocCtx<'tcx> {
13381351
self.ensure_struct(self.ty_mangled_name(ty), self.ty_pretty_name(ty), |ctx, _| {
13391352
let variant = &def.variants().raw[0];
13401353
let layout = ctx.layout_of(ty);
1341-
ctx.codegen_variant_struct_fields(variant, subst, &layout.layout, Size::ZERO)
1354+
ctx.codegen_variant_struct_fields(variant, subst, &layout.layout.0, Size::ZERO)
13421355
})
13431356
}
13441357

@@ -1347,7 +1360,7 @@ impl<'tcx> GotocCtx<'tcx> {
13471360
&mut self,
13481361
variant: &VariantDef,
13491362
subst: &'tcx InternalSubsts<'tcx>,
1350-
layout: &Layout,
1363+
layout: &LayoutS<VariantIdx>,
13511364
initial_offset: Size,
13521365
) -> Vec<DatatypeComponent> {
13531366
let flds: Vec<_> =
@@ -1430,7 +1443,7 @@ impl<'tcx> GotocCtx<'tcx> {
14301443
Some(variant) => {
14311444
// a single enum is pretty much like a struct
14321445
let layout = gcx.layout_of(ty).layout;
1433-
gcx.codegen_variant_struct_fields(variant, subst, &layout, Size::ZERO)
1446+
gcx.codegen_variant_struct_fields(variant, subst, &layout.0, Size::ZERO)
14341447
}
14351448
}
14361449
})
@@ -1516,9 +1529,9 @@ impl<'tcx> GotocCtx<'tcx> {
15161529
ty: Ty<'tcx>,
15171530
adtdef: &'tcx AdtDef,
15181531
subst: &'tcx InternalSubsts<'tcx>,
1519-
variants: &IndexVec<VariantIdx, Layout>,
1532+
variants: &IndexVec<VariantIdx, LayoutS<VariantIdx>>,
15201533
) -> Type {
1521-
let non_zst_count = variants.iter().filter(|layout| layout.size().bytes() > 0).count();
1534+
let non_zst_count = variants.iter().filter(|layout| layout.size.bytes() > 0).count();
15221535
let mangled_name = self.ty_mangled_name(ty);
15231536
let pretty_name = self.ty_pretty_name(ty);
15241537
tracing::trace!(?pretty_name, ?variants, ?subst, ?non_zst_count, "codegen_enum: Niche");
@@ -1535,23 +1548,20 @@ impl<'tcx> GotocCtx<'tcx> {
15351548

15361549
pub(crate) fn variant_min_offset(
15371550
&self,
1538-
variants: &IndexVec<VariantIdx, Layout>,
1551+
variants: &IndexVec<VariantIdx, LayoutS<VariantIdx>>,
15391552
) -> Option<Size> {
15401553
variants
15411554
.iter()
15421555
.filter_map(|lo| {
1543-
if lo.fields().count() == 0 {
1556+
if lo.fields.count() == 0 {
15441557
None
15451558
} else {
15461559
// get the offset of the leftmost field, which is the one
15471560
// with the least offset since we codegen fields in a struct
15481561
// in the order of increasing offsets. Note that this is not
15491562
// necessarily the 0th field since the compiler may reorder
15501563
// fields.
1551-
Some(
1552-
lo.fields()
1553-
.offset(lo.fields().index_by_increasing_offset().next().unwrap()),
1554-
)
1564+
Some(lo.fields.offset(lo.fields.index_by_increasing_offset().next().unwrap()))
15551565
}
15561566
})
15571567
.min()
@@ -1622,7 +1632,7 @@ impl<'tcx> GotocCtx<'tcx> {
16221632
pretty_name: InternedString,
16231633
def: &'tcx AdtDef,
16241634
subst: &'tcx InternalSubsts<'tcx>,
1625-
layouts: &IndexVec<VariantIdx, Layout>,
1635+
layouts: &IndexVec<VariantIdx, LayoutS<VariantIdx>>,
16261636
initial_offset: Size,
16271637
) -> Vec<DatatypeComponent> {
16281638
def.variants()
@@ -1654,7 +1664,7 @@ impl<'tcx> GotocCtx<'tcx> {
16541664
pretty_name: InternedString,
16551665
case: &VariantDef,
16561666
subst: &'tcx InternalSubsts<'tcx>,
1657-
variant: &Layout,
1667+
variant: &LayoutS<VariantIdx>,
16581668
initial_offset: Size,
16591669
) -> Type {
16601670
let case_name = format!("{name}::{}", case.name);

kani-compiler/src/codegen_cprover_gotoc/compiler_interface.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ impl CodegenBackend for GotocCodegenBackend {
229229
sess,
230230
CrateType::Rlib,
231231
outputs,
232-
codegen_results.crate_info.local_crate_name.as_str(),
232+
codegen_results.crate_info.local_crate_name,
233233
);
234234
builder.build(&rlib);
235235
Ok(())

kani-compiler/src/kani_middle/attributes.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ pub fn extract_integer_argument(attr: &Attribute) -> Option<u128> {
3333
let attr_args = attr.meta_item_list()?;
3434
// Only extracts one integer value as argument
3535
if attr_args.len() == 1 {
36-
let x = attr_args[0].literal()?;
36+
let x = attr_args[0].lit()?;
3737
match x.kind {
3838
LitKind::Int(y, ..) => Some(y),
3939
_ => None,

kani-compiler/src/kani_middle/coercion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ fn custom_coerce_unsize_info<'tcx>(
215215

216216
let trait_ref = ty::Binder::dummy(TraitRef {
217217
def_id,
218-
substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]),
218+
substs: tcx.mk_substs_trait(source_ty, [target_ty.into()]),
219219
});
220220

221221
match tcx.codegen_select_candidate((ParamEnv::reveal_all(), trait_ref)) {

kani-compiler/src/kani_middle/reachability.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,10 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MonoItemsFnCollector<'a, 'tcx> {
402402
ConstKind::Value(v) => self.tcx.valtree_to_const_val((ct.ty(), v)),
403403
ConstKind::Unevaluated(_) => unreachable!(),
404404
// Nothing to do
405-
ConstKind::Param(..) | ConstKind::Infer(..) | ConstKind::Error(..) => return,
405+
ConstKind::Param(..)
406+
| ConstKind::Infer(..)
407+
| ConstKind::Error(..)
408+
| ConstKind::Expr(..) => return,
406409

407410
// Shouldn't happen
408411
ConstKind::Placeholder(..) | ConstKind::Bound(..) => {

kani-compiler/src/kani_middle/resolve.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,8 @@ fn resolve_in_module(tcx: TyCtxt, current_module: DefId, segments: Segments) ->
305305
}
306306

307307
/// Resolves a path by exploring a non-glob use statement.
308-
fn resolve_in_use(tcx: TyCtxt, use_path: &rustc_hir::Path, segments: Segments) -> Option<DefId> {
309-
if let Res::Def(def_kind, def_id) = use_path.res {
308+
fn resolve_in_use(tcx: TyCtxt, use_path: &rustc_hir::UsePath, segments: Segments) -> Option<DefId> {
309+
if let Res::Def(def_kind, def_id) = use_path.res[0] {
310310
tracing::debug!(
311311
"Resolving `{}` via `use` import of `{}`",
312312
segments_to_string(&segments),
@@ -340,7 +340,7 @@ fn resolve_in_use(tcx: TyCtxt, use_path: &rustc_hir::Path, segments: Segments) -
340340
fn resolve_in_glob_uses(
341341
tcx: TyCtxt,
342342
current_module: LocalDefId,
343-
glob_imports: Vec<&rustc_hir::Path>,
343+
glob_imports: Vec<&rustc_hir::UsePath>,
344344
segments: &Segments,
345345
) -> Option<DefId> {
346346
let glob_resolves = glob_imports
@@ -377,10 +377,10 @@ fn resolve_in_glob_uses(
377377
/// Resolves a path by exploring a glob use statement.
378378
fn resolve_in_glob_use(
379379
tcx: TyCtxt,
380-
use_path: &rustc_hir::Path,
380+
use_path: &rustc_hir::UsePath,
381381
segments: Segments,
382382
) -> Option<DefId> {
383-
if let Res::Def(DefKind::Mod, def_id) = use_path.res {
383+
if let Res::Def(DefKind::Mod, def_id) = use_path.res[0] {
384384
resolve_in_module(tcx, def_id, segments)
385385
} else {
386386
None

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-11-20"
5+
channel = "nightly-2022-12-11"
66
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]
File renamed without changes.

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:3029:81 in function <std::vec::Vec<i32> as std::ops::Drop>::drop
4+
alloc/src/vec/mod.rs:3054:81 in function <std::vec::Vec<i32> as std::ops::Drop>::drop
55

66
VERIFICATION:- SUCCESSFUL

tools/compiletest/src/main.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,7 @@ pub fn test_opts(config: &Config) -> test::TestOpts {
285285
list: false,
286286
options: test::Options::new(),
287287
time_options: None,
288+
fail_fast: true,
288289
force_run_in_process: false,
289290
}
290291
}
@@ -565,7 +566,7 @@ fn make_test_closure(config: &Config, testpaths: &TestPaths) -> test::TestFn {
565566

566567
/// Print a message and error out without panicking
567568
fn fatal_error(message: &str) {
568-
println!("error: {}", message);
569+
println!("error: {message}");
569570
// Use resume_unwind instead of panic!() to prevent a panic message + backtrace from
570571
// compiletest, which is unnecessary noise.
571572
std::panic::resume_unwind(Box::new(()));

0 commit comments

Comments
 (0)