Skip to content

Issue 5527 rename types #15091

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 22, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/librustc/metadata/csearch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ pub fn get_struct_fields(cstore: &cstore::CStore,

pub fn get_type(tcx: &ty::ctxt,
def: ast::DefId)
-> ty::ty_param_bounds_and_ty {
-> ty::Polytype {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(def.krate);
decoder::get_type(&*cdata, def.node, tcx)
Expand All @@ -206,7 +206,7 @@ pub fn get_trait_def(tcx: &ty::ctxt, def: ast::DefId) -> ty::TraitDef {
}

pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId,
def: ast::DefId) -> ty::ty_param_bounds_and_ty {
def: ast::DefId) -> ty::Polytype {
let cstore = &tcx.sess.cstore;
let cdata = cstore.get_crate_data(class_id.krate);
let all_items = reader::get_doc(ebml::Doc::new(cdata.data()), tag_items);
Expand All @@ -224,7 +224,7 @@ pub fn get_field_type(tcx: &ty::ctxt, class_id: ast::DefId,
def)).to_string()
});
let ty = decoder::item_type(def, the_field, tcx, &*cdata);
ty::ty_param_bounds_and_ty {
ty::Polytype {
generics: ty::Generics {types: VecPerParamSpace::empty(),
regions: VecPerParamSpace::empty()},
ty: ty
Expand Down
4 changes: 2 additions & 2 deletions src/librustc/metadata/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ pub fn get_trait_def(cdata: Cmd,
}

pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt)
-> ty::ty_param_bounds_and_ty {
-> ty::Polytype {

let item = lookup_item(id, cdata.data());

Expand All @@ -432,7 +432,7 @@ pub fn get_type(cdata: Cmd, id: ast::NodeId, tcx: &ty::ctxt)
let tp_defs = item_ty_param_defs(item, tcx, cdata, tag_items_data_item_ty_param_bounds);
let rp_defs = item_region_param_defs(item, cdata);

ty::ty_param_bounds_and_ty {
ty::Polytype {
generics: ty::Generics {types: tp_defs,
regions: rp_defs},
ty: t
Expand Down
22 changes: 11 additions & 11 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,11 @@ fn encode_item_variances(ebml_w: &mut Encoder,

fn encode_bounds_and_type(ebml_w: &mut Encoder,
ecx: &EncodeContext,
tpt: &ty::ty_param_bounds_and_ty) {
encode_ty_type_param_defs(ebml_w, ecx, &tpt.generics.types,
pty: &ty::Polytype) {
encode_ty_type_param_defs(ebml_w, ecx, &pty.generics.types,
tag_items_data_item_ty_param_bounds);
encode_region_param_defs(ebml_w, &tpt.generics.regions);
encode_type(ecx, ebml_w, tpt.ty);
encode_region_param_defs(ebml_w, &pty.generics.regions);
encode_type(ecx, ebml_w, pty.ty);
}

fn encode_variant_id(ebml_w: &mut Encoder, vid: DefId) {
Expand Down Expand Up @@ -772,8 +772,8 @@ fn encode_info_for_method(ecx: &EncodeContext,
encode_stability(ebml_w, stab);

// The type for methods gets encoded twice, which is unfortunate.
let tpt = lookup_item_type(ecx.tcx, m.def_id);
encode_bounds_and_type(ebml_w, ecx, &tpt);
let pty = lookup_item_type(ecx.tcx, m.def_id);
encode_bounds_and_type(ebml_w, ecx, &pty);

let elem = ast_map::PathName(m.ident.name);
encode_path(ebml_w, impl_path.chain(Some(elem).move_iter()));
Expand All @@ -785,7 +785,7 @@ fn encode_info_for_method(ecx: &EncodeContext,
}

for &ast_method in ast_method_opt.iter() {
let any_types = !tpt.generics.types.is_empty();
let any_types = !pty.generics.types.is_empty();
if any_types || is_default_impl || should_inline(ast_method.attrs.as_slice()) {
encode_inlined_item(ecx, ebml_w,
IIMethodRef(local_def(parent_id), false,
Expand Down Expand Up @@ -1218,8 +1218,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
fn_style_static_method_family(
method_ty.fty.fn_style));

let tpt = ty::lookup_item_type(tcx, method_def_id);
encode_bounds_and_type(ebml_w, ecx, &tpt);
let pty = ty::lookup_item_type(tcx, method_def_id);
encode_bounds_and_type(ebml_w, ecx, &pty);
}

_ => {
Expand All @@ -1242,8 +1242,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
// this.
if method_ty.explicit_self != SelfStatic {
// FIXME: I feel like there is something funny going on.
let tpt = ty::lookup_item_type(tcx, method_def_id);
encode_bounds_and_type(ebml_w, ecx, &tpt);
let pty = ty::lookup_item_type(tcx, method_def_id);
encode_bounds_and_type(ebml_w, ecx, &pty);
}
encode_method_sort(ebml_w, 'p');
encode_inlined_item(ecx, ebml_w,
Expand Down
38 changes: 19 additions & 19 deletions src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -839,9 +839,9 @@ trait ebml_writer_helpers {
fn emit_type_param_def(&mut self,
ecx: &e::EncodeContext,
type_param_def: &ty::TypeParameterDef);
fn emit_tpbt(&mut self,
ecx: &e::EncodeContext,
tpbt: ty::ty_param_bounds_and_ty);
fn emit_polytype(&mut self,
ecx: &e::EncodeContext,
pty: ty::Polytype);
fn emit_substs(&mut self, ecx: &e::EncodeContext, substs: &subst::Substs);
fn emit_auto_adjustment(&mut self, ecx: &e::EncodeContext, adj: &ty::AutoAdjustment);
}
Expand All @@ -865,26 +865,26 @@ impl<'a> ebml_writer_helpers for Encoder<'a> {
});
}

fn emit_tpbt(&mut self,
fn emit_polytype(&mut self,
ecx: &e::EncodeContext,
tpbt: ty::ty_param_bounds_and_ty) {
self.emit_struct("ty_param_bounds_and_ty", 2, |this| {
pty: ty::Polytype) {
self.emit_struct("Polytype", 2, |this| {
this.emit_struct_field("generics", 0, |this| {
this.emit_struct("Generics", 2, |this| {
this.emit_struct_field("types", 0, |this| {
Ok(encode_vec_per_param_space(
this, &tpbt.generics.types,
this, &pty.generics.types,
|this, def| this.emit_type_param_def(ecx, def)))
});
this.emit_struct_field("regions", 1, |this| {
Ok(encode_vec_per_param_space(
this, &tpbt.generics.regions,
this, &pty.generics.regions,
|this, def| def.encode(this).unwrap()))
})
})
});
this.emit_struct_field("ty", 1, |this| {
Ok(this.emit_ty(ecx, tpbt.ty))
Ok(this.emit_ty(ecx, pty.ty))
})
});
}
Expand Down Expand Up @@ -1030,11 +1030,11 @@ fn encode_side_tables_for_id(ecx: &e::EncodeContext,
}

let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
for &tpbt in tcx.tcache.borrow().find(&lid).iter() {
for &pty in tcx.tcache.borrow().find(&lid).iter() {
ebml_w.tag(c::tag_table_tcache, |ebml_w| {
ebml_w.id(id);
ebml_w.tag(c::tag_table_val, |ebml_w| {
ebml_w.emit_tpbt(ecx, tpbt.clone());
ebml_w.emit_polytype(ecx, pty.clone());
})
})
}
Expand Down Expand Up @@ -1142,8 +1142,8 @@ trait ebml_decoder_decoder_helpers {
fn read_tys(&mut self, xcx: &ExtendedDecodeContext) -> Vec<ty::t>;
fn read_type_param_def(&mut self, xcx: &ExtendedDecodeContext)
-> ty::TypeParameterDef;
fn read_ty_param_bounds_and_ty(&mut self, xcx: &ExtendedDecodeContext)
-> ty::ty_param_bounds_and_ty;
fn read_polytype(&mut self, xcx: &ExtendedDecodeContext)
-> ty::Polytype;
fn read_substs(&mut self, xcx: &ExtendedDecodeContext) -> subst::Substs;
fn read_auto_adjustment(&mut self, xcx: &ExtendedDecodeContext) -> ty::AutoAdjustment;
fn convert_def_id(&mut self,
Expand Down Expand Up @@ -1245,10 +1245,10 @@ impl<'a> ebml_decoder_decoder_helpers for reader::Decoder<'a> {
}).unwrap()
}

fn read_ty_param_bounds_and_ty(&mut self, xcx: &ExtendedDecodeContext)
-> ty::ty_param_bounds_and_ty {
self.read_struct("ty_param_bounds_and_ty", 2, |this| {
Ok(ty::ty_param_bounds_and_ty {
fn read_polytype(&mut self, xcx: &ExtendedDecodeContext)
-> ty::Polytype {
self.read_struct("Polytype", 2, |this| {
Ok(ty::Polytype {
generics: this.read_struct_field("generics", 0, |this| {
this.read_struct("Generics", 2, |this| {
Ok(ty::Generics {
Expand Down Expand Up @@ -1408,9 +1408,9 @@ fn decode_side_tables(xcx: &ExtendedDecodeContext,
dcx.tcx.freevars.borrow_mut().insert(id, fv_info);
}
c::tag_table_tcache => {
let tpbt = val_dsr.read_ty_param_bounds_and_ty(xcx);
let pty = val_dsr.read_polytype(xcx);
let lid = ast::DefId { krate: ast::LOCAL_CRATE, node: id };
dcx.tcx.tcache.borrow_mut().insert(lid, tpbt);
dcx.tcx.tcache.borrow_mut().insert(lid, pty);
}
c::tag_table_param_defs => {
let bounds = val_dsr.read_type_param_def(xcx);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ fn check_while_true_expr(cx: &Context, e: &ast::Expr) {
impl<'a> AstConv for Context<'a>{
fn tcx<'a>(&'a self) -> &'a ty::ctxt { self.tcx }

fn get_item_ty(&self, id: ast::DefId) -> ty::ty_param_bounds_and_ty {
fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype {
ty::lookup_item_type(self.tcx, id)
}

Expand Down
26 changes: 8 additions & 18 deletions src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1026,21 +1026,16 @@ pub struct ParameterEnvironment {

/// A polytype.
///
/// - `bounds`: The list of bounds for each type parameter. The length of the
/// list also tells you how many type parameters there are.
///
/// - `rp`: true if the type is region-parameterized. Types can have at
/// most one region parameter, always called `&self`.
///
/// - `ty`: the base type. May have reference to the (unsubstituted) bound
/// region `&self` or to (unsubstituted) ty_param types
/// - `generics`: the set of type parameters and their bounds
/// - `ty`: the base types, which may reference the parameters defined
/// in `generics`
#[deriving(Clone)]
pub struct ty_param_bounds_and_ty {
pub struct Polytype {
pub generics: Generics,
pub ty: t
}

/// As `ty_param_bounds_and_ty` but for a trait ref.
/// As `Polytype` but for a trait ref.
pub struct TraitDef {
pub generics: Generics,
pub bounds: BuiltinBounds,
Expand All @@ -1054,12 +1049,7 @@ pub struct ItemSubsts {
pub substs: Substs,
}

pub struct ty_param_substs_and_ty {
pub substs: Substs,
pub ty: ty::t
}

pub type type_cache = RefCell<DefIdMap<ty_param_bounds_and_ty>>;
pub type type_cache = RefCell<DefIdMap<Polytype>>;

pub type node_type_table = RefCell<HashMap<uint,t>>;

Expand Down Expand Up @@ -3848,7 +3838,7 @@ pub fn enum_variant_with_id(cx: &ctxt,
// the type cache. Returns the type parameters and type.
pub fn lookup_item_type(cx: &ctxt,
did: ast::DefId)
-> ty_param_bounds_and_ty {
-> Polytype {
lookup_locally_or_in_crate_store(
"tcache", did, &mut *cx.tcache.borrow_mut(),
|| csearch::get_type(cx, did))
Expand Down Expand Up @@ -3946,7 +3936,7 @@ pub fn lookup_field_type(tcx: &ctxt,
} else {
let mut tcache = tcx.tcache.borrow_mut();
match tcache.find(&id) {
Some(&ty_param_bounds_and_ty {ty, ..}) => ty,
Some(&Polytype {ty, ..}) => ty,
None => {
let tpt = csearch::get_field_type(tcx, struct_id, id);
tcache.insert(id, tpt.clone());
Expand Down
33 changes: 16 additions & 17 deletions src/librustc/middle/typeck/astconv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,9 @@ use middle::const_eval;
use middle::def;
use middle::lang_items::FnMutTraitLangItem;
use rl = middle::resolve_lifetime;
use middle::subst::{Subst, Substs};
use middle::subst;
use middle::ty::ty_param_substs_and_ty;
use middle::subst::{FnSpace, TypeSpace, SelfSpace, Subst, Substs};
use middle::ty;
use middle::typeck::TypeAndSubsts;
use middle::typeck::lookup_def_tcx;
use middle::typeck::rscope::RegionScope;
use middle::typeck::rscope;
Expand All @@ -71,7 +70,7 @@ use syntax::print::pprust::{lifetime_to_str, path_to_str};

pub trait AstConv {
fn tcx<'a>(&'a self) -> &'a ty::ctxt;
fn get_item_ty(&self, id: ast::DefId) -> ty::ty_param_bounds_and_ty;
fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype;
fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef>;

// what type should we use when a type is omitted?
Expand Down Expand Up @@ -154,7 +153,7 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
rscope: &RS,
decl_generics: &ty::Generics,
self_ty: Option<ty::t>,
path: &ast::Path) -> subst::Substs
path: &ast::Path) -> Substs
{
/*!
* Given a path `path` that refers to an item `I` with the
Expand All @@ -172,13 +171,13 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
// Note: in the case of traits, the self parameter is also
// defined, but we don't currently create a `type_param_def` for
// `Self` because it is implicit.
assert!(decl_generics.regions.all(|d| d.space == subst::TypeSpace));
assert!(decl_generics.types.all(|d| d.space != subst::FnSpace));
assert!(decl_generics.regions.all(|d| d.space == TypeSpace));
assert!(decl_generics.types.all(|d| d.space != FnSpace));

// If the type is parameterized by the this region, then replace this
// region with the current anon region binding (in other words,
// whatever & would get replaced with).
let expected_num_region_params = decl_generics.regions.len(subst::TypeSpace);
let expected_num_region_params = decl_generics.regions.len(TypeSpace);
let supplied_num_region_params = path.segments.last().unwrap().lifetimes.len();
let regions = if expected_num_region_params == supplied_num_region_params {
path.segments.last().unwrap().lifetimes.iter().map(
Expand All @@ -204,7 +203,7 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
};

// Convert the type parameters supplied by the user.
let ty_param_defs = decl_generics.types.get_vec(subst::TypeSpace);
let ty_param_defs = decl_generics.types.get_vec(TypeSpace);
let supplied_ty_param_count = path.segments.iter().flat_map(|s| s.types.iter()).count();
let formal_ty_param_count = ty_param_defs.len();
let required_ty_param_count = ty_param_defs.iter()
Expand Down Expand Up @@ -246,7 +245,7 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
.map(|a_t| ast_ty_to_ty(this, rscope, &**a_t))
.collect();

let mut substs = subst::Substs::new_type(tps, regions);
let mut substs = Substs::new_type(tps, regions);

match self_ty {
None => {
Expand All @@ -258,14 +257,14 @@ fn ast_path_substs<AC:AstConv,RS:RegionScope>(
// "declared" (in other words, this should be a
// trait-ref).
assert!(decl_generics.types.get_self().is_some());
substs.types.push(subst::SelfSpace, ty);
substs.types.push(SelfSpace, ty);
}
}

for param in ty_param_defs.slice_from(supplied_ty_param_count).iter() {
let default = param.default.unwrap();
let default = default.subst_spanned(tcx, &substs, Some(path.span));
substs.types.push(subst::TypeSpace, default);
substs.types.push(TypeSpace, default);
}

substs
Expand All @@ -289,17 +288,17 @@ pub fn ast_path_to_ty<AC:AstConv,RS:RegionScope>(
rscope: &RS,
did: ast::DefId,
path: &ast::Path)
-> ty_param_substs_and_ty
-> TypeAndSubsts
{
let tcx = this.tcx();
let ty::ty_param_bounds_and_ty {
let ty::Polytype {
generics: generics,
ty: decl_ty
} = this.get_item_ty(did);

let substs = ast_path_substs(this, rscope, &generics, None, path);
let ty = decl_ty.subst(tcx, &substs);
ty_param_substs_and_ty { substs: substs, ty: ty }
TypeAndSubsts { substs: substs, ty: ty }
}

pub static NO_REGIONS: uint = 1;
Expand Down Expand Up @@ -547,11 +546,11 @@ pub fn trait_ref_for_unboxed_function<AC:AstConv,
let output_type = ast_ty_to_ty(this,
rscope,
&*unboxed_function.decl.output);
let mut substs = subst::Substs::new_type(vec!(input_tuple, output_type),
let mut substs = Substs::new_type(vec!(input_tuple, output_type),
Vec::new());

match self_ty {
Some(s) => substs.types.push(subst::SelfSpace, s),
Some(s) => substs.types.push(SelfSpace, s),
None => ()
}

Expand Down
Loading