Skip to content

Commit

Permalink
Auto merge of #75077 - LeSeulArtichaut:tys-kind, r=nikomatsakis
Browse files Browse the repository at this point in the history
Refractor ty.kind -> ty.kind() and ty.flags -> ty.flags()

First step for the ["shared library to represent Rust types"](https://rust-lang.github.io/compiler-team/minutes/design-meeting/2020-03-12-shared-library-for-types/) work (rust-lang/types-team#16).

This PR makes the `TyS::kind` field private and adds a `kind()` method to access it.
As noted [on Zulip](https://rust-lang.zulipchat.com/#narrow/stream/144729-wg-traits/topic/Looking.20to.20contribute/near/205185412), this refractoring might require a MCP. I am perfectly fine with having to wait until MCP is accepted and resolving the conflicts that pop up afterwards.

r? @nikomatsakis
  • Loading branch information
bors committed Sep 4, 2020
2 parents 80cacd7 + 4d28a82 commit d245464
Show file tree
Hide file tree
Showing 250 changed files with 1,174 additions and 1,113 deletions.
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,10 +306,10 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
use rustc_ast::UintTy::*;
use rustc_middle::ty::{Int, Uint};

let new_kind = match ty.kind {
let new_kind = match ty.kind() {
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.ptr_width)),
Uint(t @ Usize) => Uint(t.normalize(self.tcx.sess.target.ptr_width)),
ref t @ (Uint(_) | Int(_)) => t.clone(),
t @ (Uint(_) | Int(_)) => t.clone(),
_ => panic!("tried to get overflow intrinsic for op applied to non-int type"),
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_llvm/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn check_and_apply_linkage(
// extern "C" fn() from being non-null, so we can't just declare a
// static and call it a day. Some linkages (like weak) will make it such
// that the static actually has a null value.
let llty2 = if let ty::RawPtr(ref mt) = ty.kind {
let llty2 = if let ty::RawPtr(ref mt) = ty.kind() {
cx.layout_of(mt.ty).llvm_type(cx)
} else {
cx.sess().span_fatal(
Expand Down
38 changes: 19 additions & 19 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ fn fixed_vec_metadata(

let (size, align) = cx.size_and_align_of(array_or_slice_type);

let upper_bound = match array_or_slice_type.kind {
let upper_bound = match array_or_slice_type.kind() {
ty::Array(_, len) => len.eval_usize(cx.tcx, ty::ParamEnv::reveal_all()) as c_longlong,
_ => -1,
};
Expand Down Expand Up @@ -432,7 +432,7 @@ fn subroutine_type_metadata(

let signature_metadata: Vec<_> = iter::once(
// return type
match signature.output().kind {
match signature.output().kind() {
ty::Tuple(ref tys) if tys.is_empty() => None,
_ => Some(type_metadata(cx, signature.output(), span)),
},
Expand Down Expand Up @@ -472,7 +472,7 @@ fn trait_pointer_metadata(
// type is assigned the correct name, size, namespace, and source location.
// However, it does not describe the trait's methods.

let containing_scope = match trait_type.kind {
let containing_scope = match trait_type.kind() {
ty::Dynamic(ref data, ..) => {
data.principal_def_id().map(|did| get_namespace_for_item(cx, did))
}
Expand Down Expand Up @@ -572,7 +572,7 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp

debug!("type_metadata: {:?}", t);

let ptr_metadata = |ty: Ty<'tcx>| match ty.kind {
let ptr_metadata = |ty: Ty<'tcx>| match *ty.kind() {
ty::Slice(typ) => Ok(vec_slice_metadata(cx, t, typ, unique_type_id, usage_site_span)),
ty::Str => Ok(vec_slice_metadata(cx, t, cx.tcx.types.u8, unique_type_id, usage_site_span)),
ty::Dynamic(..) => Ok(MetadataCreationResult::new(
Expand All @@ -592,7 +592,7 @@ pub fn type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>, usage_site_span: Sp
}
};

let MetadataCreationResult { metadata, already_stored_in_typemap } = match t.kind {
let MetadataCreationResult { metadata, already_stored_in_typemap } = match *t.kind() {
ty::Never | ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Float(_) => {
MetadataCreationResult::new(basic_type_metadata(cx, t), false)
}
Expand Down Expand Up @@ -876,7 +876,7 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
// .natvis visualizers (and perhaps other existing native debuggers?)
let msvc_like_names = cx.tcx.sess.target.target.options.is_like_msvc;

let (name, encoding) = match t.kind {
let (name, encoding) = match t.kind() {
ty::Never => ("!", DW_ATE_unsigned),
ty::Tuple(ref elements) if elements.is_empty() => ("()", DW_ATE_unsigned),
ty::Bool => ("bool", DW_ATE_boolean),
Expand Down Expand Up @@ -904,7 +904,7 @@ fn basic_type_metadata(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
return ty_metadata;
}

let typedef_name = match t.kind {
let typedef_name = match t.kind() {
ty::Int(int_ty) => int_ty.name_str(),
ty::Uint(uint_ty) => uint_ty.name_str(),
ty::Float(float_ty) => float_ty.name_str(),
Expand Down Expand Up @@ -1239,7 +1239,7 @@ fn prepare_struct_metadata(
) -> RecursiveTypeDescription<'ll, 'tcx> {
let struct_name = compute_debuginfo_type_name(cx.tcx, struct_type, false);

let (struct_def_id, variant) = match struct_type.kind {
let (struct_def_id, variant) = match struct_type.kind() {
ty::Adt(def, _) => (def.did, def.non_enum_variant()),
_ => bug!("prepare_struct_metadata on a non-ADT"),
};
Expand Down Expand Up @@ -1373,7 +1373,7 @@ fn prepare_union_metadata(
) -> RecursiveTypeDescription<'ll, 'tcx> {
let union_name = compute_debuginfo_type_name(cx.tcx, union_type, false);

let (union_def_id, variant) = match union_type.kind {
let (union_def_id, variant) = match union_type.kind() {
ty::Adt(def, _) => (def.did, def.non_enum_variant()),
_ => bug!("prepare_union_metadata on a non-ADT"),
};
Expand Down Expand Up @@ -1457,14 +1457,14 @@ struct EnumMemberDescriptionFactory<'ll, 'tcx> {

impl EnumMemberDescriptionFactory<'ll, 'tcx> {
fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>) -> Vec<MemberDescription<'ll>> {
let generator_variant_info_data = match self.enum_type.kind {
let generator_variant_info_data = match *self.enum_type.kind() {
ty::Generator(def_id, ..) => {
Some(generator_layout_and_saved_local_names(cx.tcx, def_id))
}
_ => None,
};

let variant_info_for = |index: VariantIdx| match self.enum_type.kind {
let variant_info_for = |index: VariantIdx| match *self.enum_type.kind() {
ty::Adt(adt, _) => VariantInfo::Adt(&adt.variants[index]),
ty::Generator(def_id, _, _) => {
let (generator_layout, generator_saved_local_names) =
Expand All @@ -1486,14 +1486,14 @@ impl EnumMemberDescriptionFactory<'ll, 'tcx> {
} else {
type_metadata(cx, self.enum_type, self.span)
};
let flags = match self.enum_type.kind {
let flags = match self.enum_type.kind() {
ty::Generator(..) => DIFlags::FlagArtificial,
_ => DIFlags::FlagZero,
};

match self.layout.variants {
Variants::Single { index } => {
if let ty::Adt(adt, _) = &self.enum_type.kind {
if let ty::Adt(adt, _) = self.enum_type.kind() {
if adt.variants.is_empty() {
return vec![];
}
Expand Down Expand Up @@ -1942,7 +1942,7 @@ fn prepare_enum_metadata(
let tcx = cx.tcx;
let enum_name = compute_debuginfo_type_name(tcx, enum_type, false);
// FIXME(tmandry): This doesn't seem to have any effect.
let enum_flags = match enum_type.kind {
let enum_flags = match enum_type.kind() {
ty::Generator(..) => DIFlags::FlagArtificial,
_ => DIFlags::FlagZero,
};
Expand All @@ -1957,13 +1957,13 @@ fn prepare_enum_metadata(
let file_metadata = unknown_file_metadata(cx);

let discriminant_type_metadata = |discr: Primitive| {
let enumerators_metadata: Vec<_> = match enum_type.kind {
let enumerators_metadata: Vec<_> = match enum_type.kind() {
ty::Adt(def, _) => def
.discriminants(tcx)
.zip(&def.variants)
.map(|((_, discr), v)| {
let name = v.ident.as_str();
let is_unsigned = match discr.ty.kind {
let is_unsigned = match discr.ty.kind() {
ty::Int(_) => false,
ty::Uint(_) => true,
_ => bug!("non integer discriminant"),
Expand Down Expand Up @@ -2012,7 +2012,7 @@ fn prepare_enum_metadata(
type_metadata(cx, discr.to_ty(tcx), rustc_span::DUMMY_SP);

let item_name;
let discriminant_name = match enum_type.kind {
let discriminant_name = match enum_type.kind() {
ty::Adt(..) => {
item_name = tcx.item_name(enum_def_id).as_str();
&*item_name
Expand Down Expand Up @@ -2105,7 +2105,7 @@ fn prepare_enum_metadata(
);
}

let discriminator_name = match &enum_type.kind {
let discriminator_name = match enum_type.kind() {
ty::Generator(..) => "__state",
_ => "",
};
Expand Down Expand Up @@ -2328,7 +2328,7 @@ fn set_members_of_composite_type(

/// Computes the type parameters for a type, if any, for the given metadata.
fn compute_type_parameters(cx: &CodegenCx<'ll, 'tcx>, ty: Ty<'tcx>) -> Option<&'ll DIArray> {
if let ty::Adt(def, substs) = ty.kind {
if let ty::Adt(def, substs) = *ty.kind() {
if substs.types().next().is_some() {
let generics = cx.tcx.generics_of(def.did);
let names = get_parameter_names(cx, generics);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/debuginfo/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -361,9 +361,9 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
// already inaccurate due to ABI adjustments (see #42800).
signature.extend(fn_abi.args.iter().map(|arg| {
let t = arg.layout.ty;
let t = match t.kind {
let t = match t.kind() {
ty::Array(ct, _)
if (ct == cx.tcx.types.u8) || cx.layout_of(ct).is_zst() =>
if (*ct == cx.tcx.types.u8) || cx.layout_of(ct).is_zst() =>
{
cx.tcx.mk_imm_ptr(ct)
}
Expand Down Expand Up @@ -467,7 +467,7 @@ impl DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {

// Only "class" methods are generally understood by LLVM,
// so avoid methods on other types (e.g., `<*mut T>::null`).
match impl_self_ty.kind {
match impl_self_ty.kind() {
ty::Adt(def, ..) if !def.is_box() => {
// Again, only create type information if full debuginfo is enabled
if cx.sess().opts.debuginfo == DebugInfo::Full
Expand Down

0 comments on commit d245464

Please sign in to comment.