Skip to content

Commit 5263600

Browse files
committed
auto merge of #19362 : nikomatsakis/rust/crateification, r=nikomatsakis
This has the goal of further reducing peak memory usage and enabling more parallelism. This patch should allow trans/typeck to build in parallel. The plan is to proceed by moving as many additional passes as possible into distinct crates that lay alongside typeck/trans. Basically, the idea is that there is the `rustc` crate which defines the common data structures shared between passes. Individual passes then go into their own crates. Finally, the `rustc_driver` crate knits it all together. cc @jakub-: One wrinkle is the diagnostics plugin. Currently, it assumes all diagnostics are defined and used within one crate in order to track what is used and what is duplicated. I had to disable this. We'll have to find an alternate strategy, but I wasn't sure what was best so decided to just disable the duplicate checking for now.
2 parents 361baab + 602fc78 commit 5263600

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

97 files changed

+1160
-1101
lines changed

mk/crates.mk

+15-7
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ TARGET_CRATES := libc std flate arena term \
5353
serialize getopts collections test time rand \
5454
log regex graphviz core rbml alloc rustrt \
5555
unicode
56-
HOST_CRATES := syntax rustc rustc_trans rustdoc regex_macros fmt_macros \
57-
rustc_llvm rustc_back
56+
RUSTC_CRATES := rustc rustc_typeck rustc_driver rustc_trans rustc_back rustc_llvm
57+
HOST_CRATES := syntax $(RUSTC_CRATES) rustdoc regex_macros fmt_macros
5858
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5959
TOOLS := compiletest rustdoc rustc
6060

@@ -67,12 +67,16 @@ DEPS_std := core libc rand alloc collections rustrt unicode \
6767
native:rust_builtin native:backtrace
6868
DEPS_graphviz := std
6969
DEPS_syntax := std term serialize log fmt_macros arena libc
70-
DEPS_rustc_trans := rustc rustc_back rustc_llvm libc
70+
DEPS_rustc_driver := arena flate getopts graphviz libc rustc rustc_back \
71+
rustc_typeck log syntax serialize rustc_llvm rustc_trans
72+
DEPS_rustc_trans := arena flate getopts graphviz libc rustc rustc_back \
73+
log syntax serialize rustc_llvm
74+
DEPS_rustc_typeck := rustc syntax
7175
DEPS_rustc := syntax flate arena serialize getopts rbml \
7276
time log graphviz rustc_llvm rustc_back
7377
DEPS_rustc_llvm := native:rustllvm libc std
7478
DEPS_rustc_back := std syntax rustc_llvm flate log libc
75-
DEPS_rustdoc := rustc rustc_trans native:hoedown serialize getopts \
79+
DEPS_rustdoc := rustc rustc_driver native:hoedown serialize getopts \
7680
test time
7781
DEPS_flate := std native:miniz
7882
DEPS_arena := std
@@ -94,7 +98,7 @@ DEPS_fmt_macros = std
9498

9599
TOOL_DEPS_compiletest := test getopts
96100
TOOL_DEPS_rustdoc := rustdoc
97-
TOOL_DEPS_rustc := rustc_trans
101+
TOOL_DEPS_rustc := rustc_driver
98102
TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
99103
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
100104
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
@@ -110,8 +114,12 @@ ONLY_RLIB_unicode := 1
110114
# You should not need to edit below this line
111115
################################################################################
112116

113-
DOC_CRATES := $(filter-out rustc, $(filter-out rustc_trans, $(filter-out syntax, $(CRATES))))
114-
COMPILER_DOC_CRATES := rustc rustc_trans syntax
117+
DOC_CRATES := $(filter-out rustc, \
118+
$(filter-out rustc_trans, \
119+
$(filter-out rustc_typeck, \
120+
$(filter-out rustc_driver, \
121+
$(filter-out syntax, $(CRATES))))))
122+
COMPILER_DOC_CRATES := rustc rustc_trans rustc_typeck rustc_driver syntax
115123

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

