From 34942331a3288bbebc5a00fef57b6976afc0eb75 Mon Sep 17 00:00:00 2001 From: Ariel Ben-Yehuda Date: Thu, 6 Aug 2015 01:55:13 +0300 Subject: [PATCH] remove ty::{VariantInfo, FieldTy} --- src/librustc/metadata/csearch.rs | 13 +-- src/librustc/metadata/decoder.rs | 84 ++------------- src/librustc/middle/ty.rs | 112 +------------------- src/librustc/middle/ty_fold.rs | 9 -- src/librustc_resolve/build_reduced_graph.rs | 4 +- 5 files changed, 10 insertions(+), 212 deletions(-) diff --git a/src/librustc/metadata/csearch.rs b/src/librustc/metadata/csearch.rs index f97ffebaebb19..f0607010bf3f0 100644 --- a/src/librustc/metadata/csearch.rs +++ b/src/librustc/metadata/csearch.rs @@ -113,13 +113,6 @@ pub fn maybe_get_item_ast<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId, decoder::maybe_get_item_ast(&*cdata, tcx, def.node, decode_inlined_item) } -pub fn get_enum_variants<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId) - -> Vec>> { - let cstore = &tcx.sess.cstore; - let cdata = cstore.get_crate_data(def.krate); - decoder::get_enum_variants(cstore.intr.clone(), &*cdata, def.node, tcx) -} - /// Returns information about the given implementation. pub fn get_impl_items(cstore: &cstore::CStore, impl_def_id: ast::DefId) -> Vec { @@ -195,11 +188,9 @@ pub fn get_item_attrs(cstore: &cstore::CStore, decoder::get_item_attrs(&*cdata, def_id.node) } -pub fn get_struct_fields(cstore: &cstore::CStore, - def: ast::DefId) - -> Vec { +pub fn get_struct_field_names(cstore: &cstore::CStore, def: ast::DefId) -> Vec { let cdata = cstore.get_crate_data(def.krate); - decoder::get_struct_fields(cstore.intr.clone(), &*cdata, def.node) + decoder::get_struct_field_names(&cstore.intr, &*cdata, def.node) } pub fn get_struct_field_attrs(cstore: &cstore::CStore, def: ast::DefId) -> HashMap(cdata: Cmd, tcx: &ty::ctxt<'tcx>, id: ast::NodeI } } -pub fn get_enum_variants<'tcx>(intr: Rc, cdata: Cmd, id: ast::NodeId, - tcx: &ty::ctxt<'tcx>) -> Vec>> { - let data = cdata.data(); - let items = reader::get_doc(rbml::Doc::new(data), tag_items); - let item = find_item(id, items); - let mut disr_val = 0; - reader::tagged_docs(item, tag_items_data_item_variant).map(|p| { - let did = translated_def_id(cdata, p); - let item = find_item(did.node, items); - let ctor_ty = item_type(ast::DefId { krate: cdata.cnum, node: id}, - item, tcx, cdata); - let name = item_name(&*intr, item); - let (ctor_ty, arg_tys, arg_names) = match ctor_ty.sty { - ty::TyBareFn(_, ref f) => - (Some(ctor_ty), f.sig.0.inputs.clone(), None), - _ => { // Nullary or struct enum variant. - let mut arg_names = Vec::new(); - let arg_tys = get_struct_fields(intr.clone(), cdata, did.node) - .iter() - .map(|field_ty| { - arg_names.push(field_ty.name); - get_type(cdata, field_ty.id.node, tcx).ty - }) - .collect(); - let arg_names = if arg_names.is_empty() { None } else { Some(arg_names) }; - - (None, arg_tys, arg_names) - } - }; - match variant_disr_val(item) { - Some(val) => { disr_val = val; } - _ => { /* empty */ } - } - let old_disr_val = disr_val; - disr_val = disr_val.wrapping_add(1); - Rc::new(ty::VariantInfo { - args: arg_tys, - arg_names: arg_names, - ctor_ty: ctor_ty, - name: name, - // I'm not even sure if we encode visibility - // for variants -- TEST -- tjc - id: did, - disr_val: old_disr_val, - vis: ast::Inherited - }) - }).collect() -} - fn get_explicit_self(item: rbml::Doc) -> ty::ExplicitSelfCategory { fn get_mutability(ch: u8) -> ast::Mutability { match ch as char { @@ -1136,37 +1087,14 @@ fn struct_field_family_to_visibility(family: Family) -> ast::Visibility { } } -pub fn get_struct_fields(intr: Rc, cdata: Cmd, id: ast::NodeId) - -> Vec { +pub fn get_struct_field_names(intr: &IdentInterner, cdata: Cmd, id: ast::NodeId) + -> Vec { let data = cdata.data(); let item = lookup_item(id, data); - reader::tagged_docs(item, tag_item_field).filter_map(|an_item| { - let f = item_family(an_item); - if f == PublicField || f == InheritedField { - let name = item_name(&*intr, an_item); - let did = item_def_id(an_item, cdata); - let tagdoc = reader::get_doc(an_item, tag_item_field_origin); - let origin_id = translated_def_id(cdata, tagdoc); - Some(ty::FieldTy { - name: name, - id: did, - vis: struct_field_family_to_visibility(f), - origin: origin_id, - }) - } else { - None - } - }).chain(reader::tagged_docs(item, tag_item_unnamed_field).map(|an_item| { - let did = item_def_id(an_item, cdata); - let tagdoc = reader::get_doc(an_item, tag_item_field_origin); - let f = item_family(an_item); - let origin_id = translated_def_id(cdata, tagdoc); - ty::FieldTy { - name: special_idents::unnamed_field.name, - id: did, - vis: struct_field_family_to_visibility(f), - origin: origin_id, - } + reader::tagged_docs(item, tag_item_field).map(|an_item| { + item_name(intr, an_item) + }).chain(reader::tagged_docs(item, tag_item_unnamed_field).map(|_| { + special_idents::unnamed_field.name })).collect() } diff --git a/src/librustc/middle/ty.rs b/src/librustc/middle/ty.rs index 9d339aef250e1..733fa0e71b4ee 100644 --- a/src/librustc/middle/ty.rs +++ b/src/librustc/middle/ty.rs @@ -87,8 +87,7 @@ use std::collections::{HashMap, HashSet}; use rustc_data_structures::ivar; use syntax::abi; use syntax::ast::{CrateNum, DefId, ItemImpl, ItemTrait, LOCAL_CRATE}; -use syntax::ast::{MutImmutable, MutMutable, Name, NamedField, NodeId}; -use syntax::ast::{StructField, UnnamedField, Visibility}; +use syntax::ast::{MutImmutable, MutMutable, Name, NodeId, Visibility}; use syntax::ast_util::{self, is_local, local_def}; use syntax::attr::{self, AttrMetaMethods, SignedInt, UnsignedInt}; use syntax::codemap::Span; @@ -112,83 +111,6 @@ pub struct CrateAnalysis { pub glob_map: Option, } -#[derive(Copy, Clone, PartialEq, Eq, Hash)] -pub struct Field<'tcx> { - pub name: ast::Name, - pub mt: TypeAndMut<'tcx> -} - -// Enum information -#[derive(Clone)] -pub struct VariantInfo<'tcx> { - pub args: Vec>, - pub arg_names: Option>, - pub ctor_ty: Option>, - pub name: ast::Name, - pub id: ast::DefId, - pub disr_val: Disr, - pub vis: Visibility -} - -impl<'tcx> VariantInfo<'tcx> { - - /// Creates a new VariantInfo from the corresponding ast representation. - /// - /// Does not do any caching of the value in the type context. - pub fn from_ast_variant(cx: &ctxt<'tcx>, - ast_variant: &ast::Variant, - discriminant: Disr) -> VariantInfo<'tcx> { - let ctor_ty = cx.node_id_to_type(ast_variant.node.id); - - match ast_variant.node.kind { - ast::TupleVariantKind(ref args) => { - let arg_tys = if !args.is_empty() { - // the regions in the argument types come from the - // enum def'n, and hence will all be early bound - cx.no_late_bound_regions(&ctor_ty.fn_args()).unwrap() - } else { - Vec::new() - }; - - return VariantInfo { - args: arg_tys, - arg_names: None, - ctor_ty: Some(ctor_ty), - name: ast_variant.node.name.name, - id: ast_util::local_def(ast_variant.node.id), - disr_val: discriminant, - vis: ast_variant.node.vis - }; - }, - ast::StructVariantKind(ref struct_def) => { - let fields: &[StructField] = &struct_def.fields; - - assert!(!fields.is_empty()); - - let arg_tys = struct_def.fields.iter() - .map(|field| cx.node_id_to_type(field.node.id)).collect(); - let arg_names = fields.iter().map(|field| { - match field.node.kind { - NamedField(ident, _) => ident.name, - UnnamedField(..) => cx.sess.bug( - "enum_variants: all fields in struct must have a name") - } - }).collect(); - - return VariantInfo { - args: arg_tys, - arg_names: Some(arg_names), - ctor_ty: None, - name: ast_variant.node.name.name, - id: ast_util::local_def(ast_variant.node.id), - disr_val: discriminant, - vis: ast_variant.node.vis - }; - } - } - } -} - #[derive(Copy, Clone)] pub enum DtorKind { NoDtor, @@ -495,14 +417,6 @@ pub struct TypeAndMut<'tcx> { pub mutbl: ast::Mutability, } -#[derive(Clone, Copy, Debug)] -pub struct FieldTy { - pub name: Name, - pub id: DefId, - pub vis: ast::Visibility, - pub origin: ast::DefId, // The DefId of the struct in which the field is declared. -} - #[derive(Clone, PartialEq, RustcDecodable, RustcEncodable)] pub struct ItemVariances { pub types: VecPerParamSpace, @@ -5667,18 +5581,6 @@ impl<'tcx> ctxt<'tcx> { } } - pub fn field_idx_strict(&self, name: ast::Name, fields: &[Field<'tcx>]) - -> usize { - let mut i = 0; - for f in fields { if f.name == name { return i; } i += 1; } - self.sess.bug(&format!( - "no field named `{}` found in the list of fields `{:?}`", - name, - fields.iter() - .map(|f| f.name.to_string()) - .collect::>())); - } - pub fn note_and_explain_type_err(&self, err: &TypeError<'tcx>, sp: Span) { use self::TypeError::*; @@ -7341,12 +7243,6 @@ impl<'tcx> HasTypeFlags for FnSig<'tcx> { } } -impl<'tcx> HasTypeFlags for Field<'tcx> { - fn has_type_flags(&self, flags: TypeFlags) -> bool { - self.mt.ty.has_type_flags(flags) - } -} - impl<'tcx> HasTypeFlags for BareFnTy<'tcx> { fn has_type_flags(&self, flags: TypeFlags) -> bool { self.sig.has_type_flags(flags) @@ -7377,12 +7273,6 @@ impl<'tcx> fmt::Debug for ClosureUpvar<'tcx> { } } -impl<'tcx> fmt::Debug for Field<'tcx> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "field({},{})", self.name, self.mt) - } -} - impl<'a, 'tcx> fmt::Debug for ParameterEnvironment<'a, 'tcx> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "ParameterEnvironment(\ diff --git a/src/librustc/middle/ty_fold.rs b/src/librustc/middle/ty_fold.rs index 0c694926ba4b5..cc1efeaea080f 100644 --- a/src/librustc/middle/ty_fold.rs +++ b/src/librustc/middle/ty_fold.rs @@ -275,15 +275,6 @@ impl<'tcx> TypeFoldable<'tcx> for ty::TraitRef<'tcx> { } } -impl<'tcx> TypeFoldable<'tcx> for ty::Field<'tcx> { - fn fold_with>(&self, folder: &mut F) -> ty::Field<'tcx> { - ty::Field { - name: self.name, - mt: self.mt.fold_with(folder), - } - } -} - impl<'tcx> TypeFoldable<'tcx> for ty::Region { fn fold_with>(&self, folder: &mut F) -> ty::Region { folder.fold_region(*self) diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index 656d6a3661470..190e217aac15d 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -791,9 +791,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> { crate) building type and value for {}", final_ident); child_name_bindings.define_type(def, DUMMY_SP, modifiers); - let fields = csearch::get_struct_fields(&self.session.cstore, def_id).iter().map(|f| { - f.name - }).collect::>(); + let fields = csearch::get_struct_field_names(&self.session.cstore, def_id); if fields.is_empty() { child_name_bindings.define_value(def, DUMMY_SP, modifiers);