Skip to content

Commit

Permalink
auto merge of #19070 : nikomatsakis/rust/crates, r=nikomatsakis
Browse files Browse the repository at this point in the history
Reduces memory usage significantly and opens opportunities for more parallel compilation.

This PR was previously #19002 but I closed it because bors didn't seem to recognize the `r+` annotations there.
  • Loading branch information
bors committed Nov 18, 2014
2 parents d7a29d8 + dc6e414 commit 618bd5d
Show file tree
Hide file tree
Showing 80 changed files with 641 additions and 533 deletions.
11 changes: 6 additions & 5 deletions mk/crates.mk
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ TARGET_CRATES := libc std green native flate arena term \
serialize sync getopts collections test time rand \
log regex graphviz core rbml alloc rustrt \
unicode
HOST_CRATES := syntax rustc rustdoc regex_macros fmt_macros \
HOST_CRATES := syntax rustc rustc_trans rustdoc regex_macros fmt_macros \
rustc_llvm rustc_back
CRATES := $(TARGET_CRATES) $(HOST_CRATES)
TOOLS := compiletest rustdoc rustc
Expand All @@ -69,11 +69,12 @@ DEPS_graphviz := std
DEPS_green := std native:context_switch
DEPS_native := std
DEPS_syntax := std term serialize log fmt_macros arena libc
DEPS_rustc_trans := rustc rustc_back rustc_llvm libc
DEPS_rustc := syntax flate arena serialize getopts rbml \
time log graphviz rustc_llvm rustc_back
DEPS_rustc_llvm := native:rustllvm libc std
DEPS_rustc_back := std syntax rustc_llvm flate log libc
DEPS_rustdoc := rustc native:hoedown serialize getopts \
DEPS_rustdoc := rustc rustc_trans native:hoedown serialize getopts \
test time
DEPS_flate := std native:miniz
DEPS_arena := std
Expand All @@ -96,7 +97,7 @@ DEPS_fmt_macros = std

TOOL_DEPS_compiletest := test getopts native
TOOL_DEPS_rustdoc := rustdoc native
TOOL_DEPS_rustc := rustc native
TOOL_DEPS_rustc := rustc_trans native
TOOL_SOURCE_compiletest := $(S)src/compiletest/compiletest.rs
TOOL_SOURCE_rustdoc := $(S)src/driver/driver.rs
TOOL_SOURCE_rustc := $(S)src/driver/driver.rs
Expand All @@ -112,8 +113,8 @@ ONLY_RLIB_unicode := 1
# You should not need to edit below this line
################################################################################

DOC_CRATES := $(filter-out rustc, $(filter-out syntax, $(CRATES)))
COMPILER_DOC_CRATES := rustc syntax
DOC_CRATES := $(filter-out rustc, $(filter-out rustc_trans, $(filter-out syntax, $(CRATES))))
COMPILER_DOC_CRATES := rustc rustc_trans syntax

# This macro creates some simple definitions for each crate being built, just
# some munging of all of the parameters above.
Expand Down
2 changes: 1 addition & 1 deletion src/driver/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
extern crate "rustdoc" as this;

#[cfg(rustc)]
extern crate "rustc" as this;
extern crate "rustc_trans" as this;

fn main() { this::main() }
87 changes: 59 additions & 28 deletions src/librustc/README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,62 @@ https://github.com/rust-lang/rust/issues

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


High-level concepts
The crates of rustc
===================

Rustc consists of the following subdirectories:

front/ - front-end: attributes, conditional compilation
middle/ - middle-end: name resolution, typechecking, LLVM code
Rustc consists of four crates altogether: `libsyntax`, `librustc`,
`librustc_back`, and `librustc_trans` (the names and divisions are not
set in stone and may change; in general, a finer-grained division of
crates is preferable):

- `libsyntax` contains those things concerned purely with syntax --
that is, the AST, parser, pretty-printer, lexer, macro expander, and
utilities for traversing ASTs -- are in a separate crate called
"syntax", whose files are in ./../libsyntax, where . is the current
directory (that is, the parent directory of front/, middle/, back/,
and so on).

- `librustc` (the current directory) contains the high-level analysis
passes, such as the type checker, borrow checker, and so forth.
It is the heart of the compiler.

- `librustc_back` contains some very low-level details that are
specific to different LLVM targets and so forth.

- `librustc_trans` contains the code to convert from Rust IR into LLVM
IR, and then from LLVM IR into machine code, as well as the main
driver that orchestrates all the other passes and various other bits
of miscellany. In general it contains code that runs towards the
end of the compilation process.

