refactor(rustc_middle): Substs -> GenericArg
This commit is contained in:
parent
df5c2cf9bc
commit
e55583c4b8
466 changed files with 4574 additions and 4604 deletions
|
@ -27,8 +27,8 @@ pub fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) ->
|
|||
|
||||
debug!("get_fn(instance={:?})", instance);
|
||||
|
||||
assert!(!instance.substs.has_infer());
|
||||
assert!(!instance.substs.has_escaping_bound_vars());
|
||||
assert!(!instance.args.has_infer());
|
||||
assert!(!instance.args.has_escaping_bound_vars());
|
||||
|
||||
if let Some(&llfn) = cx.instances.borrow().get(&instance) {
|
||||
return llfn;
|
||||
|
@ -129,7 +129,7 @@ pub fn get_fn<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) ->
|
|||
unsafe {
|
||||
llvm::LLVMRustSetLinkage(llfn, llvm::Linkage::ExternalLinkage);
|
||||
|
||||
let is_generic = instance.substs.non_erasable_generics().next().is_some();
|
||||
let is_generic = instance.args.non_erasable_generics().next().is_some();
|
||||
|
||||
if is_generic {
|
||||
// This is a monomorphization. Its expected visibility depends
|
||||
|
|
|
@ -22,7 +22,7 @@ use rustc_middle::mir::coverage::{
|
|||
use rustc_middle::mir::Coverage;
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::layout::{FnAbiOf, HasTyCtxt};
|
||||
use rustc_middle::ty::subst::InternalSubsts;
|
||||
use rustc_middle::ty::GenericArgs;
|
||||
use rustc_middle::ty::Instance;
|
||||
use rustc_middle::ty::Ty;
|
||||
|
||||
|
@ -250,7 +250,7 @@ fn declare_unused_fn<'tcx>(cx: &CodegenCx<'_, 'tcx>, def_id: DefId) -> Instance<
|
|||
|
||||
let instance = Instance::new(
|
||||
def_id,
|
||||
InternalSubsts::for_item(tcx, def_id, |param, _| {
|
||||
GenericArgs::for_item(tcx, def_id, |param, _| {
|
||||
if let ty::GenericParamDefKind::Lifetime = param.kind {
|
||||
tcx.lifetimes.re_erased.into()
|
||||
} else {
|
||||
|
|
|
@ -91,7 +91,7 @@ fn make_mir_scope<'ll, 'tcx>(
|
|||
// FIXME(eddyb) this would be `self.monomorphize(&callee)`
|
||||
// if this is moved to `rustc_codegen_ssa::mir::debuginfo`.
|
||||
let callee = cx.tcx.subst_and_normalize_erasing_regions(
|
||||
instance.substs,
|
||||
instance.args,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
ty::EarlyBinder::bind(callee),
|
||||
);
|
||||
|
|
|
@ -449,7 +449,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
|
|||
}
|
||||
// Box<T, A> may have a non-ZST allocator A. In that case, we
|
||||
// cannot treat Box<T, A> as just an owned alias of `*mut T`.
|
||||
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
|
||||
ty::Adt(def, args) if def.is_box() && cx.layout_of(args.type_at(1)).is_zst() => {
|
||||
build_pointer_or_reference_di_node(cx, t, t.boxed_ty(), unique_type_id)
|
||||
}
|
||||
ty::FnDef(..) | ty::FnPtr(_) => build_subroutine_type_di_node(cx, unique_type_id),
|
||||
|
@ -1007,12 +1007,12 @@ fn build_upvar_field_di_nodes<'ll, 'tcx>(
|
|||
closure_or_generator_di_node: &'ll DIType,
|
||||
) -> SmallVec<&'ll DIType> {
|
||||
let (&def_id, up_var_tys) = match closure_or_generator_ty.kind() {
|
||||
ty::Generator(def_id, substs, _) => {
|
||||
let upvar_tys: SmallVec<_> = substs.as_generator().prefix_tys().collect();
|
||||
ty::Generator(def_id, args, _) => {
|
||||
let upvar_tys: SmallVec<_> = args.as_generator().prefix_tys().collect();
|
||||
(def_id, upvar_tys)
|
||||
}
|
||||
ty::Closure(def_id, substs) => {
|
||||
let upvar_tys: SmallVec<_> = substs.as_closure().upvar_tys().collect();
|
||||
ty::Closure(def_id, args) => {
|
||||
let upvar_tys: SmallVec<_> = args.as_closure().upvar_tys().collect();
|
||||
(def_id, upvar_tys)
|
||||
}
|
||||
_ => {
|
||||
|
@ -1102,7 +1102,7 @@ fn build_closure_env_di_node<'ll, 'tcx>(
|
|||
unique_type_id: UniqueTypeId<'tcx>,
|
||||
) -> DINodeCreationResult<'ll> {
|
||||
let closure_env_type = unique_type_id.expect_ty();
|
||||
let &ty::Closure(def_id, _substs) = closure_env_type.kind() else {
|
||||
let &ty::Closure(def_id, _args) = closure_env_type.kind() else {
|
||||
bug!("build_closure_env_di_node() called with non-closure-type: {:?}", closure_env_type)
|
||||
};
|
||||
let containing_scope = get_namespace_for_item(cx, def_id);
|
||||
|
@ -1180,11 +1180,11 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
|
|||
cx: &CodegenCx<'ll, 'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
) -> SmallVec<&'ll DIType> {
|
||||
if let ty::Adt(def, substs) = *ty.kind() {
|
||||
if substs.types().next().is_some() {
|
||||
if let ty::Adt(def, args) = *ty.kind() {
|
||||
if args.types().next().is_some() {
|
||||
let generics = cx.tcx.generics_of(def.did());
|
||||
let names = get_parameter_names(cx, generics);
|
||||
let template_params: SmallVec<_> = iter::zip(substs, names)
|
||||
let template_params: SmallVec<_> = iter::zip(args, names)
|
||||
.filter_map(|(kind, name)| {
|
||||
kind.as_type().map(|ty| {
|
||||
let actual_type =
|
||||
|
|
|
@ -12,7 +12,7 @@ use rustc_middle::{
|
|||
ty::{
|
||||
self,
|
||||
layout::{LayoutOf, TyAndLayout},
|
||||
AdtDef, GeneratorSubsts, Ty,
|
||||
AdtDef, GeneratorArgs, Ty,
|
||||
},
|
||||
};
|
||||
use rustc_target::abi::{Align, Endian, Size, TagEncoding, VariantIdx, Variants};
|
||||
|
@ -673,15 +673,15 @@ fn build_union_fields_for_direct_tag_generator<'ll, 'tcx>(
|
|||
bug!("This function only supports layouts with directly encoded tags.")
|
||||
};
|
||||
|
||||
let (generator_def_id, generator_substs) = match generator_type_and_layout.ty.kind() {
|
||||
&ty::Generator(def_id, substs, _) => (def_id, substs.as_generator()),
|
||||
let (generator_def_id, generator_args) = match generator_type_and_layout.ty.kind() {
|
||||
&ty::Generator(def_id, args, _) => (def_id, args.as_generator()),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
let generator_layout = cx.tcx.optimized_mir(generator_def_id).generator_layout().unwrap();
|
||||
|
||||
let common_upvar_names = cx.tcx.closure_saved_names_of_captured_variables(generator_def_id);
|
||||
let variant_range = generator_substs.variant_range(generator_def_id, cx.tcx);
|
||||
let variant_range = generator_args.variant_range(generator_def_id, cx.tcx);
|
||||
let variant_count = (variant_range.start.as_u32()..variant_range.end.as_u32()).len();
|
||||
|
||||
let tag_base_type = tag_base_type(cx, generator_type_and_layout);
|
||||
|
@ -691,11 +691,11 @@ fn build_union_fields_for_direct_tag_generator<'ll, 'tcx>(
|
|||
generator_type_di_node,
|
||||
variant_range
|
||||
.clone()
|
||||
.map(|variant_index| (variant_index, GeneratorSubsts::variant_name(variant_index))),
|
||||
.map(|variant_index| (variant_index, GeneratorArgs::variant_name(variant_index))),
|
||||
);
|
||||
|
||||
let discriminants: IndexVec<VariantIdx, DiscrResult> = {
|
||||
let discriminants_iter = generator_substs.discriminants(generator_def_id, cx.tcx);
|
||||
let discriminants_iter = generator_args.discriminants(generator_def_id, cx.tcx);
|
||||
let mut discriminants: IndexVec<VariantIdx, DiscrResult> =
|
||||
IndexVec::with_capacity(variant_count);
|
||||
for (variant_index, discr) in discriminants_iter {
|
||||
|
|
|
@ -10,7 +10,7 @@ use rustc_middle::{
|
|||
ty::{
|
||||
self,
|
||||
layout::{IntegerExt, LayoutOf, PrimitiveExt, TyAndLayout},
|
||||
AdtDef, GeneratorSubsts, Ty, VariantDef,
|
||||
AdtDef, GeneratorArgs, Ty, VariantDef,
|
||||
},
|
||||
};
|
||||
use rustc_span::Symbol;
|
||||
|
@ -325,7 +325,7 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>(
|
|||
generator_layout: &GeneratorLayout<'tcx>,
|
||||
common_upvar_names: &IndexSlice<FieldIdx, Symbol>,
|
||||
) -> &'ll DIType {
|
||||
let variant_name = GeneratorSubsts::variant_name(variant_index);
|
||||
let variant_name = GeneratorArgs::variant_name(variant_index);
|
||||
let unique_type_id = UniqueTypeId::for_enum_variant_struct_type(
|
||||
cx.tcx,
|
||||
generator_type_and_layout.ty,
|
||||
|
@ -334,8 +334,8 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>(
|
|||
|
||||
let variant_layout = generator_type_and_layout.for_variant(cx, variant_index);
|
||||
|
||||
let generator_substs = match generator_type_and_layout.ty.kind() {
|
||||
ty::Generator(_, substs, _) => substs.as_generator(),
|
||||
let generator_args = match generator_type_and_layout.ty.kind() {
|
||||
ty::Generator(_, args, _) => args.as_generator(),
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
|
@ -377,7 +377,7 @@ pub fn build_generator_variant_struct_type_di_node<'ll, 'tcx>(
|
|||
.collect();
|
||||
|
||||
// Fields that are common to all states
|
||||
let common_fields: SmallVec<_> = generator_substs
|
||||
let common_fields: SmallVec<_> = generator_args
|
||||
.prefix_tys()
|
||||
.zip(common_upvar_names)
|
||||
.enumerate()
|
||||
|
|
|
@ -175,7 +175,7 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
|
|||
.indices()
|
||||
.map(|variant_index| {
|
||||
// FIXME: This is problematic because just a number is not a valid identifier.
|
||||
// GeneratorSubsts::variant_name(variant_index), would be consistent
|
||||
// GeneratorArgs::variant_name(variant_index), would be consistent
|
||||
// with enums?
|
||||
let variant_name = format!("{}", variant_index.as_usize()).into();
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ use rustc_hir::def_id::{DefId, DefIdMap};
|
|||
use rustc_index::IndexVec;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::ty::layout::LayoutOf;
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::GenericArgsRef;
|
||||
use rustc_middle::ty::{self, Instance, ParamEnv, Ty, TypeVisitableExt};
|
||||
use rustc_session::config::{self, DebugInfo};
|
||||
use rustc_session::Session;
|
||||
|
@ -338,19 +338,19 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
|||
// Find the enclosing function, in case this is a closure.
|
||||
let enclosing_fn_def_id = tcx.typeck_root_def_id(def_id);
|
||||
|
||||
// We look up the generics of the enclosing function and truncate the substs
|
||||
// We look up the generics of the enclosing function and truncate the args
|
||||
// to their length in order to cut off extra stuff that might be in there for
|
||||
// closures or generators.
|
||||
let generics = tcx.generics_of(enclosing_fn_def_id);
|
||||
let substs = instance.substs.truncate_to(tcx, generics);
|
||||
let args = instance.args.truncate_to(tcx, generics);
|
||||
|
||||
type_names::push_generic_params(
|
||||
tcx,
|
||||
tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), substs),
|
||||
tcx.normalize_erasing_regions(ty::ParamEnv::reveal_all(), args),
|
||||
&mut name,
|
||||
);
|
||||
|
||||
let template_parameters = get_template_parameters(self, generics, substs);
|
||||
let template_parameters = get_template_parameters(self, generics, args);
|
||||
|
||||
let linkage_name = &mangled_name_of_instance(self, instance).name;
|
||||
// Omit the linkage_name if it is the same as subprogram name.
|
||||
|
@ -471,16 +471,16 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
|||
fn get_template_parameters<'ll, 'tcx>(
|
||||
cx: &CodegenCx<'ll, 'tcx>,
|
||||
generics: &ty::Generics,
|
||||
substs: SubstsRef<'tcx>,
|
||||
args: GenericArgsRef<'tcx>,
|
||||
) -> &'ll DIArray {
|
||||
if substs.types().next().is_none() {
|
||||
if args.types().next().is_none() {
|
||||
return create_DIArray(DIB(cx), &[]);
|
||||
}
|
||||
|
||||
// Again, only create type information if full debuginfo is enabled
|
||||
let template_params: Vec<_> = if cx.sess().opts.debuginfo == DebugInfo::Full {
|
||||
let names = get_parameter_names(cx, generics);
|
||||
iter::zip(substs, names)
|
||||
iter::zip(args, names)
|
||||
.filter_map(|(kind, name)| {
|
||||
kind.as_type().map(|ty| {
|
||||
let actual_type =
|
||||
|
@ -527,7 +527,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
|||
// If the method does *not* belong to a trait, proceed
|
||||
if cx.tcx.trait_id_of_impl(impl_def_id).is_none() {
|
||||
let impl_self_ty = cx.tcx.subst_and_normalize_erasing_regions(
|
||||
instance.substs,
|
||||
instance.args,
|
||||
ty::ParamEnv::reveal_all(),
|
||||
cx.tcx.type_of(impl_def_id),
|
||||
);
|
||||
|
|
|
@ -90,7 +90,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
|||
let tcx = self.tcx;
|
||||
let callee_ty = instance.ty(tcx, ty::ParamEnv::reveal_all());
|
||||
|
||||
let ty::FnDef(def_id, substs) = *callee_ty.kind() else {
|
||||
let ty::FnDef(def_id, fn_args) = *callee_ty.kind() else {
|
||||
bug!("expected fn item type, found {}", callee_ty);
|
||||
};
|
||||
|
||||
|
@ -163,7 +163,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
|||
}
|
||||
|
||||
sym::volatile_load | sym::unaligned_volatile_load => {
|
||||
let tp_ty = substs.type_at(0);
|
||||
let tp_ty = fn_args.type_at(0);
|
||||
let ptr = args[0].immediate();
|
||||
let load = if let PassMode::Cast(ty, _) = &fn_abi.ret.mode {
|
||||
let llty = ty.llvm_type(self);
|
||||
|
@ -298,7 +298,7 @@ impl<'ll, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'_, 'll, 'tcx> {
|
|||
|
||||
sym::raw_eq => {
|
||||
use abi::Abi::*;
|
||||
let tp_ty = substs.type_at(0);
|
||||
let tp_ty = fn_args.type_at(0);
|
||||
let layout = self.layout_of(tp_ty).layout;
|
||||
let use_integer_compare = match layout.abi() {
|
||||
Scalar(_) | ScalarPair(_, _) => true,
|
||||
|
|
|
@ -48,7 +48,7 @@ impl<'tcx> PreDefineMethods<'tcx> for CodegenCx<'_, 'tcx> {
|
|||
visibility: Visibility,
|
||||
symbol_name: &str,
|
||||
) {
|
||||
assert!(!instance.substs.has_infer());
|
||||
assert!(!instance.args.has_infer());
|
||||
|
||||
let fn_abi = self.fn_abi_of_instance(instance, ty::List::empty());
|
||||
let lldecl = self.declare_fn(symbol_name, fn_abi, Some(instance));
|
||||
|
|
|
@ -57,7 +57,7 @@ fn uncached_llvm_type<'a, 'tcx>(
|
|||
if let (&ty::Generator(_, _, _), &Variants::Single { index }) =
|
||||
(layout.ty.kind(), &layout.variants)
|
||||
{
|
||||
write!(&mut name, "::{}", ty::GeneratorSubsts::variant_name(index)).unwrap();
|
||||
write!(&mut name, "::{}", ty::GeneratorArgs::variant_name(index)).unwrap();
|
||||
}
|
||||
Some(name)
|
||||
}
|
||||
|
@ -336,7 +336,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
|
|||
}
|
||||
// only wide pointer boxes are handled as pointers
|
||||
// thin pointer boxes with scalar allocators are handled by the general logic below
|
||||
ty::Adt(def, substs) if def.is_box() && cx.layout_of(substs.type_at(1)).is_zst() => {
|
||||
ty::Adt(def, args) if def.is_box() && cx.layout_of(args.type_at(1)).is_zst() => {
|
||||
let ptr_ty = Ty::new_mut_ptr(cx.tcx, self.ty.boxed_ty());
|
||||
return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue