Skip to content

Commit 8443b09

Browse files
committed
auto merge of #19995 : eddyb/rust/split-resolve, r=nikomatsakis
r? @nikomatsakis
2 parents 1c2df5c + 948cc66 commit 8443b09

File tree

23 files changed

+565
-475
lines changed

23 files changed

+565
-475
lines changed

mk/crates.mk

+8-4
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ TARGET_CRATES := libc std flate arena term \
5353
serialize getopts collections test time rand \
5454
log regex graphviz core rbml alloc \
5555
unicode
56-
RUSTC_CRATES := rustc rustc_typeck rustc_borrowck rustc_driver rustc_trans rustc_back rustc_llvm
56+
RUSTC_CRATES := rustc rustc_typeck rustc_borrowck rustc_resolve rustc_driver \
57+
rustc_trans rustc_back rustc_llvm
5758
HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc regex_macros fmt_macros
5859
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5960
TOOLS := compiletest rustdoc rustc
@@ -67,11 +68,12 @@ DEPS_std := core libc rand alloc collections unicode \
6768
DEPS_graphviz := std
6869
DEPS_syntax := std term serialize log fmt_macros arena libc
6970
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back rustc_borrowck \
70-
rustc_typeck log syntax serialize rustc_llvm rustc_trans
71+
rustc_typeck rustc_resolve log syntax serialize rustc_llvm rustc_trans
7172
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
7273
log syntax serialize rustc_llvm
7374
DEPS_rustc_typeck := rustc syntax
7475
DEPS_rustc_borrowck := rustc log graphviz syntax
76+
DEPS_rustc_resolve := rustc log syntax
7577
DEPS_rustc := syntax flate arena serialize getopts rbml \
7678
time log graphviz rustc_llvm rustc_back
7779
DEPS_rustc_llvm := native:rustllvm libc std
@@ -118,9 +120,11 @@ DOC_CRATES := $(filter-out rustc, \
118120
$(filter-out rustc_trans, \
119121
$(filter-out rustc_typeck, \
120122
$(filter-out rustc_borrowck, \
123+
$(filter-out rustc_resolve, \
121124
$(filter-out rustc_driver, \
122-
$(filter-out syntax, $(CRATES)))))))
123-
COMPILER_DOC_CRATES := rustc rustc_trans rustc_borrowck rustc_typeck rustc_driver syntax
125+
$(filter-out syntax, $(CRATES))))))))
126+
COMPILER_DOC_CRATES := rustc rustc_trans rustc_borrowck rustc_resolve \
127+
rustc_typeck rustc_driver syntax
124128

125129
# This macro creates some simple definitions for each crate being built, just
126130
# some munging of all of the parameters above.

mk/tests.mk

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ $(eval $(call RUST_CRATE,coretest))
2121

2222
TEST_TARGET_CRATES = $(filter-out core unicode,$(TARGET_CRATES)) coretest
2323
TEST_DOC_CRATES = $(DOC_CRATES)
24-
TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_trans,$(HOST_CRATES))
24+
TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_borrowck rustc_resolve rustc_trans,\
25+
$(HOST_CRATES))
2526
TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
2627

2728
######################################################################

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ pub mod middle {
9090
pub mod reachable;
9191
pub mod region;
9292
pub mod recursion_limit;
93-
pub mod resolve;
9493
pub mod resolve_lifetime;
9594
pub mod stability;
9695
pub mod subst;

src/librustc/metadata/csearch.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ use metadata::cstore;
1919
use metadata::decoder;
2020
use middle::def;
2121
use middle::lang_items;
22-
use middle::resolve;
2322
use middle::ty;
2423

2524
use rbml;
@@ -148,7 +147,7 @@ pub fn get_impl_or_trait_item<'tcx>(tcx: &ty::ctxt<'tcx>, def: ast::DefId)
148147
}
149148

