Skip to content

Commit

Permalink
rustc: de-@ ty::ParamBounds.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyb committed Apr 22, 2014
1 parent 1a76ac3 commit 811bbfc
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
3 changes: 2 additions & 1 deletion src/librustc/metadata/tydecode.rs
Expand Up @@ -18,6 +18,7 @@

use middle::ty;

use std::rc::Rc;
use std::str;
use std::strbuf::StrBuf;
use std::uint;
Expand Down Expand Up @@ -563,7 +564,7 @@ fn parse_type_param_def(st: &mut PState, conv: conv_did) -> ty::TypeParameterDef
ty::TypeParameterDef {
ident: parse_ident(st, ':'),
def_id: parse_def(st, NominalType, |x,y| conv(x,y)),
bounds: @parse_bounds(st, |x,y| conv(x,y)),
bounds: Rc::new(parse_bounds(st, |x,y| conv(x,y))),
default: parse_opt(st, |st| parse_ty(st, |x,y| conv(x,y)))
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/tyencode.rs
Expand Up @@ -376,6 +376,6 @@ fn enc_bounds(w: &mut MemWriter, cx: &ctxt, bs: &ty::ParamBounds) {

pub fn enc_type_param_def(w: &mut MemWriter, cx: &ctxt, v: &ty::TypeParameterDef) {
mywrite!(w, "{}:{}|", token::get_ident(v.ident), (cx.ds)(v.def_id));
enc_bounds(w, cx, v.bounds);
enc_bounds(w, cx, &*v.bounds);
enc_opt(w, v.default, |w, t| enc_ty(w, cx, t));
}
5 changes: 3 additions & 2 deletions src/librustc/middle/ty.rs
Expand Up @@ -833,7 +833,8 @@ pub enum type_err {
#[deriving(Eq, TotalEq, Hash)]
pub struct ParamBounds {
pub builtin_bounds: BuiltinBounds,
pub trait_bounds: Vec<@TraitRef> }
pub trait_bounds: Vec<@TraitRef>
}

pub type BuiltinBounds = EnumSet<BuiltinBound>;

Expand Down Expand Up @@ -987,7 +988,7 @@ impl fmt::Show for IntVarValue {
pub struct TypeParameterDef {
pub ident: ast::Ident,
pub def_id: ast::DefId,
pub bounds: @ParamBounds,
pub bounds: Rc<ParamBounds>,
pub default: Option<ty::t>
}

Expand Down
32 changes: 16 additions & 16 deletions src/librustc/middle/typeck/collect.rs
Expand Up @@ -342,10 +342,10 @@ pub fn ensure_trait_methods(ccx: &CrateCtxt, trait_id: ast::NodeId) {
new_type_param_defs.push(ty::TypeParameterDef {
ident: special_idents::self_,
def_id: dummy_defid,
bounds: @ty::ParamBounds {
bounds: Rc::new(ty::ParamBounds {
builtin_bounds: ty::EmptyBuiltinBounds(),
trait_bounds: vec!(self_trait_ref)
},
}),
default: None
});

Expand Down Expand Up @@ -999,24 +999,24 @@ pub fn ty_of_foreign_item(ccx: &CrateCtxt,
}
}

pub fn ty_generics_for_type(ccx: &CrateCtxt,
generics: &ast::Generics)
-> ty::Generics {
fn ty_generics_for_type(ccx: &CrateCtxt,
generics: &ast::Generics)
-> ty::Generics {
ty_generics(ccx, &generics.lifetimes, &generics.ty_params, 0)
}

pub fn ty_generics_for_fn_or_method(ccx: &CrateCtxt,
generics: &ast::Generics,
base_index: uint)
-> ty::Generics {
fn ty_generics_for_fn_or_method(ccx: &CrateCtxt,
generics: &ast::Generics,
base_index: uint)
-> ty::Generics {
let early_lifetimes = resolve_lifetime::early_bound_lifetimes(generics);
ty_generics(ccx, &early_lifetimes, &generics.ty_params, base_index)
}

pub fn ty_generics(ccx: &CrateCtxt,
lifetimes: &Vec<ast::Lifetime>,
ty_params: &OwnedSlice<ast::TyParam>,
base_index: uint) -> ty::Generics {
fn ty_generics(ccx: &CrateCtxt,
lifetimes: &Vec<ast::Lifetime>,
ty_params: &OwnedSlice<ast::TyParam>,
base_index: uint) -> ty::Generics {
return ty::Generics {
region_param_defs: Rc::new(lifetimes.iter().map(|l| {
ty::RegionParameterDef { name: l.name,
Expand All @@ -1025,12 +1025,12 @@ pub fn ty_generics(ccx: &CrateCtxt,
type_param_defs: Rc::new(ty_params.iter().enumerate().map(|(offset, param)| {
let existing_def_opt = {
let ty_param_defs = ccx.tcx.ty_param_defs.borrow();
ty_param_defs.find(&param.id).map(|&def| def)
ty_param_defs.find(&param.id).map(|def| def.clone())
};
existing_def_opt.unwrap_or_else(|| {
let param_ty = ty::param_ty {idx: base_index + offset,
def_id: local_def(param.id)};
let bounds = @compute_bounds(ccx, param_ty, &param.bounds);
let bounds = Rc::new(compute_bounds(ccx, param_ty, &param.bounds));
let default = param.default.map(|path| {
let ty = ast_ty_to_ty(ccx, &ExplicitRscope, path);
let cur_idx = param_ty.idx;
Expand All @@ -1056,7 +1056,7 @@ pub fn ty_generics(ccx: &CrateCtxt,
default: default
};
debug!("def for param: {}", def.repr(ccx.tcx));
ccx.tcx.ty_param_defs.borrow_mut().insert(param.id, def);
ccx.tcx.ty_param_defs.borrow_mut().insert(param.id, def.clone());
def
})
}).collect()),
Expand Down

0 comments on commit 811bbfc

Please sign in to comment.