2015-11-24 16:00:26 -06:00
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// the rustc crate store interface. This also includes types that
|
|
|
|
// are *mostly* used as a part of that interface, but these should
|
|
|
|
// probably get a better home if someone can find one.
|
|
|
|
|
|
|
|
use back::svh::Svh;
|
|
|
|
use front::map as hir_map;
|
2016-01-20 13:31:10 -06:00
|
|
|
use middle::def::{self, Def};
|
2015-11-24 16:00:26 -06:00
|
|
|
use middle::lang_items;
|
2016-02-29 17:36:51 -06:00
|
|
|
use middle::ty::{self, Ty, TyCtxt, VariantKind};
|
2015-11-24 16:00:26 -06:00
|
|
|
use middle::def_id::{DefId, DefIndex};
|
2015-12-08 14:53:19 -06:00
|
|
|
use mir::repr::Mir;
|
2016-02-05 02:32:33 -06:00
|
|
|
use mir::mir_map::MirMap;
|
2015-11-24 16:00:26 -06:00
|
|
|
use session::Session;
|
|
|
|
use session::search_paths::PathKind;
|
|
|
|
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
|
|
|
|
use std::any::Any;
|
|
|
|
use std::cell::RefCell;
|
|
|
|
use std::rc::Rc;
|
|
|
|
use std::path::PathBuf;
|
|
|
|
use syntax::ast;
|
|
|
|
use syntax::ast_util::{IdVisitingOperation};
|
|
|
|
use syntax::attr;
|
|
|
|
use syntax::codemap::Span;
|
|
|
|
use syntax::ptr::P;
|
|
|
|
use rustc_back::target::Target;
|
|
|
|
use rustc_front::hir;
|
2015-11-25 09:02:59 -06:00
|
|
|
use rustc_front::intravisit::Visitor;
|
2015-11-24 16:00:26 -06:00
|
|
|
use rustc_front::util::IdVisitor;
|
|
|
|
|
|
|
|
pub use self::DefLike::{DlDef, DlField, DlImpl};
|
|
|
|
pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown};
|
|
|
|
|
|
|
|
// lonely orphan structs and enums looking for a better home
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct LinkMeta {
|
|
|
|
pub crate_name: String,
|
|
|
|
pub crate_hash: Svh,
|
|
|
|
}
|
|
|
|
|
|
|
|
// Where a crate came from on the local filesystem. One of these two options
|
|
|
|
// must be non-None.
|
|
|
|
#[derive(PartialEq, Clone, Debug)]
|
|
|
|
pub struct CrateSource {
|
|
|
|
pub dylib: Option<(PathBuf, PathKind)>,
|
|
|
|
pub rlib: Option<(PathBuf, PathKind)>,
|
|
|
|
pub cnum: ast::CrateNum,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Debug, PartialEq, Clone)]
|
|
|
|
pub enum LinkagePreference {
|
|
|
|
RequireDynamic,
|
|
|
|
RequireStatic,
|
|
|
|
}
|
|
|
|
|
|
|
|
enum_from_u32! {
|
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
pub enum NativeLibraryKind {
|
|
|
|
NativeStatic, // native static library (.a archive)
|
|
|
|
NativeFramework, // OSX-specific
|
|
|
|
NativeUnknown, // default way to specify a dynamic library
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Something that a name can resolve to.
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
pub enum DefLike {
|
2016-01-20 13:31:10 -06:00
|
|
|
DlDef(Def),
|
2015-11-24 16:00:26 -06:00
|
|
|
DlImpl(DefId),
|
|
|
|
DlField
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The data we save and restore about an inlined item or method. This is not
|
|
|
|
/// part of the AST that we parse from a file, but it becomes part of the tree
|
|
|
|
/// that we trans.
|
|
|
|
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug)]
|
|
|
|
pub enum InlinedItem {
|
|
|
|
Item(P<hir::Item>),
|
|
|
|
TraitItem(DefId /* impl id */, P<hir::TraitItem>),
|
|
|
|
ImplItem(DefId /* impl id */, P<hir::ImplItem>),
|
|
|
|
Foreign(P<hir::ForeignItem>),
|
|
|
|
}
|
|
|
|
|
|
|
|
/// A borrowed version of `hir::InlinedItem`.
|
2015-12-08 14:53:19 -06:00
|
|
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
2015-11-24 16:00:26 -06:00
|
|
|
pub enum InlinedItemRef<'a> {
|
|
|
|
Item(&'a hir::Item),
|
|
|
|
TraitItem(DefId, &'a hir::TraitItem),
|
|
|
|
ImplItem(DefId, &'a hir::ImplItem),
|
|
|
|
Foreign(&'a hir::ForeignItem)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Item definitions in the currently-compiled crate would have the CrateNum
|
|
|
|
/// LOCAL_CRATE in their DefId.
|
|
|
|
pub const LOCAL_CRATE: ast::CrateNum = 0;
|
|
|
|
|
|
|
|
pub struct ChildItem {
|
|
|
|
pub def: DefLike,
|
|
|
|
pub name: ast::Name,
|
|
|
|
pub vis: hir::Visibility
|
|
|
|
}
|
|
|
|
|
|
|
|
pub enum FoundAst<'ast> {
|
|
|
|
Found(&'ast InlinedItem),
|
2016-02-23 13:10:29 -06:00
|
|
|
FoundParent(DefId, &'ast hir::Item),
|
2015-11-24 16:00:26 -06:00
|
|
|
NotFound,
|
|
|
|
}
|
|
|
|
|
2015-11-25 09:02:59 -06:00
|
|
|
/// A store of Rust crates, through with their metadata
|
|
|
|
/// can be accessed.
|
|
|
|
///
|
|
|
|
/// The `: Any` bound is a temporary measure that allows access
|
|
|
|
/// to the backing `rustc_metadata::cstore::CStore` object. It
|
|
|
|
/// will be removed in the near future - if you need to access
|
|
|
|
/// internal APIs, please tell us.
|
2015-11-24 16:00:26 -06:00
|
|
|
pub trait CrateStore<'tcx> : Any {
|
|
|
|
// item info
|
|
|
|
fn stability(&self, def: DefId) -> Option<attr::Stability>;
|
2015-12-04 10:34:28 -06:00
|
|
|
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;
|
2016-03-05 16:22:44 -06:00
|
|
|
fn visibility(&self, def: DefId) -> hir::Visibility;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn closure_kind(&self, tcx: &TyCtxt<'tcx>, def_id: DefId)
|
2015-11-24 16:00:26 -06:00
|
|
|
-> ty::ClosureKind;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn closure_ty(&self, tcx: &TyCtxt<'tcx>, def_id: DefId)
|
2015-11-24 16:00:26 -06:00
|
|
|
-> ty::ClosureTy<'tcx>;
|
|
|
|
fn item_variances(&self, def: DefId) -> ty::ItemVariances;
|
|
|
|
fn repr_attrs(&self, def: DefId) -> Vec<attr::ReprAttr>;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn item_type(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-24 16:00:26 -06:00
|
|
|
-> ty::TypeScheme<'tcx>;
|
|
|
|
fn item_path(&self, def: DefId) -> Vec<hir_map::PathElem>;
|
2015-12-03 16:11:19 -06:00
|
|
|
fn extern_item_path(&self, def: DefId) -> Vec<hir_map::PathElem>;
|
2015-11-24 16:00:26 -06:00
|
|
|
fn item_name(&self, def: DefId) -> ast::Name;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn item_predicates(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-24 16:00:26 -06:00
|
|
|
-> ty::GenericPredicates<'tcx>;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn item_super_predicates(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-24 16:00:26 -06:00
|
|
|
-> ty::GenericPredicates<'tcx>;
|
|
|
|
fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>;
|
|
|
|
fn item_symbol(&self, def: DefId) -> String;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn trait_def(&self, tcx: &TyCtxt<'tcx>, def: DefId)-> ty::TraitDef<'tcx>;
|
|
|
|
fn adt_def(&self, tcx: &TyCtxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>;
|
2015-11-24 16:00:26 -06:00
|
|
|
fn method_arg_names(&self, did: DefId) -> Vec<String>;
|
|
|
|
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>;
|
|
|
|
|
|
|
|
// trait info
|
|
|
|
fn implementations_of_trait(&self, def_id: DefId) -> Vec<DefId>;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn provided_trait_methods(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-24 16:00:26 -06:00
|
|
|
-> Vec<Rc<ty::Method<'tcx>>>;
|
|
|
|
fn trait_item_def_ids(&self, def: DefId)
|
|
|
|
-> Vec<ty::ImplOrTraitItemId>;
|
|
|
|
|
|
|
|
// impl info
|
|
|
|
fn impl_items(&self, impl_def_id: DefId) -> Vec<ty::ImplOrTraitItemId>;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn impl_trait_ref(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-24 16:00:26 -06:00
|
|
|
-> Option<ty::TraitRef<'tcx>>;
|
|
|
|
fn impl_polarity(&self, def: DefId) -> Option<hir::ImplPolarity>;
|
|
|
|
fn custom_coerce_unsized_kind(&self, def: DefId)
|
|
|
|
-> Option<ty::adjustment::CustomCoerceUnsized>;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn associated_consts(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-24 16:00:26 -06:00
|
|
|
-> Vec<Rc<ty::AssociatedConst<'tcx>>>;
|
2015-12-22 12:20:47 -06:00
|
|
|
fn impl_parent(&self, impl_def_id: DefId) -> Option<DefId>;
|
2015-11-24 16:00:26 -06:00
|
|
|
|
|
|
|
// trait/impl-item info
|
2016-02-29 17:36:51 -06:00
|
|
|
fn trait_of_item(&self, tcx: &TyCtxt<'tcx>, def_id: DefId)
|
2015-11-24 16:00:26 -06:00
|
|
|
-> Option<DefId>;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn impl_or_trait_item(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2016-02-23 14:04:27 -06:00
|
|
|
-> Option<ty::ImplOrTraitItem<'tcx>>;
|
2015-11-24 16:00:26 -06:00
|
|
|
|
|
|
|
// flags
|
|
|
|
fn is_const_fn(&self, did: DefId) -> bool;
|
|
|
|
fn is_defaulted_trait(&self, did: DefId) -> bool;
|
|
|
|
fn is_impl(&self, did: DefId) -> bool;
|
|
|
|
fn is_default_impl(&self, impl_did: DefId) -> bool;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn is_extern_item(&self, tcx: &TyCtxt<'tcx>, did: DefId) -> bool;
|
2015-11-24 16:00:26 -06:00
|
|
|
fn is_static_method(&self, did: DefId) -> bool;
|
|
|
|
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool;
|
|
|
|
fn is_typedef(&self, did: DefId) -> bool;
|
|
|
|
|
|
|
|
// crate metadata
|
|
|
|
fn dylib_dependency_formats(&self, cnum: ast::CrateNum)
|
|
|
|
-> Vec<(ast::CrateNum, LinkagePreference)>;
|
|
|
|
fn lang_items(&self, cnum: ast::CrateNum) -> Vec<(DefIndex, usize)>;
|
|
|
|
fn missing_lang_items(&self, cnum: ast::CrateNum) -> Vec<lang_items::LangItem>;
|
|
|
|
fn is_staged_api(&self, cnum: ast::CrateNum) -> bool;
|
|
|
|
fn is_explicitly_linked(&self, cnum: ast::CrateNum) -> bool;
|
|
|
|
fn is_allocator(&self, cnum: ast::CrateNum) -> bool;
|
|
|
|
fn crate_attrs(&self, cnum: ast::CrateNum) -> Vec<ast::Attribute>;
|
|
|
|
fn crate_name(&self, cnum: ast::CrateNum) -> String;
|
|
|
|
fn crate_hash(&self, cnum: ast::CrateNum) -> Svh;
|
|
|
|
fn crate_struct_field_attrs(&self, cnum: ast::CrateNum)
|
|
|
|
-> FnvHashMap<DefId, Vec<ast::Attribute>>;
|
|
|
|
fn plugin_registrar_fn(&self, cnum: ast::CrateNum) -> Option<DefId>;
|
|
|
|
fn native_libraries(&self, cnum: ast::CrateNum) -> Vec<(NativeLibraryKind, String)>;
|
|
|
|
fn reachable_ids(&self, cnum: ast::CrateNum) -> Vec<DefId>;
|
|
|
|
|
|
|
|
// resolve
|
|
|
|
fn def_path(&self, def: DefId) -> hir_map::DefPath;
|
2016-01-17 13:57:54 -06:00
|
|
|
fn variant_kind(&self, def_id: DefId) -> Option<VariantKind>;
|
|
|
|
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>;
|
2015-11-24 16:00:26 -06:00
|
|
|
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>;
|
|
|
|
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
|
|
|
|
fn item_children(&self, did: DefId) -> Vec<ChildItem>;
|
|
|
|
fn crate_top_level_items(&self, cnum: ast::CrateNum) -> Vec<ChildItem>;
|
|
|
|
|
|
|
|
// misc. metadata
|
2016-02-29 17:36:51 -06:00
|
|
|
fn maybe_get_item_ast(&'tcx self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-24 16:00:26 -06:00
|
|
|
-> FoundAst<'tcx>;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn maybe_get_item_mir(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-12-08 14:53:19 -06:00
|
|
|
-> Option<Mir<'tcx>>;
|
2015-11-02 07:46:39 -06:00
|
|
|
fn is_item_mir_available(&self, def: DefId) -> bool;
|
|
|
|
|
2015-11-24 16:00:26 -06:00
|
|
|
// This is basically a 1-based range of ints, which is a little
|
|
|
|
// silly - I may fix that.
|
|
|
|
fn crates(&self) -> Vec<ast::CrateNum>;
|
|
|
|
fn used_libraries(&self) -> Vec<(String, NativeLibraryKind)>;
|
|
|
|
fn used_link_args(&self) -> Vec<String>;
|
|
|
|
|
|
|
|
// utility functions
|
|
|
|
fn metadata_filename(&self) -> &str;
|
|
|
|
fn metadata_section_name(&self, target: &Target) -> &str;
|
2016-02-29 17:36:51 -06:00
|
|
|
fn encode_type(&self, tcx: &TyCtxt<'tcx>, ty: Ty<'tcx>) -> Vec<u8>;
|
2015-11-24 16:00:26 -06:00
|
|
|
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(ast::CrateNum, Option<PathBuf>)>;
|
|
|
|
fn used_crate_source(&self, cnum: ast::CrateNum) -> CrateSource;
|
|
|
|
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<ast::CrateNum>;
|
|
|
|
fn encode_metadata(&self,
|
2016-02-29 17:36:51 -06:00
|
|
|
tcx: &TyCtxt<'tcx>,
|
2015-11-24 16:00:26 -06:00
|
|
|
reexports: &def::ExportMap,
|
|
|
|
item_symbols: &RefCell<NodeMap<String>>,
|
|
|
|
link_meta: &LinkMeta,
|
|
|
|
reachable: &NodeSet,
|
2016-02-05 02:32:33 -06:00
|
|
|
mir_map: &MirMap<'tcx>,
|
2015-11-24 16:00:26 -06:00
|
|
|
krate: &hir::Crate) -> Vec<u8>;
|
|
|
|
fn metadata_encoding_version(&self) -> &[u8];
|
|
|
|
}
|
|
|
|
|
|
|
|
impl InlinedItem {
|
|
|
|
pub fn visit<'ast,V>(&'ast self, visitor: &mut V)
|
|
|
|
where V: Visitor<'ast>
|
|
|
|
{
|
|
|
|
match *self {
|
2016-02-09 15:00:20 -06:00
|
|
|
InlinedItem::Item(ref i) => visitor.visit_item(&i),
|
|
|
|
InlinedItem::Foreign(ref i) => visitor.visit_foreign_item(&i),
|
2015-11-24 16:00:26 -06:00
|
|
|
InlinedItem::TraitItem(_, ref ti) => visitor.visit_trait_item(ti),
|
|
|
|
InlinedItem::ImplItem(_, ref ii) => visitor.visit_impl_item(ii),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn visit_ids<O: IdVisitingOperation>(&self, operation: &mut O) {
|
2015-11-25 09:02:59 -06:00
|
|
|
let mut id_visitor = IdVisitor::new(operation);
|
2015-11-24 16:00:26 -06:00
|
|
|
self.visit(&mut id_visitor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: find a better place for this?
|
|
|
|
pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
|
2016-01-21 13:55:54 -06:00
|
|
|
let mut err_count = 0;
|
|
|
|
{
|
|
|
|
let mut say = |s: &str| {
|
|
|
|
match (sp, sess) {
|
|
|
|
(_, None) => panic!("{}", s),
|
|
|
|
(Some(sp), Some(sess)) => sess.span_err(sp, s),
|
|
|
|
(None, Some(sess)) => sess.err(s),
|
|
|
|
}
|
|
|
|
err_count += 1;
|
|
|
|
};
|
|
|
|
if s.is_empty() {
|
|
|
|
say("crate name must not be empty");
|
|
|
|
}
|
|
|
|
for c in s.chars() {
|
|
|
|
if c.is_alphanumeric() { continue }
|
|
|
|
if c == '_' { continue }
|
|
|
|
say(&format!("invalid character `{}` in crate name: `{}`", c, s));
|
2015-11-24 16:00:26 -06:00
|
|
|
}
|
|
|
|
}
|
2016-01-21 13:55:54 -06:00
|
|
|
|
|
|
|
if err_count > 0 {
|
|
|
|
sess.unwrap().abort_if_errors();
|
2015-11-24 16:00:26 -06:00
|
|
|
}
|
|
|
|
}
|
2015-11-26 11:19:54 -06:00
|
|
|
|
|
|
|
/// A dummy crate store that does not support any non-local crates,
|
|
|
|
/// for test purposes.
|
|
|
|
pub struct DummyCrateStore;
|
|
|
|
#[allow(unused_variables)]
|
|
|
|
impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
|
|
|
|
// item info
|
|
|
|
fn stability(&self, def: DefId) -> Option<attr::Stability> { unimplemented!() }
|
2015-12-04 10:34:28 -06:00
|
|
|
fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { unimplemented!() }
|
2016-03-05 16:22:44 -06:00
|
|
|
fn visibility(&self, def: DefId) -> hir::Visibility { unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn closure_kind(&self, tcx: &TyCtxt<'tcx>, def_id: DefId)
|
2015-11-26 11:19:54 -06:00
|
|
|
-> ty::ClosureKind { unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn closure_ty(&self, tcx: &TyCtxt<'tcx>, def_id: DefId)
|
2015-11-26 11:19:54 -06:00
|
|
|
-> ty::ClosureTy<'tcx> { unimplemented!() }
|
|
|
|
fn item_variances(&self, def: DefId) -> ty::ItemVariances { unimplemented!() }
|
|
|
|
fn repr_attrs(&self, def: DefId) -> Vec<attr::ReprAttr> { unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn item_type(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-26 11:19:54 -06:00
|
|
|
-> ty::TypeScheme<'tcx> { unimplemented!() }
|
|
|
|
fn item_path(&self, def: DefId) -> Vec<hir_map::PathElem> { unimplemented!() }
|
2015-12-03 16:11:19 -06:00
|
|
|
fn extern_item_path(&self, def: DefId) -> Vec<hir_map::PathElem> { unimplemented!() }
|
2015-11-26 11:19:54 -06:00
|
|
|
fn item_name(&self, def: DefId) -> ast::Name { unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn item_predicates(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-26 11:19:54 -06:00
|
|
|
-> ty::GenericPredicates<'tcx> { unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn item_super_predicates(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-26 11:19:54 -06:00
|
|
|
-> ty::GenericPredicates<'tcx> { unimplemented!() }
|
|
|
|
fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute> { unimplemented!() }
|
|
|
|
fn item_symbol(&self, def: DefId) -> String { unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn trait_def(&self, tcx: &TyCtxt<'tcx>, def: DefId)-> ty::TraitDef<'tcx>
|
2015-11-26 11:19:54 -06:00
|
|
|
{ unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn adt_def(&self, tcx: &TyCtxt<'tcx>, def: DefId) -> ty::AdtDefMaster<'tcx>
|
2015-11-26 11:19:54 -06:00
|
|
|
{ unimplemented!() }
|
|
|
|
fn method_arg_names(&self, did: DefId) -> Vec<String> { unimplemented!() }
|
|
|
|
fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId> { vec![] }
|
|
|
|
|
|
|
|
// trait info
|
|
|
|
fn implementations_of_trait(&self, def_id: DefId) -> Vec<DefId> { vec![] }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn provided_trait_methods(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-26 11:19:54 -06:00
|
|
|
-> Vec<Rc<ty::Method<'tcx>>> { unimplemented!() }
|
|
|
|
fn trait_item_def_ids(&self, def: DefId)
|
|
|
|
-> Vec<ty::ImplOrTraitItemId> { unimplemented!() }
|
|
|
|
|
|
|
|
// impl info
|
|
|
|
fn impl_items(&self, impl_def_id: DefId) -> Vec<ty::ImplOrTraitItemId>
|
|
|
|
{ unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn impl_trait_ref(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-26 11:19:54 -06:00
|
|
|
-> Option<ty::TraitRef<'tcx>> { unimplemented!() }
|
|
|
|
fn impl_polarity(&self, def: DefId) -> Option<hir::ImplPolarity> { unimplemented!() }
|
|
|
|
fn custom_coerce_unsized_kind(&self, def: DefId)
|
|
|
|
-> Option<ty::adjustment::CustomCoerceUnsized>
|
|
|
|
{ unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn associated_consts(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-26 11:19:54 -06:00
|
|
|
-> Vec<Rc<ty::AssociatedConst<'tcx>>> { unimplemented!() }
|
2015-12-22 12:20:47 -06:00
|
|
|
fn impl_parent(&self, def: DefId) -> Option<DefId> { unimplemented!() }
|
2015-11-26 11:19:54 -06:00
|
|
|
|
|
|
|
// trait/impl-item info
|
2016-02-29 17:36:51 -06:00
|
|
|
fn trait_of_item(&self, tcx: &TyCtxt<'tcx>, def_id: DefId)
|
2015-11-26 11:19:54 -06:00
|
|
|
-> Option<DefId> { unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn impl_or_trait_item(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2016-02-23 14:04:27 -06:00
|
|
|
-> Option<ty::ImplOrTraitItem<'tcx>> { unimplemented!() }
|
2015-11-26 11:19:54 -06:00
|
|
|
|
|
|
|
// flags
|
|
|
|
fn is_const_fn(&self, did: DefId) -> bool { unimplemented!() }
|
|
|
|
fn is_defaulted_trait(&self, did: DefId) -> bool { unimplemented!() }
|
|
|
|
fn is_impl(&self, did: DefId) -> bool { unimplemented!() }
|
|
|
|
fn is_default_impl(&self, impl_did: DefId) -> bool { unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn is_extern_item(&self, tcx: &TyCtxt<'tcx>, did: DefId) -> bool { unimplemented!() }
|
2015-11-26 11:19:54 -06:00
|
|
|
fn is_static_method(&self, did: DefId) -> bool { unimplemented!() }
|
|
|
|
fn is_statically_included_foreign_item(&self, id: ast::NodeId) -> bool { false }
|
|
|
|
fn is_typedef(&self, did: DefId) -> bool { unimplemented!() }
|
|
|
|
|
|
|
|
// crate metadata
|
|
|
|
fn dylib_dependency_formats(&self, cnum: ast::CrateNum)
|
|
|
|
-> Vec<(ast::CrateNum, LinkagePreference)>
|
|
|
|
{ unimplemented!() }
|
|
|
|
fn lang_items(&self, cnum: ast::CrateNum) -> Vec<(DefIndex, usize)>
|
|
|
|
{ unimplemented!() }
|
|
|
|
fn missing_lang_items(&self, cnum: ast::CrateNum) -> Vec<lang_items::LangItem>
|
|
|
|
{ unimplemented!() }
|
|
|
|
fn is_staged_api(&self, cnum: ast::CrateNum) -> bool { unimplemented!() }
|
|
|
|
fn is_explicitly_linked(&self, cnum: ast::CrateNum) -> bool { unimplemented!() }
|
|
|
|
fn is_allocator(&self, cnum: ast::CrateNum) -> bool { unimplemented!() }
|
|
|
|
fn crate_attrs(&self, cnum: ast::CrateNum) -> Vec<ast::Attribute>
|
|
|
|
{ unimplemented!() }
|
|
|
|
fn crate_name(&self, cnum: ast::CrateNum) -> String { unimplemented!() }
|
|
|
|
fn crate_hash(&self, cnum: ast::CrateNum) -> Svh { unimplemented!() }
|
|
|
|
fn crate_struct_field_attrs(&self, cnum: ast::CrateNum)
|
|
|
|
-> FnvHashMap<DefId, Vec<ast::Attribute>>
|
|
|
|
{ unimplemented!() }
|
|
|
|
fn plugin_registrar_fn(&self, cnum: ast::CrateNum) -> Option<DefId>
|
|
|
|
{ unimplemented!() }
|
|
|
|
fn native_libraries(&self, cnum: ast::CrateNum) -> Vec<(NativeLibraryKind, String)>
|
|
|
|
{ unimplemented!() }
|
|
|
|
fn reachable_ids(&self, cnum: ast::CrateNum) -> Vec<DefId> { unimplemented!() }
|
|
|
|
|
|
|
|
// resolve
|
|
|
|
fn def_path(&self, def: DefId) -> hir_map::DefPath { unimplemented!() }
|
2016-01-17 13:57:54 -06:00
|
|
|
fn variant_kind(&self, def_id: DefId) -> Option<VariantKind> { unimplemented!() }
|
|
|
|
fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option<DefId>
|
|
|
|
{ unimplemented!() }
|
2015-11-26 11:19:54 -06:00
|
|
|
fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option<DefId>
|
|
|
|
{ unimplemented!() }
|
|
|
|
fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { unimplemented!() }
|
|
|
|
fn item_children(&self, did: DefId) -> Vec<ChildItem> { unimplemented!() }
|
|
|
|
fn crate_top_level_items(&self, cnum: ast::CrateNum) -> Vec<ChildItem>
|
|
|
|
{ unimplemented!() }
|
|
|
|
|
|
|
|
// misc. metadata
|
2016-02-29 17:36:51 -06:00
|
|
|
fn maybe_get_item_ast(&'tcx self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-11-26 11:19:54 -06:00
|
|
|
-> FoundAst<'tcx> { unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn maybe_get_item_mir(&self, tcx: &TyCtxt<'tcx>, def: DefId)
|
2015-12-08 14:53:19 -06:00
|
|
|
-> Option<Mir<'tcx>> { unimplemented!() }
|
2015-11-02 07:46:39 -06:00
|
|
|
fn is_item_mir_available(&self, def: DefId) -> bool {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
2015-12-08 14:53:19 -06:00
|
|
|
|
2015-11-26 11:19:54 -06:00
|
|
|
// This is basically a 1-based range of ints, which is a little
|
|
|
|
// silly - I may fix that.
|
|
|
|
fn crates(&self) -> Vec<ast::CrateNum> { vec![] }
|
|
|
|
fn used_libraries(&self) -> Vec<(String, NativeLibraryKind)> { vec![] }
|
|
|
|
fn used_link_args(&self) -> Vec<String> { vec![] }
|
|
|
|
|
|
|
|
// utility functions
|
|
|
|
fn metadata_filename(&self) -> &str { unimplemented!() }
|
|
|
|
fn metadata_section_name(&self, target: &Target) -> &str { unimplemented!() }
|
2016-02-29 17:36:51 -06:00
|
|
|
fn encode_type(&self, tcx: &TyCtxt<'tcx>, ty: Ty<'tcx>) -> Vec<u8>
|
2015-11-26 11:19:54 -06:00
|
|
|
{ unimplemented!() }
|
|
|
|
fn used_crates(&self, prefer: LinkagePreference) -> Vec<(ast::CrateNum, Option<PathBuf>)>
|
|
|
|
{ vec![] }
|
|
|
|
fn used_crate_source(&self, cnum: ast::CrateNum) -> CrateSource { unimplemented!() }
|
|
|
|
fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<ast::CrateNum> { None }
|
|
|
|
fn encode_metadata(&self,
|
2016-02-29 17:36:51 -06:00
|
|
|
tcx: &TyCtxt<'tcx>,
|
2015-11-26 11:19:54 -06:00
|
|
|
reexports: &def::ExportMap,
|
|
|
|
item_symbols: &RefCell<NodeMap<String>>,
|
|
|
|
link_meta: &LinkMeta,
|
|
|
|
reachable: &NodeSet,
|
2016-02-05 02:32:33 -06:00
|
|
|
mir_map: &MirMap<'tcx>,
|
2015-11-26 11:19:54 -06:00
|
|
|
krate: &hir::Crate) -> Vec<u8> { vec![] }
|
|
|
|
fn metadata_encoding_version(&self) -> &[u8] { unimplemented!() }
|
|
|
|
}
|
2015-12-01 09:07:15 -06:00
|
|
|
|
|
|
|
|
|
|
|
/// Metadata encoding and decoding can make use of thread-local encoding and
|
|
|
|
/// decoding contexts. These allow implementers of serialize::Encodable and
|
|
|
|
/// Decodable to access information and datastructures that would otherwise not
|
|
|
|
/// be available to them. For example, we can automatically translate def-id and
|
|
|
|
/// span information during decoding because the decoding context knows which
|
|
|
|
/// crate the data is decoded from. Or it allows to make ty::Ty decodable
|
2016-02-29 17:36:51 -06:00
|
|
|
/// because the context has access to the TyCtxt that is needed for creating
|
2015-12-01 09:07:15 -06:00
|
|
|
/// ty::Ty instances.
|
|
|
|
///
|
|
|
|
/// Note, however, that this only works for RBML-based encoding and decoding at
|
|
|
|
/// the moment.
|
|
|
|
pub mod tls {
|
2015-12-25 12:59:02 -06:00
|
|
|
use rbml::opaque::Encoder as OpaqueEncoder;
|
|
|
|
use rbml::opaque::Decoder as OpaqueDecoder;
|
2015-12-01 09:07:15 -06:00
|
|
|
use serialize;
|
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
2016-02-25 17:52:29 -06:00
|
|
|
use std::cell::Cell;
|
2015-12-01 09:07:15 -06:00
|
|
|
use std::mem;
|
2016-02-29 17:36:51 -06:00
|
|
|
use middle::ty::{self, Ty, TyCtxt};
|
2015-12-01 09:07:15 -06:00
|
|
|
use middle::subst::Substs;
|
|
|
|
use middle::def_id::DefId;
|
|
|
|
|
|
|
|
pub trait EncodingContext<'tcx> {
|
2016-02-29 17:36:51 -06:00
|
|
|
fn tcx<'a>(&'a self) -> &'a TyCtxt<'tcx>;
|
2015-12-25 12:59:02 -06:00
|
|
|
fn encode_ty(&self, encoder: &mut OpaqueEncoder, t: Ty<'tcx>);
|
|
|
|
fn encode_substs(&self, encoder: &mut OpaqueEncoder, substs: &Substs<'tcx>);
|
2015-12-01 09:07:15 -06:00
|
|
|
}
|
|
|
|
|
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
2016-02-25 17:52:29 -06:00
|
|
|
/// Marker type used for the TLS slot.
|
|
|
|
/// The type context cannot be used directly because the TLS
|
2015-12-01 09:07:15 -06:00
|
|
|
/// in libstd doesn't allow types generic over lifetimes.
|
|
|
|
struct TlsPayload;
|
|
|
|
|
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
2016-02-25 17:52:29 -06:00
|
|
|
thread_local! {
|
|
|
|
static TLS_ENCODING: Cell<Option<*const TlsPayload>> = Cell::new(None)
|
|
|
|
}
|
2015-12-01 09:07:15 -06:00
|
|
|
|
|
|
|
/// Execute f after pushing the given EncodingContext onto the TLS stack.
|
|
|
|
pub fn enter_encoding_context<'tcx, F, R>(ecx: &EncodingContext<'tcx>,
|
2015-12-25 12:59:02 -06:00
|
|
|
encoder: &mut OpaqueEncoder,
|
2015-12-01 09:07:15 -06:00
|
|
|
f: F) -> R
|
2015-12-25 12:59:02 -06:00
|
|
|
where F: FnOnce(&EncodingContext<'tcx>, &mut OpaqueEncoder) -> R
|
2015-12-01 09:07:15 -06:00
|
|
|
{
|
2015-12-25 12:59:02 -06:00
|
|
|
let tls_payload = (ecx as *const _, encoder as *mut _);
|
2015-12-01 09:07:15 -06:00
|
|
|
let tls_ptr = &tls_payload as *const _ as *const TlsPayload;
|
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
2016-02-25 17:52:29 -06:00
|
|
|
TLS_ENCODING.with(|tls| {
|
|
|
|
let prev = tls.get();
|
|
|
|
tls.set(Some(tls_ptr));
|
|
|
|
let ret = f(ecx, encoder);
|
|
|
|
tls.set(prev);
|
|
|
|
return ret
|
|
|
|
})
|
2015-12-01 09:07:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Execute f with access to the thread-local encoding context and
|
|
|
|
/// rbml encoder. This function will panic if the encoder passed in and the
|
|
|
|
/// context encoder are not the same.
|
|
|
|
///
|
|
|
|
/// Note that this method is 'practically' safe due to its checking that the
|
|
|
|
/// encoder passed in is the same as the one in TLS, but it would still be
|
|
|
|
/// possible to construct cases where the EncodingContext is exchanged
|
|
|
|
/// while the same encoder is used, thus working with a wrong context.
|
|
|
|
pub fn with_encoding_context<'tcx, E, F, R>(encoder: &mut E, f: F) -> R
|
2015-12-25 12:59:02 -06:00
|
|
|
where F: FnOnce(&EncodingContext<'tcx>, &mut OpaqueEncoder) -> R,
|
2015-12-01 09:07:15 -06:00
|
|
|
E: serialize::Encoder
|
|
|
|
{
|
|
|
|
unsafe {
|
2015-12-25 12:59:02 -06:00
|
|
|
unsafe_with_encoding_context(|ecx, tls_encoder| {
|
|
|
|
assert!(encoder as *mut _ as usize == tls_encoder as *mut _ as usize);
|
2015-12-01 09:07:15 -06:00
|
|
|
|
|
|
|
let ecx: &EncodingContext<'tcx> = mem::transmute(ecx);
|
|
|
|
|
2015-12-25 12:59:02 -06:00
|
|
|
f(ecx, tls_encoder)
|
2015-12-01 09:07:15 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Execute f with access to the thread-local encoding context and
|
|
|
|
/// rbml encoder.
|
|
|
|
pub unsafe fn unsafe_with_encoding_context<F, R>(f: F) -> R
|
2015-12-25 12:59:02 -06:00
|
|
|
where F: FnOnce(&EncodingContext, &mut OpaqueEncoder) -> R
|
2015-12-01 09:07:15 -06:00
|
|
|
{
|
|
|
|
TLS_ENCODING.with(|tls| {
|
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
2016-02-25 17:52:29 -06:00
|
|
|
let tls = tls.get().unwrap();
|
|
|
|
let tls_payload = tls as *mut (&EncodingContext, &mut OpaqueEncoder);
|
2015-12-01 09:07:15 -06:00
|
|
|
f((*tls_payload).0, (*tls_payload).1)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait DecodingContext<'tcx> {
|
2016-02-29 17:36:51 -06:00
|
|
|
fn tcx<'a>(&'a self) -> &'a TyCtxt<'tcx>;
|
2015-12-25 12:59:02 -06:00
|
|
|
fn decode_ty(&self, decoder: &mut OpaqueDecoder) -> ty::Ty<'tcx>;
|
|
|
|
fn decode_substs(&self, decoder: &mut OpaqueDecoder) -> Substs<'tcx>;
|
2015-12-01 09:07:15 -06:00
|
|
|
fn translate_def_id(&self, def_id: DefId) -> DefId;
|
|
|
|
}
|
|
|
|
|
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
2016-02-25 17:52:29 -06:00
|
|
|
thread_local! {
|
|
|
|
static TLS_DECODING: Cell<Option<*const TlsPayload>> = Cell::new(None)
|
|
|
|
}
|
2015-12-01 09:07:15 -06:00
|
|
|
|
|
|
|
/// Execute f after pushing the given DecodingContext onto the TLS stack.
|
|
|
|
pub fn enter_decoding_context<'tcx, F, R>(dcx: &DecodingContext<'tcx>,
|
2015-12-25 12:59:02 -06:00
|
|
|
decoder: &mut OpaqueDecoder,
|
2015-12-01 09:07:15 -06:00
|
|
|
f: F) -> R
|
2015-12-25 12:59:02 -06:00
|
|
|
where F: FnOnce(&DecodingContext<'tcx>, &mut OpaqueDecoder) -> R
|
2015-12-01 09:07:15 -06:00
|
|
|
{
|
2015-12-25 12:59:02 -06:00
|
|
|
let tls_payload = (dcx as *const _, decoder as *mut _);
|
2015-12-01 09:07:15 -06:00
|
|
|
let tls_ptr = &tls_payload as *const _ as *const TlsPayload;
|
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
2016-02-25 17:52:29 -06:00
|
|
|
TLS_DECODING.with(|tls| {
|
|
|
|
let prev = tls.get();
|
|
|
|
tls.set(Some(tls_ptr));
|
|
|
|
let ret = f(dcx, decoder);
|
|
|
|
tls.set(prev);
|
|
|
|
return ret
|
|
|
|
})
|
2015-12-01 09:07:15 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Execute f with access to the thread-local decoding context and
|
|
|
|
/// rbml decoder. This function will panic if the decoder passed in and the
|
|
|
|
/// context decoder are not the same.
|
|
|
|
///
|
|
|
|
/// Note that this method is 'practically' safe due to its checking that the
|
|
|
|
/// decoder passed in is the same as the one in TLS, but it would still be
|
|
|
|
/// possible to construct cases where the DecodingContext is exchanged
|
|
|
|
/// while the same decoder is used, thus working with a wrong context.
|
|
|
|
pub fn with_decoding_context<'decoder, 'tcx, D, F, R>(d: &'decoder mut D, f: F) -> R
|
|
|
|
where D: serialize::Decoder,
|
|
|
|
F: FnOnce(&DecodingContext<'tcx>,
|
2015-12-25 12:59:02 -06:00
|
|
|
&mut OpaqueDecoder) -> R,
|
2015-12-01 09:07:15 -06:00
|
|
|
'tcx: 'decoder
|
|
|
|
{
|
|
|
|
unsafe {
|
2015-12-25 12:59:02 -06:00
|
|
|
unsafe_with_decoding_context(|dcx, decoder| {
|
|
|
|
assert!((d as *mut _ as usize) == (decoder as *mut _ as usize));
|
2015-12-01 09:07:15 -06:00
|
|
|
|
|
|
|
let dcx: &DecodingContext<'tcx> = mem::transmute(dcx);
|
|
|
|
|
2015-12-25 12:59:02 -06:00
|
|
|
f(dcx, decoder)
|
2015-12-01 09:07:15 -06:00
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Execute f with access to the thread-local decoding context and
|
|
|
|
/// rbml decoder.
|
|
|
|
pub unsafe fn unsafe_with_decoding_context<F, R>(f: F) -> R
|
2015-12-25 12:59:02 -06:00
|
|
|
where F: FnOnce(&DecodingContext, &mut OpaqueDecoder) -> R
|
2015-12-01 09:07:15 -06:00
|
|
|
{
|
|
|
|
TLS_DECODING.with(|tls| {
|
std: Stabilize APIs for the 1.8 release
This commit is the result of the FCPs ending for the 1.8 release cycle for both
the libs and the lang suteams. The full list of changes are:
Stabilized
* `braced_empty_structs`
* `augmented_assignments`
* `str::encode_utf16` - renamed from `utf16_units`
* `str::EncodeUtf16` - renamed from `Utf16Units`
* `Ref::map`
* `RefMut::map`
* `ptr::drop_in_place`
* `time::Instant`
* `time::SystemTime`
* `{Instant,SystemTime}::now`
* `{Instant,SystemTime}::duration_since` - renamed from `duration_from_earlier`
* `{Instant,SystemTime}::elapsed`
* Various `Add`/`Sub` impls for `Time` and `SystemTime`
* `SystemTimeError`
* `SystemTimeError::duration`
* Various impls for `SystemTimeError`
* `UNIX_EPOCH`
* `ops::{Add,Sub,Mul,Div,Rem,BitAnd,BitOr,BitXor,Shl,Shr}Assign`
Deprecated
* Scoped TLS (the `scoped_thread_local!` macro)
* `Ref::filter_map`
* `RefMut::filter_map`
* `RwLockReadGuard::map`
* `RwLockWriteGuard::map`
* `Condvar::wait_timeout_with`
Closes #27714
Closes #27715
Closes #27746
Closes #27748
Closes #27908
Closes #29866
2016-02-25 17:52:29 -06:00
|
|
|
let tls = tls.get().unwrap();
|
|
|
|
let tls_payload = tls as *mut (&DecodingContext, &mut OpaqueDecoder);
|
2015-12-01 09:07:15 -06:00
|
|
|
f((*tls_payload).0, (*tls_payload).1)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|