Skip to content

Commit

Permalink
Upgrade to Rust 1.73
Browse files Browse the repository at this point in the history
  • Loading branch information
nbdd0121 committed Jul 29, 2023
1 parent f1f25e7 commit 155a128
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 180 deletions.
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "beta"
channel = "nightly"
components = ["llvm-tools-preview", "rustc-dev", "rust-src"]
7 changes: 3 additions & 4 deletions src/atomic_context.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
Expand Down
18 changes: 6 additions & 12 deletions src/infallible_allocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,20 @@ 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()
};

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,
Expand All @@ -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)
Expand All @@ -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)
),
);
}
Expand Down Expand Up @@ -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";
Expand Down
8 changes: 4 additions & 4 deletions src/mir/drop_shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
35 changes: 17 additions & 18 deletions src/monomorphize_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -713,12 +713,11 @@ fn visit_fn_use<'tcx>(
source: Span,
output: &mut Vec<Spanned<MonoItem<'tcx>>>,
) {
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}"),
}
Expand Down Expand Up @@ -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) =
Expand All @@ -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!(
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand Down
64 changes: 29 additions & 35 deletions src/preempt_count/adjustment.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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<G: EmissionGuarantee>(
Expand Down Expand Up @@ -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.
Expand All @@ -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))?;
Expand All @@ -383,21 +383,20 @@ 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) => (),
adjustment => return adjustment,
}
}

// 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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -547,21 +546,20 @@ 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) => (),
result => return result,
}
}

// 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());
Expand All @@ -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();

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
Loading

0 comments on commit 155a128

Please sign in to comment.