Skip to content

Commit c5db1df

Browse files
committed
Upgrade toolchain to nightly-2023-01-23
to overcome an issue with async generators. Updated the codegen_generator to follow the new logic implemented in rust-lang/rust#105977
1 parent 379413f commit c5db1df

File tree

5 files changed

+38
-22
lines changed

5 files changed

+38
-22
lines changed

kani-compiler/kani_queries/src/lib.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,27 +15,22 @@ use {
1515
std::sync::{Arc, Mutex},
1616
};
1717

18-
#[derive(Debug, Clone, Copy, AsRefStr, EnumString, EnumVariantNames, PartialEq, Eq)]
18+
#[derive(Debug, Default, Clone, Copy, AsRefStr, EnumString, EnumVariantNames, PartialEq, Eq)]
1919
#[strum(serialize_all = "snake_case")]
2020
pub enum ReachabilityType {
2121
/// Start the cross-crate reachability analysis from all harnesses in the local crate.
2222
Harnesses,
2323
/// Use standard rustc monomorphizer algorithm.
2424
Legacy,
2525
/// Don't perform any reachability analysis. This will skip codegen for this crate.
26+
#[default]
2627
None,
2728
/// Start the cross-crate reachability analysis from all public functions in the local crate.
2829
PubFns,
2930
/// Start the cross-crate reachability analysis from all *test* (i.e. `#[test]`) harnesses in the local crate.
3031
Tests,
3132
}
3233

33-
impl Default for ReachabilityType {
34-
fn default() -> Self {
35-
ReachabilityType::None
36-
}
37-
}
38-
3934
pub trait UserInput {
4035
fn set_emit_vtable_restrictions(&mut self, restrictions: bool);
4136
fn get_emit_vtable_restrictions(&self) -> bool;

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

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -358,20 +358,41 @@ impl<'tcx> GotocCtx<'tcx> {
358358
// `Generator::resume(...) -> GeneratorState` function in case we
359359
// have an ordinary generator, or the `Future::poll(...) -> Poll`
360360
// 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)
361+
let tcx = self.tcx;
362+
let (resume_ty, ret_ty) = if tcx.generator_is_async(*did) {
363+
// The signature should be `Future::poll(_, &mut Context<'_>) -> Poll<Output>`
364+
let poll_did = tcx.require_lang_item(LangItem::Poll, None);
365+
let poll_adt_ref = tcx.adt_def(poll_did);
366+
let poll_substs = tcx.intern_substs(&[sig.return_ty.into()]);
367+
let ret_ty = tcx.mk_adt(poll_adt_ref, poll_substs);
368+
369+
// We have to replace the `ResumeTy` that is used for type and borrow checking
370+
// with `&mut Context<'_>` which is used in codegen.
371+
#[cfg(debug_assertions)]
372+
{
373+
if let ty::Adt(resume_ty_adt, _) = sig.resume_ty.kind() {
374+
let expected_adt = tcx.adt_def(tcx.require_lang_item(LangItem::ResumeTy, None));
375+
assert_eq!(*resume_ty_adt, expected_adt);
376+
} else {
377+
panic!("expected `ResumeTy`, found `{:?}`", sig.resume_ty);
378+
};
379+
}
380+
let context_mut_ref = tcx.mk_task_context();
381+
382+
(context_mut_ref, ret_ty)
366383
} 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)
384+
// The signature should be `Generator::resume(_, Resume) -> GeneratorState<Yield, Return>`
385+
let state_did = tcx.require_lang_item(LangItem::GeneratorState, None);
386+
let state_adt_ref = tcx.adt_def(state_did);
387+
let state_substs = tcx.intern_substs(&[sig.yield_ty.into(), sig.return_ty.into()]);
388+
let ret_ty = tcx.mk_adt(state_adt_ref, state_substs);
389+
390+
(sig.resume_ty, ret_ty)
371391
};
392+
372393
ty::Binder::bind_with_vars(
373-
self.tcx.mk_fn_sig(
374-
[env_ty, sig.resume_ty].iter(),
394+
tcx.mk_fn_sig(
395+
[env_ty, resume_ty].iter(),
375396
&ret_ty,
376397
false,
377398
Unsafety::Normal,

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-01-16"
5+
channel = "nightly-2023-01-23"
66
components = ["llvm-tools-preview", "rustc-dev", "rust-src", "rustfmt"]

tests/cargo-kani/vecdeque-cve/src/abstract_vecdeque.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ impl AbstractRawVec {
275275

276276
fn handle_reserve(result: Result<(), TryReserveError>) {
277277
match result.map_err(|e| e.kind()) {
278-
Err(CapacityOverflow) => capacity_overflow(),
279-
Err(AllocError) => handle_alloc_error(),
278+
Err(TryReserveErrorKind::CapacityOverflow) => capacity_overflow(),
279+
Err(TryReserveErrorKind::AllocError) => handle_alloc_error(),
280280
Ok(()) => { /* yay */ }
281281
}
282282
}

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

66
VERIFICATION:- SUCCESSFUL

0 commit comments

Comments
 (0)