Roughly speaking the "order" of the three crates is as follows:

libsyntax -> librustc -> librustc_trans
| |
+-----------------+-------------------+
|
librustc_trans/driver

Here the role of `librustc_trans/driver` is to invoke the compiler
from libsyntax, then the analysis phases from librustc, and finally
the lowering and codegen passes from librustc_trans.

Modules in the rustc crate
==========================

The rustc crate itself consists of the following subdirectories
(mostly, but not entirely, in their own directories):

session - options and data that pertain to the compilation session as a whole
middle - middle-end: name resolution, typechecking, LLVM code
generation
back/ - back-end: linking and ABI
metadata/ - encoder and decoder for data required by
metadata - encoder and decoder for data required by
separate compilation
driver/ - command-line processing, main() entrypoint
util/ - ubiquitous types and helper functions
lib/ - bindings to LLVM

The files concerned purely with syntax -- that is, the AST, parser,
pretty-printer, lexer, macro expander, and utilities for traversing
ASTs -- are in a separate crate called "syntax", whose files are in
./../libsyntax, where . is the current directory (that is, the parent
directory of front/, middle/, back/, and so on).

The entry-point for the compiler is main() in lib.rs, and
this file sequences the various parts together.
util - ubiquitous types and helper functions
lib - bindings to LLVM

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

The 3 central data structures:
------------------------------
Expand Down Expand Up @@ -66,10 +97,10 @@ The 3 central data structures:
compilation. Most variants in the ast::ty tag have a
corresponding variant in the ty::sty tag.

#3: lib/llvm.rs defines the exported types ValueRef, TypeRef,
BasicBlockRef, and several others. Each of these is an opaque
pointer to an LLVM type, manipulated through the lib::llvm
interface.
#3: lib/llvm.rs (in librustc_trans) defines the exported types
ValueRef, TypeRef, BasicBlockRef, and several others. Each of
these is an opaque pointer to an LLVM type, manipulated through
the lib::llvm interface.


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

- Finally middle/trans.rs translates the Rust AST to LLVM bitcode in a
type-directed way. When it's finished synthesizing LLVM values,
rustc asks LLVM to write them out in some form (.bc, .o) and
possibly run the system linker.
- Finally, the `trans` module in `librustc_trans` translates the Rust
AST to LLVM bitcode in a type-directed way. When it's finished
synthesizing LLVM values, rustc asks LLVM to write them out in some
form (.bc, .o) and possibly run the system linker.
15 changes: 1 addition & 14 deletions src/librustc/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ pub mod back {
pub use rustc_back::target_strs;
pub use rustc_back::x86;
pub use rustc_back::x86_64;

pub mod link;
pub mod lto;
pub mod write;

}