mk/tests.mk

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ $(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 = $(HOST_CRATES)
24+
TEST_HOST_CRATES = $(filter-out rustc_typeck rustc_trans,$(HOST_CRATES))
2525
TEST_CRATES = $(TEST_TARGET_CRATES) $(TEST_HOST_CRATES)
2626

2727
######################################################################

src/driver/driver.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@
1212
extern crate "rustdoc" as this;
1313

1414
#[cfg(rustc)]
15-
extern crate "rustc_trans" as this;
15+
extern crate "rustc_driver" as this;
1616

1717
fn main() { this::main() }

src/librustc/lib.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ pub mod back {
5959
}
6060

6161
pub mod middle {
62+
pub mod astconv_util;
6263
pub mod astencode;
6364
pub mod borrowck;
6465
pub mod cfg;
@@ -79,6 +80,7 @@ pub mod middle {
7980
pub mod fast_reject;
8081
pub mod graph;
8182
pub mod intrinsicck;
83+
pub mod infer;
8284
pub mod lang_items;
8385
pub mod liveness;
8486
pub mod mem_categorization;
@@ -93,7 +95,6 @@ pub mod middle {
9395
pub mod traits;
9496
pub mod ty;
9597
pub mod ty_fold;
96-
pub mod typeck;
9798
pub mod weak_lang_items;
9899
}
99100

src/librustc/lint/builtin.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ use self::MethodContext::*;
2929
use metadata::csearch;
3030
use middle::def::*;
3131
use middle::ty::{mod, Ty};
32-
use middle::typeck::astconv::ast_ty_to_ty;
33-
use middle::typeck::{mod, infer};
3432
use middle::{def, pat_util, stability};
3533
use middle::const_eval::{eval_const_expr_partial, const_int, const_uint};
3634
use util::ppaux::{ty_to_string};
@@ -84,7 +82,7 @@ impl LintPass for UnusedCasts {
8482

8583
fn check_expr(&mut self, cx: &Context, e: &ast::Expr) {
8684
if let ast::ExprCast(ref expr, ref ty) = e.node {
87-
let t_t = ast_ty_to_ty(cx, &infer::new_infer_ctxt(cx.tcx), &**ty);
85+
let t_t = ty::expr_ty(cx.tcx, e);
8886
if ty::expr_ty(cx.tcx, &**expr) == t_t {
8987
cx.span_lint(UNUSED_TYPECASTS, ty.span, "unnecessary type cast");
9088
}
@@ -1589,22 +1587,22 @@ impl LintPass for Stability {
15891587
}
15901588
ast::ExprMethodCall(i, _, _) => {
15911589
span = i.span;
1592-
let method_call = typeck::MethodCall::expr(e.id);
1590+
let method_call = ty::MethodCall::expr(e.id);
15931591
match cx.tcx.method_map.borrow().get(&method_call) {
15941592
Some(method) => {
15951593
match method.origin {
1596-
typeck::MethodStatic(def_id) => {
1594+
ty::MethodStatic(def_id) => {
15971595
def_id
15981596
}
1599-
typeck::MethodStaticUnboxedClosure(def_id) => {
1597+
ty::MethodStaticUnboxedClosure(def_id) => {
16001598
def_id
16011599
}
1602-
typeck::MethodTypeParam(typeck::MethodParam {
1600+
ty::MethodTypeParam(ty::MethodParam {
16031601
ref trait_ref,
16041602
method_num: index,
16051603
..
16061604
}) |
1607-
typeck::MethodTraitObject(typeck::MethodObject {
1605+
ty::MethodTraitObject(ty::MethodObject {
16081606
ref trait_ref,
16091607
method_num: index,
16101608
..

src/librustc/lint/context.rs

-40
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,13 @@
2626
use self::TargetLint::*;
2727

2828
use middle::privacy::ExportedItems;
29-
use middle::subst;
3029
use middle::ty::{mod, Ty};
31-
use middle::typeck::astconv::AstConv;
32-
use middle::typeck::infer;
3330
use session::{early_error, Session};
3431
use lint::{Level, LevelSource, Lint, LintId, LintArray, LintPass, LintPassObject};
3532
use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid};
3633
use lint::builtin;
3734
use util::nodemap::FnvHashMap;
3835

39-
use std::rc::Rc;
4036
use std::cell::RefCell;
4137
use std::tuple::Tuple2;
4238
use std::mem;
@@ -541,42 +537,6 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
541537
}
542538
}
543539

544-
impl<'a, 'tcx> AstConv<'tcx> for Context<'a, 'tcx>{
545-
fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx> { self.tcx }
546-
547-
fn get_item_ty(&self, id: ast::DefId) -> ty::Polytype<'tcx> {
548-
ty::lookup_item_type(self.tcx, id)
549-
}
550-
551-
fn get_trait_def(&self, id: ast::DefId) -> Rc<ty::TraitDef<'tcx>> {
552-
ty::lookup_trait_def(self.tcx, id)
553-
}
554-
555-
fn ty_infer(&self, _span: Span) -> Ty<'tcx> {
556-
infer::new_infer_ctxt(self.tcx).next_ty_var()
557-
}
558-
559-
fn associated_types_of_trait_are_valid(&self, _: Ty<'tcx>, _: ast::DefId)
560-
-> bool {
561-
// FIXME(pcwalton): This is wrong.
562-
true
563-
}
564-
565-
fn associated_type_binding(&self,
566-
_: Span,
567-
_: Option<Ty<'tcx>>,
568-
trait_id: ast::DefId,
569-
associated_type_id: ast::DefId)
570-
-> Ty<'tcx> {
571-
// FIXME(pcwalton): This is wrong.
572-
let trait_def = self.get_trait_def(trait_id);
573-
let index = ty::associated_type_parameter_index(self.tcx,
574-
&*trait_def,
575-
associated_type_id);
576-
ty::mk_param(self.tcx, subst::TypeSpace, index, associated_type_id)
577-
}
578-
}
579-
580540
impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
581541
fn visit_item(&mut self, it: &ast::Item) {
582542
self.with_lint_attrs(it.attrs.as_slice(), |cx| {

src/librustc/metadata/csearch.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ use middle::def;
2121
use middle::lang_items;
2222
use middle::resolve;
2323
use middle::ty;
24-
use middle::typeck;
2524
use middle::subst::VecPerParamSpace;
2625

2726
use rbml;
@@ -268,7 +267,7 @@ pub fn get_impl_trait<'tcx>(tcx: &ty::ctxt<'tcx>,
268267
// Given a def_id for an impl, return information about its vtables
269268
pub fn get_impl_vtables<'tcx>(tcx: &ty::ctxt<'tcx>,
270269
def: ast::DefId)
271-
-> typeck::vtable_res<'tcx> {
270+
-> ty::vtable_res<'tcx> {
272271
let cstore = &tcx.sess.cstore;
273272
let cdata = cstore.get_crate_data(def.krate);
274273
decoder::get_impl_vtables(&*cdata, def.node, tcx)

src/librustc/metadata/decoder.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use middle::resolve::{TraitItemKind, TypeTraitItemKind};
3030
use middle::subst;
3131
use middle::ty::{ImplContainer, TraitContainer};
3232
use middle::ty::{mod, Ty};
33-
use middle::typeck;
3433
use middle::astencode::vtable_decoder_helpers;
3534

3635
use std::hash::Hash;
@@ -422,7 +421,7 @@ pub fn get_impl_trait<'tcx>(cdata: Cmd,
422421
pub fn get_impl_vtables<'tcx>(cdata: Cmd,
423422
id: ast::NodeId,
424423
tcx: &ty::ctxt<'tcx>)
425-
-> typeck::vtable_res<'tcx>
424+
-> ty::vtable_res<'tcx>
426425
{
427426
let item_doc = lookup_item(id, cdata.data());
428427
let vtables_doc = reader::get_doc(item_doc, tag_item_impl_vtables);

src/librustc/middle/astconv_util.rs

+89
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
// Copyright 2012-2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
/*!
12+
* This module contains a simple utility routine
13+
* used by both `typeck` and `const_eval`.
14+
* Almost certainly this could (and should) be refactored out of existence.
15+
*/
16+
17+
use middle::def;
18+
use middle::ty::{mod, Ty};
19+
use syntax::ast;
20+
use util::ppaux::Repr;
21+
22+
pub const NO_REGIONS: uint = 1;
23+
pub const NO_TPS: uint = 2;
24+
25+
pub fn check_path_args(tcx: &ty::ctxt,
26+
path: &ast::Path,
27+
flags: uint) {
28+
if (flags & NO_TPS) != 0u {
29+
if path.segments.iter().any(|s| s.parameters.has_types()) {
30+
span_err!(tcx.sess, path.span, E0109,
31+
"type parameters are not allowed on this type");
32+
}
33+
}
34+
35+
if (flags & NO_REGIONS) != 0u {
36+
if path.segments.iter().any(|s| s.parameters.has_lifetimes()) {
37+
span_err!(tcx.sess, path.span, E0110,
38+
"region parameters are not allowed on this type");
39+
}
40+
}
41+
}
42+
43+
pub fn ast_ty_to_prim_ty<'tcx>(tcx: &ty::ctxt<'tcx>, ast_ty: &ast::Ty)
44+
-> Option<Ty<'tcx>> {
45+
match ast_ty.node {
46+
ast::TyPath(ref path, id) => {
47+
let a_def = match tcx.def_map.borrow().get(&id) {
48+
None => {
49+
tcx.sess.span_bug(ast_ty.span,
50+
format!("unbound path {}",
51+
path.repr(tcx)).as_slice())
52+
}
53+
Some(&d) => d
54+
};
55+
match a_def {
56+
def::DefPrimTy(nty) => {
57+
match nty {
58+
ast::TyBool => {
59+
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
60+
Some(ty::mk_bool())
61+
}
62+
ast::TyChar => {
63+
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
64+
Some(ty::mk_char())
65+
}
66+
ast::TyInt(it) => {
67+
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
68+
Some(ty::mk_mach_int(it))
69+
}
70+
ast::TyUint(uit) => {
71+
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
72+
Some(ty::mk_mach_uint(uit))
73+
}
74+
ast::TyFloat(ft) => {
75+
check_path_args(tcx, path, NO_TPS | NO_REGIONS);
76+
Some(ty::mk_mach_float(ft))
77+
}
78+
ast::TyStr => {
79+
Some(ty::mk_str(tcx))
80+
}
81+
}
82+
}
83+
_ => None
84+
}
85+
}
86+
_ => None
87+
}
88+
}
89+

0 commit comments

Comments
 (0)