150149
pub fn get_trait_item_name_and_kind(cstore: &cstore::CStore, def: ast::DefId)
151-
-> (ast::Name, resolve::TraitItemKind) {
150+
-> (ast::Name, def::TraitItemKind) {
152151
let cdata = cstore.get_crate_data(def.krate);
153152
decoder::get_trait_item_name_and_kind(cstore.intr.clone(),
154153
&*cdata,

src/librustc/metadata/decoder.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ use metadata::tydecode::{parse_ty_data, parse_region_data, parse_def_id,
2727
parse_predicate_data};
2828
use middle::def;
2929
use middle::lang_items;
30-
use middle::resolve::{TraitItemKind, TypeTraitItemKind};
3130
use middle::subst;
3231
use middle::ty::{ImplContainer, TraitContainer};
3332
use middle::ty::{mod, Ty};
@@ -785,15 +784,15 @@ pub fn get_impl_items(cdata: Cmd, impl_id: ast::NodeId)
785784
pub fn get_trait_item_name_and_kind(intr: Rc<IdentInterner>,
786785
cdata: Cmd,
787786
id: ast::NodeId)
788-
-> (ast::Name, TraitItemKind) {
787+
-> (ast::Name, def::TraitItemKind) {
789788
let doc = lookup_item(id, cdata.data());
790789
let name = item_name(&*intr, doc);
791790
match item_sort(doc) {
792791
'r' | 'p' => {
793792
let explicit_self = get_explicit_self(doc);
794-
(name, TraitItemKind::from_explicit_self_category(explicit_self))
793+
(name, def::TraitItemKind::from_explicit_self_category(explicit_self))
795794
}
796-
't' => (name, TypeTraitItemKind),
795+
't' => (name, def::TypeTraitItemKind),
797796
c => {
798797
panic!("get_trait_item_name_and_kind(): unknown trait item kind \
799798
in metadata: `{}`", c)

src/librustc/metadata/encoder.rs

+14-16
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use metadata::common::*;
2121
use metadata::cstore;
2222
use metadata::decoder;
2323
use metadata::tyencode;
24+
use middle::def;
2425
use middle::ty::{lookup_item_type};
2526
use middle::ty::{mod, Ty};
2627
use middle::stability;
27-
use middle;
2828
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
2929

3030
use serialize::Encodable;
@@ -66,7 +66,7 @@ pub type EncodeInlinedItem<'a> = |ecx: &EncodeContext,
6666
pub struct EncodeParams<'a, 'tcx: 'a> {
6767
pub diag: &'a SpanHandler,
6868
pub tcx: &'a ty::ctxt<'tcx>,
69-
pub reexports2: &'a middle::resolve::ExportMap2,
69+
pub reexports: &'a def::ExportMap,
7070
pub item_symbols: &'a RefCell<NodeMap<String>>,
7171
pub link_meta: &'a LinkMeta,
7272
pub cstore: &'a cstore::CStore,
@@ -77,7 +77,7 @@ pub struct EncodeParams<'a, 'tcx: 'a> {
7777
pub struct EncodeContext<'a, 'tcx: 'a> {
7878
pub diag: &'a SpanHandler,
7979
pub tcx: &'a ty::ctxt<'tcx>,
80-
pub reexports2: &'a middle::resolve::ExportMap2,
80+
pub reexports: &'a def::ExportMap,
8181
pub item_symbols: &'a RefCell<NodeMap<String>>,
8282
pub link_meta: &'a LinkMeta,
8383
pub cstore: &'a cstore::CStore,
@@ -379,7 +379,7 @@ fn encode_path<PI: Iterator<PathElem>>(rbml_w: &mut Encoder, path: PI) {
379379
}
380380

381381
fn encode_reexported_static_method(rbml_w: &mut Encoder,
382-
exp: &middle::resolve::Export2,
382+
exp: &def::Export,
383383
method_def_id: DefId,
384384
method_name: ast::Name) {
385385
debug!("(encode reexported static method) {}::{}",
@@ -398,7 +398,7 @@ fn encode_reexported_static_method(rbml_w: &mut Encoder,
398398

399399
fn encode_reexported_static_base_methods(ecx: &EncodeContext,
400400
rbml_w: &mut Encoder,
401-
exp: &middle::resolve::Export2)
401+
exp: &def::Export)
402402
-> bool {
403403
let impl_items = ecx.tcx.impl_items.borrow();
404404
match ecx.tcx.inherent_impls.borrow().get(&exp.def_id) {
@@ -428,7 +428,7 @@ fn encode_reexported_static_base_methods(ecx: &EncodeContext,
428428

429429
fn encode_reexported_static_trait_methods(ecx: &EncodeContext,
430430
rbml_w: &mut Encoder,
431-
exp: &middle::resolve::Export2)
431+
exp: &def::Export)
432432
-> bool {
433433
match ecx.tcx.trait_items_cache.borrow().get(&exp.def_id) {
434434
Some(trait_items) => {
@@ -449,10 +449,8 @@ fn encode_reexported_static_trait_methods(ecx: &EncodeContext,
449449
fn encode_reexported_static_methods(ecx: &EncodeContext,
450450
rbml_w: &mut Encoder,
451451
mod_path: PathElems,
452-
exp: &middle::resolve::Export2) {
452+
exp: &def::Export) {
453453
if let Some(ast_map::NodeItem(item)) = ecx.tcx.map.find(exp.def_id.node) {
454-
let original_name = token::get_ident(item.ident);
455-
456454
let path_differs = ecx.tcx.map.with_path(exp.def_id.node, |path| {
457455
let (mut a, mut b) = (path, mod_path.clone());
458456
loop {
@@ -474,16 +472,16 @@ fn encode_reexported_static_methods(ecx: &EncodeContext,
474472
// encoded metadata for static methods relative to Bar,
475473
// but not yet for Foo.
476474
//
477-
if path_differs || original_name.get() != exp.name {
475+
if path_differs || item.ident.name != exp.name {
478476
if !encode_reexported_static_base_methods(ecx, rbml_w, exp) {
479477
if encode_reexported_static_trait_methods(ecx, rbml_w, exp) {
480478
debug!("(encode reexported static methods) {} [trait]",
481-
original_name);
479+
item.ident.name);
482480
}
483481
}
484482
else {
485483
debug!("(encode reexported static methods) {} [base]",
486-
original_name);
484+
item.ident.name);
487485
}
488486
}
489487
}
@@ -519,7 +517,7 @@ fn encode_reexports(ecx: &EncodeContext,
519517
id: NodeId,
520518
path: PathElems) {
521519
debug!("(encoding info for module) encoding reexports for {}", id);
522-
match ecx.reexports2.get(&id) {
520+
match ecx.reexports.get(&id) {
523521
Some(ref exports) => {
524522
debug!("(encoding info for module) found reexports for {}", id);
525523
for exp in exports.iter() {
@@ -534,7 +532,7 @@ fn encode_reexports(ecx: &EncodeContext,
534532
rbml_w.wr_str(def_to_string(exp.def_id).as_slice());
535533
rbml_w.end_tag();
536534
rbml_w.start_tag(tag_items_data_item_reexport_name);
537-
rbml_w.wr_str(exp.name.as_slice());
535+
rbml_w.wr_str(exp.name.as_str());
538536
rbml_w.end_tag();
539537
rbml_w.end_tag();
540538
encode_reexported_static_methods(ecx, rbml_w, path.clone(), exp);
@@ -2071,7 +2069,7 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter,
20712069
item_symbols,
20722070
diag,
20732071
tcx,
2074-
reexports2,
2072+
reexports,
20752073
cstore,
20762074
encode_inlined_item,
20772075
link_meta,
@@ -2081,7 +2079,7 @@ fn encode_metadata_inner(wr: &mut SeekableMemWriter,
20812079
let ecx = EncodeContext {
20822080
diag: diag,
20832081
tcx: tcx,
2084-
reexports2: reexports2,
2082+
reexports: reexports,
20852083
item_symbols: item_symbols,
20862084
link_meta: link_meta,
20872085
cstore: cstore,

src/librustc/middle/check_static_recursion.rs

+5-6
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212
// recursively.
1313

1414
use session::Session;
15-
use middle::resolve;
16-
use middle::def::{DefStatic, DefConst};
15+
use middle::def::{DefStatic, DefConst, DefMap};
1716

1817
use syntax::ast;
1918
use syntax::{ast_util, ast_map};
@@ -22,7 +21,7 @@ use syntax::visit;
2221

2322
struct CheckCrateVisitor<'a, 'ast: 'a> {
2423
sess: &'a Session,
25-
def_map: &'a resolve::DefMap,
24+
def_map: &'a DefMap,
2625
ast_map: &'a ast_map::Map<'ast>
2726
}
2827

@@ -34,7 +33,7 @@ impl<'v, 'a, 'ast> Visitor<'v> for CheckCrateVisitor<'a, 'ast> {
3433

3534
pub fn check_crate<'ast>(sess: &Session,
3635
krate: &ast::Crate,
37-
def_map: &resolve::DefMap,
36+
def_map: &DefMap,
3837
ast_map: &ast_map::Map<'ast>) {
3938
let mut visitor = CheckCrateVisitor {
4039
sess: sess,
@@ -60,15 +59,15 @@ struct CheckItemRecursionVisitor<'a, 'ast: 'a> {
6059
root_it: &'a ast::Item,
6160
sess: &'a Session,
6261
ast_map: &'a ast_map::Map<'ast>,
63-
def_map: &'a resolve::DefMap,
62+
def_map: &'a DefMap,
6463
idstack: Vec<ast::NodeId>
6564
}
6665

6766
// Make sure a const item doesn't recursively refer to itself
6867
// FIXME: Should use the dependency graph when it's available (#1356)
6968
pub fn check_item_recursion<'a>(sess: &'a Session,
7069
ast_map: &'a ast_map::Map,
71-
def_map: &'a resolve::DefMap,
70+
def_map: &'a DefMap,
7271
it: &'a ast::Item) {
7372

7473
let mut visitor = CheckItemRecursionVisitor {

src/librustc/middle/def.rs

+36-1
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,16 @@
1010

1111
pub use self::Def::*;
1212
pub use self::MethodProvenance::*;
13+
pub use self::TraitItemKind::*;
1314

1415
use middle::subst::ParamSpace;
16+
use middle::ty::{ExplicitSelfCategory, StaticExplicitSelfCategory};
17+
use util::nodemap::NodeMap;
1518
use syntax::ast;
1619
use syntax::ast_util::local_def;
1720

21+
use std::cell::RefCell;
22+
1823
#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
1924
pub enum Def {
2025
DefFn(ast::DefId, bool /* is_ctor */),
@@ -56,6 +61,18 @@ pub enum Def {
5661
DefMethod(ast::DefId /* method */, Option<ast::DefId> /* trait */, MethodProvenance),
5762
}
5863

64+
// Definition mapping
65+
pub type DefMap = RefCell<NodeMap<Def>>;
66+
// This is the replacement export map. It maps a module to all of the exports
67+
// within.
68+
pub type ExportMap = NodeMap<Vec<Export>>;
69+
70+
#[deriving(Copy)]
71+
pub struct Export {
72+
pub name: ast::Name, // The name of the target.
73+
pub def_id: ast::DefId, // The definition of the target.
74+
}
75+
5976
#[deriving(Clone, Copy, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
6077
pub enum MethodProvenance {
6178
FromTrait(ast::DefId),
@@ -88,6 +105,25 @@ impl TyParamProvenance {
88105
}
89106
}
90107

108+
#[deriving(Clone, Copy, Eq, PartialEq)]
109+
pub enum TraitItemKind {
110+
NonstaticMethodTraitItemKind,
111+
StaticMethodTraitItemKind,
112+
TypeTraitItemKind,
113+
}
114+
115+
impl TraitItemKind {
116+
pub fn from_explicit_self_category(explicit_self_category:
117+
ExplicitSelfCategory)
118+
-> TraitItemKind {
119+
if explicit_self_category == StaticExplicitSelfCategory {
120+
StaticMethodTraitItemKind
121+
} else {
122+
NonstaticMethodTraitItemKind
123+
}
124+
}
125+
}
126+
91127
impl Def {
92128
pub fn def_id(&self) -> ast::DefId {
93129
match *self {
@@ -122,4 +158,3 @@ impl Def {
122158
}
123159
}
124160
}
125-

0 commit comments

Comments
 (0)