From 155a128fac4ec43b422381eaf0688846327006cc Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Sat, 29 Jul 2023 14:11:58 +0100 Subject: [PATCH] Upgrade to Rust 1.73 --- rust-toolchain | 2 +- src/atomic_context.rs | 7 +-- src/infallible_allocation.rs | 18 ++---- src/mir/drop_shim.rs | 8 +-- src/monomorphize_collector.rs | 35 +++++------ src/preempt_count/adjustment.rs | 64 +++++++++---------- src/preempt_count/check.rs | 75 +++++++++++----------- src/preempt_count/dataflow.rs | 11 +--- src/preempt_count/expectation.rs | 104 ++++++++++++++----------------- src/serde.rs | 2 +- 10 files changed, 146 insertions(+), 180 deletions(-) diff --git a/rust-toolchain b/rust-toolchain index 81fae0c..d071d29 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1,3 +1,3 @@ [toolchain] -channel = "beta" +channel = "nightly" components = ["llvm-tools-preview", "rustc-dev", "rust-src"] diff --git a/src/atomic_context.rs b/src/atomic_context.rs index 9639ed9..3c24f5c 100644 --- a/src/atomic_context.rs +++ b/src/atomic_context.rs @@ -1,7 +1,7 @@ -use rustc_hir::{def_id::LocalDefId, Constness}; +use rustc_hir::def_id::LocalDefId; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::mir::mono::MonoItem; -use rustc_middle::ty::{Instance, InternalSubsts, ParamEnv, TyCtxt}; +use rustc_middle::ty::{GenericArgs, Instance, ParamEnv, TyCtxt}; use rustc_session::{declare_tool_lint, impl_lint_pass}; use rustc_span::Span; @@ -337,12 +337,11 @@ impl<'tcx> LateLintPass<'tcx> for AtomicContext<'tcx> { let identity = cx .tcx - .erase_regions(InternalSubsts::identity_for_item(self.cx.tcx, def_id)); + .erase_regions(GenericArgs::identity_for_item(self.cx.tcx, def_id)); let instance = Instance::new(def_id.into(), identity); let param_and_instance = self .cx .param_env_reveal_all_normalized(def_id) - .with_constness(Constness::NotConst) .and(instance); let _ = self.cx.instance_adjustment(param_and_instance); let _ = self.cx.instance_expectation(param_and_instance); diff --git a/src/infallible_allocation.rs b/src/infallible_allocation.rs index ecb529c..e714604 100644 --- a/src/infallible_allocation.rs +++ b/src/infallible_allocation.rs @@ -151,12 +151,12 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleAllocation { let accessee = item.node; if !accessee.def_id().is_local() && infallible.contains(&accessee) { - let is_generic = accessor.substs.non_erasable_generics().next().is_some(); + let is_generic = accessor.args.non_erasable_generics().next().is_some(); let generic_note = if is_generic { format!( " when the caller is monomorphized as `{}`", cx.tcx - .def_path_str_with_substs(accessor.def_id(), accessor.substs) + .def_path_str_with_args(accessor.def_id(), accessor.args) ) } else { String::new() @@ -164,7 +164,7 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleAllocation { let accessee_path = cx .tcx - .def_path_str_with_substs(accessee.def_id(), accessee.substs); + .def_path_str_with_args(accessee.def_id(), accessee.args); cx.struct_span_lint( &INFALLIBLE_ALLOCATION, @@ -179,7 +179,7 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleAllocation { let mut visited = FxHashSet::default(); visited.insert(*accessor); visited.insert(accessee); - while caller.substs.non_erasable_generics().next().is_some() { + while caller.args.non_erasable_generics().next().is_some() { let spanned_caller = match backward .get(&caller) .map(|x| &**x) @@ -197,10 +197,7 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleAllocation { spanned_caller.span, format!( "which is called from `{}`", - cx.tcx.def_path_str_with_substs( - caller.def_id(), - caller.substs - ) + cx.tcx.def_path_str_with_args(caller.def_id(), caller.args) ), ); } @@ -231,10 +228,7 @@ impl<'tcx> LateLintPass<'tcx> for InfallibleAllocation { format!( "{} calls into `{}`", msg, - cx.tcx.def_path_str_with_substs( - callee.def_id(), - callee.substs - ) + cx.tcx.def_path_str_with_args(callee.def_id(), callee.args) ), ); msg = "which"; diff --git a/src/mir/drop_shim.rs b/src/mir/drop_shim.rs index ba4800e..10050e5 100644 --- a/src/mir/drop_shim.rs +++ b/src/mir/drop_shim.rs @@ -33,14 +33,14 @@ pub fn build_drop_shim<'tcx>( param_env: ParamEnv<'tcx>, ty: Ty<'tcx>, ) -> Body<'tcx> { - if let ty::Generator(gen_def_id, substs, _) = ty.kind() { + if let ty::Generator(gen_def_id, args, _) = ty.kind() { let body = cx.analysis_mir(*gen_def_id).generator_drop().unwrap(); - let body = EarlyBinder::bind(body.clone()).subst(cx.tcx, substs); + let body = EarlyBinder::bind(body.clone()).instantiate(cx.tcx, args); return body; } - let substs = cx.mk_substs(&[ty.into()]); - let sig = cx.fn_sig(def_id).subst(cx.tcx, substs); + let args = cx.mk_args(&[ty.into()]); + let sig = cx.fn_sig(def_id).instantiate(cx.tcx, args); let sig = cx.erase_late_bound_regions(sig); let span = cx.def_span(def_id); diff --git a/src/monomorphize_collector.rs b/src/monomorphize_collector.rs index 8344133..1e63c54 100644 --- a/src/monomorphize_collector.rs +++ b/src/monomorphize_collector.rs @@ -18,9 +18,9 @@ use rustc_middle::mir::{self, Local, Location}; use rustc_middle::query::TyCtxtAt; use rustc_middle::ty::adjustment::{CustomCoerceUnsized, PointerCoercion}; use rustc_middle::ty::print::with_no_trimmed_paths; -use rustc_middle::ty::subst::{GenericArgKind, InternalSubsts}; use rustc_middle::ty::{ - self, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, VtblEntry, + self, GenericArgKind, GenericArgs, GenericParamDefKind, Instance, Ty, TyCtxt, TypeFoldable, + TypeVisitableExt, VtblEntry, }; use rustc_middle::{middle::codegen_fn_attrs::CodegenFnAttrFlags, mir::visit::TyContext}; use rustc_session::config::EntryFnType; @@ -437,7 +437,7 @@ fn check_recursion_limit<'tcx>( fn check_type_length_limit<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx>) { let type_length = instance - .substs + .args .iter() .flat_map(|arg| arg.walk()) .filter(|arg| match arg.unpack() { @@ -554,11 +554,11 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirUsedCollector<'a, 'tcx> { let source_ty = operand.ty(self.body, self.tcx); let source_ty = self.monomorphize(source_ty); match *source_ty.kind() { - ty::Closure(def_id, substs) => { + ty::Closure(def_id, args) => { let instance = Instance::resolve_closure( self.tcx, def_id, - substs, + args, ty::ClosureKind::FnOnce, ) .expect("failed to normalize and resolve closure during codegen"); @@ -713,12 +713,11 @@ fn visit_fn_use<'tcx>( source: Span, output: &mut Vec>>, ) { - if let ty::FnDef(def_id, substs) = *ty.kind() { + if let ty::FnDef(def_id, args) = *ty.kind() { let instance = if is_direct_call { - ty::Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs) + ty::Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, args) } else { - match ty::Instance::resolve_for_fn_ptr(tcx, ty::ParamEnv::reveal_all(), def_id, substs) - { + match ty::Instance::resolve_for_fn_ptr(tcx, ty::ParamEnv::reveal_all(), def_id, args) { Some(instance) => instance, _ => bug!("failed to resolve instance for {ty}"), } @@ -884,7 +883,7 @@ pub fn find_vtable_types_for_unsizing<'tcx>( // T as dyn* Trait (_, &ty::Dynamic(_, _, ty::DynStar)) => ptr_vtable(source_ty, target_ty), - (&ty::Adt(source_adt_def, source_substs), &ty::Adt(target_adt_def, target_substs)) => { + (&ty::Adt(source_adt_def, source_args), &ty::Adt(target_adt_def, target_args)) => { assert_eq!(source_adt_def, target_adt_def); let CustomCoerceUnsized::Struct(coerce_index) = @@ -901,8 +900,8 @@ pub fn find_vtable_types_for_unsizing<'tcx>( find_vtable_types_for_unsizing( tcx, param_env, - source_fields[coerce_index].ty(*tcx, source_substs), - target_fields[coerce_index].ty(*tcx, target_substs), + source_fields[coerce_index].ty(*tcx, source_args), + target_fields[coerce_index].ty(*tcx, target_args), ) } _ => bug!( @@ -982,7 +981,7 @@ impl<'v> RootCollector<'_, 'v> { debug!("RootCollector: ADT drop-glue for {id:?}",); let item = self.tcx.hir().item(id); - let ty = Instance::new(item.owner_id.to_def_id(), InternalSubsts::empty()) + let ty = Instance::new(item.owner_id.to_def_id(), GenericArgs::empty()) .ty(self.tcx, ty::ParamEnv::reveal_all()); visit_drop_use(self.tcx, ty, true, DUMMY_SP, self.output); } @@ -1089,7 +1088,7 @@ impl<'v> RootCollector<'_, 'v> { self.tcx, ty::ParamEnv::reveal_all(), start_def_id, - self.tcx.mk_substs(&[main_ret_ty.into()]), + self.tcx.mk_args(&[main_ret_ty.into()]), ) .unwrap() .unwrap(); @@ -1125,7 +1124,7 @@ fn create_mono_items_for_default_impls<'tcx>( return; }; - let trait_ref = trait_ref.subst_identity(); + let trait_ref = trait_ref.instantiate_identity(); let param_env = ty::ParamEnv::reveal_all(); let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref); @@ -1143,13 +1142,13 @@ fn create_mono_items_for_default_impls<'tcx>( continue; } - let substs = InternalSubsts::for_item(tcx, method.def_id, |param, _| match param.kind { + let args = GenericArgs::for_item(tcx, method.def_id, |param, _| match param.kind { GenericParamDefKind::Lifetime => tcx.lifetimes.re_erased.into(), GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => { - trait_ref.substs[param.index as usize] + trait_ref.args[param.index as usize] } }); - let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, substs); + let instance = ty::Instance::expect_resolve(tcx, param_env, method.def_id, args); let mono_item = create_fn_mono_item(tcx, instance, DUMMY_SP); if mono_item.node.is_instantiable(tcx) { diff --git a/src/preempt_count/adjustment.rs b/src/preempt_count/adjustment.rs index d111be0..5b664e5 100644 --- a/src/preempt_count/adjustment.rs +++ b/src/preempt_count/adjustment.rs @@ -1,8 +1,8 @@ use rustc_errors::{DiagnosticBuilder, EmissionGuarantee, MultiSpan}; use rustc_hir::def_id::{CrateNum, DefId}; -use rustc_hir::{Constness, LangItem}; +use rustc_hir::LangItem; use rustc_middle::mir::{Body, TerminatorKind, UnwindAction}; -use rustc_middle::ty::{self, Instance, InternalSubsts, ParamEnv, ParamEnvAnd, Ty}; +use rustc_middle::ty::{self, GenericArgs, Instance, ParamEnv, ParamEnvAnd, Ty}; use rustc_mir_dataflow::Analysis; use rustc_mir_dataflow::JoinSemiLattice; @@ -21,8 +21,8 @@ impl<'tcx> AnalysisCtxt<'tcx> { fn poly_instance_of_def_id(&self, def_id: DefId) -> ParamEnvAnd<'tcx, Instance<'tcx>> { let poly_param_env = self.param_env_reveal_all_normalized(def_id); - let poly_substs = self.erase_regions(InternalSubsts::identity_for_item(self.tcx, def_id)); - poly_param_env.and(Instance::new(def_id, poly_substs)) + let poly_args = self.erase_regions(GenericArgs::identity_for_item(self.tcx, def_id)); + poly_param_env.and(Instance::new(def_id, poly_args)) } pub fn emit_with_use_site_info( @@ -348,8 +348,8 @@ memoize!( } match ty.kind() { - ty::Closure(_, substs) => { - return cx.drop_adjustment(param_env.and(substs.as_closure().tupled_upvars_ty())); + ty::Closure(_, args) => { + return cx.drop_adjustment(param_env.and(args.as_closure().tupled_upvars_ty())); } // Generator drops are non-trivial, use the generated drop shims instead. @@ -367,12 +367,12 @@ memoize!( return Ok(adj); } - ty::Adt(def, substs) if def.is_box() => { - let adj = cx.drop_adjustment(param_env.and(substs.type_at(0)))?; + ty::Adt(def, args) if def.is_box() => { + let adj = cx.drop_adjustment(param_env.and(args.type_at(0)))?; let drop_trait = cx.require_lang_item(LangItem::Drop, None); let drop_fn = cx.associated_item_def_ids(drop_trait)[0]; let box_free = - ty::Instance::resolve(cx.tcx, param_env, drop_fn, cx.mk_substs(&[ty.into()])) + ty::Instance::resolve(cx.tcx, param_env, drop_fn, cx.mk_args(&[ty.into()])) .unwrap() .unwrap(); let box_free_adj = cx.instance_adjustment(param_env.and(box_free))?; @@ -383,13 +383,12 @@ memoize!( } ty::Adt(def, _) => { - // For Adts, we first try to not use any of the substs and just try the most + // For Adts, we first try to not use any of the args and just try the most // polymorphic version of the type. let poly_param_env = cx.param_env_reveal_all_normalized(def.did()); - let poly_substs = - cx.erase_regions(InternalSubsts::identity_for_item(cx.tcx, def.did())); + let poly_args = cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, def.did())); let poly_poly_ty = - poly_param_env.and(cx.tcx.mk_ty_from_kind(ty::Adt(*def, poly_substs))); + poly_param_env.and(cx.tcx.mk_ty_from_kind(ty::Adt(*def, poly_args))); if poly_poly_ty != poly_ty { match cx.drop_adjustment(poly_poly_ty) { Err(Error::TooGeneric) => (), @@ -397,7 +396,7 @@ memoize!( } } - // If that fails, we try to use the substs. + // If that fails, we try to use the args. // Fallthrough to the MIR drop shim based logic. if let Some(adj) = cx.drop_preemption_count_annotation(def.did()).adjustment { @@ -462,8 +461,8 @@ memoize!( // Do not call `resolve_drop_in_place` because we need param_env. let drop_in_place = cx.require_lang_item(LangItem::DropInPlace, None); - let substs = cx.mk_substs(&[ty.into()]); - let instance = ty::Instance::resolve(cx.tcx, param_env, drop_in_place, substs) + let args = cx.mk_args(&[ty.into()]); + let instance = ty::Instance::resolve(cx.tcx, param_env, drop_in_place, args) .unwrap() .unwrap(); let poly_instance = param_env.and(instance); @@ -547,13 +546,12 @@ memoize!( ty::Adt(def, _) if def.is_box() => return Ok(()), ty::Adt(def, _) => { - // For Adts, we first try to not use any of the substs and just try the most + // For Adts, we first try to not use any of the args and just try the most // polymorphic version of the type. let poly_param_env = cx.param_env_reveal_all_normalized(def.did()); - let poly_substs = - cx.erase_regions(InternalSubsts::identity_for_item(cx.tcx, def.did())); + let poly_args = cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, def.did())); let poly_poly_ty = - poly_param_env.and(cx.tcx.mk_ty_from_kind(ty::Adt(*def, poly_substs))); + poly_param_env.and(cx.tcx.mk_ty_from_kind(ty::Adt(*def, poly_args))); if poly_poly_ty != poly_ty { match cx.drop_adjustment_check(poly_poly_ty) { Err(Error::TooGeneric) => (), @@ -561,7 +559,7 @@ memoize!( } } - // If that fails, we try to use the substs. + // If that fails, we try to use the args. // Fallthrough to the MIR drop shim based logic. annotation = cx.drop_preemption_count_annotation(def.did()); @@ -581,8 +579,8 @@ memoize!( // Do not call `resolve_drop_in_place` because we need param_env. let drop_in_place = cx.require_lang_item(LangItem::DropInPlace, None); - let substs = cx.mk_substs(&[ty.into()]); - let instance = ty::Instance::resolve(cx.tcx, param_env, drop_in_place, substs) + let args = cx.mk_args(&[ty.into()]); + let instance = ty::Instance::resolve(cx.tcx, param_env, drop_in_place, args) .unwrap() .unwrap(); @@ -636,13 +634,11 @@ memoize!( let mut generic = false; if matches!(instance.def, ty::InstanceDef::Item(_)) { - let poly_param_env = cx - .param_env_reveal_all_normalized(instance.def_id()) - .with_constness(Constness::NotConst); - let poly_substs = - cx.erase_regions(InternalSubsts::identity_for_item(cx.tcx, instance.def_id())); + let poly_param_env = cx.param_env_reveal_all_normalized(instance.def_id()); + let poly_args = + cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, instance.def_id())); let poly_poly_instance = - poly_param_env.and(Instance::new(instance.def_id(), poly_substs)); + poly_param_env.and(Instance::new(instance.def_id(), poly_args)); generic = poly_poly_instance == poly_instance; if !generic { match cx.instance_adjustment(poly_poly_instance) { @@ -781,13 +777,11 @@ memoize!( // Prefer to do polymorphic check if possible. if matches!(instance.def, ty::InstanceDef::Item(_)) { - let poly_param_env = cx - .param_env_reveal_all_normalized(instance.def_id()) - .with_constness(Constness::NotConst); - let poly_substs = - cx.erase_regions(InternalSubsts::identity_for_item(cx.tcx, instance.def_id())); + let poly_param_env = cx.param_env_reveal_all_normalized(instance.def_id()); + let poly_args = + cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, instance.def_id())); let poly_poly_instance = - poly_param_env.and(Instance::new(instance.def_id(), poly_substs)); + poly_param_env.and(Instance::new(instance.def_id(), poly_args)); let generic = poly_poly_instance == poly_instance; if !generic { match cx.instance_adjustment_check(poly_poly_instance) { diff --git a/src/preempt_count/check.rs b/src/preempt_count/check.rs index 72272ef..8394cc5 100644 --- a/src/preempt_count/check.rs +++ b/src/preempt_count/check.rs @@ -1,13 +1,13 @@ use super::*; use crate::ctxt::AnalysisCtxt; use rustc_hir::def_id::DefId; -use rustc_hir::{Constness, LangItem}; +use rustc_hir::LangItem; use rustc_infer::traits::util::PredicateSet; use rustc_middle::mir::interpret::{AllocId, ConstValue, ErrorHandled, GlobalAlloc, Scalar}; use rustc_middle::mir::{self, visit::Visitor as MirVisitor, Body, Location}; use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::{ - self, GenericParamDefKind, Instance, InternalSubsts, ParamEnv, ParamEnvAnd, ToPredicate, Ty, + self, GenericArgs, GenericParamDefKind, Instance, ParamEnv, ParamEnvAnd, ToPredicate, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, }; @@ -155,11 +155,10 @@ impl<'mir, 'tcx, 'cx> MirNeighborVisitor<'mir, 'tcx, 'cx> { ) => { let fn_ty = operand.ty(self.body, self.cx.tcx); let fn_ty = self.monomorphize(fn_ty); - if let ty::FnDef(def_id, substs) = *fn_ty.kind() { - let instance = - ty::Instance::resolve(self.cx.tcx, self.param_env, def_id, substs) - .unwrap() - .ok_or(Error::TooGeneric)?; + if let ty::FnDef(def_id, args) = *fn_ty.kind() { + let instance = ty::Instance::resolve(self.cx.tcx, self.param_env, def_id, args) + .unwrap() + .ok_or(Error::TooGeneric)?; self.check_fn_pointer_cast(instance, span)?; } } @@ -171,11 +170,11 @@ impl<'mir, 'tcx, 'cx> MirNeighborVisitor<'mir, 'tcx, 'cx> { let source_ty = operand.ty(self.body, self.cx.tcx); let source_ty = self.monomorphize(source_ty); match *source_ty.kind() { - ty::Closure(def_id, substs) => { + ty::Closure(def_id, args) => { let instance = Instance::resolve_closure( self.cx.tcx, def_id, - substs, + args, ty::ClosureKind::FnOnce, ) .ok_or(Error::TooGeneric)?; @@ -251,11 +250,10 @@ impl<'mir, 'tcx, 'cx> MirNeighborVisitor<'mir, 'tcx, 'cx> { let callee_ty = func.ty(self.body, tcx); let callee_ty = self.monomorphize(callee_ty); - if let ty::FnDef(def_id, substs) = *callee_ty.kind() { - let instance = - ty::Instance::resolve(self.cx.tcx, self.param_env, def_id, substs) - .unwrap() - .ok_or(Error::TooGeneric)?; + if let ty::FnDef(def_id, args) = *callee_ty.kind() { + let instance = ty::Instance::resolve(self.cx.tcx, self.param_env, def_id, args) + .unwrap() + .ok_or(Error::TooGeneric)?; self.cx.call_stack.borrow_mut().push(UseSite { instance: self.param_env.and(self.instance), kind: UseSiteKind::Call(span), @@ -284,12 +282,12 @@ impl<'mir, 'tcx, 'cx> MirNeighborVisitor<'mir, 'tcx, 'cx> { match *op { mir::InlineAsmOperand::SymFn { ref value } => { let fn_ty = self.monomorphize(value.literal.ty()); - if let ty::FnDef(def_id, substs) = *fn_ty.kind() { + if let ty::FnDef(def_id, args) = *fn_ty.kind() { let instance = ty::Instance::resolve( self.cx.tcx, self.param_env, def_id, - substs, + args, ) .unwrap() .ok_or(Error::TooGeneric)?; @@ -531,18 +529,18 @@ memoize!( } for &entry in cx.own_existential_vtable_entries(trait_ref.def_id()) { - let substs = trait_ref.map_bound(|trait_ref| { - InternalSubsts::for_item(cx.tcx, entry, |param, _| match param.kind { + let args = trait_ref.map_bound(|trait_ref| { + GenericArgs::for_item(cx.tcx, entry, |param, _| match param.kind { GenericParamDefKind::Lifetime => cx.tcx.lifetimes.re_erased.into(), GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => { - trait_ref.substs[param.index as usize] + trait_ref.args[param.index as usize] } }) }); - let substs = cx.normalize_erasing_late_bound_regions(param_env, substs); + let args = cx.normalize_erasing_late_bound_regions(param_env, args); - let predicates = cx.predicates_of(entry).instantiate_own(cx.tcx, substs); + let predicates = cx.predicates_of(entry).instantiate_own(cx.tcx, args); if rustc_trait_selection::traits::impossible_predicates( cx.tcx, predicates.map(|(predicate, _)| predicate).collect(), @@ -550,7 +548,7 @@ memoize!( continue; } - let instance = ty::Instance::resolve(cx.tcx, param_env, entry, substs) + let instance = ty::Instance::resolve(cx.tcx, param_env, entry, args) .unwrap() .ok_or(Error::TooGeneric)?; let poly_instance = param_env.and(instance); @@ -668,8 +666,8 @@ memoize!( } match ty.kind() { - ty::Closure(_, substs) => { - return cx.drop_check(param_env.and(substs.as_closure().tupled_upvars_ty())); + ty::Closure(_, args) => { + return cx.drop_check(param_env.and(args.as_closure().tupled_upvars_ty())); } // Generator drops are non-trivial, use the generated drop shims instead. @@ -682,12 +680,12 @@ memoize!( return Ok(()); } - ty::Adt(def, substs) if def.is_box() => { - cx.drop_check(param_env.and(substs.type_at(0)))?; + ty::Adt(def, args) if def.is_box() => { + cx.drop_check(param_env.and(args.type_at(0)))?; let drop_trait = cx.require_lang_item(LangItem::Drop, None); let drop_fn = cx.associated_item_def_ids(drop_trait)[0]; let box_free = - ty::Instance::resolve(cx.tcx, param_env, drop_fn, cx.mk_substs(&[ty.into()])) + ty::Instance::resolve(cx.tcx, param_env, drop_fn, cx.mk_args(&[ty.into()])) .unwrap() .unwrap(); cx.instance_check(param_env.and(box_free))?; @@ -695,13 +693,12 @@ memoize!( } ty::Adt(def, _) => { - // For Adts, we first try to not use any of the substs and just try the most + // For Adts, we first try to not use any of the args and just try the most // polymorphic version of the type. let poly_param_env = cx.param_env_reveal_all_normalized(def.did()); - let poly_substs = - cx.erase_regions(InternalSubsts::identity_for_item(cx.tcx, def.did())); + let poly_args = cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, def.did())); let poly_poly_ty = - poly_param_env.and(cx.tcx.mk_ty_from_kind(ty::Adt(*def, poly_substs))); + poly_param_env.and(cx.tcx.mk_ty_from_kind(ty::Adt(*def, poly_args))); if poly_poly_ty != poly_ty { match cx.drop_check(poly_poly_ty) { Err(Error::TooGeneric) => (), @@ -709,7 +706,7 @@ memoize!( } } - // If that fails, we try to use the substs. + // If that fails, we try to use the args. // Fallthrough to the MIR drop shim based logic. } @@ -725,8 +722,8 @@ memoize!( // Do not call `resolve_drop_in_place` because we need param_env. let drop_in_place = cx.require_lang_item(LangItem::DropInPlace, None); - let substs = cx.mk_substs(&[ty.into()]); - let instance = ty::Instance::resolve(cx.tcx, param_env, drop_in_place, substs) + let args = cx.mk_args(&[ty.into()]); + let instance = ty::Instance::resolve(cx.tcx, param_env, drop_in_place, args) .unwrap() .unwrap(); let poly_instance = param_env.and(instance); @@ -780,13 +777,11 @@ memoize!( } if matches!(instance.def, ty::InstanceDef::Item(_)) { - let poly_param_env = cx - .param_env_reveal_all_normalized(instance.def_id()) - .with_constness(Constness::NotConst); - let poly_substs = - cx.erase_regions(InternalSubsts::identity_for_item(cx.tcx, instance.def_id())); + let poly_param_env = cx.param_env_reveal_all_normalized(instance.def_id()); + let poly_args = + cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, instance.def_id())); let poly_poly_instance = - poly_param_env.and(Instance::new(instance.def_id(), poly_substs)); + poly_param_env.and(Instance::new(instance.def_id(), poly_args)); let generic = poly_poly_instance == poly_instance; if !generic { match cx.instance_check(poly_poly_instance) { diff --git a/src/preempt_count/dataflow.rs b/src/preempt_count/dataflow.rs index acf9a44..b09fba7 100644 --- a/src/preempt_count/dataflow.rs +++ b/src/preempt_count/dataflow.rs @@ -245,19 +245,14 @@ impl<'tcx> Analysis<'tcx> for AdjustmentComputation<'_, 'tcx, '_> { self.param_env, ty::EarlyBinder::bind(callee_ty), ); - if let ty::FnDef(def_id, substs) = *callee_ty.kind() { + if let ty::FnDef(def_id, args) = *callee_ty.kind() { if let Some(v) = self.checker.preemption_count_annotation(def_id).adjustment { // Fast path, no need to resolve the instance. // This also avoids `TooGeneric` when def_id is an trait method. Ok(v) } else { - match ty::Instance::resolve( - self.checker.tcx, - self.param_env, - def_id, - substs, - ) - .unwrap() + match ty::Instance::resolve(self.checker.tcx, self.param_env, def_id, args) + .unwrap() { Some(instance) => { self.checker.call_stack.borrow_mut().push(UseSite { diff --git a/src/preempt_count/expectation.rs b/src/preempt_count/expectation.rs index d1b79cd..a59a4f6 100644 --- a/src/preempt_count/expectation.rs +++ b/src/preempt_count/expectation.rs @@ -1,8 +1,8 @@ use rustc_errors::{EmissionGuarantee, MultiSpan}; use rustc_hir::def_id::CrateNum; -use rustc_hir::{Constness, LangItem}; +use rustc_hir::LangItem; use rustc_middle::mir::{self, Body, TerminatorKind}; -use rustc_middle::ty::{self, Instance, InternalSubsts, ParamEnv, ParamEnvAnd, Ty}; +use rustc_middle::ty::{self, GenericArgs, Instance, ParamEnv, ParamEnvAnd, Ty}; use rustc_mir_dataflow::lattice::MeetSemiLattice; use rustc_mir_dataflow::Analysis; use rustc_span::DUMMY_SP; @@ -27,14 +27,14 @@ impl<'tcx> AnalysisCtxt<'tcx> { param_env, ty::EarlyBinder::bind(callee_ty), ); - if let ty::FnDef(def_id, substs) = *callee_ty.kind() { + if let ty::FnDef(def_id, args) = *callee_ty.kind() { if let Some(v) = self.preemption_count_annotation(def_id).expectation { // Fast path, no need to resolve the instance. // This also avoids `TooGeneric` when def_id is an trait method. v } else { let callee_instance = - ty::Instance::resolve(self.tcx, param_env, def_id, substs) + ty::Instance::resolve(self.tcx, param_env, def_id, args) .unwrap() .ok_or(Error::TooGeneric)?; self.call_stack.borrow_mut().push(UseSite { @@ -125,7 +125,7 @@ impl<'tcx> AnalysisCtxt<'tcx> { param_env, ty::EarlyBinder::bind(callee_ty), ); - if let ty::FnDef(def_id, substs) = *callee_ty.kind() { + if let ty::FnDef(def_id, args) = *callee_ty.kind() { if let Some(v) = self.preemption_count_annotation(def_id).expectation { if !span.has_primary_spans() { span = self.def_span(def_id).into(); @@ -142,7 +142,7 @@ impl<'tcx> AnalysisCtxt<'tcx> { return Ok(()); } else { let callee_instance = - ty::Instance::resolve(self.tcx, param_env, def_id, substs) + ty::Instance::resolve(self.tcx, param_env, def_id, args) .unwrap() .ok_or(Error::TooGeneric)?; @@ -326,10 +326,10 @@ impl<'tcx> AnalysisCtxt<'tcx> { assert!(ty.needs_drop(self.tcx, param_env)); match ty.kind() { - ty::Closure(_, substs) => { + ty::Closure(_, args) => { return self.report_drop_expectation_error( param_env, - substs.as_closure().tupled_upvars_ty(), + args.as_closure().tupled_upvars_ty(), expected, span, diag, @@ -341,29 +341,25 @@ impl<'tcx> AnalysisCtxt<'tcx> { ty::Tuple(_list) => (), - ty::Adt(def, substs) if def.is_box() => { - let exp = self.drop_expectation(param_env.and(substs.type_at(0)))?; + ty::Adt(def, args) if def.is_box() => { + let exp = self.drop_expectation(param_env.and(args.type_at(0)))?; if !exp.contains_range(expected) { return self.report_drop_expectation_error( param_env, - substs.type_at(0), + args.type_at(0), expected, span, diag, ); } - let adj = self.drop_adjustment(param_env.and(substs.type_at(0)))?; + let adj = self.drop_adjustment(param_env.and(args.type_at(0)))?; let drop_trait = self.require_lang_item(LangItem::Drop, None); let drop_fn = self.associated_item_def_ids(drop_trait)[0]; - let box_free = ty::Instance::resolve( - self.tcx, - param_env, - drop_fn, - self.mk_substs(&[ty.into()]), - ) - .unwrap() - .unwrap(); + let box_free = + ty::Instance::resolve(self.tcx, param_env, drop_fn, self.mk_args(&[ty.into()])) + .unwrap() + .unwrap(); return self.report_instance_expectation_error( param_env, box_free, @@ -448,8 +444,8 @@ impl<'tcx> AnalysisCtxt<'tcx> { // Do not call `resolve_drop_in_place` because we need param_env. let drop_in_place = self.require_lang_item(LangItem::DropInPlace, None); - let substs = self.mk_substs(&[ty.into()]); - let instance = ty::Instance::resolve(self.tcx, param_env, drop_in_place, substs) + let args = self.mk_args(&[ty.into()]); + let instance = ty::Instance::resolve(self.tcx, param_env, drop_in_place, args) .unwrap() .unwrap(); @@ -504,14 +500,14 @@ impl<'tcx> AnalysisCtxt<'tcx> { param_env, ty::EarlyBinder::bind(callee_ty), ); - if let ty::FnDef(def_id, substs) = *callee_ty.kind() { + if let ty::FnDef(def_id, args) = *callee_ty.kind() { if let Some(v) = self.preemption_count_annotation(def_id).expectation { // Fast path, no need to resolve the instance. // This also avoids `TooGeneric` when def_id is an trait method. v } else { let callee_instance = - ty::Instance::resolve(self.tcx, param_env, def_id, substs) + ty::Instance::resolve(self.tcx, param_env, def_id, args) .unwrap() .ok_or(Error::TooGeneric)?; self.call_stack.borrow_mut().push(UseSite { @@ -637,8 +633,8 @@ memoize!( } match ty.kind() { - ty::Closure(_, substs) => { - return cx.drop_expectation(param_env.and(substs.as_closure().tupled_upvars_ty())); + ty::Closure(_, args) => { + return cx.drop_expectation(param_env.and(args.as_closure().tupled_upvars_ty())); } // Generator drops are non-trivial, use the generated drop shims instead. @@ -646,12 +642,12 @@ memoize!( ty::Tuple(_list) => (), - ty::Adt(def, substs) if def.is_box() => { - let exp = cx.drop_expectation(param_env.and(substs.type_at(0)))?; + ty::Adt(def, args) if def.is_box() => { + let exp = cx.drop_expectation(param_env.and(args.type_at(0)))?; let drop_trait = cx.require_lang_item(LangItem::Drop, None); let drop_fn = cx.associated_item_def_ids(drop_trait)[0]; let box_free = - ty::Instance::resolve(cx.tcx, param_env, drop_fn, cx.mk_substs(&[ty.into()])) + ty::Instance::resolve(cx.tcx, param_env, drop_fn, cx.mk_args(&[ty.into()])) .unwrap() .unwrap(); let box_free_exp = cx.instance_expectation(param_env.and(box_free))?; @@ -661,7 +657,7 @@ memoize!( return Ok(exp); } - let adj = cx.drop_adjustment(param_env.and(substs.type_at(0)))?; + let adj = cx.drop_adjustment(param_env.and(args.type_at(0)))?; let adj_bound = AdjustmentBounds::single_value(adj); let mut expected = box_free_exp - adj_bound; @@ -675,7 +671,7 @@ memoize!( "but the possible preemption count after dropping the content is {}", exp + adj_bound )); - diag.note(format!("content being dropped is `{}`", substs.type_at(0))); + diag.note(format!("content being dropped is `{}`", args.type_at(0))); return Err(Error::Error(cx.emit_with_use_site_info(diag))); } @@ -683,13 +679,12 @@ memoize!( } ty::Adt(def, _) => { - // For Adts, we first try to not use any of the substs and just try the most + // For Adts, we first try to not use any of the args and just try the most // polymorphic version of the type. let poly_param_env = cx.param_env_reveal_all_normalized(def.did()); - let poly_substs = - cx.erase_regions(InternalSubsts::identity_for_item(cx.tcx, def.did())); + let poly_args = cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, def.did())); let poly_poly_ty = - poly_param_env.and(cx.tcx.mk_ty_from_kind(ty::Adt(*def, poly_substs))); + poly_param_env.and(cx.tcx.mk_ty_from_kind(ty::Adt(*def, poly_args))); if poly_poly_ty != poly_ty { match cx.drop_expectation(poly_poly_ty) { Err(Error::TooGeneric) => (), @@ -697,7 +692,7 @@ memoize!( } } - // If that fails, we try to use the substs. + // If that fails, we try to use the args. // Fallthrough to the MIR drop shim based logic. if let Some(exp) = cx.drop_preemption_count_annotation(def.did()).expectation { @@ -778,8 +773,8 @@ memoize!( // Do not call `resolve_drop_in_place` because we need param_env. let drop_in_place = cx.require_lang_item(LangItem::DropInPlace, None); - let substs = cx.mk_substs(&[ty.into()]); - let instance = ty::Instance::resolve(cx.tcx, param_env, drop_in_place, substs) + let args = cx.mk_args(&[ty.into()]); + let instance = ty::Instance::resolve(cx.tcx, param_env, drop_in_place, args) .unwrap() .unwrap(); let poly_instance = param_env.and(instance); @@ -868,13 +863,12 @@ memoize!( ty::Adt(def, _) if def.is_box() => return Ok(()), ty::Adt(def, _) => { - // For Adts, we first try to not use any of the substs and just try the most + // For Adts, we first try to not use any of the args and just try the most // polymorphic version of the type. let poly_param_env = cx.param_env_reveal_all_normalized(def.did()); - let poly_substs = - cx.erase_regions(InternalSubsts::identity_for_item(cx.tcx, def.did())); + let poly_args = cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, def.did())); let poly_poly_ty = - poly_param_env.and(cx.tcx.mk_ty_from_kind(ty::Adt(*def, poly_substs))); + poly_param_env.and(cx.tcx.mk_ty_from_kind(ty::Adt(*def, poly_args))); if poly_poly_ty != poly_ty { match cx.drop_expectation_check(poly_poly_ty) { Err(Error::TooGeneric) => (), @@ -882,7 +876,7 @@ memoize!( } } - // If that fails, we try to use the substs. + // If that fails, we try to use the args. // Fallthrough to the MIR drop shim based logic. annotation = cx.drop_preemption_count_annotation(def.did()); @@ -902,8 +896,8 @@ memoize!( // Do not call `resolve_drop_in_place` because we need param_env. let drop_in_place = cx.require_lang_item(LangItem::DropInPlace, None); - let substs = cx.mk_substs(&[ty.into()]); - let instance = ty::Instance::resolve(cx.tcx, param_env, drop_in_place, substs) + let args = cx.mk_args(&[ty.into()]); + let instance = ty::Instance::resolve(cx.tcx, param_env, drop_in_place, args) .unwrap() .unwrap(); @@ -960,13 +954,11 @@ memoize!( let mut generic = false; if matches!(instance.def, ty::InstanceDef::Item(_)) { - let poly_param_env = cx - .param_env_reveal_all_normalized(instance.def_id()) - .with_constness(Constness::NotConst); - let poly_substs = - cx.erase_regions(InternalSubsts::identity_for_item(cx.tcx, instance.def_id())); + let poly_param_env = cx.param_env_reveal_all_normalized(instance.def_id()); + let poly_args = + cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, instance.def_id())); let poly_poly_instance = - poly_param_env.and(Instance::new(instance.def_id(), poly_substs)); + poly_param_env.and(Instance::new(instance.def_id(), poly_args)); generic = poly_poly_instance == poly_instance; if !generic { match cx.instance_expectation(poly_poly_instance) { @@ -1117,13 +1109,11 @@ memoize!( // Prefer to do polymorphic check if possible. if matches!(instance.def, ty::InstanceDef::Item(_)) { - let poly_param_env = cx - .param_env_reveal_all_normalized(instance.def_id()) - .with_constness(Constness::NotConst); - let poly_substs = - cx.erase_regions(InternalSubsts::identity_for_item(cx.tcx, instance.def_id())); + let poly_param_env = cx.param_env_reveal_all_normalized(instance.def_id()); + let poly_args = + cx.erase_regions(GenericArgs::identity_for_item(cx.tcx, instance.def_id())); let poly_poly_instance = - poly_param_env.and(Instance::new(instance.def_id(), poly_substs)); + poly_param_env.and(Instance::new(instance.def_id(), poly_args)); let generic = poly_poly_instance == poly_instance; if !generic { match cx.instance_expectation_check(poly_poly_instance) { diff --git a/src/serde.rs b/src/serde.rs index 2a11fc2..9c16604 100644 --- a/src/serde.rs +++ b/src/serde.rs @@ -276,7 +276,7 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> { let vec_position = u64::from_le_bytes(bytes[bytes.len() - 8..].try_into().unwrap()) as usize; let mut decoder = MemDecoder::new(bytes, vec_position); - let interpret_alloc_index = Vec::::decode(&mut decoder); + let interpret_alloc_index = Vec::::decode(&mut decoder); let alloc_decoding_state = Lrc::new(interpret::AllocDecodingState::new(interpret_alloc_index));