Skip to content

syntax: convert ast_map to use a SmallIntMap. #11616

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

Merged
merged 1 commit into from
Jan 19, 2014
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
11 changes: 4 additions & 7 deletions src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,9 +496,8 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
ebml_w: &mut writer::Encoder,
mod_path: &[ast_map::PathElem],
exp: &middle::resolve::Export2) {
let items = ecx.tcx.items.borrow();
match items.get().find(&exp.def_id.node) {
Some(&ast_map::NodeItem(item, path)) => {
match ecx.tcx.items.find(exp.def_id.node) {
Some(ast_map::NodeItem(item, path)) => {
let original_name = ecx.tcx.sess.str_of(item.ident);

//
Expand Down Expand Up @@ -1347,8 +1346,7 @@ fn my_visit_item(i: &Item,
ebml_w: &mut writer::Encoder,
ecx_ptr: *int,
index: @RefCell<~[entry<i64>]>) {
let items = items.borrow();
match items.get().get_copy(&i.id) {
match items.get(i.id) {
ast_map::NodeItem(_, pt) => {
let mut ebml_w = unsafe {
ebml_w.unsafe_clone()
Expand All @@ -1366,8 +1364,7 @@ fn my_visit_foreign_item(ni: &ForeignItem,
ebml_w: &mut writer::Encoder,
ecx_ptr:*int,
index: @RefCell<~[entry<i64>]>) {
let items = items.borrow();
match items.get().get_copy(&ni.id) {
match items.get(ni.id) {
ast_map::NodeForeignItem(_, abi, _, pt) => {
debug!("writing foreign item {}::{}",
ast_map::path_to_str(
Expand Down
15 changes: 6 additions & 9 deletions src/librustc/middle/borrowck/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,9 +550,8 @@ impl BorrowckCtxt {
move_data::Declared => {}

move_data::MoveExpr => {
let items = self.tcx.items.borrow();
let (expr_ty, expr_span) = match items.get().find(&move.id) {
Some(&ast_map::NodeExpr(expr)) => {
let (expr_ty, expr_span) = match self.tcx.items.find(move.id) {
Some(ast_map::NodeExpr(expr)) => {
(ty::expr_ty_adjusted(self.tcx, expr), expr.span)
}
r => self.tcx.sess.bug(format!("MoveExpr({:?}) maps to {:?}, not Expr",
Expand All @@ -578,9 +577,8 @@ impl BorrowckCtxt {
}

move_data::Captured => {
let items = self.tcx.items.borrow();
let (expr_ty, expr_span) = match items.get().find(&move.id) {
Some(&ast_map::NodeExpr(expr)) => {
let (expr_ty, expr_span) = match self.tcx.items.find(move.id) {
Some(ast_map::NodeExpr(expr)) => {
(ty::expr_ty_adjusted(self.tcx, expr), expr.span)
}
r => self.tcx.sess.bug(format!("Captured({:?}) maps to {:?}, not Expr",
Expand Down Expand Up @@ -768,9 +766,8 @@ impl BorrowckCtxt {
out: &mut ~str) {
match *loan_path {
LpVar(id) => {
let items = self.tcx.items.borrow();
match items.get().find(&id) {
Some(&ast_map::NodeLocal(ref ident, _)) => {
match self.tcx.items.find(id) {
Some(ast_map::NodeLocal(ref ident, _)) => {
out.push_str(token::ident_to_str(ident));
}
r => {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/check_const.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,8 +250,7 @@ impl<'a> Visitor<()> for CheckItemRecursionVisitor<'a> {
match def_map.get().find(&e.id) {
Some(&DefStatic(def_id, _)) if
ast_util::is_local(def_id) => {
let ast_map = self.ast_map.borrow();
match ast_map.get().get_copy(&def_id.node) {
match self.ast_map.get(def_id.node) {
ast_map::NodeItem(it, _) => {
self.visit_item(it, ());
}
Expand Down
10 changes: 4 additions & 6 deletions src/librustc/middle/const_eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,9 @@ pub fn lookup_variant_by_id(tcx: ty::ctxt,

if ast_util::is_local(enum_def) {
{
let items = tcx.items.borrow();
match items.get().find(&enum_def.node) {
match tcx.items.find(enum_def.node) {
None => None,
Some(&ast_map::NodeItem(it, _)) => match it.node {
Some(ast_map::NodeItem(it, _)) => match it.node {
ItemEnum(ast::EnumDef { variants: ref variants }, _) => {
variant_expr(*variants, variant_def.node)
}
Expand Down Expand Up @@ -161,10 +160,9 @@ pub fn lookup_const_by_id(tcx: ty::ctxt, def_id: ast::DefId)
-> Option<@Expr> {
if ast_util::is_local(def_id) {
{
let items = tcx.items.borrow();
match items.get().find(&def_id.node) {
match tcx.items.find(def_id.node) {
None => None,
Some(&ast_map::NodeItem(it, _)) => match it.node {
Some(ast_map::NodeItem(it, _)) => match it.node {
ItemStatic(_, ast::MutImmutable, const_expr) => {
Some(const_expr)
}
Expand Down
16 changes: 7 additions & 9 deletions src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ fn should_explore(tcx: ty::ctxt, def_id: ast::DefId) -> bool {
return false;
}

let items = tcx.items.borrow();
match items.get().find(&def_id.node) {
Some(&ast_map::NodeItem(..))
| Some(&ast_map::NodeMethod(..))
| Some(&ast_map::NodeForeignItem(..))
| Some(&ast_map::NodeTraitMethod(..)) => true,
match tcx.items.find(def_id.node) {
Some(ast_map::NodeItem(..))
| Some(ast_map::NodeMethod(..))
| Some(ast_map::NodeForeignItem(..))
| Some(ast_map::NodeTraitMethod(..)) => true,
_ => false
}
}
Expand Down Expand Up @@ -136,9 +135,8 @@ impl MarkSymbolVisitor {
}
scanned.insert(id);

let items = self.tcx.items.borrow();
match items.get().find(&id) {
Some(node) => {
match self.tcx.items.find(id) {
Some(ref node) => {
self.live_symbols.insert(id);
self.visit_node(node);
}
Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,8 @@ fn find_item(item: &Item, ctxt: &mut EntryContext) {
ItemFn(..) => {
if item.ident.name == special_idents::main.name {
{
let ast_map = ctxt.ast_map.borrow();
match ast_map.get().find(&item.id) {
Some(&ast_map::NodeItem(_, path)) => {
match ctxt.ast_map.find(item.id) {
Some(ast_map::NodeItem(_, path)) => {
if path.len() == 0 {
// This is a top-level function so can be 'main'
if ctxt.main_fn.is_none() {
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1330,8 +1330,7 @@ fn check_stability(cx: &Context, e: &ast::Expr) {

let stability = if ast_util::is_local(id) {
// this crate
let items = cx.tcx.items.borrow();
match items.get().find(&id.node) {
match cx.tcx.items.find(id.node) {
Some(ast_node) => {
let s = ast_node.with_attrs(|attrs| {
attrs.map(|a| {
Expand Down
18 changes: 8 additions & 10 deletions src/librustc/middle/privacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,8 +431,7 @@ impl<'a> PrivacyVisitor<'a> {
let mut closest_private_id = did.node;
loop {
debug!("privacy - examining {}", self.nodestr(closest_private_id));
let items = self.tcx.items.borrow();
let vis = match items.get().find(&closest_private_id) {
let vis = match self.tcx.items.find(closest_private_id) {
// If this item is a method, then we know for sure that it's an
// actual method and not a static method. The reason for this is
// that these cases are only hit in the ExprMethodCall
Expand All @@ -449,22 +448,22 @@ impl<'a> PrivacyVisitor<'a> {
// invocation.
// FIXME(#10573) is this the right behavior? Why not consider
// where the method was defined?
Some(&ast_map::NodeMethod(ref m, imp, _)) => {
Some(ast_map::NodeMethod(ref m, imp, _)) => {
match ty::impl_trait_ref(self.tcx, imp) {
Some(..) => return Allowable,
_ if m.vis == ast::Public => return Allowable,
_ => m.vis
}
}
Some(&ast_map::NodeTraitMethod(..)) => {
Some(ast_map::NodeTraitMethod(..)) => {
return Allowable;
}

// This is not a method call, extract the visibility as one
// would normally look at it
Some(&ast_map::NodeItem(it, _)) => it.vis,
Some(&ast_map::NodeForeignItem(_, _, v, _)) => v,
Some(&ast_map::NodeVariant(ref v, _, _)) => {
Some(ast_map::NodeItem(it, _)) => it.vis,
Some(ast_map::NodeForeignItem(_, _, v, _)) => v,
Some(ast_map::NodeVariant(ref v, _, _)) => {
// sadly enum variants still inherit visibility, so only
// break out of this is explicitly private
if v.node.vis == ast::Private { break }
Expand Down Expand Up @@ -538,9 +537,8 @@ impl<'a> PrivacyVisitor<'a> {
self.tcx.sess.span_err(span, format!("{} is inaccessible",
msg));
}
let items = self.tcx.items.borrow();
match items.get().find(&id) {
Some(&ast_map::NodeItem(item, _)) => {
match self.tcx.items.find(id) {
Some(ast_map::NodeItem(item, _)) => {
let desc = match item.node {
ast::ItemMod(..) => "module",
ast::ItemTrait(..) => "trait",
Expand Down
23 changes: 10 additions & 13 deletions src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,8 @@ fn method_might_be_inlined(tcx: ty::ctxt, method: &ast::Method,
}
if is_local(impl_src) {
{
let items = tcx.items.borrow();
match items.get().find(&impl_src.node) {
Some(&ast_map::NodeItem(item, _)) => {
match tcx.items.find(impl_src.node) {
Some(ast_map::NodeItem(item, _)) => {
item_might_be_inlined(item)
}
Some(..) | None => {
Expand Down Expand Up @@ -213,30 +212,29 @@ impl ReachableContext {
}

let node_id = def_id.node;
let items = tcx.items.borrow();
match items.get().find(&node_id) {
Some(&ast_map::NodeItem(item, _)) => {
match tcx.items.find(node_id) {
Some(ast_map::NodeItem(item, _)) => {
match item.node {
ast::ItemFn(..) => item_might_be_inlined(item),
_ => false,
}
}
Some(&ast_map::NodeTraitMethod(trait_method, _, _)) => {
Some(ast_map::NodeTraitMethod(trait_method, _, _)) => {
match *trait_method {
ast::Required(_) => false,
ast::Provided(_) => true,
}
}
Some(&ast_map::NodeMethod(method, impl_did, _)) => {
Some(ast_map::NodeMethod(method, impl_did, _)) => {
if generics_require_inlining(&method.generics) ||
attributes_specify_inlining(method.attrs) {
true
} else {
// Check the impl. If the generics on the self type of the
// impl require inlining, this method does too.
assert!(impl_did.crate == ast::LOCAL_CRATE);
match items.get().find(&impl_did.node) {
Some(&ast_map::NodeItem(item, _)) => {
match tcx.items.find(impl_did.node) {
Some(ast_map::NodeItem(item, _)) => {
match item.node {
ast::ItemImpl(ref generics, _, _, _) => {
generics_require_inlining(generics)
Expand Down Expand Up @@ -294,9 +292,8 @@ impl ReachableContext {
};

scanned.insert(search_item);
let items = self.tcx.items.borrow();
match items.get().find(&search_item) {
Some(item) => self.propagate_node(item, search_item,
match self.tcx.items.find(search_item) {
Some(ref item) => self.propagate_node(item, search_item,
&mut visitor),
None if search_item == ast::CRATE_NODE_ID => {}
None => {
Expand Down
8 changes: 2 additions & 6 deletions src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1731,8 +1731,7 @@ impl Visitor<()> for TransItemVisitor {
pub fn trans_item(ccx: @CrateContext, item: &ast::Item) {
let _icx = push_ctxt("trans_item");
let path = {
let items = ccx.tcx.items.borrow();
match items.get().get_copy(&item.id) {
match ccx.tcx.items.get(item.id) {
ast_map::NodeItem(_, p) => p,
// tjc: ?
_ => fail!("trans_item"),
Expand Down Expand Up @@ -2034,10 +2033,7 @@ pub fn get_item_val(ccx: @CrateContext, id: ast::NodeId) -> ValueRef {
Some(v) => v,
None => {
let mut foreign = false;
let item = {
let items = ccx.tcx.items.borrow();
items.get().get_copy(&id)
};
let item = ccx.tcx.items.get(id);
let val = match item {
ast_map::NodeItem(i, pth) => {

Expand Down
5 changes: 2 additions & 3 deletions src/librustc/middle/trans/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -365,13 +365,12 @@ pub fn trans_fn_ref_with_vtables(
must_monomorphise = true;
} else if def_id.crate == ast::LOCAL_CRATE {
{
let items = ccx.tcx.items.borrow();
let map_node = session::expect(
ccx.sess,
items.get().find(&def_id.node),
ccx.tcx.items.find(def_id.node),
|| format!("local item should be in ast map"));

match *map_node {
match map_node {
ast_map::NodeForeignItem(_, abis, _, _) => {
must_monomorphise = abis.is_intrinsic()
}
Expand Down
5 changes: 1 addition & 4 deletions src/librustc/middle/trans/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,7 @@ pub fn get_const_val(cx: @CrateContext,
def_id = inline::maybe_instantiate_inline(cx, def_id);
}

let opt_item = {
let items = cx.tcx.items.borrow();
items.get().get_copy(&def_id.node)
};
let opt_item = cx.tcx.items.get(def_id.node);

match opt_item {
ast_map::NodeItem(item, _) => {
Expand Down
30 changes: 10 additions & 20 deletions src/librustc/middle/trans/debuginfo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,8 @@ pub fn create_captured_var_metadata(bcx: &Block,

let cx = bcx.ccx();

let ast_item = {
let items = cx.tcx.items.borrow();
items.get().find_copy(&node_id)
};
let ast_item = cx.tcx.items.find(node_id);

let variable_ident = match ast_item {
None => {
cx.sess.span_bug(span, "debuginfo::create_captured_var_metadata() - NodeId not found");
Expand Down Expand Up @@ -423,10 +421,7 @@ pub fn create_self_argument_metadata(bcx: &Block,
}

// Extract the span of the self argument from the method's AST
let fnitem = {
let items = bcx.ccx().tcx.items.borrow();
items.get().get_copy(&bcx.fcx.id)
};
let fnitem = bcx.ccx().tcx.items.get(bcx.fcx.id);
let span = match fnitem {
ast_map::NodeMethod(method, _, _) => {
method.explicit_self.span
Expand Down Expand Up @@ -613,10 +608,8 @@ pub fn create_function_debug_context(cx: &CrateContext,

let empty_generics = ast::Generics { lifetimes: opt_vec::Empty, ty_params: opt_vec::Empty };

let fnitem = {
let items = cx.tcx.items.borrow();
items.get().get_copy(&fn_ast_id)
};
let fnitem = cx.tcx.items.get(fn_ast_id);

let (ident, fn_decl, generics, top_level_block, span, has_path) = match fnitem {
ast_map::NodeItem(ref item, _) => {
match item.node {
Expand Down Expand Up @@ -1098,8 +1091,7 @@ fn scope_metadata(fcx: &FunctionContext,
match scope_map.get().find_copy(&node_id) {
Some(scope_metadata) => scope_metadata,
None => {
let items = fcx.ccx.tcx.items.borrow();
let node = items.get().get_copy(&node_id);
let node = fcx.ccx.tcx.items.get(node_id);

fcx.ccx.sess.span_bug(span,
format!("debuginfo: Could not find scope info for node {:?}", node));
Expand Down Expand Up @@ -1419,9 +1411,8 @@ fn describe_enum_variant(cx: &CrateContext,
// Find the source code location of the variant's definition
let variant_definition_span = if variant_info.id.crate == ast::LOCAL_CRATE {
{
let items = cx.tcx.items.borrow();
match items.get().find(&variant_info.id.node) {
Some(&ast_map::NodeVariant(ref variant, _, _)) => variant.span,
match cx.tcx.items.find(variant_info.id.node) {
Some(ast_map::NodeVariant(ref variant, _, _)) => variant.span,
ref node => {
cx.sess.span_warn(span,
format!("debuginfo::enum_metadata()::\
Expand Down Expand Up @@ -2300,9 +2291,8 @@ fn get_namespace_and_span_for_item(cx: &CrateContext,
let containing_scope = namespace_for_item(cx, def_id, warning_span).scope;
let definition_span = if def_id.crate == ast::LOCAL_CRATE {
{
let items = cx.tcx.items.borrow();
let definition_span = match items.get().find(&def_id.node) {
Some(&ast_map::NodeItem(item, _)) => item.span,
let definition_span = match cx.tcx.items.find(def_id.node) {
Some(ast_map::NodeItem(item, _)) => item.span,
ref node => {
cx.sess.span_warn(warning_span,
format!("debuginfo::\
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -354,9 +354,8 @@ pub fn trans_foreign_mod(ccx: @CrateContext,
for &foreign_item in foreign_mod.items.iter() {
match foreign_item.node {
ast::ForeignItemFn(..) => {
let items = ccx.tcx.items.borrow();
let (abis, mut path) =
match items.get().get_copy(&foreign_item.id) {
match ccx.tcx.items.get(foreign_item.id) {
ast_map::NodeForeignItem(_, abis, _, path) => {
(abis, (*path).clone())
}
Expand Down
Loading