Skip to content

Commit

Permalink
Update to Rust 1.70
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Jul 29, 2023
1 parent de61ee1 commit 96a82cc
Show file tree
Hide file tree
Showing 16 changed files with 92 additions and 91 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ cd klint
cargo install --path .
```

Note that klint currently is based on Rust 1.68 so it is likely that running `cargo install --git` will not work as it will not use the `rust-toolchain` file in the repository.
Note that klint currently is based on Rust 1.70 so it is likely that running `cargo install --git` will not work as it will not use the `rust-toolchain` file in the repository.

To run this tool, use rustup which will prepare the necessary environment variables:
```
rustup run 1.68.0 klint
rustup run 1.70.0 klint
```

`klint` will behave like rustc, just with additional lints.
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.68.2"
channel = "1.70.0"
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]
43 changes: 19 additions & 24 deletions src/atomic_context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_hir::Constness;
use rustc_hir::{def_id::LocalDefId, Constness};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::ty::{Instance, InternalSubsts, ParamEnv, TyCtxt};
Expand Down Expand Up @@ -240,8 +240,8 @@ impl<'tcx> LateLintPass<'tcx> for AtomicContext<'tcx> {

impl<'tcx, F, A> hir_visit::Visitor<'tcx> for FnAdtVisitor<'tcx, F, A>
where
F: FnMut(HirId),
A: FnMut(HirId),
F: FnMut(LocalDefId),
A: FnMut(LocalDefId),
{
type NestedFilter = rustc_middle::hir::nested_filter::All;

Expand All @@ -255,11 +255,11 @@ impl<'tcx> LateLintPass<'tcx> for AtomicContext<'tcx> {
fn visit_item(&mut self, i: &'tcx Item<'tcx>) {
match i.kind {
ItemKind::Struct(..) | ItemKind::Union(..) | ItemKind::Enum(..) => {
(self.adt_callback)(i.hir_id());
(self.adt_callback)(i.item_id().owner_id.def_id);
}
ItemKind::Trait(..) => {
// Not exactly an ADT, but we want to track drop_preempt_count on traits as well.
(self.adt_callback)(i.hir_id());
(self.adt_callback)(i.item_id().owner_id.def_id);
}
_ => (),
}
Expand All @@ -269,7 +269,7 @@ impl<'tcx> LateLintPass<'tcx> for AtomicContext<'tcx> {
fn visit_foreign_item(&mut self, i: &'tcx ForeignItem<'tcx>) {
match i.kind {
ForeignItemKind::Fn(..) => {
(self.fn_callback)(i.hir_id());
(self.fn_callback)(i.owner_id.def_id);
}
_ => (),
}
Expand All @@ -279,7 +279,7 @@ impl<'tcx> LateLintPass<'tcx> for AtomicContext<'tcx> {
fn visit_trait_item(&mut self, ti: &'tcx TraitItem<'tcx>) {
match ti.kind {
TraitItemKind::Fn(_, TraitFn::Required(_)) => {
(self.fn_callback)(ti.hir_id());
(self.fn_callback)(ti.owner_id.def_id);
}
_ => (),
}
Expand All @@ -292,7 +292,7 @@ impl<'tcx> LateLintPass<'tcx> for AtomicContext<'tcx> {
fd: &'tcx FnDecl<'tcx>,
b: BodyId,
_: Span,
id: HirId,
id: LocalDefId,
) {
(self.fn_callback)(id);
hir_visit::walk_fn(self, fk, fd, b, id)
Expand All @@ -304,20 +304,18 @@ impl<'tcx> LateLintPass<'tcx> for AtomicContext<'tcx> {
.hir()
.visit_all_item_likes_in_crate(&mut FnAdtVisitor {
tcx: self.cx.tcx,
fn_callback: |hir_id| {
let def_id = self.cx.hir().local_def_id(hir_id).to_def_id();
let annotation = self.cx.preemption_count_annotation(def_id);
fn_callback: |def_id: LocalDefId| {
let annotation = self.cx.preemption_count_annotation(def_id.into());
self.cx
.sql_store::<crate::preempt_count::annotation::preemption_count_annotation>(
def_id, annotation,
def_id.into(), annotation,
);
},
adt_callback: |hir_id| {
let def_id = self.cx.hir().local_def_id(hir_id).to_def_id();
let annotation = self.cx.drop_preemption_count_annotation(def_id);
adt_callback: |def_id: LocalDefId| {
let annotation = self.cx.drop_preemption_count_annotation(def_id.into());
self.cx
.sql_store::<crate::preempt_count::annotation::drop_preemption_count_annotation>(
def_id, annotation,
def_id.into(), annotation,
);
},
});
Expand All @@ -328,21 +326,18 @@ impl<'tcx> LateLintPass<'tcx> for AtomicContext<'tcx> {
cx: &LateContext<'tcx>,
_: rustc_hir::intravisit::FnKind<'tcx>,
_: &'tcx rustc_hir::FnDecl<'tcx>,
body: &'tcx rustc_hir::Body<'tcx>,
_body: &'tcx rustc_hir::Body<'tcx>,
_: rustc_span::Span,
_hir_id: rustc_hir::HirId,
def_id: LocalDefId,
) {
let def_id = cx.tcx.hir().body_owner_def_id(body.id());

// Building MIR for `fn`s with unsatisfiable preds results in ICE.
if crate::util::fn_has_unsatisfiable_preds(cx, def_id.to_def_id()) {
return;
}

let identity = cx.tcx.erase_regions(InternalSubsts::identity_for_item(
self.cx.tcx,
def_id.into(),
));
let identity = cx
.tcx
.erase_regions(InternalSubsts::identity_for_item(self.cx.tcx, def_id));
let instance = Instance::new(def_id.into(), identity);
let param_and_instance = self
.cx
Expand Down
4 changes: 2 additions & 2 deletions src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ pub enum KlintAttribute {

struct Cursor<'a> {
eof: TokenTree,
cursor: tokenstream::CursorRef<'a>,
cursor: tokenstream::RefTokenTreeCursor<'a>,
}

impl<'a> Cursor<'a> {
fn new(cursor: tokenstream::CursorRef<'a>, end_span: Span) -> Self {
fn new(cursor: tokenstream::RefTokenTreeCursor<'a>, end_span: Span) -> Self {
let eof = TokenTree::Token(
token::Token {
kind: token::TokenKind::Eof,
Expand Down
6 changes: 3 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(rustc_private)]
#![feature(once_cell)]
#![feature(lazy_cell)]
#![feature(min_specialization)]
#![feature(box_patterns)]
#![feature(if_let_guard)]
Expand Down Expand Up @@ -72,8 +72,8 @@ impl Callbacks for MyCallbacks {

// Skip `analysis_mir` call if this is a constructor, since it will be delegated back to
// `optimized_mir` for building ADT constructor shim.
if !tcx.is_constructor(def_id) {
crate::mir::local_analysis_mir(tcx, def_id.expect_local());
if !tcx.is_constructor(def_id.to_def_id()) {
crate::mir::local_analysis_mir(tcx, def_id);
}

let ptr = ORIGINAL_OPTIMIZED_MIR.load(Ordering::Relaxed);
Expand Down
10 changes: 6 additions & 4 deletions src/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ fn remap_mir_for_const_eval_select<'tcx>(
ref mut args,
destination,
target,
cleanup,
unwind,
fn_span,
..
} if let ty::FnDef(def_id, _) = *literal.ty().kind()
Expand Down Expand Up @@ -96,14 +96,14 @@ fn remap_mir_for_const_eval_select<'tcx>(
let arguments = (0..num_args).map(|x| {
let mut place_elems = place_elems.to_vec();
place_elems.push(ProjectionElem::Field(x.into(), fields[x]));
let projection = tcx.intern_place_elems(&place_elems);
let projection = tcx.mk_place_elems(&place_elems);
let place = Place {
local: place.local,
projection,
};
method(place)
}).collect();
terminator.kind = TerminatorKind::Call { func, args: arguments, destination, target, cleanup, from_hir_call: false, fn_span };
terminator.kind = TerminatorKind::Call { func, args: arguments, destination, target, unwind, from_hir_call: false, fn_span };
}
_ => {}
}
Expand Down Expand Up @@ -181,7 +181,9 @@ impl<'tcx> AnalysisCtxt<'tcx> {
| ty::InstanceDef::Virtual(..)
| ty::InstanceDef::ClosureOnceShim { .. }
| ty::InstanceDef::DropGlue(..)
| ty::InstanceDef::CloneShim(..) => self.mir_shims(instance),
| ty::InstanceDef::CloneShim(..)
| ty::InstanceDef::ThreadLocalShim(..)
| ty::InstanceDef::FnPtrAddrShim(..) => self.mir_shims(instance),
}
}
}
8 changes: 4 additions & 4 deletions src/mir/drop_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::mir::*;
use rustc_middle::ty::{self, EarlyBinder, ParamEnv, Ty, TyCtxt};
use rustc_mir_dataflow::elaborate_drops::{self, *};
use rustc_span::Span;
use rustc_target::abi::VariantIdx;
use rustc_target::abi::{FieldIdx, VariantIdx};
use std::{fmt, iter};

use crate::ctxt::AnalysisCtxt;
Expand Down Expand Up @@ -39,8 +39,8 @@ pub fn build_drop_shim<'tcx>(
return body;
}

let substs = cx.intern_substs(&[ty.into()]);
let sig = cx.bound_fn_sig(def_id).subst(cx.tcx, substs);
let substs = cx.mk_substs(&[ty.into()]);
let sig = cx.fn_sig(def_id).subst(cx.tcx, substs);
let sig = cx.erase_late_bound_regions(sig);
let span = cx.def_span(def_id);

Expand Down Expand Up @@ -179,7 +179,7 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> {

fn clear_drop_flag(&mut self, _location: Location, _path: Self::Path, _mode: DropFlagMode) {}

fn field_subpath(&self, _path: Self::Path, _field: Field) -> Option<Self::Path> {
fn field_subpath(&self, _path: Self::Path, _field: FieldIdx) -> Option<Self::Path> {
None
}
fn deref_subpath(&self, _path: Self::Path) -> Option<Self::Path> {
Expand Down
37 changes: 23 additions & 14 deletions src/monomorphize_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// * `Spanned<MonoItem>` is returned in `AccessMap` instead of just `MonoItem`.

use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::sync::{par_for_each_in, MTLock, MTRef};
use rustc_data_structures::sync::{par_for_each_in, MTLock, MTLockRef};
use rustc_hir as hir;
use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, DefIdMap, LocalDefId};
Expand All @@ -20,7 +20,7 @@ use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::query::TyCtxtAt;
use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts};
use rustc_middle::ty::{
self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitable, VtblEntry,
self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, VtblEntry,
};
use rustc_middle::{middle::codegen_fn_attrs::CodegenFnAttrFlags, mir::visit::TyContext};
use rustc_session::config::EntryFnType;
Expand Down Expand Up @@ -114,8 +114,8 @@ pub fn collect_crate_mono_items(
let recursion_limit = tcx.recursion_limit();

{
let visited: MTRef<'_, _> = &mut visited;
let access_map: MTRef<'_, _> = &mut access_map;
let visited: MTLockRef<'_, _> = &mut visited;
let access_map: MTLockRef<'_, _> = &mut access_map;

tcx.sess.time("monomorphization_collector_graph_walk", || {
par_for_each_in(roots, |root| {
Expand Down Expand Up @@ -194,10 +194,10 @@ fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<
fn collect_items_rec<'tcx>(
tcx: TyCtxt<'tcx>,
starting_point: Spanned<MonoItem<'tcx>>,
visited: MTRef<'_, MTLock<FxHashSet<MonoItem<'tcx>>>>,
visited: MTLockRef<'_, FxHashSet<MonoItem<'tcx>>>,
recursion_depths: &mut DefIdMap<usize>,
recursion_limit: Limit,
access_map: MTRef<'_, MTLock<AccessMap<'tcx>>>,
access_map: MTLockRef<'_, AccessMap<'tcx>>,
) {
if !visited.lock_mut().insert(starting_point.node) {
// We've been here already, no need to search again.
Expand Down Expand Up @@ -481,7 +481,7 @@ struct MirNeighborCollector<'a, 'tcx> {
impl<'a, 'tcx> MirNeighborCollector<'a, 'tcx> {
pub fn monomorphize<T>(&self, value: T) -> T
where
T: TypeFoldable<'tcx>,
T: TypeFoldable<TyCtxt<'tcx>>,
{
debug!("monomorphize: self.instance={:?}", self.instance);
self.instance.subst_mir_and_normalize_erasing_regions(
Expand Down Expand Up @@ -628,8 +628,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
let callee_ty = self.monomorphize(callee_ty);
visit_fn_use(self.tcx, callee_ty, true, source, &mut self.output)
}
mir::TerminatorKind::Drop { ref place, .. }
| mir::TerminatorKind::DropAndReplace { ref place, .. } => {
mir::TerminatorKind::Drop { ref place, .. } => {
let ty = place.ty(self.body, self.tcx).ty;
let ty = self.monomorphize(ty);
visit_drop_use(self.tcx, ty, true, source, self.output);
Expand Down Expand Up @@ -657,7 +656,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
let instance = Instance::mono(tcx, tcx.require_lang_item(lang_item, Some(source)));
self.output.push(create_fn_mono_item(tcx, instance, source));
}
mir::TerminatorKind::Abort { .. } => {
mir::TerminatorKind::Terminate { .. } => {
let instance = Instance::mono(
tcx,
tcx.require_lang_item(LangItem::PanicCannotUnwind, Some(source)),
Expand Down Expand Up @@ -741,6 +740,9 @@ fn visit_instance_use<'tcx>(
bug!("{:?} being reified", instance);
}
}
ty::InstanceDef::ThreadLocalShim(..) => {
bug!("{:?} being reified", instance);
}
ty::InstanceDef::DropGlue(_, None) => {
// Don't need to emit noop drop glue if we are calling directly.
if !is_direct_call {
Expand All @@ -753,7 +755,8 @@ fn visit_instance_use<'tcx>(
| ty::InstanceDef::ClosureOnceShim { .. }
| ty::InstanceDef::Item(..)
| ty::InstanceDef::FnPtrShim(..)
| ty::InstanceDef::CloneShim(..) => {
| ty::InstanceDef::CloneShim(..)
| ty::InstanceDef::FnPtrAddrShim(..) => {
output.push(create_fn_mono_item(tcx, instance, source));
}
}
Expand Down Expand Up @@ -886,7 +889,8 @@ pub fn find_vtable_types_for_unsizing<'tcx>(
let target_fields = &target_adt_def.non_enum_variant().fields;

assert!(
coerce_index < source_fields.len() && source_fields.len() == target_fields.len()
coerce_index.index() < source_fields.len()
&& source_fields.len() == target_fields.len()
);

find_vtable_types_for_unsizing(
Expand Down Expand Up @@ -1059,7 +1063,12 @@ impl<'v> RootCollector<'_, 'v> {
};

let start_def_id = self.tcx.require_lang_item(LangItem::Start, None);
let main_ret_ty = self.tcx.fn_sig(main_def_id).output();
let main_ret_ty = self
.tcx
.fn_sig(main_def_id)
.no_bound_vars()
.unwrap()
.output();

// Given that `main()` has no arguments,
// then its return type cannot have
Expand All @@ -1075,7 +1084,7 @@ impl<'v> RootCollector<'_, 'v> {
self.tcx,
ty::ParamEnv::reveal_all(),
start_def_id,
self.tcx.intern_substs(&[main_ret_ty.into()]),
self.tcx.mk_substs(&[main_ret_ty.into()]),
)
.unwrap()
.unwrap();
Expand Down
Loading

0 comments on commit 96a82cc

Please sign in to comment.