Skip to content

Commit dc6e414

Browse files
committed
Move trans, back, driver, and back into a new crate, rustc_trans. Reduces memory usage significantly and opens opportunities for more parallel compilation.
1 parent f637f1c commit dc6e414

Some content is hidden

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

80 files changed

+641
-533
lines changed

mk/crates.mk

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ TARGET_CRATES := libc std green native flate arena term \
5353
serialize sync getopts collections test time rand \
5454
log regex graphviz core rbml alloc rustrt \
5555
unicode
56-
HOST_CRATES := syntax rustc rustdoc regex_macros fmt_macros \
56+
HOST_CRATES := syntax rustc rustc_trans rustdoc regex_macros fmt_macros \
5757
rustc_llvm rustc_back
5858
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
5959
TOOLS := compiletest rustdoc rustc
@@ -69,11 +69,12 @@ DEPS_graphviz := std
6969
DEPS_green := std native:context_switch
7070
DEPS_native := std
7171
DEPS_syntax := std term serialize log fmt_macros arena libc
72+
DEPS_rustc_trans := rustc rustc_back rustc_llvm libc
7273
DEPS_rustc := syntax flate arena serialize getopts rbml \
7374
time log graphviz rustc_llvm rustc_back
7475
DEPS_rustc_llvm := native:rustllvm libc std
7576
DEPS_rustc_back := std syntax rustc_llvm flate log libc
76-
DEPS_rustdoc := rustc native:hoedown serialize getopts \
77+
DEPS_rustdoc := rustc rustc_trans native:hoedown serialize getopts \
7778
test time
7879
DEPS_flate := std native:miniz
7980
DEPS_arena := std
@@ -96,7 +97,7 @@ DEPS_fmt_macros = std
9697

9798
TOOL_DEPS_compiletest := test getopts native
9899
TOOL_DEPS_rustdoc := rustdoc native
99-
TOOL_DEPS_rustc := rustc native
100+
TOOL_DEPS_rustc := rustc_trans native
100101
TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
101102
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
102103
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
@@ -112,8 +113,8 @@ ONLY_RLIB_unicode := 1
112113
# You should not need to edit below this line
113114
################################################################################
114115

115-
DOC_CRATES := $(filter-out rustc, $(filter-out syntax, $(CRATES)))
116-
COMPILER_DOC_CRATES := rustc syntax
116+
DOC_CRATES := $(filter-out rustc, $(filter-out rustc_trans, $(filter-out syntax, $(CRATES))))
117+
COMPILER_DOC_CRATES := rustc rustc_trans syntax
117118

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

src/driver/driver.rs

Lines changed: 1 addition & 1 deletion
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" as this;
15+
extern crate "rustc_trans" as this;
1616

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

src/librustc/README.txt

Lines changed: 59 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,62 @@ https://github.com/rust-lang/rust/issues
1313

1414
Your concerns are probably the same as someone else's.
1515

16-
17-
High-level concepts
16+
The crates of rustc
1817
===================
1918

20-
Rustc consists of the following subdirectories:
21-
22-
front/ - front-end: attributes, conditional compilation
23-
middle/ - middle-end: name resolution, typechecking, LLVM code
19+
Rustc consists of four crates altogether: `libsyntax`, `librustc`,
20+
`librustc_back`, and `librustc_trans` (the names and divisions are not
21+
set in stone and may change; in general, a finer-grained division of
22+
crates is preferable):
23+
24+
- `libsyntax` contains those things concerned purely with syntax --
25+
that is, the AST, parser, pretty-printer, lexer, macro expander, and
26+
utilities for traversing ASTs -- are in a separate crate called
27+
"syntax", whose files are in ./../libsyntax, where . is the current
28+
directory (that is, the parent directory of front/, middle/, back/,
29+
and so on).
30+
31+
- `librustc` (the current directory) contains the high-level analysis
32+
passes, such as the type checker, borrow checker, and so forth.
33+
It is the heart of the compiler.
34+
35+
- `librustc_back` contains some very low-level details that are
36+
specific to different LLVM targets and so forth.
37+
38+
- `librustc_trans` contains the code to convert from Rust IR into LLVM
39+
IR, and then from LLVM IR into machine code, as well as the main
40+
driver that orchestrates all the other passes and various other bits
41+
of miscellany. In general it contains code that runs towards the
42+
end of the compilation process.
43+
44+
Roughly speaking the "order" of the three crates is as follows:
45+
46+
libsyntax -> librustc -> librustc_trans
47+
| |
48+
+-----------------+-------------------+
49+
|
50+
librustc_trans/driver
51+
52+
Here the role of `librustc_trans/driver` is to invoke the compiler
53+
from libsyntax, then the analysis phases from librustc, and finally
54+
the lowering and codegen passes from librustc_trans.
55+
56+
Modules in the rustc crate
57+
==========================
58+
59+
The rustc crate itself consists of the following subdirectories
60+
(mostly, but not entirely, in their own directories):
61+
62+
session - options and data that pertain to the compilation session as a whole
63+
middle - middle-end: name resolution, typechecking, LLVM code
2464
generation
25-
back/ - back-end: linking and ABI
26-
metadata/ - encoder and decoder for data required by
65+
metadata - encoder and decoder for data required by
2766
separate compilation
28-
driver/ - command-line processing, main() entrypoint
29-
util/ - ubiquitous types and helper functions
30-
lib/ - bindings to LLVM
31-
32-
The files concerned purely with syntax -- that is, the AST, parser,
33-
pretty-printer, lexer, macro expander, and utilities for traversing
34-
ASTs -- are in a separate crate called "syntax", whose files are in
35-
./../libsyntax, where . is the current directory (that is, the parent
36-
directory of front/, middle/, back/, and so on).
37-
38-
The entry-point for the compiler is main() in lib.rs, and
39-
this file sequences the various parts together.
67+
util - ubiquitous types and helper functions
68+
lib - bindings to LLVM
4069

