Skip to content

Commit

Permalink
auto merge of #19254 : nick29581/rust/dxr-glob, r=pcwalton
Browse files Browse the repository at this point in the history
There is also some work here to make resolve a bit more stable - it no longer overwrites a specific import with a glob import.

r?
  • Loading branch information
bors committed Dec 27, 2014
2 parents c06edba + 4b92a5a commit 3c60bc0
Show file tree
Hide file tree
Showing 27 changed files with 286 additions and 97 deletions.
2 changes: 1 addition & 1 deletion src/libcollections/str.rs
Expand Up @@ -3330,10 +3330,10 @@ mod tests {

#[cfg(test)]
mod bench {
use super::*;
use prelude::*;
use test::Bencher;
use test::black_box;
use super::*;

#[bench]
fn char_iterator(b: &mut Bencher) {
Expand Down
1 change: 0 additions & 1 deletion src/libgraphviz/maybe_owned_vec.rs
Expand Up @@ -14,7 +14,6 @@ pub use self::MaybeOwnedVector::*;

use std::default::Default;
use std::fmt;
use std::iter::FromIterator;
use std::path::BytesContainer;
use std::slice;

Expand Down
7 changes: 7 additions & 0 deletions src/librustc/metadata/csearch.rs
Expand Up @@ -146,6 +146,13 @@ pub fn get_impl_or_trait_item<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId)
tcx)
}

pub fn get_trait_name(cstore: &cstore::CStore, def: ast::DefId) -> ast::Name {
let cdata = cstore.get_crate_data(def.krate);
decoder::get_trait_name(cstore.intr.clone(),
&*cdata,
def.node)
}

pub fn get_trait_item_name_and_kind(cstore: &cstore::CStore, def: ast::DefId)
-> (ast::Name, def::TraitItemKind) {
let cdata = cstore.get_crate_data(def.krate);
Expand Down
8 changes: 8 additions & 0 deletions src/librustc/metadata/decoder.rs
Expand Up @@ -781,6 +781,14 @@ pub fn get_impl_items(cdata: Cmd, impl_id: ast::NodeId)
impl_items
}

pub fn get_trait_name(intr: Rc<IdentInterner>,
cdata: Cmd,
id: ast::NodeId)
-> ast::Name {
let doc = lookup_item(id, cdata.data());
item_name(&*intr, doc)
}

pub fn get_trait_item_name_and_kind(intr: Rc<IdentInterner>,
cdata: Cmd,
id: ast::NodeId)
Expand Down
7 changes: 6 additions & 1 deletion src/librustc/middle/ty.rs
Expand Up @@ -77,7 +77,7 @@ use std::mem;
use std::ops;
use std::rc::Rc;
use collections::enum_set::{EnumSet, CLike};
use std::collections::hash_map::HashMap;
use std::collections::{HashMap, HashSet};
use std::collections::hash_map::Entry::{Occupied, Vacant};
use syntax::abi;
use syntax::ast::{CrateNum, DefId, DUMMY_NODE_ID, Ident, ItemTrait, LOCAL_CRATE};
Expand Down Expand Up @@ -105,6 +105,7 @@ pub struct CrateAnalysis<'tcx> {
pub ty_cx: ty::ctxt<'tcx>,
pub reachable: NodeSet,
pub name: String,
pub glob_map: Option<GlobMap>,
}

#[deriving(Copy, PartialEq, Eq, Hash)]
Expand Down Expand Up @@ -6285,6 +6286,10 @@ pub type CaptureModeMap = NodeMap<ast::CaptureClause>;
// Trait method resolution
pub type TraitMap = NodeMap<Vec<DefId>>;

// Map from the NodeId of a glob import to a list of items which are actually
// imported.
pub type GlobMap = HashMap<NodeId, HashSet<Name>>;

pub fn with_freevars<T, F>(tcx: &ty::ctxt, fid: ast::NodeId, f: F) -> T where
F: FnOnce(&[Freevar]) -> T,
{
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_borrowck/borrowck/check_loans.rs
Expand Up @@ -19,8 +19,6 @@
use self::UseError::*;

use borrowck::*;
use borrowck::LoanPathElem::*;
use borrowck::LoanPathKind::*;
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc;
use rustc::middle::region;
Expand Down
Expand Up @@ -11,7 +11,6 @@
//! Computes moves.

use borrowck::*;
use borrowck::LoanPathKind::*;
use borrowck::gather_loans::move_error::MoveSpanAndPath;
use borrowck::gather_loans::move_error::{MoveError, MoveErrorCollector};
use borrowck::move_data::*;
Expand Down
1 change: 0 additions & 1 deletion src/librustc_borrowck/borrowck/gather_loans/mod.rs
Expand Up @@ -17,7 +17,6 @@
// sure that all of these loans are honored.

use borrowck::*;
use borrowck::LoanPathKind::*;
use borrowck::move_data::MoveData;
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc;
Expand Down
2 changes: 0 additions & 2 deletions src/librustc_borrowck/borrowck/gather_loans/restrictions.rs
Expand Up @@ -13,8 +13,6 @@
pub use self::RestrictionResult::*;

use borrowck::*;
use borrowck::LoanPathElem::*;
use borrowck::LoanPathKind::*;
use rustc::middle::expr_use_visitor as euv;
use rustc::middle::mem_categorization as mc;
use rustc::middle::ty;
Expand Down
21 changes: 18 additions & 3 deletions src/librustc_driver/driver.rs
Expand Up @@ -342,17 +342,27 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
let lang_items = time(time_passes, "language item collection", (), |_|
middle::lang_items::collect_language_items(krate, &sess));

let make_glob_map = if save_analysis(&sess) {
resolve::MakeGlobMap::Yes
} else {
resolve::MakeGlobMap::No
};
let resolve::CrateMap {
def_map,
freevars,
capture_mode_map,
export_map,
trait_map,
external_exports,
last_private_map
last_private_map,
glob_map,
} =
time(time_passes, "resolution", (),
|_| resolve::resolve_crate(&sess, &lang_items, krate));
|_| resolve::resolve_crate(&sess,
&ast_map,
&lang_items,
krate,
make_glob_map));

