Auto merge of #27851 - nikomatsakis:cleanup-ty-decoder, r=eddyb
Just a little code cleanup I was doing as part of another refactoring (which may turn out not to be needed). The main thrust of this is to cleanup the interface to `tydecode.rs` to be less ridiculously repetitive. I also purged the generic "def-id conversion" parameter in favor of a trait object, just to reduce code duplication a bit and make the signatures a bit less messy. I measured the bootstrapping time to build stage2 with these changes, it was identical. (But it'd be easy enough to restore the unboxed closure if we wanted it.)
This commit is contained in:
commit
fc7efab3ab
@ -12,6 +12,8 @@ pub use self::Node::*;
|
||||
pub use self::PathElem::*;
|
||||
use self::MapEntry::*;
|
||||
|
||||
use metadata::inline::InlinedItem;
|
||||
use metadata::inline::InlinedItem as II;
|
||||
use syntax::abi;
|
||||
use syntax::ast::*;
|
||||
use syntax::ast_util;
|
||||
@ -374,8 +376,8 @@ impl<'ast> Map<'ast> {
|
||||
pub fn get_parent_did(&self, id: NodeId) -> DefId {
|
||||
let parent = self.get_parent(id);
|
||||
match self.find_entry(parent) {
|
||||
Some(RootInlinedParent(&InlinedParent {ii: IITraitItem(did, _), ..})) => did,
|
||||
Some(RootInlinedParent(&InlinedParent {ii: IIImplItem(did, _), ..})) => did,
|
||||
Some(RootInlinedParent(&InlinedParent {ii: II::TraitItem(did, _), ..})) => did,
|
||||
Some(RootInlinedParent(&InlinedParent {ii: II::ImplItem(did, _), ..})) => did,
|
||||
_ => ast_util::local_def(parent)
|
||||
}
|
||||
}
|
||||
@ -967,16 +969,16 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
|
||||
-> &'ast InlinedItem {
|
||||
let mut fld = IdAndSpanUpdater { fold_ops: fold_ops };
|
||||
let ii = match ii {
|
||||
IIItem(i) => IIItem(fld.fold_item(i).expect_one("expected one item")),
|
||||
IITraitItem(d, ti) => {
|
||||
IITraitItem(fld.fold_ops.new_def_id(d),
|
||||
fld.fold_trait_item(ti).expect_one("expected one trait item"))
|
||||
II::Item(i) => II::Item(fld.fold_item(i).expect_one("expected one item")),
|
||||
II::TraitItem(d, ti) => {
|
||||
II::TraitItem(fld.fold_ops.new_def_id(d),
|
||||
fld.fold_trait_item(ti).expect_one("expected one trait item"))
|
||||
}
|
||||
IIImplItem(d, ii) => {
|
||||
IIImplItem(fld.fold_ops.new_def_id(d),
|
||||
fld.fold_impl_item(ii).expect_one("expected one impl item"))
|
||||
II::ImplItem(d, ii) => {
|
||||
II::ImplItem(fld.fold_ops.new_def_id(d),
|
||||
fld.fold_impl_item(ii).expect_one("expected one impl item"))
|
||||
}
|
||||
IIForeign(i) => IIForeign(fld.fold_foreign_item(i))
|
||||
II::Foreign(i) => II::Foreign(fld.fold_foreign_item(i))
|
||||
};
|
||||
|
||||
let ii_parent = map.forest.inlined_items.alloc(InlinedParent {
|
||||
@ -990,20 +992,20 @@ pub fn map_decoded_item<'ast, F: FoldOps>(map: &Map<'ast>,
|
||||
parent_node: ii_parent_id,
|
||||
};
|
||||
collector.insert_entry(ii_parent_id, RootInlinedParent(ii_parent));
|
||||
visit::walk_inlined_item(&mut collector, &ii_parent.ii);
|
||||
ii_parent.ii.visit(&mut collector);
|
||||
|
||||
// Methods get added to the AST map when their impl is visited. Since we
|
||||
// don't decode and instantiate the impl, but just the method, we have to
|
||||
// add it to the table now. Likewise with foreign items.
|
||||
match ii_parent.ii {
|
||||
IIItem(_) => {}
|
||||
IITraitItem(_, ref ti) => {
|
||||
II::Item(_) => {}
|
||||
II::TraitItem(_, ref ti) => {
|
||||
collector.insert(ti.id, NodeTraitItem(ti));
|
||||
}
|
||||
IIImplItem(_, ref ii) => {
|
||||
II::ImplItem(_, ref ii) => {
|
||||
collector.insert(ii.id, NodeImplItem(ii));
|
||||
}
|
||||
IIForeign(ref i) => {
|
||||
II::Foreign(ref i) => {
|
||||
collector.insert(i.id, NodeForeignItem(i));
|
||||
}
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ use ast_map;
|
||||
use metadata::common::*;
|
||||
use metadata::cstore;
|
||||
use metadata::decoder;
|
||||
use metadata::inline::InlinedItem;
|
||||
use middle::lang_items;
|
||||
use middle::ty;
|
||||
|
||||
@ -96,8 +97,8 @@ pub fn get_item_path(tcx: &ty::ctxt, def: ast::DefId) -> Vec<ast_map::PathElem>
|
||||
}
|
||||
|
||||
pub enum FoundAst<'ast> {
|
||||
Found(&'ast ast::InlinedItem),
|
||||
FoundParent(ast::DefId, &'ast ast::InlinedItem),
|
||||
Found(&'ast InlinedItem),
|
||||
FoundParent(ast::DefId, &'ast InlinedItem),
|
||||
NotFound,
|
||||
}
|
||||
|
||||
|
@ -23,9 +23,8 @@ use metadata::csearch::MethodInfo;
|
||||
use metadata::csearch;
|
||||
use metadata::cstore;
|
||||
use metadata::encoder::def_to_u64;
|
||||
use metadata::tydecode::{parse_ty_data, parse_region_data,
|
||||
parse_type_param_def_data, parse_bare_fn_ty_data,
|
||||
parse_trait_ref_data, parse_predicate_data};
|
||||
use metadata::inline::InlinedItem;
|
||||
use metadata::tydecode::TyDecoder;
|
||||
use middle::def;
|
||||
use middle::lang_items;
|
||||
use middle::subst;
|
||||
@ -234,22 +233,25 @@ fn variant_disr_val(d: rbml::Doc) -> Option<ty::Disr> {
|
||||
|
||||
fn doc_type<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd) -> Ty<'tcx> {
|
||||
let tp = reader::get_doc(doc, tag_items_data_item_type);
|
||||
parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
TyDecoder::with_doc(tcx, cdata.cnum, tp,
|
||||
&mut |_, did| translate_def_id(cdata, did))
|
||||
.parse_ty()
|
||||
}
|
||||
|
||||
fn maybe_doc_type<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd) -> Option<Ty<'tcx>> {
|
||||
reader::maybe_get_doc(doc, tag_items_data_item_type).map(|tp| {
|
||||
parse_ty_data(tp.data, cdata.cnum, tp.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
TyDecoder::with_doc(tcx, cdata.cnum, tp,
|
||||
&mut |_, did| translate_def_id(cdata, did))
|
||||
.parse_ty()
|
||||
})
|
||||
}
|
||||
|
||||
fn doc_method_fty<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>,
|
||||
cdata: Cmd) -> ty::BareFnTy<'tcx> {
|
||||
let tp = reader::get_doc(doc, tag_item_method_fty);
|
||||
parse_bare_fn_ty_data(tp.data, cdata.cnum, tp.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
TyDecoder::with_doc(tcx, cdata.cnum, tp,
|
||||
&mut |_, did| translate_def_id(cdata, did))
|
||||
.parse_bare_fn_ty()
|
||||
}
|
||||
|
||||
pub fn item_type<'tcx>(_item_id: ast::DefId, item: rbml::Doc,
|
||||
@ -259,8 +261,9 @@ pub fn item_type<'tcx>(_item_id: ast::DefId, item: rbml::Doc,
|
||||
|
||||
fn doc_trait_ref<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd)
|
||||
-> ty::TraitRef<'tcx> {
|
||||
parse_trait_ref_data(doc.data, cdata.cnum, doc.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
TyDecoder::with_doc(tcx, cdata.cnum, doc,
|
||||
&mut |_, did| translate_def_id(cdata, did))
|
||||
.parse_trait_ref()
|
||||
}
|
||||
|
||||
fn item_trait_ref<'tcx>(doc: rbml::Doc, tcx: &ty::ctxt<'tcx>, cdata: Cmd)
|
||||
@ -776,7 +779,7 @@ pub type DecodeInlinedItem<'a> =
|
||||
&ty::ctxt<'tcx>,
|
||||
Vec<ast_map::PathElem>,
|
||||
rbml::Doc)
|
||||
-> Result<&'tcx ast::InlinedItem, Vec<ast_map::PathElem>> + 'a>;
|
||||
-> Result<&'tcx InlinedItem, Vec<ast_map::PathElem>> + 'a>;
|
||||
|
||||
pub fn maybe_get_item_ast<'tcx>(cdata: Cmd, tcx: &ty::ctxt<'tcx>, id: ast::NodeId,
|
||||
mut decode_inlined_item: DecodeInlinedItem)
|
||||
@ -1468,9 +1471,10 @@ fn doc_generics<'tcx>(base_doc: rbml::Doc,
|
||||
|
||||
let mut types = subst::VecPerParamSpace::empty();
|
||||
for p in reader::tagged_docs(doc, tag_type_param_def) {
|
||||
let bd = parse_type_param_def_data(
|
||||
p.data, p.start, cdata.cnum, tcx,
|
||||
|_, did| translate_def_id(cdata, did));
|
||||
let bd =
|
||||
TyDecoder::with_doc(tcx, cdata.cnum, p,
|
||||
&mut |_, did| translate_def_id(cdata, did))
|
||||
.parse_type_param_def();
|
||||
types.push(bd.space, bd);
|
||||
}
|
||||
|
||||
@ -1490,8 +1494,9 @@ fn doc_generics<'tcx>(base_doc: rbml::Doc,
|
||||
let index = reader::doc_as_u64(doc) as u32;
|
||||
|
||||
let bounds = reader::tagged_docs(rp_doc, tag_items_data_region).map(|p| {
|
||||
parse_region_data(p.data, cdata.cnum, p.start, tcx,
|
||||
|_, did| translate_def_id(cdata, did))
|
||||
TyDecoder::with_doc(tcx, cdata.cnum, p,
|
||||
&mut |_, did| translate_def_id(cdata, did))
|
||||
.parse_region()
|
||||
}).collect();
|
||||
|
||||
regions.push(space, ty::RegionParameterDef { name: name,
|
||||
@ -1518,8 +1523,10 @@ fn doc_predicates<'tcx>(base_doc: rbml::Doc,
|
||||
let space = subst::ParamSpace::from_uint(reader::doc_as_u8(space_doc) as usize);
|
||||
|
||||
let data_doc = reader::get_doc(predicate_doc, tag_predicate_data);
|
||||
let data = parse_predicate_data(data_doc.data, data_doc.start, cdata.cnum, tcx,
|
||||
|_, did| translate_def_id(cdata, did));
|
||||
let data =
|
||||
TyDecoder::with_doc(tcx, cdata.cnum, data_doc,
|
||||
&mut |_, did| translate_def_id(cdata, did))
|
||||
.parse_predicate();
|
||||
|
||||
predicates.push(space, data);
|
||||
}
|
||||
|
@ -13,8 +13,6 @@
|
||||
#![allow(unused_must_use)] // everything is just a MemWriter, can't fail
|
||||
#![allow(non_camel_case_types)]
|
||||
|
||||
pub use self::InlinedItemRef::*;
|
||||
|
||||
use ast_map::{self, LinkedPath, PathElem, PathElems};
|
||||
use back::svh::Svh;
|
||||
use session::config;
|
||||
@ -22,6 +20,7 @@ use metadata::common::*;
|
||||
use metadata::cstore;
|
||||
use metadata::decoder;
|
||||
use metadata::tyencode;
|
||||
use metadata::inline::InlinedItemRef;
|
||||
use middle::def;
|
||||
use middle::dependency_format::Linkage;
|
||||
use middle::stability;
|
||||
@ -48,14 +47,6 @@ use syntax::visit;
|
||||
use syntax;
|
||||
use rbml::writer::Encoder;
|
||||
|
||||
/// A borrowed version of `ast::InlinedItem`.
|
||||
pub enum InlinedItemRef<'a> {
|
||||
IIItemRef(&'a ast::Item),
|
||||
IITraitItemRef(DefId, &'a ast::TraitItem),
|
||||
IIImplItemRef(DefId, &'a ast::ImplItem),
|
||||
IIForeignRef(&'a ast::ForeignItem)
|
||||
}
|
||||
|
||||
pub type EncodeInlinedItem<'a> =
|
||||
Box<FnMut(&EncodeContext, &mut Encoder, InlinedItemRef) + 'a>;
|
||||
|
||||
@ -832,7 +823,7 @@ fn encode_info_for_associated_const(ecx: &EncodeContext,
|
||||
|
||||
if let Some(ii) = impl_item_opt {
|
||||
encode_attributes(rbml_w, &ii.attrs);
|
||||
encode_inlined_item(ecx, rbml_w, IIImplItemRef(local_def(parent_id), ii));
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::ImplItem(local_def(parent_id), ii));
|
||||
}
|
||||
|
||||
rbml_w.end_tag();
|
||||
@ -870,7 +861,7 @@ fn encode_info_for_method<'a, 'tcx>(ecx: &EncodeContext<'a, 'tcx>,
|
||||
let needs_inline = any_types || is_default_impl ||
|
||||
attr::requests_inline(&impl_item.attrs);
|
||||
if needs_inline || sig.constness == ast::Constness::Const {
|
||||
encode_inlined_item(ecx, rbml_w, IIImplItemRef(local_def(parent_id),
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::ImplItem(local_def(parent_id),
|
||||
impl_item));
|
||||
}
|
||||
encode_constness(rbml_w, sig.constness);
|
||||
@ -1052,7 +1043,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_name(rbml_w, item.ident.name);
|
||||
encode_path(rbml_w, path);
|
||||
encode_attributes(rbml_w, &item.attrs);
|
||||
encode_inlined_item(ecx, rbml_w, IIItemRef(item));
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
|
||||
encode_visibility(rbml_w, vis);
|
||||
encode_stability(rbml_w, stab);
|
||||
rbml_w.end_tag();
|
||||
@ -1069,7 +1060,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
encode_attributes(rbml_w, &item.attrs);
|
||||
let needs_inline = tps_len > 0 || attr::requests_inline(&item.attrs);
|
||||
if needs_inline || constness == ast::Constness::Const {
|
||||
encode_inlined_item(ecx, rbml_w, IIItemRef(item));
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
|
||||
}
|
||||
if tps_len == 0 {
|
||||
encode_symbol(ecx, rbml_w, item.id);
|
||||
@ -1134,7 +1125,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
for v in &enum_definition.variants {
|
||||
encode_variant_id(rbml_w, local_def(v.node.id));
|
||||
}
|
||||
encode_inlined_item(ecx, rbml_w, IIItemRef(item));
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
|
||||
encode_path(rbml_w, path);
|
||||
|
||||
// Encode inherent implementations for this enumeration.
|
||||
@ -1182,7 +1173,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
needs to know*/
|
||||
encode_struct_fields(rbml_w, variant, def_id);
|
||||
|
||||
encode_inlined_item(ecx, rbml_w, IIItemRef(item));
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Item(item));
|
||||
|
||||
// Encode inherent implementations for this structure.
|
||||
encode_inherent_implementations(ecx, rbml_w, def_id);
|
||||
@ -1457,7 +1448,7 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
match trait_item.node {
|
||||
ast::ConstTraitItem(_, _) => {
|
||||
encode_inlined_item(ecx, rbml_w,
|
||||
IITraitItemRef(def_id, trait_item));
|
||||
InlinedItemRef::TraitItem(def_id, trait_item));
|
||||
}
|
||||
ast::MethodTraitItem(ref sig, ref body) => {
|
||||
// If this is a static method, we've already
|
||||
@ -1471,7 +1462,8 @@ fn encode_info_for_item(ecx: &EncodeContext,
|
||||
|
||||
if body.is_some() {
|
||||
encode_item_sort(rbml_w, 'p');
|
||||
encode_inlined_item(ecx, rbml_w, IITraitItemRef(def_id, trait_item));
|
||||
encode_inlined_item(ecx, rbml_w,
|
||||
InlinedItemRef::TraitItem(def_id, trait_item));
|
||||
} else {
|
||||
encode_item_sort(rbml_w, 'r');
|
||||
}
|
||||
@ -1510,7 +1502,7 @@ fn encode_info_for_foreign_item(ecx: &EncodeContext,
|
||||
encode_bounds_and_type_for_item(rbml_w, ecx, nitem.id);
|
||||
encode_name(rbml_w, nitem.ident.name);
|
||||
if abi == abi::RustIntrinsic {
|
||||
encode_inlined_item(ecx, rbml_w, IIForeignRef(nitem));
|
||||
encode_inlined_item(ecx, rbml_w, InlinedItemRef::Foreign(nitem));
|
||||
}
|
||||
encode_attributes(rbml_w, &*nitem.attrs);
|
||||
let stab = stability::lookup(ecx.tcx, ast_util::local_def(nitem.id));
|
||||
|
64
src/librustc/metadata/inline.rs
Normal file
64
src/librustc/metadata/inline.rs
Normal file
@ -0,0 +1,64 @@
|
||||
// Copyright 2012-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.
|
||||
|
||||
use syntax::ast;
|
||||
use syntax::ast_util::{IdRange, IdRangeComputingVisitor,
|
||||
IdVisitor, IdVisitingOperation};
|
||||
use syntax::ptr::P;
|
||||
use syntax::visit::Visitor;
|
||||
use self::InlinedItem::*;
|
||||
|
||||
/// 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<ast::Item>),
|
||||
TraitItem(ast::DefId /* impl id */, P<ast::TraitItem>),
|
||||
ImplItem(ast::DefId /* impl id */, P<ast::ImplItem>),
|
||||
Foreign(P<ast::ForeignItem>),
|
||||
}
|
||||
|
||||
/// A borrowed version of `ast::InlinedItem`.
|
||||
pub enum InlinedItemRef<'a> {
|
||||
Item(&'a ast::Item),
|
||||
TraitItem(ast::DefId, &'a ast::TraitItem),
|
||||
ImplItem(ast::DefId, &'a ast::ImplItem),
|
||||
Foreign(&'a ast::ForeignItem)
|
||||
}
|
||||
|
||||
impl InlinedItem {
|
||||
pub fn visit<'ast,V>(&'ast self, visitor: &mut V)
|
||||
where V: Visitor<'ast>
|
||||
{
|
||||
match *self {
|
||||
Item(ref i) => visitor.visit_item(&**i),
|
||||
Foreign(ref i) => visitor.visit_foreign_item(&**i),
|
||||
TraitItem(_, ref ti) => visitor.visit_trait_item(ti),
|
||||
ImplItem(_, ref ii) => visitor.visit_impl_item(ii),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn visit_ids<O: IdVisitingOperation>(&self, operation: &mut O) {
|
||||
let mut id_visitor = IdVisitor {
|
||||
operation: operation,
|
||||
pass_through_items: true,
|
||||
visited_outermost: false,
|
||||
};
|
||||
self.visit(&mut id_visitor);
|
||||
}
|
||||
|
||||
pub fn compute_id_range(&self) -> IdRange {
|
||||
let mut visitor = IdRangeComputingVisitor::new();
|
||||
self.visit_ids(&mut visitor);
|
||||
visitor.result()
|
||||
}
|
||||
}
|
||||
|
@ -19,3 +19,4 @@ pub mod csearch;
|
||||
pub mod loader;
|
||||
pub mod filesearch;
|
||||
pub mod macro_import;
|
||||
pub mod inline;
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -17,16 +17,17 @@ use metadata::common as c;
|
||||
use metadata::cstore as cstore;
|
||||
use session::Session;
|
||||
use metadata::decoder;
|
||||
use middle::def;
|
||||
use metadata::encoder as e;
|
||||
use middle::region;
|
||||
use metadata::inline::{InlinedItem, InlinedItemRef};
|
||||
use metadata::tydecode;
|
||||
use metadata::tydecode::{DefIdSource, NominalType, TypeWithId};
|
||||
use metadata::tydecode::{RegionParameter, ClosureSource};
|
||||
use metadata::tyencode;
|
||||
use middle::cast;
|
||||
use middle::check_const::ConstQualif;
|
||||
use middle::def;
|
||||
use middle::privacy::{AllPublic, LastMod};
|
||||
use middle::region;
|
||||
use middle::subst;
|
||||
use middle::subst::VecPerParamSpace;
|
||||
use middle::ty::{self, Ty};
|
||||
@ -75,12 +76,12 @@ trait tr_intern {
|
||||
|
||||
pub fn encode_inlined_item(ecx: &e::EncodeContext,
|
||||
rbml_w: &mut Encoder,
|
||||
ii: e::InlinedItemRef) {
|
||||
ii: InlinedItemRef) {
|
||||
let id = match ii {
|
||||
e::IIItemRef(i) => i.id,
|
||||
e::IIForeignRef(i) => i.id,
|
||||
e::IITraitItemRef(_, ti) => ti.id,
|
||||
e::IIImplItemRef(_, ii) => ii.id,
|
||||
InlinedItemRef::Item(i) => i.id,
|
||||
InlinedItemRef::Foreign(i) => i.id,
|
||||
InlinedItemRef::TraitItem(_, ti) => ti.id,
|
||||
InlinedItemRef::ImplItem(_, ii) => ii.id,
|
||||
};
|
||||
debug!("> Encoding inlined item: {} ({:?})",
|
||||
ecx.tcx.map.path_to_string(id),
|
||||
@ -88,7 +89,7 @@ pub fn encode_inlined_item(ecx: &e::EncodeContext,
|
||||
|
||||
// Folding could be avoided with a smarter encoder.
|
||||
let ii = simplify_ast(ii);
|
||||
let id_range = ast_util::compute_id_range_for_inlined_item(&ii);
|
||||
let id_range = ii.compute_id_range();
|
||||
|
||||
rbml_w.start_tag(c::tag_ast as usize);
|
||||
id_range.encode(rbml_w);
|
||||
@ -124,7 +125,7 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
|
||||
tcx: &ty::ctxt<'tcx>,
|
||||
path: Vec<ast_map::PathElem>,
|
||||
par_doc: rbml::Doc)
|
||||
-> Result<&'tcx ast::InlinedItem, Vec<ast_map::PathElem>> {
|
||||
-> Result<&'tcx InlinedItem, Vec<ast_map::PathElem>> {
|
||||
match par_doc.opt_child(c::tag_ast) {
|
||||
None => Err(path),
|
||||
Some(ast_doc) => {
|
||||
@ -150,10 +151,10 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
|
||||
let ii = ast_map::map_decoded_item(&dcx.tcx.map, path, raw_ii, dcx);
|
||||
|
||||
let ident = match *ii {
|
||||
ast::IIItem(ref i) => i.ident,
|
||||
ast::IIForeign(ref i) => i.ident,
|
||||
ast::IITraitItem(_, ref ti) => ti.ident,
|
||||
ast::IIImplItem(_, ref ii) => ii.ident
|
||||
InlinedItem::Item(ref i) => i.ident,
|
||||
InlinedItem::Foreign(ref i) => i.ident,
|
||||
InlinedItem::TraitItem(_, ref ti) => ti.ident,
|
||||
InlinedItem::ImplItem(_, ref ii) => ii.ident
|
||||
};
|
||||
debug!("Fn named: {}", ident);
|
||||
debug!("< Decoded inlined fn: {}::{}",
|
||||
@ -162,7 +163,7 @@ pub fn decode_inlined_item<'tcx>(cdata: &cstore::crate_metadata,
|
||||
region::resolve_inlined_item(&tcx.sess, &tcx.region_maps, ii);
|
||||
decode_side_tables(dcx, ast_doc);
|
||||
match *ii {
|
||||
ast::IIItem(ref i) => {
|
||||
InlinedItem::Item(ref i) => {
|
||||
debug!(">>> DECODED ITEM >>>\n{}\n<<< DECODED ITEM <<<",
|
||||
syntax::print::pprust::item_to_string(&**i));
|
||||
}
|
||||
@ -349,7 +350,7 @@ impl<D:serialize::Decoder> def_id_decoder_helpers for D
|
||||
// We also have to adjust the spans: for now we just insert a dummy span,
|
||||
// but eventually we should add entries to the local codemap as required.
|
||||
|
||||
fn encode_ast(rbml_w: &mut Encoder, item: &ast::InlinedItem) {
|
||||
fn encode_ast(rbml_w: &mut Encoder, item: &InlinedItem) {
|
||||
rbml_w.start_tag(c::tag_tree as usize);
|
||||
item.encode(rbml_w);
|
||||
rbml_w.end_tag();
|
||||
@ -399,34 +400,34 @@ impl Folder for NestedItemsDropper {
|
||||
// As it happens, trans relies on the fact that we do not export
|
||||
// nested items, as otherwise it would get confused when translating
|
||||
// inlined items.
|
||||
fn simplify_ast(ii: e::InlinedItemRef) -> ast::InlinedItem {
|
||||
fn simplify_ast(ii: InlinedItemRef) -> InlinedItem {
|
||||
let mut fld = NestedItemsDropper;
|
||||
|
||||
match ii {
|
||||
// HACK we're not dropping items.
|
||||
e::IIItemRef(i) => {
|
||||
ast::IIItem(fold::noop_fold_item(P(i.clone()), &mut fld)
|
||||
InlinedItemRef::Item(i) => {
|
||||
InlinedItem::Item(fold::noop_fold_item(P(i.clone()), &mut fld)
|
||||
.expect_one("expected one item"))
|
||||
}
|
||||
e::IITraitItemRef(d, ti) => {
|
||||
ast::IITraitItem(d,
|
||||
InlinedItemRef::TraitItem(d, ti) => {
|
||||
InlinedItem::TraitItem(d,
|
||||
fold::noop_fold_trait_item(P(ti.clone()), &mut fld)
|
||||
.expect_one("noop_fold_trait_item must produce \
|
||||
exactly one trait item"))
|
||||
}
|
||||
e::IIImplItemRef(d, ii) => {
|
||||
ast::IIImplItem(d,
|
||||
InlinedItemRef::ImplItem(d, ii) => {
|
||||
InlinedItem::ImplItem(d,
|
||||
fold::noop_fold_impl_item(P(ii.clone()), &mut fld)
|
||||
.expect_one("noop_fold_impl_item must produce \
|
||||
exactly one impl item"))
|
||||
}
|
||||
e::IIForeignRef(i) => {
|
||||
ast::IIForeign(fold::noop_fold_foreign_item(P(i.clone()), &mut fld))
|
||||
InlinedItemRef::Foreign(i) => {
|
||||
InlinedItem::Foreign(fold::noop_fold_foreign_item(P(i.clone()), &mut fld))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn decode_ast(par_doc: rbml::Doc) -> ast::InlinedItem {
|
||||
fn decode_ast(par_doc: rbml::Doc) -> InlinedItem {
|
||||
let chi_doc = par_doc.get(c::tag_tree as usize);
|
||||
let mut d = reader::Decoder::new(chi_doc);
|
||||
Decodable::decode(&mut d).unwrap()
|
||||
@ -920,9 +921,9 @@ impl<'a, 'b, 'c, 'tcx> ast_util::IdVisitingOperation for
|
||||
|
||||
fn encode_side_tables_for_ii(ecx: &e::EncodeContext,
|
||||
rbml_w: &mut Encoder,
|
||||
ii: &ast::InlinedItem) {
|
||||
ii: &InlinedItem) {
|
||||
rbml_w.start_tag(c::tag_table as usize);
|
||||
ast_util::visit_ids_for_inlined_item(ii, &mut SideTableEncodingIdVisitor {
|
||||
ii.visit_ids(&mut SideTableEncodingIdVisitor {
|
||||
ecx: ecx,
|
||||
rbml_w: rbml_w
|
||||
});
|
||||
@ -1074,6 +1075,10 @@ impl<'a> doc_decoder_helpers for rbml::Doc<'a> {
|
||||
}
|
||||
|
||||
trait rbml_decoder_decoder_helpers<'tcx> {
|
||||
fn read_ty_encoded<'a, 'b, F, R>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>,
|
||||
f: F) -> R
|
||||
where F: for<'x> FnOnce(&mut tydecode::TyDecoder<'x, 'tcx>) -> R;
|
||||
|
||||
fn read_ty<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> Ty<'tcx>;
|
||||
fn read_tys<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>) -> Vec<Ty<'tcx>>;
|
||||
fn read_trait_ref<'a, 'b>(&mut self, dcx: &DecodeContext<'a, 'b, 'tcx>)
|
||||
@ -1122,14 +1127,14 @@ trait rbml_decoder_decoder_helpers<'tcx> {
|
||||
|
||||
impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
|
||||
fn read_ty_nodcx(&mut self,
|
||||
tcx: &ty::ctxt<'tcx>, cdata: &cstore::crate_metadata) -> Ty<'tcx> {
|
||||
tcx: &ty::ctxt<'tcx>,
|
||||
cdata: &cstore::crate_metadata)
|
||||
-> Ty<'tcx> {
|
||||
self.read_opaque(|_, doc| {
|
||||
Ok(tydecode::parse_ty_data(
|
||||
doc.data,
|
||||
cdata.cnum,
|
||||
doc.start,
|
||||
tcx,
|
||||
|_, id| decoder::translate_def_id(cdata, id)))
|
||||
Ok(
|
||||
tydecode::TyDecoder::with_doc(tcx, cdata.cnum, doc,
|
||||
&mut |_, id| decoder::translate_def_id(cdata, id))
|
||||
.parse_ty())
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
@ -1148,32 +1153,22 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
|
||||
-> subst::Substs<'tcx>
|
||||
{
|
||||
self.read_opaque(|_, doc| {
|
||||
Ok(tydecode::parse_substs_data(
|
||||
doc.data,
|
||||
cdata.cnum,
|
||||
doc.start,
|
||||
tcx,
|
||||
|_, id| decoder::translate_def_id(cdata, id)))
|
||||
Ok(
|
||||
tydecode::TyDecoder::with_doc(tcx, cdata.cnum, doc,
|
||||
&mut |_, id| decoder::translate_def_id(cdata, id))
|
||||
.parse_substs())
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
fn read_ty<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>) -> Ty<'tcx> {
|
||||
// Note: regions types embed local node ids. In principle, we
|
||||
// should translate these node ids into the new decode
|
||||
// context. However, we do not bother, because region types
|
||||
// are not used during trans.
|
||||
|
||||
fn read_ty_encoded<'b, 'c, F, R>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>, op: F) -> R
|
||||
where F: for<'x> FnOnce(&mut tydecode::TyDecoder<'x,'tcx>) -> R
|
||||
{
|
||||
return self.read_opaque(|this, doc| {
|
||||
debug!("read_ty({})", type_string(doc));
|
||||
|
||||
let ty = tydecode::parse_ty_data(
|
||||
doc.data,
|
||||
dcx.cdata.cnum,
|
||||
doc.start,
|
||||
dcx.tcx,
|
||||
|s, a| this.convert_def_id(dcx, s, a));
|
||||
|
||||
Ok(ty)
|
||||
debug!("read_ty_encoded({})", type_string(doc));
|
||||
Ok(op(
|
||||
&mut tydecode::TyDecoder::with_doc(
|
||||
dcx.tcx, dcx.cdata.cnum, doc,
|
||||
&mut |s, a| this.convert_def_id(dcx, s, a))))
|
||||
}).unwrap();
|
||||
|
||||
fn type_string(doc: rbml::Doc) -> String {
|
||||
@ -1185,6 +1180,15 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_ty<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>) -> Ty<'tcx> {
|
||||
// Note: regions types embed local node ids. In principle, we
|
||||
// should translate these node ids into the new decode
|
||||
// context. However, we do not bother, because region types
|
||||
// are not used during trans.
|
||||
|
||||
return self.read_ty_encoded(dcx, |decoder| decoder.parse_ty());
|
||||
}
|
||||
|
||||
fn read_tys<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
|
||||
-> Vec<Ty<'tcx>> {
|
||||
self.read_to_vec(|this| Ok(this.read_ty(dcx))).unwrap().into_iter().collect()
|
||||
@ -1192,49 +1196,23 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
|
||||
|
||||
fn read_trait_ref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
|
||||
-> ty::TraitRef<'tcx> {
|
||||
self.read_opaque(|this, doc| {
|
||||
let ty = tydecode::parse_trait_ref_data(
|
||||
doc.data,
|
||||
dcx.cdata.cnum,
|
||||
doc.start,
|
||||
dcx.tcx,
|
||||
|s, a| this.convert_def_id(dcx, s, a));
|
||||
Ok(ty)
|
||||
}).unwrap()
|
||||
self.read_ty_encoded(dcx, |decoder| decoder.parse_trait_ref())
|
||||
}
|
||||
|
||||
fn read_poly_trait_ref<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
|
||||
-> ty::PolyTraitRef<'tcx> {
|
||||
ty::Binder(self.read_opaque(|this, doc| {
|
||||
let ty = tydecode::parse_trait_ref_data(
|
||||
doc.data,
|
||||
dcx.cdata.cnum,
|
||||
doc.start,
|
||||
dcx.tcx,
|
||||
|s, a| this.convert_def_id(dcx, s, a));
|
||||
Ok(ty)
|
||||
}).unwrap())
|
||||
ty::Binder(self.read_ty_encoded(dcx, |decoder| decoder.parse_trait_ref()))
|
||||
}
|
||||
|
||||
fn read_type_param_def<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
|
||||
-> ty::TypeParameterDef<'tcx> {
|
||||
self.read_opaque(|this, doc| {
|
||||
Ok(tydecode::parse_type_param_def_data(
|
||||
doc.data,
|
||||
doc.start,
|
||||
dcx.cdata.cnum,
|
||||
dcx.tcx,
|
||||
|s, a| this.convert_def_id(dcx, s, a)))
|
||||
}).unwrap()
|
||||
self.read_ty_encoded(dcx, |decoder| decoder.parse_type_param_def())
|
||||
}
|
||||
|
||||
fn read_predicate<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
|
||||
-> ty::Predicate<'tcx>
|
||||
{
|
||||
self.read_opaque(|this, doc| {
|
||||
Ok(tydecode::parse_predicate_data(doc.data, doc.start, dcx.cdata.cnum, dcx.tcx,
|
||||
|s, a| this.convert_def_id(dcx, s, a)))
|
||||
}).unwrap()
|
||||
self.read_ty_encoded(dcx, |decoder| decoder.parse_predicate())
|
||||
}
|
||||
|
||||
fn read_type_scheme<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
|
||||
@ -1268,23 +1246,15 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
|
||||
fn read_existential_bounds<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
|
||||
-> ty::ExistentialBounds<'tcx>
|
||||
{
|
||||
self.read_opaque(|this, doc| {
|
||||
Ok(tydecode::parse_existential_bounds_data(doc.data,
|
||||
dcx.cdata.cnum,
|
||||
doc.start,
|
||||
dcx.tcx,
|
||||
|s, a| this.convert_def_id(dcx, s, a)))
|
||||
}).unwrap()
|
||||
self.read_ty_encoded(dcx, |decoder| decoder.parse_existential_bounds())
|
||||
}
|
||||
|
||||
fn read_substs<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
|
||||
-> subst::Substs<'tcx> {
|
||||
self.read_opaque(|this, doc| {
|
||||
Ok(tydecode::parse_substs_data(doc.data,
|
||||
dcx.cdata.cnum,
|
||||
doc.start,
|
||||
dcx.tcx,
|
||||
|s, a| this.convert_def_id(dcx, s, a)))
|
||||
Ok(tydecode::TyDecoder::with_doc(dcx.tcx, dcx.cdata.cnum, doc,
|
||||
&mut |s, a| this.convert_def_id(dcx, s, a))
|
||||
.parse_substs())
|
||||
}).unwrap()
|
||||
}
|
||||
|
||||
@ -1379,14 +1349,7 @@ impl<'a, 'tcx> rbml_decoder_decoder_helpers<'tcx> for reader::Decoder<'a> {
|
||||
fn read_closure_ty<'b, 'c>(&mut self, dcx: &DecodeContext<'b, 'c, 'tcx>)
|
||||
-> ty::ClosureTy<'tcx>
|
||||
{
|
||||
self.read_opaque(|this, doc| {
|
||||
Ok(tydecode::parse_ty_closure_data(
|
||||
doc.data,
|
||||
dcx.cdata.cnum,
|
||||
doc.start,
|
||||
dcx.tcx,
|
||||
|s, a| this.convert_def_id(dcx, s, a)))
|
||||
}).unwrap()
|
||||
self.read_ty_encoded(dcx, |decoder| decoder.parse_closure_ty())
|
||||
}
|
||||
|
||||
/// Converts a def-id that appears in a type. The correct
|
||||
@ -1644,15 +1607,15 @@ fn test_simplification() {
|
||||
return alist {eq_fn: eq_int, data: Vec::new()};
|
||||
}
|
||||
).unwrap();
|
||||
let item_in = e::IIItemRef(&*item);
|
||||
let item_in = InlinedItemRef::Item(&*item);
|
||||
let item_out = simplify_ast(item_in);
|
||||
let item_exp = ast::IIItem(quote_item!(&cx,
|
||||
let item_exp = InlinedItem::Item(quote_item!(&cx,
|
||||
fn new_int_alist<B>() -> alist<isize, B> {
|
||||
return alist {eq_fn: eq_int, data: Vec::new()};
|
||||
}
|
||||
).unwrap());
|
||||
match (item_out, item_exp) {
|
||||
(ast::IIItem(item_out), ast::IIItem(item_exp)) => {
|
||||
(InlinedItem::Item(item_out), InlinedItem::Item(item_exp)) => {
|
||||
assert!(pprust::item_to_string(&*item_out) ==
|
||||
pprust::item_to_string(&*item_exp));
|
||||
}
|
||||
|
@ -17,6 +17,7 @@ use self::EvalHint::*;
|
||||
use ast_map;
|
||||
use ast_map::blocks::FnLikeNode;
|
||||
use metadata::csearch;
|
||||
use metadata::inline::InlinedItem;
|
||||
use middle::{astencode, def, infer, subst, traits};
|
||||
use middle::pat_util::def_to_path;
|
||||
use middle::ty::{self, Ty};
|
||||
@ -86,7 +87,7 @@ fn lookup_variant_by_id<'a>(tcx: &'a ty::ctxt,
|
||||
}
|
||||
let expr_id = match csearch::maybe_get_item_ast(tcx, enum_def,
|
||||
Box::new(|a, b, c, d| astencode::decode_inlined_item(a, b, c, d))) {
|
||||
csearch::FoundAst::Found(&ast::IIItem(ref item)) => match item.node {
|
||||
csearch::FoundAst::Found(&InlinedItem::Item(ref item)) => match item.node {
|
||||
ast::ItemEnum(ast::EnumDef { ref variants }, _) => {
|
||||
// NOTE this doesn't do the right thing, it compares inlined
|
||||
// NodeId's to the original variant_def's NodeId, but they
|
||||
@ -161,11 +162,11 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>,
|
||||
let mut used_ref_id = false;
|
||||
let expr_id = match csearch::maybe_get_item_ast(tcx, def_id,
|
||||
Box::new(|a, b, c, d| astencode::decode_inlined_item(a, b, c, d))) {
|
||||
csearch::FoundAst::Found(&ast::IIItem(ref item)) => match item.node {
|
||||
csearch::FoundAst::Found(&InlinedItem::Item(ref item)) => match item.node {
|
||||
ast::ItemConst(_, ref const_expr) => Some(const_expr.id),
|
||||
_ => None
|
||||
},
|
||||
csearch::FoundAst::Found(&ast::IITraitItem(trait_id, ref ti)) => match ti.node {
|
||||
csearch::FoundAst::Found(&InlinedItem::TraitItem(trait_id, ref ti)) => match ti.node {
|
||||
ast::ConstTraitItem(_, _) => {
|
||||
used_ref_id = true;
|
||||
match maybe_ref_id {
|
||||
@ -184,7 +185,7 @@ pub fn lookup_const_by_id<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>,
|
||||
}
|
||||
_ => None
|
||||
},
|
||||
csearch::FoundAst::Found(&ast::IIImplItem(_, ref ii)) => match ii.node {
|
||||
csearch::FoundAst::Found(&InlinedItem::ImplItem(_, ref ii)) => match ii.node {
|
||||
ast::ConstImplItem(_, ref expr) => Some(expr.id),
|
||||
_ => None
|
||||
},
|
||||
@ -217,8 +218,8 @@ fn inline_const_fn_from_external_crate(tcx: &ty::ctxt, def_id: ast::DefId)
|
||||
|
||||
let fn_id = match csearch::maybe_get_item_ast(tcx, def_id,
|
||||
box |a, b, c, d| astencode::decode_inlined_item(a, b, c, d)) {
|
||||
csearch::FoundAst::Found(&ast::IIItem(ref item)) => Some(item.id),
|
||||
csearch::FoundAst::Found(&ast::IIImplItem(_, ref item)) => Some(item.id),
|
||||
csearch::FoundAst::Found(&InlinedItem::Item(ref item)) => Some(item.id),
|
||||
csearch::FoundAst::Found(&InlinedItem::ImplItem(_, ref item)) => Some(item.id),
|
||||
_ => None
|
||||
};
|
||||
tcx.extern_const_fns.borrow_mut().insert(def_id,
|
||||
|
@ -17,8 +17,9 @@
|
||||
//! `middle/typeck/infer/region_inference.rs`
|
||||
|
||||
use ast_map;
|
||||
use session::Session;
|
||||
use metadata::inline::InlinedItem;
|
||||
use middle::ty::{self, Ty};
|
||||
use session::Session;
|
||||
use util::nodemap::{FnvHashMap, FnvHashSet, NodeMap};
|
||||
|
||||
use std::cell::RefCell;
|
||||
@ -1231,7 +1232,7 @@ pub fn resolve_crate(sess: &Session, krate: &ast::Crate) -> RegionMaps {
|
||||
|
||||
pub fn resolve_inlined_item(sess: &Session,
|
||||
region_maps: &RegionMaps,
|
||||
item: &ast::InlinedItem) {
|
||||
item: &InlinedItem) {
|
||||
let mut visitor = RegionResolutionVisitor {
|
||||
sess: sess,
|
||||
region_maps: region_maps,
|
||||
@ -1241,5 +1242,5 @@ pub fn resolve_inlined_item(sess: &Session,
|
||||
var_parent: InnermostDeclaringBlock::None
|
||||
}
|
||||
};
|
||||
visit::walk_inlined_item(&mut visitor, item);
|
||||
item.visit(&mut visitor);
|
||||
}
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
use llvm::{AvailableExternallyLinkage, InternalLinkage, SetLinkage};
|
||||
use metadata::csearch;
|
||||
use metadata::inline::InlinedItem;
|
||||
use middle::astencode;
|
||||
use middle::subst::Substs;
|
||||
use trans::base::{push_ctxt, trans_item, get_item_val, trans_fn};
|
||||
@ -48,7 +49,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
|
||||
ccx.external().borrow_mut().insert(fn_id, None);
|
||||
return None;
|
||||
}
|
||||
csearch::FoundAst::Found(&ast::IIItem(ref item)) => {
|
||||
csearch::FoundAst::Found(&InlinedItem::Item(ref item)) => {
|
||||
ccx.external().borrow_mut().insert(fn_id, Some(item.id));
|
||||
ccx.external_srcs().borrow_mut().insert(item.id, fn_id);
|
||||
|
||||
@ -91,12 +92,12 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
|
||||
|
||||
item.id
|
||||
}
|
||||
csearch::FoundAst::Found(&ast::IIForeign(ref item)) => {
|
||||
csearch::FoundAst::Found(&InlinedItem::Foreign(ref item)) => {
|
||||
ccx.external().borrow_mut().insert(fn_id, Some(item.id));
|
||||
ccx.external_srcs().borrow_mut().insert(item.id, fn_id);
|
||||
item.id
|
||||
}
|
||||
csearch::FoundAst::FoundParent(parent_id, &ast::IIItem(ref item)) => {
|
||||
csearch::FoundAst::FoundParent(parent_id, &InlinedItem::Item(ref item)) => {
|
||||
ccx.external().borrow_mut().insert(parent_id, Some(item.id));
|
||||
ccx.external_srcs().borrow_mut().insert(item.id, parent_id);
|
||||
|
||||
@ -131,7 +132,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
|
||||
ccx.sess().bug("maybe_get_item_ast returned a FoundParent \
|
||||
with a non-item parent");
|
||||
}
|
||||
csearch::FoundAst::Found(&ast::IITraitItem(_, ref trait_item)) => {
|
||||
csearch::FoundAst::Found(&InlinedItem::TraitItem(_, ref trait_item)) => {
|
||||
ccx.external().borrow_mut().insert(fn_id, Some(trait_item.id));
|
||||
ccx.external_srcs().borrow_mut().insert(trait_item.id, fn_id);
|
||||
|
||||
@ -150,7 +151,7 @@ fn instantiate_inline(ccx: &CrateContext, fn_id: ast::DefId)
|
||||
// don't.
|
||||
trait_item.id
|
||||
}
|
||||
csearch::FoundAst::Found(&ast::IIImplItem(impl_did, ref impl_item)) => {
|
||||
csearch::FoundAst::Found(&InlinedItem::ImplItem(impl_did, ref impl_item)) => {
|
||||
ccx.external().borrow_mut().insert(fn_id, Some(impl_item.id));
|
||||
ccx.external_srcs().borrow_mut().insert(impl_item.id, fn_id);
|
||||
|
||||
|
@ -23,7 +23,6 @@ pub use self::FloatTy::*;
|
||||
pub use self::FunctionRetTy::*;
|
||||
pub use self::ForeignItem_::*;
|
||||
pub use self::ImplItem_::*;
|
||||
pub use self::InlinedItem::*;
|
||||
pub use self::IntTy::*;
|
||||
pub use self::Item_::*;
|
||||
pub use self::KleeneOp::*;
|
||||
@ -1925,17 +1924,6 @@ impl ForeignItem_ {
|
||||
}
|
||||
}
|
||||
|
||||
/// 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 {
|
||||
IIItem(P<Item>),
|
||||
IITraitItem(DefId /* impl id */, P<TraitItem>),
|
||||
IIImplItem(DefId /* impl id */, P<ImplItem>),
|
||||
IIForeign(P<ForeignItem>),
|
||||
}
|
||||
|
||||
/// A macro definition, in this crate or imported from another.
|
||||
///
|
||||
/// Not parsed directly, but created on macro import or `macro_rules!` expansion.
|
||||
|
@ -503,19 +503,18 @@ impl<'a, 'v, O: IdVisitingOperation> Visitor<'v> for IdVisitor<'a, O> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn visit_ids_for_inlined_item<O: IdVisitingOperation>(item: &InlinedItem,
|
||||
operation: &mut O) {
|
||||
let mut id_visitor = IdVisitor {
|
||||
operation: operation,
|
||||
pass_through_items: true,
|
||||
visited_outermost: false,
|
||||
};
|
||||
|
||||
visit::walk_inlined_item(&mut id_visitor, item);
|
||||
pub struct IdRangeComputingVisitor {
|
||||
result: IdRange,
|
||||
}
|
||||
|
||||
struct IdRangeComputingVisitor {
|
||||
result: IdRange,
|
||||
impl IdRangeComputingVisitor {
|
||||
pub fn new() -> IdRangeComputingVisitor {
|
||||
IdRangeComputingVisitor { result: IdRange::max() }
|
||||
}
|
||||
|
||||
pub fn result(&self) -> IdRange {
|
||||
self.result
|
||||
}
|
||||
}
|
||||
|
||||
impl IdVisitingOperation for IdRangeComputingVisitor {
|
||||
@ -524,14 +523,6 @@ impl IdVisitingOperation for IdRangeComputingVisitor {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn compute_id_range_for_inlined_item(item: &InlinedItem) -> IdRange {
|
||||
let mut visitor = IdRangeComputingVisitor {
|
||||
result: IdRange::max()
|
||||
};
|
||||
visit_ids_for_inlined_item(item, &mut visitor);
|
||||
visitor.result
|
||||
}
|
||||
|
||||
/// Computes the id range for a single fn body, ignoring nested items.
|
||||
pub fn compute_id_range_for_fn_body(fk: visit::FnKind,
|
||||
decl: &FnDecl,
|
||||
@ -540,9 +531,7 @@ pub fn compute_id_range_for_fn_body(fk: visit::FnKind,
|
||||
id: NodeId)
|
||||
-> IdRange
|
||||
{
|
||||
let mut visitor = IdRangeComputingVisitor {
|
||||
result: IdRange::max()
|
||||
};
|
||||
let mut visitor = IdRangeComputingVisitor::new();
|
||||
let mut id_visitor = IdVisitor {
|
||||
operation: &mut visitor,
|
||||
pass_through_items: false,
|
||||
|
@ -142,17 +142,6 @@ pub trait Visitor<'v> : Sized {
|
||||
fn visit_attribute(&mut self, _attr: &'v Attribute) {}
|
||||
}
|
||||
|
||||
pub fn walk_inlined_item<'v,V>(visitor: &mut V, item: &'v InlinedItem)
|
||||
where V: Visitor<'v> {
|
||||
match *item {
|
||||
IIItem(ref i) => visitor.visit_item(&**i),
|
||||
IIForeign(ref i) => visitor.visit_foreign_item(&**i),
|
||||
IITraitItem(_, ref ti) => visitor.visit_trait_item(ti),
|
||||
IIImplItem(_, ref ii) => visitor.visit_impl_item(ii),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
pub fn walk_crate<'v, V: Visitor<'v>>(visitor: &mut V, krate: &'v Crate) {
|
||||
visitor.visit_mod(&krate.module, krate.span, CRATE_NODE_ID);
|
||||
for attr in &krate.attrs {
|
||||
|
Loading…
x
Reference in New Issue
Block a user