70+
The entry-point for the compiler is main() in the librustc_trans
71+
crate. But the
4172

4273
The 3 central data structures:
4374
------------------------------
@@ -66,10 +97,10 @@ The 3 central data structures:
6697
compilation. Most variants in the ast::ty tag have a
6798
corresponding variant in the ty::sty tag.
6899

69-
#3: lib/llvm.rs defines the exported types ValueRef, TypeRef,
70-
BasicBlockRef, and several others. Each of these is an opaque
71-
pointer to an LLVM type, manipulated through the lib::llvm
72-
interface.
100+
#3: lib/llvm.rs (in librustc_trans) defines the exported types
101+
ValueRef, TypeRef, BasicBlockRef, and several others. Each of
102+
these is an opaque pointer to an LLVM type, manipulated through
103+
the lib::llvm interface.
73104

74105

75106
Control and information flow within the compiler:
@@ -87,7 +118,7 @@ Control and information flow within the compiler:
87118
structures. The driver passes environments to each compiler pass
88119
that needs to refer to them.
89120

90-
- Finally middle/trans.rs translates the Rust AST to LLVM bitcode in a
91-
type-directed way. When it's finished synthesizing LLVM values,
92-
rustc asks LLVM to write them out in some form (.bc, .o) and
93-
possibly run the system linker.
121+
- Finally, the `trans` module in `librustc_trans` translates the Rust
122+
AST to LLVM bitcode in a type-directed way. When it's finished
123+
synthesizing LLVM values, rustc asks LLVM to write them out in some
124+
form (.bc, .o) and possibly run the system linker.

src/librustc/lib.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,6 @@ pub mod back {
6262
pub use rustc_back::target_strs;
6363
pub use rustc_back::x86;
6464
pub use rustc_back::x86_64;
65-
66-
pub mod link;
67-
pub mod lto;
68-
pub mod write;
69-
7065
}
7166

