Skip to content
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

rustc: use methods instead of functions in middle::ty. #26575

Merged
merged 6 commits into from
Jun 27, 2015
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
51 changes: 24 additions & 27 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use metadata::cstore;
use metadata::decoder;
use metadata::tyencode;
use middle::def;
use middle::ty::lookup_item_type;
use middle::ty::{self, Ty};
use middle::stability;
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
Expand Down Expand Up @@ -133,7 +132,7 @@ pub fn def_to_string(did: DefId) -> String {
fn encode_item_variances(rbml_w: &mut Encoder,
ecx: &EncodeContext,
id: NodeId) {
let v = ty::item_variances(ecx.tcx, ast_util::local_def(id));
let v = ecx.tcx.item_variances(ast_util::local_def(id));
rbml_w.start_tag(tag_item_variances);
v.encode(rbml_w);
rbml_w.end_tag();
Expand All @@ -144,8 +143,8 @@ fn encode_bounds_and_type_for_item<'a, 'tcx>(rbml_w: &mut Encoder,
id: ast::NodeId) {
encode_bounds_and_type(rbml_w,
ecx,
&ty::lookup_item_type(ecx.tcx, local_def(id)),
&ty::lookup_predicates(ecx.tcx, local_def(id)));
&ecx.tcx.lookup_item_type(local_def(id)),
&ecx.tcx.lookup_predicates(local_def(id)));
}

fn encode_bounds_and_type<'a, 'tcx>(rbml_w: &mut Encoder,
Expand Down Expand Up @@ -293,8 +292,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext,

let mut disr_val = 0;
let mut i = 0;
let vi = ty::enum_variants(ecx.tcx,
DefId { krate: ast::LOCAL_CRATE, node: id });
let vi = ecx.tcx.enum_variants(local_def(id));
for variant in variants {
let def_id = local_def(variant.node.id);
index.push(entry {
Expand All @@ -319,7 +317,7 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
match variant.node.kind {
ast::TupleVariantKind(_) => {},
ast::StructVariantKind(_) => {
let fields = ty::lookup_struct_fields(ecx.tcx, def_id);
let fields = ecx.tcx.lookup_struct_fields(def_id);
let idx = encode_info_for_struct(ecx,
rbml_w,
&fields[..],
Expand All @@ -328,9 +326,10 @@ fn encode_enum_variant_info(ecx: &EncodeContext,
encode_index(rbml_w, idx, write_i64);
}
}
if (*vi)[i].disr_val != disr_val {
encode_disr_val(ecx, rbml_w, (*vi)[i].disr_val);
disr_val = (*vi)[i].disr_val;
let specified_disr_val = vi[i].disr_val;
if specified_disr_val != disr_val {
encode_disr_val(ecx, rbml_w, specified_disr_val);
disr_val = specified_disr_val;
}
encode_bounds_and_type_for_item(rbml_w, ecx, def_id.local_id());

Expand Down Expand Up @@ -379,9 +378,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
Some(implementations) => {
for base_impl_did in implementations.iter() {
for &method_did in impl_items.get(base_impl_did).unwrap() {
let impl_item = ty::impl_or_trait_item(
ecx.tcx,
method_did.def_id());
let impl_item = ecx.tcx.impl_or_trait_item(method_did.def_id());
if let ty::MethodTraitItem(ref m) = impl_item {
encode_reexported_static_method(rbml_w,
exp,
Expand Down Expand Up @@ -875,7 +872,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
if let Some(impl_item) = impl_item_opt {
if let ast::MethodImplItem(ref sig, _) = impl_item.node {
encode_attributes(rbml_w, &impl_item.attrs);
let scheme = ty::lookup_item_type(ecx.tcx, m.def_id);
let scheme = ecx.tcx.lookup_item_type(m.def_id);
let any_types = !scheme.generics.types.is_empty();
let needs_inline = any_types || is_default_impl ||
attr::requests_inline(&impl_item.attrs);
Expand Down Expand Up @@ -923,7 +920,7 @@ fn encode_info_for_associated_type<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
encode_attributes(rbml_w, &ii.attrs);
} else {
encode_predicates(rbml_w, ecx,
&ty::lookup_predicates(ecx.tcx, associated_type.def_id),
&ecx.tcx.lookup_predicates(associated_type.def_id),
tag_item_generics);
}

Expand Down Expand Up @@ -995,7 +992,7 @@ fn encode_extension_implementations(ecx: &EncodeContext,
rbml_w: &mut Encoder,
trait_def_id: DefId) {
assert!(ast_util::is_local(trait_def_id));
let def = ty::lookup_trait_def(ecx.tcx, trait_def_id);
let def = ecx.tcx.lookup_trait_def(trait_def_id);

def.for_each_impl(ecx.tcx, |impl_def_id| {
rbml_w.start_tag(tag_items_data_item_extension_impl);
Expand Down Expand Up @@ -1161,7 +1158,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
index);
}
ast::ItemStruct(ref struct_def, _) => {
let fields = ty::lookup_struct_fields(tcx, def_id);
let fields = tcx.lookup_struct_fields(def_id);

/* First, encode the fields
These come first because we need to write them to make
Expand Down Expand Up @@ -1220,7 +1217,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_name(rbml_w, item.ident.name);
encode_unsafety(rbml_w, unsafety);

let trait_ref = ty::impl_trait_ref(tcx, local_def(item.id)).unwrap();
let trait_ref = tcx.impl_trait_ref(local_def(item.id)).unwrap();
encode_trait_ref(rbml_w, ecx, trait_ref, tag_item_trait_ref);
rbml_w.end_tag();
}
Expand Down Expand Up @@ -1274,7 +1271,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
}
rbml_w.end_tag();
}
if let Some(trait_ref) = ty::impl_trait_ref(tcx, local_def(item.id)) {
if let Some(trait_ref) = tcx.impl_trait_ref(local_def(item.id)) {
encode_trait_ref(rbml_w, ecx, trait_ref, tag_item_trait_ref);
}
encode_path(rbml_w, path.clone());
Expand All @@ -1298,7 +1295,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
pos: rbml_w.mark_stable_position(),
});

match ty::impl_or_trait_item(tcx, trait_item_def_id.def_id()) {
match tcx.impl_or_trait_item(trait_item_def_id.def_id()) {
ty::ConstTraitItem(ref associated_const) => {
encode_info_for_associated_const(ecx,
rbml_w,
Expand Down Expand Up @@ -1333,22 +1330,22 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_def_id(rbml_w, def_id);
encode_family(rbml_w, 'I');
encode_item_variances(rbml_w, ecx, item.id);
let trait_def = ty::lookup_trait_def(tcx, def_id);
let trait_predicates = ty::lookup_predicates(tcx, def_id);
let trait_def = tcx.lookup_trait_def(def_id);
let trait_predicates = tcx.lookup_predicates(def_id);
encode_unsafety(rbml_w, trait_def.unsafety);
encode_paren_sugar(rbml_w, trait_def.paren_sugar);
encode_defaulted(rbml_w, ty::trait_has_default_impl(tcx, def_id));
encode_defaulted(rbml_w, tcx.trait_has_default_impl(def_id));
encode_associated_type_names(rbml_w, &trait_def.associated_type_names);
encode_generics(rbml_w, ecx, &trait_def.generics, &trait_predicates,
tag_item_generics);
encode_predicates(rbml_w, ecx, &ty::lookup_super_predicates(tcx, def_id),
encode_predicates(rbml_w, ecx, &tcx.lookup_super_predicates(def_id),
tag_item_super_predicates);
encode_trait_ref(rbml_w, ecx, trait_def.trait_ref, tag_item_trait_ref);
encode_name(rbml_w, item.ident.name);
encode_attributes(rbml_w, &item.attrs);
encode_visibility(rbml_w, vis);
encode_stability(rbml_w, stab);
for &method_def_id in ty::trait_item_def_ids(tcx, def_id).iter() {
for &method_def_id in tcx.trait_item_def_ids(def_id).iter() {
rbml_w.start_tag(tag_item_trait_item);
match method_def_id {
ty::ConstTraitItemId(const_def_id) => {
Expand Down Expand Up @@ -1380,7 +1377,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
rbml_w.end_tag();

// Now output the trait item info for each trait item.
let r = ty::trait_item_def_ids(tcx, def_id);
let r = tcx.trait_item_def_ids(def_id);
for (i, &item_def_id) in r.iter().enumerate() {
assert_eq!(item_def_id.def_id().krate, ast::LOCAL_CRATE);

Expand All @@ -1397,7 +1394,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
encode_stability(rbml_w, stab);

let trait_item_type =
ty::impl_or_trait_item(tcx, item_def_id.def_id());
tcx.impl_or_trait_item(item_def_id.def_id());
let is_nonstatic_method;
match trait_item_type {
ty::ConstTraitItem(associated_const) => {
Expand Down
38 changes: 19 additions & 19 deletions src/librustc/metadata/tydecode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub use self::DefIdSource::*;
use middle::region;
use middle::subst;
use middle::subst::VecPerParamSpace;
use middle::ty::{self, ToPredicate, Ty};
use middle::ty::{self, ToPredicate, Ty, HasTypeFlags};

use std::str;
use syntax::abi;
Expand Down Expand Up @@ -471,14 +471,14 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
let def = parse_def_(st, NominalType, conv);
let substs = parse_substs_(st, conv);
assert_eq!(next(st), ']');
return ty::mk_enum(tcx, def, st.tcx.mk_substs(substs));
return tcx.mk_enum(def, st.tcx.mk_substs(substs));
}
'x' => {
assert_eq!(next(st), '[');
let trait_ref = ty::Binder(parse_trait_ref_(st, conv));
let bounds = parse_existential_bounds_(st, conv);
assert_eq!(next(st), ']');
return ty::mk_trait(tcx, trait_ref, bounds);
return tcx.mk_trait(trait_ref, bounds);
}
'p' => {
assert_eq!(next(st), '[');
Expand All @@ -487,38 +487,38 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
let space = parse_param_space(st);
assert_eq!(next(st), '|');
let name = token::intern(&parse_str(st, ']'));
return ty::mk_param(tcx, space, index, name);
return tcx.mk_param(space, index, name);
}
'~' => return ty::mk_uniq(tcx, parse_ty_(st, conv)),
'*' => return ty::mk_ptr(tcx, parse_mt_(st, conv)),
'~' => return tcx.mk_box(parse_ty_(st, conv)),
'*' => return tcx.mk_ptr(parse_mt_(st, conv)),
'&' => {
let r = parse_region_(st, conv);
let mt = parse_mt_(st, conv);
return ty::mk_rptr(tcx, tcx.mk_region(r), mt);
return tcx.mk_ref(tcx.mk_region(r), mt);
}
'V' => {
let t = parse_ty_(st, conv);
let sz = parse_size(st);
return ty::mk_vec(tcx, t, sz);
return match parse_size(st) {
Some(n) => tcx.mk_array(t, n),
None => tcx.mk_slice(t)
};
}
'v' => {
return ty::mk_str(tcx);
return tcx.mk_str();
}
'T' => {
assert_eq!(next(st), '[');
let mut params = Vec::new();
while peek(st) != ']' { params.push(parse_ty_(st, conv)); }
st.pos = st.pos + 1;
return ty::mk_tup(tcx, params);
return tcx.mk_tup(params);
}
'F' => {
let def_id = parse_def_(st, NominalType, conv);
return ty::mk_bare_fn(tcx, Some(def_id),
tcx.mk_bare_fn(parse_bare_fn_ty_(st, conv)));
return tcx.mk_fn(Some(def_id), tcx.mk_bare_fn(parse_bare_fn_ty_(st, conv)));
}
'G' => {
return ty::mk_bare_fn(tcx, None,
tcx.mk_bare_fn(parse_bare_fn_ty_(st, conv)));
return tcx.mk_fn(None, tcx.mk_bare_fn(parse_bare_fn_ty_(st, conv)));
}
'#' => {
let pos = parse_hex(st);
Expand All @@ -534,7 +534,7 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
// If there is a closure buried in the type some where, then we
// need to re-convert any def ids (see case 'k', below). That means
// we can't reuse the cached version.
if !ty::type_has_ty_closure(tt) {
if !tt.has_closure_types() {
return tt;
}
}
Expand All @@ -558,20 +558,20 @@ fn parse_ty_<'a, 'tcx, F>(st: &mut PState<'a, 'tcx>, conv: &mut F) -> Ty<'tcx> w
let did = parse_def_(st, NominalType, conv);
let substs = parse_substs_(st, conv);
assert_eq!(next(st), ']');
return ty::mk_struct(st.tcx, did, st.tcx.mk_substs(substs));
return st.tcx.mk_struct(did, st.tcx.mk_substs(substs));
}
'k' => {
assert_eq!(next(st), '[');
let did = parse_def_(st, ClosureSource, conv);
let substs = parse_substs_(st, conv);
assert_eq!(next(st), ']');
return ty::mk_closure(st.tcx, did, st.tcx.mk_substs(substs));
return st.tcx.mk_closure(did, st.tcx.mk_substs(substs));
}
'P' => {
assert_eq!(next(st), '[');
let trait_ref = parse_trait_ref_(st, conv);
let name = token::intern(&parse_str(st, ']'));
return ty::mk_projection(tcx, trait_ref, name);
return tcx.mk_projection(trait_ref, name);
}
'e' => {
return tcx.types.err;
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/astconv_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ pub fn prim_ty_to_ty<'tcx>(tcx: &ty::ctxt<'tcx>,
match nty {
ast::TyBool => tcx.types.bool,
ast::TyChar => tcx.types.char,
ast::TyInt(it) => ty::mk_mach_int(tcx, it),
ast::TyUint(uit) => ty::mk_mach_uint(tcx, uit),
ast::TyFloat(ft) => ty::mk_mach_float(tcx, ft),
ast::TyStr => ty::mk_str(tcx)
ast::TyInt(it) => tcx.mk_mach_int(it),
ast::TyUint(uit) => tcx.mk_mach_uint(uit),
ast::TyFloat(ft) => tcx.mk_mach_float(ft),
ast::TyStr => tcx.mk_str()
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ impl<'tcx> CastTy<'tcx> {
ty::TyInt(_) => Some(CastTy::Int(IntTy::I)),
ty::TyUint(u) => Some(CastTy::Int(IntTy::U(u))),
ty::TyFloat(_) => Some(CastTy::Float),
ty::TyEnum(..) if ty::type_is_c_like_enum(
tcx, t) => Some(CastTy::Int(IntTy::CEnum)),
ty::TyEnum(..) if t.is_c_like_enum(tcx) =>
Some(CastTy::Int(IntTy::CEnum)),
ty::TyRawPtr(ref mt) => Some(CastTy::Ptr(mt)),
ty::TyRef(_, ref mt) => Some(CastTy::RPtr(mt)),
ty::TyBareFn(..) => Some(CastTy::FnPtr),
Expand Down
8 changes: 4 additions & 4 deletions src/librustc/middle/cfg/construct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -411,14 +411,14 @@ impl<'a, 'tcx> CFGBuilder<'a, 'tcx> {
func_or_rcvr: &ast::Expr,
args: I) -> CFGIndex {
let method_call = ty::MethodCall::expr(call_expr.id);
let return_ty = ty::ty_fn_ret(match self.tcx.method_map.borrow().get(&method_call) {
let fn_ty = match self.tcx.method_map.borrow().get(&method_call) {
Some(method) => method.ty,
None => ty::expr_ty_adjusted(self.tcx, func_or_rcvr)
});
None => self.tcx.expr_ty_adjusted(func_or_rcvr)
};

let func_or_rcvr_exit = self.expr(func_or_rcvr, pred);
let ret = self.straightline(call_expr, func_or_rcvr_exit, args);
if return_ty.diverges() {
if fn_ty.fn_ret().diverges() {
self.add_unreachable_node()
} else {
ret
Expand Down
Loading