Skip to content

Commit

Permalink
Upgrade to Rust 1.71
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Jul 29, 2023
1 parent 96a82cc commit e84382c
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 74 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.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.
Note that klint currently is based on Rust 1.71 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.70.0 klint
rustup run 1.71.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.70.0"
channel = "1.71.0"
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]
5 changes: 4 additions & 1 deletion src/attribute.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ impl<'tcx> AttrParser<'tcx> {
"incorrect usage of `#[kint::preempt_count]`",
decorate,
);
Err(ErrorGuaranteed::unchecked_claim_error_was_emitted())
Err(self
.tcx
.sess
.delay_span_bug(span, "incorrect usage of `#[kint::preempt_count]`"))
}

fn parse_comma_delimited(
Expand Down
6 changes: 3 additions & 3 deletions src/infallible_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleAllocation {

diag.span_note(
spanned_caller.span,
&format!(
format!(
"which is called from `{}`",
cx.tcx.def_path_str_with_substs(
caller.def_id(),
Expand Down Expand Up @@ -228,7 +228,7 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleAllocation {

diag.span_note(
callee_callee.span,
&format!(
format!(
"{} calls into `{}`",
msg,
cx.tcx.def_path_str_with_substs(
Expand All @@ -240,7 +240,7 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleAllocation {
msg = "which";
}

diag.note(&format!("{} may call alloc_error_handler", msg));
diag.note(format!("{} may call alloc_error_handler", msg));
diag
},
);
Expand Down
13 changes: 5 additions & 8 deletions src/mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub fn local_analysis_mir<'tcx>(tcx: TyCtxt<'tcx>, did: LocalDefId) -> &'tcx Bod
}

let body = tcx
.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam::unknown(did))
.mir_drops_elaborated_and_const_checked(did)
.borrow()
.clone();
let body = remap_mir_for_const_eval_select(tcx, body, hir::Constness::NotConst);
Expand Down Expand Up @@ -159,19 +159,16 @@ impl<'tcx> AnalysisCtxt<'tcx> {

pub fn analysis_instance_mir(&self, instance: ty::InstanceDef<'tcx>) -> &'tcx Body<'tcx> {
match instance {
ty::InstanceDef::Item(def) => {
let def_kind = self.def_kind(def.did);
ty::InstanceDef::Item(did) => {
let def_kind = self.def_kind(did);
match def_kind {
DefKind::Const
| DefKind::Static(..)
| DefKind::AssocConst
| DefKind::Ctor(..)
| DefKind::AnonConst
| DefKind::InlineConst => self.mir_for_ctfe_opt_const_arg(def),
_ => {
assert_eq!(def.const_param_did, None);
self.analysis_mir(def.did)
}
| DefKind::InlineConst => self.mir_for_ctfe(did),
_ => self.analysis_mir(did),
}
}
ty::InstanceDef::VTableShim(..)
Expand Down
2 changes: 1 addition & 1 deletion src/mir/drop_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Adopted to support polymorphic drop shims

use rustc_hir::def_id::DefId;
use rustc_index::vec::{Idx, IndexVec};
use rustc_index::{Idx, IndexVec};
use rustc_middle::mir::patch::MirPatch;
use rustc_middle::mir::*;
use rustc_middle::ty::{self, EarlyBinder, ParamEnv, Ty, TyCtxt};
Expand Down
64 changes: 34 additions & 30 deletions src/monomorphize_collector.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// This module is from rustc_monomorphize/collector.rs, modified so that
// * All neighbors are collected, including those that should not be codegen-ed locally.
// * All uses are collected, including those that should not be codegen-ed locally.
// * `inlines` field is removed from `InliningMap`.
// * Due to the above reasons, `InliningMap` is renamed to `AccessMap`.
// * `Spanned<MonoItem>` is returned in `AccessMap` instead of just `MonoItem`.
Expand All @@ -15,9 +15,9 @@ use rustc_middle::mir::interpret::{ErrorHandled, GlobalAlloc, Scalar};
use rustc_middle::mir::mono::MonoItem;
use rustc_middle::mir::visit::Visitor as MirVisitor;
use rustc_middle::mir::{self, Local, Location};
use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCast};
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, TypeVisitableExt, VtblEntry,
Expand All @@ -37,8 +37,12 @@ fn custom_coerce_unsize_info<'tcx>(
source_ty: Ty<'tcx>,
target_ty: Ty<'tcx>,
) -> CustomCoerceUnsized {
let trait_ref =
ty::Binder::dummy(tcx.mk_trait_ref(LangItem::CoerceUnsized, [source_ty, target_ty]));
let trait_ref = ty::Binder::dummy(ty::TraitRef::from_lang_item(
tcx.tcx,
LangItem::CoerceUnsized,
tcx.span,
[source_ty, target_ty],
));

match tcx.codegen_select_candidate((param_env, trait_ref)) {
Ok(traits::ImplSource::UserDefined(traits::ImplSourceUserDefinedData {
Expand All @@ -59,17 +63,17 @@ pub enum MonoItemCollectionMode {

/// Maps every mono item to all mono items it references in its
/// body.
pub struct AccessMap<'tcx> {
pub struct UsageMap<'tcx> {
// Maps a source mono item to the range of mono items
// accessed by it.
// The range selects elements within the `targets` vecs.
index: FxHashMap<MonoItem<'tcx>, Range<usize>>,
targets: Vec<Spanned<MonoItem<'tcx>>>,
}

impl<'tcx> AccessMap<'tcx> {
fn new() -> AccessMap<'tcx> {
AccessMap {
impl<'tcx> UsageMap<'tcx> {
fn new() -> UsageMap<'tcx> {
UsageMap {
index: FxHashMap::default(),
targets: Vec::new(),
}
Expand Down Expand Up @@ -98,7 +102,7 @@ impl<'tcx> AccessMap<'tcx> {
pub fn collect_crate_mono_items(
tcx: TyCtxt<'_>,
mode: MonoItemCollectionMode,
) -> (FxHashSet<MonoItem<'_>>, AccessMap<'_>) {
) -> (FxHashSet<MonoItem<'_>>, UsageMap<'_>) {
let _prof_timer = tcx.prof.generic_activity("monomorphization_collector");

let roots = tcx
Expand All @@ -110,7 +114,7 @@ pub fn collect_crate_mono_items(
debug!("building mono item graph, beginning at roots");

let mut visited = MTLock::new(FxHashSet::default());
let mut access_map = MTLock::new(AccessMap::new());
let mut access_map = MTLock::new(UsageMap::new());
let recursion_limit = tcx.recursion_limit();

{
Expand Down Expand Up @@ -193,13 +197,13 @@ fn collect_roots(tcx: TyCtxt<'_>, mode: MonoItemCollectionMode) -> Vec<MonoItem<
/// post-monorphization error is encountered during a collection step.
fn collect_items_rec<'tcx>(
tcx: TyCtxt<'tcx>,
starting_point: Spanned<MonoItem<'tcx>>,
starting_item: Spanned<MonoItem<'tcx>>,
visited: MTLockRef<'_, FxHashSet<MonoItem<'tcx>>>,
recursion_depths: &mut DefIdMap<usize>,
recursion_limit: Limit,
access_map: MTLockRef<'_, AccessMap<'tcx>>,
access_map: MTLockRef<'_, UsageMap<'tcx>>,
) {
if !visited.lock_mut().insert(starting_point.node) {
if !visited.lock_mut().insert(starting_item.node) {
// We've been here already, no need to search again.
return;
}
Expand Down Expand Up @@ -233,15 +237,15 @@ fn collect_items_rec<'tcx>(
// FIXME: don't rely on global state, instead bubble up errors. Note: this is very hard to do.
let error_count = tcx.sess.diagnostic().err_count();

match starting_point.node {
match starting_item.node {
MonoItem::Static(def_id) => {
let instance = Instance::mono(tcx, def_id);

// Sanity check whether this ended up being collected accidentally
debug_assert!(should_codegen_locally(tcx, &instance));

let ty = instance.ty(tcx, ty::ParamEnv::reveal_all());
visit_drop_use(tcx, ty, true, starting_point.span, &mut neighbors);
visit_drop_use(tcx, ty, true, starting_item.span, &mut neighbors);

recursion_depth_reset = None;

Expand All @@ -259,7 +263,7 @@ fn collect_items_rec<'tcx>(
recursion_depth_reset = Some(check_recursion_limit(
tcx,
instance,
starting_point.span,
starting_item.span,
recursion_depths,
recursion_limit,
));
Expand Down Expand Up @@ -311,13 +315,13 @@ fn collect_items_rec<'tcx>(
// Check for PMEs and emit a diagnostic if one happened. To try to show relevant edges of the
// mono item graph.
if tcx.sess.diagnostic().err_count() > error_count
&& starting_point.node.is_generic_fn()
&& starting_point.node.is_user_defined()
&& starting_item.node.is_generic_fn()
&& starting_item.node.is_user_defined()
{
let formatted_item = with_no_trimmed_paths!(starting_point.node.to_string());
let formatted_item = with_no_trimmed_paths!(starting_item.node.to_string());
tcx.sess.span_note_without_error(
starting_point.span,
&format!(
starting_item.span,
format!(
"the above error was encountered while instantiating `{}`",
formatted_item
),
Expand All @@ -326,7 +330,7 @@ fn collect_items_rec<'tcx>(

access_map
.lock_mut()
.record_accesses(starting_point.node, &neighbors);
.record_accesses(starting_item.node, &neighbors);

for neighbour in neighbors {
let should_gen = match neighbour.node {
Expand Down Expand Up @@ -414,10 +418,10 @@ fn check_recursion_limit<'tcx>(
"reached the recursion limit while instantiating `{}`",
shrunk
);
let mut err = tcx.sess.struct_span_fatal(span, &error);
err.span_note(def_span, &format!("`{}` defined here", def_path_str));
let mut err = tcx.sess.struct_span_fatal(span, error);
err.span_note(def_span, format!("`{}` defined here", def_path_str));
if let Some(path) = written_to_path {
err.note(&format!(
err.note(format!(
"the full type name has been written to '{}'",
path.display()
));
Expand Down Expand Up @@ -456,14 +460,14 @@ fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) {
);
let mut diag = tcx
.sess
.struct_span_fatal(tcx.def_span(instance.def_id()), &msg);
.struct_span_fatal(tcx.def_span(instance.def_id()), msg);
if let Some(path) = written_to_path {
diag.note(&format!(
diag.note(format!(
"the full type name has been written to '{}'",
path.display()
));
}
diag.help(&format!(
diag.help(format!(
"consider adding a `#![type_length_limit=\"{}\"]` attribute to your crate",
type_length
));
Expand All @@ -487,7 +491,7 @@ impl<'a, 'tcx> MirNeighborCollector<'a, 'tcx> {
self.instance.subst_mir_and_normalize_erasing_regions(
self.tcx,
ty::ParamEnv::reveal_all(),
value,
ty::EarlyBinder(value),
)
}
}
Expand Down Expand Up @@ -649,7 +653,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
}
}
mir::TerminatorKind::Assert { ref msg, .. } => {
let lang_item = match msg {
let lang_item = match &**msg {
mir::AssertKind::BoundsCheck { .. } => LangItem::PanicBoundsCheck,
_ => LangItem::Panic,
};
Expand Down
4 changes: 3 additions & 1 deletion src/preempt_count/adjustment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ impl<'tcx> AnalysisCtxt<'tcx> {
let mut first_problematic_block = return_bb;
let dominators = body.basic_blocks.dominators();
loop {
let b = dominators.immediate_dominator(first_problematic_block);
let b = dominators
.immediate_dominator(first_problematic_block)
.expect("block not reachable!");
if b == first_problematic_block {
// Shouldn't actually happen because the entry block should always have a single value.
break;
Expand Down
7 changes: 5 additions & 2 deletions src/preempt_count/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,11 @@ struct MirNeighborVisitor<'mir, 'tcx, 'cx> {

impl<'mir, 'tcx, 'cx> MirNeighborVisitor<'mir, 'tcx, 'cx> {
fn monomorphize<T: TypeFoldable<TyCtxt<'tcx>> + Clone>(&self, v: T) -> T {
self.instance
.subst_mir_and_normalize_erasing_regions(self.cx.tcx, self.param_env, v)
self.instance.subst_mir_and_normalize_erasing_regions(
self.cx.tcx,
self.param_env,
ty::EarlyBinder(v),
)
}

fn check_vtable_unsizing(
Expand Down
4 changes: 2 additions & 2 deletions src/preempt_count/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ impl<'tcx> Analysis<'tcx> for AdjustmentComputation<'_, 'tcx, '_> {
let callee_ty = self.instance.subst_mir_and_normalize_erasing_regions(
self.checker.tcx,
self.param_env,
callee_ty,
ty::EarlyBinder(callee_ty),
);
if let ty::FnDef(def_id, substs) = *callee_ty.kind() {
if let Some(v) = self.checker.preemption_count_annotation(def_id).adjustment {
Expand Down Expand Up @@ -282,7 +282,7 @@ impl<'tcx> Analysis<'tcx> for AdjustmentComputation<'_, 'tcx, '_> {
let ty = self.instance.subst_mir_and_normalize_erasing_regions(
self.checker.tcx,
self.param_env,
ty,
ty::EarlyBinder(ty),
);

self.checker.call_stack.borrow_mut().push(UseSite {
Expand Down
Loading

0 comments on commit e84382c

Please sign in to comment.