pub mod middle {
Expand Down Expand Up @@ -99,11 +94,9 @@ pub mod middle {
pub mod region;
pub mod resolve;
pub mod resolve_lifetime;
pub mod save;
pub mod stability;
pub mod subst;
pub mod traits;
pub mod trans;
pub mod ty;
pub mod ty_fold;
pub mod typeck;
Expand All @@ -112,7 +105,7 @@ pub mod middle {

pub mod metadata;

pub mod driver;
pub mod session;

pub mod plugin;

Expand Down Expand Up @@ -142,9 +135,3 @@ __build_diagnostic_array!(DIAGNOSTICS)
mod rustc {
pub use lint;
}

pub fn main() {
let args = std::os::args();
let result = driver::run(args);
std::os::set_exit_status(result);
}
3 changes: 1 addition & 2 deletions src/librustc/lint/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@ use middle::subst;
use middle::ty;
use middle::typeck::astconv::AstConv;
use middle::typeck::infer;
use driver::session::Session;
use driver::early_error;
use session::{early_error, Session};
use lint::{Level, LevelSource, Lint, LintId, LintArray, LintPass, LintPassObject};
use lint::{Default, CommandLine, Node, Allow, Warn, Deny, Forbid};
use lint::builtin;
Expand Down
9 changes: 4 additions & 5 deletions src/librustc/metadata/creader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@
//! Validates all used crates and extern libraries and loads their metadata
use back::svh::Svh;
use driver::session::Session;
use driver::driver;
use session::{config, Session};
use metadata::cstore;
use metadata::cstore::{CStore, CrateSource};
use metadata::decoder;
Expand Down Expand Up @@ -455,7 +454,7 @@ impl<'a> PluginMetadataReader<'a> {
pub fn read_plugin_metadata(&mut self, krate: &ast::ViewItem) -> PluginMetadata {
let info = extract_crate_info(&self.env, krate).unwrap();
let target_triple = self.env.sess.opts.target_triple.as_slice();
let is_cross = target_triple != driver::host_triple();
let is_cross = target_triple != config::host_triple();
let mut should_link = info.should_link && !is_cross;
let mut load_ctxt = loader::Context {
sess: self.env.sess,
Expand All @@ -464,7 +463,7 @@ impl<'a> PluginMetadataReader<'a> {
crate_name: info.name.as_slice(),
hash: None,
filesearch: self.env.sess.host_filesearch(),
triple: driver::host_triple(),
triple: config::host_triple(),
root: &None,
rejected_via_hash: vec!(),
rejected_via_triple: vec!(),
Expand All @@ -481,7 +480,7 @@ impl<'a> PluginMetadataReader<'a> {
if decoder::get_plugin_registrar_fn(lib.metadata.as_slice()).is_some() {
let message = format!("crate `{}` contains a plugin_registrar fn but \
only a version for triple `{}` could be found (need {})",
info.ident, target_triple, driver::host_triple());
info.ident, target_triple, config::host_triple());
self.env.sess.span_err(krate.span, message.as_slice());
// need to abort now because the syntax expansion
// code will shortly attempt to load and execute
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
pub use self::InlinedItemRef::*;

use back::svh::Svh;
use driver::config;
use session::config;
use metadata::common::*;
use metadata::cstore;
use metadata::decoder;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/metadata/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
use back::archive::{METADATA_FILENAME};
use back::svh::Svh;
use driver::session::Session;
use session::Session;
use llvm;
use llvm::{False, ObjectFile, mk_section_iter};
use llvm::archive_ro::ArchiveRO;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/astencode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use metadata::common as c;
use metadata::cstore as cstore;
use driver::session::Session;
use session::Session;
use metadata::decoder;
use middle::def;
use metadata::encoder as e;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
// except according to those terms.
use self::Context::*;

use driver::session::Session;
use session::Session;

use syntax::ast;
use syntax::codemap::Span;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/check_static_recursion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
// This compiler pass detects static items that refer to themselves
// recursively.

use driver::session::Session;
use session::Session;
use middle::resolve;
use middle::def::{DefStatic, DefConst};

Expand Down
4 changes: 2 additions & 2 deletions src/librustc/middle/dependency_format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@
use syntax::ast;

use driver::session;
use driver::config;
use session;
use session::config;
use metadata::cstore;
use metadata::csearch;
use middle::ty;
Expand Down
3 changes: 1 addition & 2 deletions src/librustc/middle/entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
// except according to those terms.


use driver::config;
use driver::session::Session;
use session::{config, Session};
use syntax::ast::{Name, NodeId, Item, ItemFn};
use syntax::ast_map;
use syntax::attr;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

pub use self::LangItem::*;

use driver::session::Session;
use session::Session;
use metadata::csearch::each_lang_item;
use middle::ty;
use middle::weak_lang_items;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/reachable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
// makes all other generics or inline functions that it references
// reachable as well.

use driver::config;
use middle::def;
use middle::ty;
use middle::typeck;
use middle::privacy;
use session::config;
use util::nodemap::NodeSet;

use std::collections::HashSet;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Most of the documentation on regions can be found in
*/


use driver::session::Session;
use session::Session;
use middle::ty::{FreeRegion};
use middle::ty;
use util::nodemap::{FnvHashMap, NodeMap, NodeSet};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ use self::ModuleKind::*;
use self::TraitReferenceType::*;
use self::FallbackChecks::*;

use driver::session::Session;
use session::Session;
use lint;
use metadata::csearch;
use metadata::decoder::{DefLike, DlDef, DlField, DlImpl};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/resolve_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
pub use self::DefRegion::*;
use self::ScopeChain::*;

use driver::session::Session;
use session::Session;
use middle::subst;
use std::fmt;
use syntax::ast;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub use self::sty::*;
pub use self::IntVarValue::*;

use back::svh::Svh;
use driver::session::Session;
use session::Session;
use lint;
use metadata::csearch;
use middle::const_eval;
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/middle/typeck/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ use self::Expectation::*;
use self::IsBinopAssignment::*;
use self::TupleArgumentsFlag::*;

use driver::session::Session;
use session::Session;
use middle::const_eval;
use middle::def;
use middle::lang_items::IteratorItem;
Expand Down
Loading

0 comments on commit 618bd5d

Please sign in to comment.