decoder::get_impl_trait(&*cdata, def.node, tcx)
}
-// Given a def_id for an impl, return information about its vtables
-pub fn get_impl_vtables<'tcx>(tcx: &ty::ctxt<'tcx>,
- def: ast::DefId)
- -> ty::vtable_res<'tcx> {
- let cstore = &tcx.sess.cstore;
- let cdata = cstore.get_crate_data(def.krate);
- decoder::get_impl_vtables(&*cdata, def.node, tcx)
-}
-
pub fn get_native_libraries(cstore: &cstore::CStore, crate_num: ast::CrateNum)
-> Vec<(cstore::NativeLibraryKind, String)> {
let cdata = cstore.get_crate_data(crate_num);
decoder::get_repr_attrs(&*cdata, def.node)
}
-pub fn is_associated_type(cstore: &cstore::CStore, def: ast::DefId) -> bool {
- let cdata = cstore.get_crate_data(def.krate);
- decoder::is_associated_type(&*cdata, def.node)
-}
-
pub fn is_defaulted_trait(cstore: &cstore::CStore, trait_def_id: ast::DefId) -> bool {
let cdata = cstore.get_crate_data(trait_def_id.krate);
decoder::is_defaulted_trait(&*cdata, trait_def_id.node)
use middle::subst;
use middle::ty::{ImplContainer, TraitContainer};
use middle::ty::{self, Ty};
-use middle::astencode::vtable_decoder_helpers;
use util::nodemap::FnvHashMap;
use std::cell::{Cell, RefCell};
}
}
-pub fn get_impl_vtables<'tcx>(cdata: Cmd,
- id: ast::NodeId,
- tcx: &ty::ctxt<'tcx>)
- -> ty::vtable_res<'tcx>
-{
- let item_doc = lookup_item(id, cdata.data());
- let vtables_doc = reader::get_doc(item_doc, tag_item_impl_vtables);
- let mut decoder = reader::Decoder::new(vtables_doc);
- decoder.read_vtable_res(tcx, cdata)
-}
-
-
pub fn get_symbol(data: &[u8], id: ast::NodeId) -> String {
return item_symbol(lookup_item(id, data));
}
ty::GenericPredicates { predicates: predicates }
}
-pub fn is_associated_type(cdata: Cmd, id: ast::NodeId) -> bool {
- let items = reader::get_doc(rbml::Doc::new(cdata.data()), tag_items);
- match maybe_find_item(id, items) {
- None => false,
- Some(item) => item_sort(item) == Some('t'),
- }
-}
-
pub fn is_defaulted_trait(cdata: Cmd, trait_id: ast::NodeId) -> bool {
let trait_doc = lookup_item(trait_id, cdata.data());
assert!(item_family(trait_doc) == Family::Trait);
pub trait vtable_decoder_helpers<'tcx> {
fn read_vec_per_param_space<T, F>(&mut self, f: F) -> VecPerParamSpace<T> where
F: FnMut(&mut Self) -> T;
- fn read_vtable_res_with_key(&mut self,
- tcx: &ty::ctxt<'tcx>,
- cdata: &cstore::crate_metadata)
- -> (u32, ty::vtable_res<'tcx>);
- fn read_vtable_res(&mut self,
- tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata)
- -> ty::vtable_res<'tcx>;
- fn read_vtable_param_res(&mut self,
- tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata)
- -> ty::vtable_param_res<'tcx>;
- fn read_vtable_origin(&mut self,
- tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata)
- -> ty::vtable_origin<'tcx>;
}
impl<'tcx, 'a> vtable_decoder_helpers<'tcx> for reader::Decoder<'a> {
let fns = self.read_to_vec(|this| Ok(f(this))).unwrap();
VecPerParamSpace::new(types, selfs, fns)
}
-
- fn read_vtable_res_with_key(&mut self,
- tcx: &ty::ctxt<'tcx>,
- cdata: &cstore::crate_metadata)
- -> (u32, ty::vtable_res<'tcx>) {
- self.read_struct("VtableWithKey", 2, |this| {
- let autoderef = this.read_struct_field("autoderef", 0, |this| {
- Decodable::decode(this)
- }).unwrap();
- Ok((autoderef, this.read_struct_field("vtable_res", 1, |this| {
- Ok(this.read_vtable_res(tcx, cdata))
- }).unwrap()))
- }).unwrap()
- }
-
- fn read_vtable_res(&mut self,
- tcx: &ty::ctxt<'tcx>,
- cdata: &cstore::crate_metadata)
- -> ty::vtable_res<'tcx>
- {
- self.read_vec_per_param_space(
- |this| this.read_vtable_param_res(tcx, cdata))
- }
-
- fn read_vtable_param_res(&mut self,
- tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata)
- -> ty::vtable_param_res<'tcx> {
- self.read_to_vec(|this| Ok(this.read_vtable_origin(tcx, cdata)))
- .unwrap().into_iter().collect()
- }
-
- fn read_vtable_origin(&mut self,
- tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata)
- -> ty::vtable_origin<'tcx> {
- self.read_enum("vtable_origin", |this| {
- this.read_enum_variant(&["vtable_static",
- "vtable_param",
- "vtable_error",
- "vtable_closure"],
- |this, i| {
- Ok(match i {
- 0 => {
- ty::vtable_static(
- this.read_enum_variant_arg(0, |this| {
- Ok(this.read_def_id_nodcx(cdata))
- }).unwrap(),
- this.read_enum_variant_arg(1, |this| {
- Ok(this.read_substs_nodcx(tcx, cdata))
- }).unwrap(),
- this.read_enum_variant_arg(2, |this| {
- Ok(this.read_vtable_res(tcx, cdata))
- }).unwrap()
- )
- }
- 1 => {
- ty::vtable_param(
- this.read_enum_variant_arg(0, |this| {
- Decodable::decode(this)
- }).unwrap(),
- this.read_enum_variant_arg(1, |this| {
- this.read_uint()
- }).unwrap()
- )
- }
- 2 => {
- ty::vtable_closure(
- this.read_enum_variant_arg(0, |this| {
- Ok(this.read_def_id_nodcx(cdata))
- }).unwrap()
- )
- }
- 3 => {
- ty::vtable_error
- }
- _ => panic!("bad enum variant")
- })
- })
- }).unwrap()
- }
}
// ___________________________________________________________________________
pub use self::BoundRegion::*;
pub use self::sty::*;
pub use self::IntVarValue::*;
-pub use self::vtable_origin::*;
pub use self::MethodOrigin::*;
pub use self::CopyImplementationError::*;
Struct(usize)
}
-#[derive(Clone, Copy, RustcEncodable, RustcDecodable, PartialEq, PartialOrd, Debug)]
-pub struct param_index {
- pub space: subst::ParamSpace,
- pub index: usize
-}
-
#[derive(Clone, Debug)]
pub enum MethodOrigin<'tcx> {
// fully statically resolved method
// of the method to be invoked
pub type MethodMap<'tcx> = RefCell<FnvHashMap<MethodCall, MethodCallee<'tcx>>>;
-pub type vtable_param_res<'tcx> = Vec<vtable_origin<'tcx>>;
-
-// Resolutions for bounds of all parameters, left to right, for a given path.
-pub type vtable_res<'tcx> = VecPerParamSpace<vtable_param_res<'tcx>>;
-
-#[derive(Clone)]
-pub enum vtable_origin<'tcx> {
- /*
- Statically known vtable. def_id gives the impl item
- from whence comes the vtable, and tys are the type substs.
- vtable_res is the vtable itself.
- */
- vtable_static(ast::DefId, subst::Substs<'tcx>, vtable_res<'tcx>),
-
- /*
- Dynamic vtable, comes from a parameter that has a bound on it:
- fn foo<T:quux,baz,bar>(a: T) -- a's vtable would have a
- vtable_param origin
-
- The first argument is the param index (identifying T in the example),
- and the second is the bound number (identifying baz)
- */
- vtable_param(param_index, usize),
-
- /*
- Vtable automatically generated for a closure. The def ID is the
- ID of the closure expression.
- */
- vtable_closure(ast::DefId),
-
- /*
- Asked to determine the vtable for ty_err. This is the value used
- for the vtables of `Self` in a virtual call like `foo.bar()`
- where `foo` is of object type. The same value is also used when
- type errors occur.
- */
- vtable_error,
-}
-
-
// For every explicit cast into an object type, maps from the cast
// expr to the associated trait ref.
pub type ObjectCastMap<'tcx> = RefCell<NodeMap<ty::PolyTraitRef<'tcx>>>;
/// Maps any item's def-id to its stability index.
pub stability: RefCell<stability::Index>,
- /// Maps def IDs to true if and only if they're associated types.
- pub associated_types: RefCell<DefIdMap<bool>>,
-
/// Caches the results of trait selection. This cache is used
/// for things that do not have to do with the parameters in scope.
pub selection_cache: traits::SelectionCache<'tcx>,
node_lint_levels: RefCell::new(FnvHashMap()),
transmute_restrictions: RefCell::new(Vec::new()),
stability: RefCell::new(stability),
- associated_types: RefCell::new(DefIdMap()),
selection_cache: traits::SelectionCache::new(),
repr_hint_cache: RefCell::new(DefIdMap()),
type_impls_copy_cache: RefCell::new(HashMap::new()),
}
pub fn type_is_trait(ty: Ty) -> bool {
- type_trait_info(ty).is_some()
-}
-
-pub fn type_trait_info<'tcx>(ty: Ty<'tcx>) -> Option<&'tcx TyTrait<'tcx>> {
match ty.sty {
- ty_uniq(ty) | ty_rptr(_, mt { ty, ..}) | ty_ptr(mt { ty, ..}) => match ty.sty {
- ty_trait(ref t) => Some(&**t),
- _ => None
- },
- ty_trait(ref t) => Some(&**t),
- _ => None
+ ty_trait(..) => true,
+ _ => false
}
}
})
}
-/// Returns true if the given ID refers to an associated type and false if it
-/// refers to anything else.
-pub fn is_associated_type(cx: &ctxt, id: ast::DefId) -> bool {
- memoized(&cx.associated_types, id, |id: ast::DefId| {
- if id.krate == ast::LOCAL_CRATE {
- match cx.impl_or_trait_items.borrow().get(&id) {
- Some(ref item) => {
- match **item {
- TypeTraitItem(_) => true,
- _ => false,
- }
- }
- None => false,
- }
- } else {
- csearch::is_associated_type(&cx.sess.cstore, id)
- }
- })
-}
-
/// Returns the parameter index that the given associated type corresponds to.
pub fn associated_type_parameter_index(cx: &ctxt,
trait_def: &TraitDef,
}
}
-impl<'tcx> Repr<'tcx> for vtable_origin<'tcx> {
- fn repr(&self, tcx: &ty::ctxt<'tcx>) -> String {
- match *self {
- vtable_static(def_id, ref tys, ref vtable_res) => {
- format!("vtable_static({:?}:{}, {}, {})",
- def_id,
- ty::item_path_str(tcx, def_id),
- tys.repr(tcx),
- vtable_res.repr(tcx))
- }
-
- vtable_param(x, y) => {
- format!("vtable_param({:?}, {})", x, y)
- }
-
- vtable_closure(def_id) => {
- format!("vtable_closure({:?})", def_id)
- }
-
- vtable_error => {
- format!("vtable_error")
- }
- }
- }
-}
-
pub fn make_substs_for_receiver_types<'tcx>(tcx: &ty::ctxt<'tcx>,
trait_ref: &ty::TraitRef<'tcx>,
method: &ty::Method<'tcx>)
}
}
-impl<'tcx> TypeFoldable<'tcx> for ty::vtable_origin<'tcx> {
- fn fold_with<F: TypeFolder<'tcx>>(&self, folder: &mut F) -> ty::vtable_origin<'tcx> {
- match *self {
- ty::vtable_static(def_id, ref substs, ref origins) => {
- let r_substs = substs.fold_with(folder);
- let r_origins = origins.fold_with(folder);
- ty::vtable_static(def_id, r_substs, r_origins)
- }
- ty::vtable_param(n, b) => {
- ty::vtable_param(n, b)
- }
- ty::vtable_closure(def_id) => {
- ty::vtable_closure(def_id)
- }
- ty::vtable_error => {
- ty::vtable_error
- }
- }
- }
-}
-
impl<'tcx> TypeFoldable<'tcx> for ty::BuiltinBounds {
fn fold_with<F: TypeFolder<'tcx>>(&self, _folder: &mut F) -> ty::BuiltinBounds {
*self