7267
pub mod middle {
@@ -99,11 +94,9 @@ pub mod middle {
9994
pub mod region;
10095
pub mod resolve;
10196
pub mod resolve_lifetime;
102-
pub mod save;
10397
pub mod stability;
10498
pub mod subst;
10599
pub mod traits;
106-
pub mod trans;
107100
pub mod ty;
108101
pub mod ty_fold;
109102
pub mod typeck;
@@ -112,7 +105,7 @@ pub mod middle {
112105

113106
pub mod metadata;
114107

115-
pub mod driver;
108+
pub mod session;
116109

117110
pub mod plugin;
118111

@@ -142,9 +135,3 @@ __build_diagnostic_array!(DIAGNOSTICS)
142135
mod rustc {
143136
pub use lint;
144137
}
145-
146-
pub fn main() {
147-
let args = std::os::args();
148-
let result = driver::run(args);
149-
std::os::set_exit_status(result);
150-
}

src/librustc/lint/context.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ use middle::subst;
3030
use middle::ty;
3131
use middle::typeck::astconv::AstConv;
3232
use middle::typeck::infer;
33-
use driver::session::Session;
34-
use driver::early_error;
33+
use session::{early_error, Session};
3534
use lint::{Level, LevelSource, Lint, LintId, LintArray, LintPass, LintPassObject};
3635
use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid};
3736
use lint::builtin;

src/librustc/metadata/creader.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
//! Validates all used crates and extern libraries and loads their metadata
1414
1515
use back::svh::Svh;
16-
use driver::session::Session;
17-
use driver::driver;
16+
use session::{config, Session};
1817
use metadata::cstore;
1918
use metadata::cstore::{CStore, CrateSource};
2019
use metadata::decoder;
@@ -455,7 +454,7 @@ impl<'a> PluginMetadataReader<'a> {
455454
pub fn read_plugin_metadata(&mut self, krate: &ast::ViewItem) -> PluginMetadata {
456455
let info = extract_crate_info(&self.env, krate).unwrap();
457456
let target_triple = self.env.sess.opts.target_triple.as_slice();
458-
let is_cross = target_triple != driver::host_triple();
457+
let is_cross = target_triple != config::host_triple();
459458
let mut should_link = info.should_link && !is_cross;
460459
let mut load_ctxt = loader::Context {
461460
sess: self.env.sess,
@@ -464,7 +463,7 @@ impl<'a> PluginMetadataReader<'a> {
464463
crate_name: info.name.as_slice(),
465464
hash: None,
466465
filesearch: self.env.sess.host_filesearch(),
467-
triple: driver::host_triple(),
466+
triple: config::host_triple(),
468467
root: &None,
469468
rejected_via_hash: vec!(),
470469
rejected_via_triple: vec!(),
@@ -481,7 +480,7 @@ impl<'a> PluginMetadataReader<'a> {
481480
if decoder::get_plugin_registrar_fn(lib.metadata.as_slice()).is_some() {
482481
let message = format!("crate `{}` contains a plugin_registrar fn but \
483482
only a version for triple `{}` could be found (need {})",
484-
info.ident, target_triple, driver::host_triple());
483+
info.ident, target_triple, config::host_triple());
485484
self.env.sess.span_err(krate.span, message.as_slice());
486485
// need to abort now because the syntax expansion
487486
// code will shortly attempt to load and execute

src/librustc/metadata/encoder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
pub use self::InlinedItemRef::*;
1717

1818
use back::svh::Svh;
19-
use driver::config;
19+
use session::config;
2020
use metadata::common::*;
2121
use metadata::cstore;
2222
use metadata::decoder;

src/librustc/metadata/loader.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@
214214
215215
use back::archive::{METADATA_FILENAME};
216216
use back::svh::Svh;
217-
use driver::session::Session;
217+
use session::Session;
218218
use llvm;
219219
use llvm::{False, ObjectFile, mk_section_iter};
220220
use llvm::archive_ro::ArchiveRO;

src/librustc/middle/astencode.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
use metadata::common as c;
1616
use metadata::cstore as cstore;
17-
use driver::session::Session;
17+
use session::Session;
1818
use metadata::decoder;
1919
use middle::def;
2020
use metadata::encoder as e;

src/librustc/middle/check_loop.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// except according to those terms.
1010
use self::Context::*;
1111

12-
use driver::session::Session;
12+
use session::Session;
1313

1414
use syntax::ast;
1515
use syntax::codemap::Span;

src/librustc/middle/check_static_recursion.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
// This compiler pass detects static items that refer to themselves
1212
// recursively.
1313

14-
use driver::session::Session;
14+
use session::Session;
1515
use middle::resolve;
1616
use middle::def::{DefStatic, DefConst};
1717

src/librustc/middle/dependency_format.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@
6363
6464
use syntax::ast;
6565

66-
use driver::session;
67-
use driver::config;
66+
use session;
67+
use session::config;
6868
use metadata::cstore;
6969
use metadata::csearch;
7070
use middle::ty;

src/librustc/middle/entry.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
// except according to those terms.
1010

1111

12-
use driver::config;
13-
use driver::session::Session;
12+
use session::{config, Session};
1413
use syntax::ast::{Name, NodeId, Item, ItemFn};
1514
use syntax::ast_map;
1615
use syntax::attr;

src/librustc/middle/lang_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
pub use self::LangItem::*;
2323

24-
use driver::session::Session;
24+
use session::Session;
2525
use metadata::csearch::each_lang_item;
2626
use middle::ty;
2727
use middle::weak_lang_items;

src/librustc/middle/reachable.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
// makes all other generics or inline functions that it references
1616
// reachable as well.
1717

18-
use driver::config;
1918
use middle::def;
2019
use middle::ty;
2120
use middle::typeck;
2221
use middle::privacy;
22+
use session::config;
2323
use util::nodemap::NodeSet;
2424

2525
use std::collections::HashSet;

src/librustc/middle/region.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Most of the documentation on regions can be found in
2121
*/
2222

2323

24-
use driver::session::Session;
24+
use session::Session;
2525
use middle::ty::{FreeRegion};
2626
use middle::ty;
2727
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};

src/librustc/middle/resolve.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use self::ModuleKind::*;
3636
use self::TraitReferenceType::*;
3737
use self::FallbackChecks::*;
3838

39-
use driver::session::Session;
39+
use session::Session;
4040
use lint;
4141
use metadata::csearch;
4242
use metadata::decoder::{DefLike, DlDef, DlField, DlImpl};

src/librustc/middle/resolve_lifetime.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
pub use self::DefRegion::*;
2121
use self::ScopeChain::*;
2222

23-
use driver::session::Session;
23+
use session::Session;
2424
use middle::subst;
2525
use std::fmt;
2626
use syntax::ast;

src/librustc/middle/ty.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub use self::sty::*;
3737
pub use self::IntVarValue::*;
3838

3939
use back::svh::Svh;
40-
use driver::session::Session;
40+
use session::Session;
4141
use lint;
4242
use metadata::csearch;
4343
use middle::const_eval;

src/librustc/middle/typeck/check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ use self::Expectation::*;
8282
use self::IsBinopAssignment::*;
8383
use self::TupleArgumentsFlag::*;
8484

85-
use driver::session::Session;
85+
use session::Session;
8686
use middle::const_eval;
8787
use middle::def;
8888
use middle::lang_items::IteratorItem;

0 commit comments

Comments
 (0)