// Discard MTWT tables that aren't required past resolution.
syntax::ext::mtwt::clear_tables();
Expand Down Expand Up @@ -454,14 +464,19 @@ pub fn phase_3_run_analysis_passes<'tcx>(sess: Session,
public_items: public_items,
reachable: reachable_map,
name: name,
glob_map: glob_map,
}
}

fn save_analysis(sess: &Session) -> bool {
(sess.opts.debugging_opts & config::SAVE_ANALYSIS) != 0
}

pub fn phase_save_analysis(sess: &Session,
krate: &ast::Crate,
analysis: &ty::CrateAnalysis,
odir: &Option<Path>) {
if (sess.opts.debugging_opts & config::SAVE_ANALYSIS) == 0 {
if !save_analysis(sess) {
return;
}
time(sess.time_passes(), "save analysis", krate, |krate|
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_driver/test.rs
Expand Up @@ -123,7 +123,7 @@ fn test_env<F>(source_string: &str,
// run just enough stuff to build a tcx:
let lang_items = lang_items::collect_language_items(krate, &sess);
let resolve::CrateMap { def_map, freevars, capture_mode_map, .. } =
resolve::resolve_crate(&sess, &lang_items, krate);
resolve::resolve_crate(&sess, &ast_map, &lang_items, krate, resolve::MakeGlobMap::No);
let named_region_map = resolve_lifetime::krate(&sess, krate, &def_map);
let region_map = region::resolve_crate(&sess, krate);
let stability_index = stability::Index::build(krate);
Expand Down
16 changes: 8 additions & 8 deletions src/librustc_resolve/check_unused.rs
Expand Up @@ -28,24 +28,24 @@ use syntax::ast::{ViewPathGlob, ViewPathList, ViewPathSimple};
use syntax::codemap::{Span, DUMMY_SP};
use syntax::visit::{mod, Visitor};

struct UnusedImportCheckVisitor<'a, 'b:'a> {
resolver: &'a mut Resolver<'b>
struct UnusedImportCheckVisitor<'a, 'b:'a, 'tcx:'b> {
resolver: &'a mut Resolver<'b, 'tcx>
}

// Deref and DerefMut impls allow treating UnusedImportCheckVisitor as Resolver.
impl<'a, 'b> Deref<Resolver<'b>> for UnusedImportCheckVisitor<'a, 'b> {
fn deref<'c>(&'c self) -> &'c Resolver<'b> {
impl<'a, 'b, 'tcx:'b> Deref<Resolver<'b, 'tcx>> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
fn deref<'c>(&'c self) -> &'c Resolver<'b, 'tcx> {
&*self.resolver
}
}

impl<'a, 'b> DerefMut<Resolver<'b>> for UnusedImportCheckVisitor<'a, 'b> {
fn deref_mut<'c>(&'c mut self) -> &'c mut Resolver<'b> {
impl<'a, 'b, 'tcx:'b> DerefMut<Resolver<'b, 'tcx>> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
fn deref_mut<'c>(&'c mut self) -> &'c mut Resolver<'b, 'tcx> {
&mut *self.resolver
}
}

impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
impl<'a, 'b, 'tcx> UnusedImportCheckVisitor<'a, 'b, 'tcx> {
// We have information about whether `use` (import) directives are actually used now.
// If an import is not used at all, we signal a lint error. If an import is only used
// for a single namespace, we remove the other namespace from the recorded privacy
Expand Down Expand Up @@ -104,7 +104,7 @@ impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
}
}

impl<'a, 'b, 'v> Visitor<'v> for UnusedImportCheckVisitor<'a, 'b> {
impl<'a, 'b, 'v, 'tcx> Visitor<'v> for UnusedImportCheckVisitor<'a, 'b, 'tcx> {
fn visit_view_item(&mut self, vi: &ViewItem) {
// Ignore is_public import statements because there's no way to be sure
// whether they're used or not. Also ignore imports with a dummy span
Expand Down

0 comments on commit 3c60bc0

Please sign in to comment.