2013-08-06 23:50:23 -05:00
|
|
|
// Copyright 2012-2013 The Rust Project Developers. See the COPYRIGHT
|
2012-12-03 18:48:01 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
2013-05-17 17:28:44 -05:00
|
|
|
|
2012-12-23 16:41:37 -06:00
|
|
|
use back::link;
|
2013-01-29 08:28:08 -06:00
|
|
|
use back::{arm, x86, x86_64, mips};
|
2014-03-08 14:36:22 -06:00
|
|
|
use driver::session::{Aggressive, CrateTypeExecutable, CrateType,
|
|
|
|
FullDebugInfo, LimitedDebugInfo, NoDebugInfo};
|
2014-03-05 08:36:01 -06:00
|
|
|
use driver::session::{Session, No, Less, Default};
|
2013-03-01 12:44:43 -06:00
|
|
|
use driver::session;
|
2012-12-23 16:41:37 -06:00
|
|
|
use front;
|
|
|
|
use lib::llvm::llvm;
|
2013-07-27 01:49:38 -05:00
|
|
|
use lib::llvm::{ContextRef, ModuleRef};
|
|
|
|
use metadata::common::LinkMeta;
|
2013-12-25 14:08:04 -06:00
|
|
|
use metadata::{creader, filesearch};
|
|
|
|
use metadata::cstore::CStore;
|
2013-12-25 12:10:33 -06:00
|
|
|
use metadata::creader::Loader;
|
2012-12-23 16:41:37 -06:00
|
|
|
use metadata;
|
2013-06-14 20:21:47 -05:00
|
|
|
use middle::{trans, freevars, kind, ty, typeck, lint, astencode, reachable};
|
2012-12-23 16:41:37 -06:00
|
|
|
use middle;
|
2013-03-21 04:50:02 -05:00
|
|
|
use util::common::time;
|
2012-09-04 13:54:36 -05:00
|
|
|
use util::ppaux;
|
2014-03-16 13:56:24 -05:00
|
|
|
use util::nodemap::{NodeMap, NodeSet};
|
2012-12-23 16:41:37 -06:00
|
|
|
|
2014-02-21 16:18:39 -06:00
|
|
|
use serialize::{json, Encodable};
|
2014-02-19 01:27:49 -06:00
|
|
|
|
2013-12-21 19:25:27 -06:00
|
|
|
use std::cell::{Cell, RefCell};
|
2013-11-11 00:46:32 -06:00
|
|
|
use std::io;
|
|
|
|
use std::io::fs;
|
2014-01-15 15:25:09 -06:00
|
|
|
use std::io::MemReader;
|
2014-03-15 15:29:34 -05:00
|
|
|
use std::mem::drop;
|
2013-06-28 17:32:26 -05:00
|
|
|
use std::os;
|
2014-03-10 14:13:19 -05:00
|
|
|
use getopts::{optopt, optmulti, optflag, optflagopt};
|
2014-02-02 17:20:32 -06:00
|
|
|
use getopts;
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax::ast;
|
2013-03-13 21:25:28 -05:00
|
|
|
use syntax::abi;
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax::attr;
|
2013-07-19 06:51:37 -05:00
|
|
|
use syntax::attr::{AttrMetaMethods};
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax::codemap;
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
use syntax::crateid::CrateId;
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax::diagnostic;
|
2014-02-06 16:38:33 -06:00
|
|
|
use syntax::diagnostic::Emitter;
|
2013-12-25 12:10:33 -06:00
|
|
|
use syntax::ext::base::CrateLoader;
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax::parse;
|
2014-01-08 12:35:15 -06:00
|
|
|
use syntax::parse::token::InternedString;
|
2013-05-14 19:27:27 -05:00
|
|
|
use syntax::parse::token;
|
2012-12-23 16:41:37 -06:00
|
|
|
use syntax::print::{pp, pprust};
|
|
|
|
use syntax;
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2013-08-31 11:13:04 -05:00
|
|
|
pub enum PpMode {
|
|
|
|
PpmNormal,
|
|
|
|
PpmExpanded,
|
|
|
|
PpmTyped,
|
|
|
|
PpmIdentified,
|
|
|
|
PpmExpandedIdentified
|
2012-12-23 16:41:37 -06:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2012-07-04 16:53:12 -05:00
|
|
|
/**
|
|
|
|
* The name used for source code that doesn't originate in a file
|
|
|
|
* (e.g. source from stdin or a string)
|
|
|
|
*/
|
2014-01-15 18:42:51 -06:00
|
|
|
pub fn anon_src() -> ~str {
|
|
|
|
"<anon>".to_str()
|
|
|
|
}
|
2012-05-09 21:41:24 -05:00
|
|
|
|
2014-01-15 18:42:51 -06:00
|
|
|
pub fn source_name(input: &Input) -> ~str {
|
2013-04-17 11:15:37 -05:00
|
|
|
match *input {
|
2014-03-16 13:56:24 -05:00
|
|
|
// FIXME (#9639): This needs to handle non-utf8 paths
|
|
|
|
FileInput(ref ifile) => ifile.as_str().unwrap().to_str(),
|
|
|
|
StrInput(_) => anon_src()
|
2012-05-09 21:41:24 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn default_configuration(sess: &Session) ->
|
2013-07-19 00:38:55 -05:00
|
|
|
ast::CrateConfig {
|
2013-08-13 19:06:27 -05:00
|
|
|
let tos = match sess.targ_cfg.os {
|
2014-01-10 16:02:36 -06:00
|
|
|
abi::OsWin32 => InternedString::new("win32"),
|
|
|
|
abi::OsMacos => InternedString::new("macos"),
|
|
|
|
abi::OsLinux => InternedString::new("linux"),
|
|
|
|
abi::OsAndroid => InternedString::new("android"),
|
|
|
|
abi::OsFreebsd => InternedString::new("freebsd"),
|
2012-01-26 03:52:08 -06:00
|
|
|
};
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2013-02-16 05:58:21 -06:00
|
|
|
// ARM is bi-endian, however using NDK seems to default
|
|
|
|
// to little-endian unless a flag is provided.
|
|
|
|
let (end,arch,wordsz) = match sess.targ_cfg.arch {
|
2014-01-10 16:02:36 -06:00
|
|
|
abi::X86 => ("little", "x86", "32"),
|
|
|
|
abi::X86_64 => ("little", "x86_64", "64"),
|
|
|
|
abi::Arm => ("little", "arm", "32"),
|
|
|
|
abi::Mips => ("big", "mips", "32")
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
|
|
|
|
2013-11-20 00:30:51 -06:00
|
|
|
let fam = match sess.targ_cfg.os {
|
2014-01-08 12:35:15 -06:00
|
|
|
abi::OsWin32 => InternedString::new("windows"),
|
|
|
|
_ => InternedString::new("unix")
|
2013-11-20 00:30:51 -06:00
|
|
|
};
|
|
|
|
|
2013-06-15 02:43:19 -05:00
|
|
|
let mk = attr::mk_name_value_item_str;
|
2014-02-28 17:25:15 -06:00
|
|
|
return vec!(// Target bindings.
|
2014-01-08 12:35:15 -06:00
|
|
|
attr::mk_word_item(fam.clone()),
|
|
|
|
mk(InternedString::new("target_os"), tos),
|
2014-01-10 16:02:36 -06:00
|
|
|
mk(InternedString::new("target_family"), fam),
|
|
|
|
mk(InternedString::new("target_arch"), InternedString::new(arch)),
|
|
|
|
mk(InternedString::new("target_endian"), InternedString::new(end)),
|
|
|
|
mk(InternedString::new("target_word_size"),
|
2014-02-28 17:25:15 -06:00
|
|
|
InternedString::new(wordsz))
|
|
|
|
);
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2014-01-08 12:35:15 -06:00
|
|
|
pub fn append_configuration(cfg: &mut ast::CrateConfig,
|
|
|
|
name: InternedString) {
|
2013-07-19 06:51:37 -05:00
|
|
|
if !cfg.iter().any(|mi| mi.name() == name) {
|
|
|
|
cfg.push(attr::mk_word_item(name))
|
2012-08-28 12:58:04 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn build_configuration(sess: &Session) -> ast::CrateConfig {
|
2011-12-20 04:17:13 -06:00
|
|
|
// Combine the configuration requested by the session (command line) with
|
|
|
|
// some default and generated configuration items
|
2013-08-13 19:06:27 -05:00
|
|
|
let default_cfg = default_configuration(sess);
|
2013-07-19 06:51:37 -05:00
|
|
|
let mut user_cfg = sess.opts.cfg.clone();
|
2011-12-20 04:17:13 -06:00
|
|
|
// If the user wants a test runner, then add the test cfg
|
2014-01-08 12:35:15 -06:00
|
|
|
if sess.opts.test {
|
|
|
|
append_configuration(&mut user_cfg, InternedString::new("test"))
|
|
|
|
}
|
2012-08-28 12:58:04 -05:00
|
|
|
// If the user requested GC, then add the GC cfg
|
2014-01-08 12:35:15 -06:00
|
|
|
append_configuration(&mut user_cfg, if sess.opts.gc {
|
|
|
|
InternedString::new("gc")
|
|
|
|
} else {
|
|
|
|
InternedString::new("nogc")
|
|
|
|
});
|
2014-03-30 22:53:26 -05:00
|
|
|
user_cfg.move_iter().collect::<Vec<_>>().append(default_cfg.as_slice())
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// Convert strings provided as --cfg [cfgspec] into a crate_cfg
|
2014-03-04 12:02:49 -06:00
|
|
|
fn parse_cfgspecs(cfgspecs: Vec<~str> )
|
2013-08-29 20:34:09 -05:00
|
|
|
-> ast::CrateConfig {
|
2013-11-21 17:42:55 -06:00
|
|
|
cfgspecs.move_iter().map(|s| {
|
2014-02-28 17:25:15 -06:00
|
|
|
parse::parse_meta_from_source_str("cfgspec".to_str(),
|
|
|
|
s,
|
|
|
|
Vec::new(),
|
2014-03-09 09:54:34 -05:00
|
|
|
&parse::new_parse_sess())
|
2013-11-21 17:42:55 -06:00
|
|
|
}).collect::<ast::CrateConfig>()
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2014-01-13 10:31:05 -06:00
|
|
|
pub enum Input {
|
2012-07-04 16:53:12 -05:00
|
|
|
/// Load source from file
|
2014-01-13 10:31:05 -06:00
|
|
|
FileInput(Path),
|
2012-07-04 16:53:12 -05:00
|
|
|
/// The string is the source
|
2014-01-15 18:26:20 -06:00
|
|
|
StrInput(~str)
|
2012-05-09 21:41:24 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
impl Input {
|
|
|
|
fn filestem(&self) -> ~str {
|
|
|
|
match *self {
|
|
|
|
FileInput(ref ifile) => ifile.filestem_str().unwrap().to_str(),
|
2014-04-15 20:17:48 -05:00
|
|
|
StrInput(_) => "rust_out".to_owned(),
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-03-18 12:58:26 -05:00
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn phase_1_parse_input(sess: &Session, cfg: ast::CrateConfig, input: &Input)
|
2013-09-27 21:46:09 -05:00
|
|
|
-> ast::Crate {
|
2014-02-19 01:27:49 -06:00
|
|
|
let krate = time(sess.time_passes(), "parsing", (), |_| {
|
2013-07-27 01:49:38 -05:00
|
|
|
match *input {
|
2014-01-13 10:31:05 -06:00
|
|
|
FileInput(ref file) => {
|
2014-03-09 09:54:34 -05:00
|
|
|
parse::parse_crate_from_file(&(*file), cfg.clone(), &sess.parse_sess)
|
2013-07-27 01:49:38 -05:00
|
|
|
}
|
2014-01-15 18:26:20 -06:00
|
|
|
StrInput(ref src) => {
|
|
|
|
parse::parse_crate_from_source_str(anon_src(),
|
|
|
|
(*src).clone(),
|
|
|
|
cfg.clone(),
|
2014-03-09 09:54:34 -05:00
|
|
|
&sess.parse_sess)
|
2013-07-27 01:49:38 -05:00
|
|
|
}
|
|
|
|
}
|
2014-02-19 01:27:49 -06:00
|
|
|
});
|
|
|
|
|
|
|
|
if sess.opts.debugging_opts & session::AST_JSON_NOEXPAND != 0 {
|
2014-03-18 07:40:07 -05:00
|
|
|
let mut stdout = io::BufferedWriter::new(io::stdout());
|
2014-02-19 01:27:49 -06:00
|
|
|
let mut json = json::PrettyEncoder::new(&mut stdout);
|
2014-03-18 12:58:26 -05:00
|
|
|
// unwrapping so IoError isn't ignored
|
2014-03-28 19:05:46 -05:00
|
|
|
krate.encode(&mut json).unwrap();
|
2014-02-19 01:27:49 -06:00
|
|
|
}
|
|
|
|
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
if sess.show_span() {
|
|
|
|
front::show_span::run(sess, &krate);
|
|
|
|
}
|
|
|
|
|
2014-02-19 01:27:49 -06:00
|
|
|
krate
|
2012-01-17 09:42:45 -06:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2013-01-22 19:19:13 -06:00
|
|
|
// For continuing compilation after a parsed crate has been
|
|
|
|
// modified
|
2013-05-28 17:31:32 -05:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
/// Run the "early phases" of the compiler: initial `cfg` processing,
|
|
|
|
/// syntax expansion, secondary `cfg` expansion, synthesis of a test
|
|
|
|
/// harness if one is to be provided and injection of a dependency on the
|
|
|
|
/// standard library and prelude.
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn phase_2_configure_and_expand(sess: &Session,
|
2013-12-25 12:10:33 -06:00
|
|
|
loader: &mut CrateLoader,
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
mut krate: ast::Crate,
|
|
|
|
crate_id: &CrateId)
|
2014-01-09 07:05:33 -06:00
|
|
|
-> (ast::Crate, syntax::ast_map::Map) {
|
2012-05-17 23:53:49 -05:00
|
|
|
let time_passes = sess.time_passes();
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2014-03-16 13:56:24 -05:00
|
|
|
sess.building_library.set(session::building_library(&sess.opts, &krate));
|
2014-04-02 08:55:33 -05:00
|
|
|
*sess.crate_types.borrow_mut() = session::collect_crate_types(sess, krate.attrs.as_slice());
|
2013-05-09 00:15:54 -05:00
|
|
|
|
2013-10-02 22:00:54 -05:00
|
|
|
time(time_passes, "gated feature checking", (), |_|
|
2014-02-05 15:15:24 -06:00
|
|
|
front::feature_gate::check_crate(sess, &krate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2014-02-05 15:15:24 -06:00
|
|
|
krate = time(time_passes, "crate injection", krate, |krate|
|
|
|
|
front::std_inject::maybe_inject_crates_ref(sess, krate));
|
2014-01-24 01:40:54 -06:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
// strip before expansion to allow macros to depend on
|
|
|
|
// configuration variables e.g/ in
|
|
|
|
//
|
|
|
|
// #[macro_escape] #[cfg(foo)]
|
|
|
|
// mod bar { macro_rules! baz!(() => {{}}) }
|
|
|
|
//
|
|
|
|
// baz! should not use this definition unless foo is enabled.
|
2013-07-16 00:05:50 -05:00
|
|
|
|
2014-02-05 15:15:24 -06:00
|
|
|
krate = time(time_passes, "configuration 1", krate, |krate|
|
|
|
|
front::config::strip_unconfigured_items(krate));
|
2013-06-21 22:20:00 -05:00
|
|
|
|
2014-02-05 15:15:24 -06:00
|
|
|
krate = time(time_passes, "expansion", krate, |krate| {
|
2014-03-01 01:17:38 -06:00
|
|
|
let cfg = syntax::ext::expand::ExpansionConfig {
|
|
|
|
loader: loader,
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
deriving_hash_type_parameter: sess.features.default_type_params.get(),
|
|
|
|
crate_id: crate_id.clone(),
|
2014-03-01 01:17:38 -06:00
|
|
|
};
|
2014-03-09 09:54:34 -05:00
|
|
|
syntax::ext::expand::expand_crate(&sess.parse_sess,
|
2014-03-01 01:17:38 -06:00
|
|
|
cfg,
|
2014-02-05 15:15:24 -06:00
|
|
|
krate)
|
2013-12-25 12:10:33 -06:00
|
|
|
});
|
2013-05-27 19:45:16 -05:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
// strip again, in case expansion added anything with a #[cfg].
|
2014-02-05 15:15:24 -06:00
|
|
|
krate = time(time_passes, "configuration 2", krate, |krate|
|
|
|
|
front::config::strip_unconfigured_items(krate));
|
2013-05-27 19:45:16 -05:00
|
|
|
|
2014-02-05 15:15:24 -06:00
|
|
|
krate = time(time_passes, "maybe building test harness", krate, |krate|
|
|
|
|
front::test::modify_for_testing(sess, krate));
|
2013-07-19 06:51:37 -05:00
|
|
|
|
2014-02-05 15:15:24 -06:00
|
|
|
krate = time(time_passes, "prelude injection", krate, |krate|
|
|
|
|
front::std_inject::maybe_inject_prelude(sess, krate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2014-02-19 01:27:49 -06:00
|
|
|
let (krate, map) = time(time_passes, "assinging node ids and indexing ast", krate, |krate|
|
|
|
|
front::assign_node_ids_and_map::assign_node_ids_and_map(sess, krate));
|
|
|
|
|
|
|
|
if sess.opts.debugging_opts & session::AST_JSON != 0 {
|
2014-03-18 07:40:07 -05:00
|
|
|
let mut stdout = io::BufferedWriter::new(io::stdout());
|
2014-02-19 01:27:49 -06:00
|
|
|
let mut json = json::PrettyEncoder::new(&mut stdout);
|
2014-03-18 12:58:26 -05:00
|
|
|
// unwrapping so IoError isn't ignored
|
2014-03-28 19:05:46 -05:00
|
|
|
krate.encode(&mut json).unwrap();
|
2014-02-19 01:27:49 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
(krate, map)
|
2013-07-27 01:49:38 -05:00
|
|
|
}
|
2012-01-26 17:20:29 -06:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
pub struct CrateAnalysis {
|
2014-03-28 12:05:27 -05:00
|
|
|
pub exp_map2: middle::resolve::ExportMap2,
|
|
|
|
pub exported_items: middle::privacy::ExportedItems,
|
|
|
|
pub public_items: middle::privacy::PublicItems,
|
|
|
|
pub ty_cx: ty::ctxt,
|
|
|
|
pub maps: astencode::Maps,
|
|
|
|
pub reachable: NodeSet,
|
2013-07-27 01:49:38 -05:00
|
|
|
}
|
2012-05-22 12:54:12 -05:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
/// Run the resolution, typechecking, region checking and other
|
|
|
|
/// miscellaneous analysis passes on the crate. Return various
|
|
|
|
/// structures carrying the results of the analysis.
|
|
|
|
pub fn phase_3_run_analysis_passes(sess: Session,
|
2014-02-05 15:15:24 -06:00
|
|
|
krate: &ast::Crate,
|
2014-01-09 07:05:33 -06:00
|
|
|
ast_map: syntax::ast_map::Map) -> CrateAnalysis {
|
2012-05-22 12:54:12 -05:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
let time_passes = sess.time_passes();
|
2013-09-06 21:11:55 -05:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "external crate/lib resolution", (), |_|
|
2014-03-05 08:36:01 -06:00
|
|
|
creader::read_crates(&sess, krate,
|
2013-07-27 01:49:38 -05:00
|
|
|
session::sess_os_to_meta_os(sess.targ_cfg.os),
|
|
|
|
token::get_ident_interner()));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
let lang_items = time(time_passes, "language item collection", (), |_|
|
2014-03-05 08:36:01 -06:00
|
|
|
middle::lang_items::collect_language_items(krate, &sess));
|
2013-04-29 16:56:05 -05:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
let middle::resolve::CrateMap {
|
|
|
|
def_map: def_map,
|
|
|
|
exp_map2: exp_map2,
|
Extract privacy checking from name resolution
This commit is the culmination of my recent effort to refine Rust's notion of
privacy and visibility among crates. The major goals of this commit were to
remove privacy checking from resolve for the sake of sane error messages, and to
attempt a much more rigid and well-tested implementation of visibility
throughout rust. The implemented rules for name visibility are:
1. Everything pub from the root namespace is visible to anyone
2. You may access any private item of your ancestors.
"Accessing a private item" depends on what the item is, so for a function this
means that you can call it, but for a module it means that you can look inside
of it. Once you look inside a private module, any accessed item must be "pub
from the root" where the new root is the private module that you looked into.
These rules required some more analysis results to get propagated from trans to
privacy in the form of a few hash tables.
I added a new test in which my goal was to showcase all of the privacy nuances
of the language, and I hope to place any new bugs into this file to prevent
regressions.
Overall, I was unable to completely remove the notion of privacy from resolve.
One use of privacy is for dealing with glob imports. Essentially a glob import
can only import *public* items from the destination, and because this must be
done at namespace resolution time, resolve must maintain the notion of "what
items are public in a module". There are some sad approximations of privacy, but
I unfortunately can't see clear methods to extract them outside.
The other use case of privacy in resolve now is one that must stick around
regardless of glob imports. When dealing with privacy, checking a private path
needs to know "what the last private thing was" when looking at a path. Resolve
is the only compiler pass which knows the answer to this question, so it
maintains the answer on a per-path resolution basis (works similarly to the
def_map generated).
Closes #8215
2013-10-05 16:37:39 -05:00
|
|
|
trait_map: trait_map,
|
|
|
|
external_exports: external_exports,
|
|
|
|
last_private_map: last_private_map
|
2013-07-27 01:49:38 -05:00
|
|
|
} =
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "resolution", (), |_|
|
2014-03-05 08:36:01 -06:00
|
|
|
middle::resolve::resolve_crate(&sess, lang_items, krate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2014-03-08 16:18:58 -06:00
|
|
|
// Discard MTWT tables that aren't required past resolution.
|
|
|
|
syntax::ext::mtwt::clear_tables();
|
|
|
|
|
2013-10-28 16:37:10 -05:00
|
|
|
let named_region_map = time(time_passes, "lifetime resolution", (),
|
2014-03-05 08:36:01 -06:00
|
|
|
|_| middle::resolve_lifetime::krate(&sess, krate));
|
2013-10-28 16:37:10 -05:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "looking for entry point", (),
|
2014-03-05 08:36:01 -06:00
|
|
|
|_| middle::entry::find_entry_point(&sess, krate, &ast_map));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2014-04-13 13:26:43 -05:00
|
|
|
sess.macro_registrar_fn.set(
|
2013-12-25 12:10:33 -06:00
|
|
|
time(time_passes, "looking for macro registrar", (), |_|
|
|
|
|
syntax::ext::registrar::find_macro_registrar(
|
2014-04-13 13:26:43 -05:00
|
|
|
sess.diagnostic(), krate)));
|
2013-12-25 12:10:33 -06:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
let freevars = time(time_passes, "freevar finding", (), |_|
|
2014-02-05 15:15:24 -06:00
|
|
|
freevars::annotate_freevars(def_map, krate));
|
2012-07-11 12:28:30 -05:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
let region_map = time(time_passes, "region resolution", (), |_|
|
2014-03-05 08:36:01 -06:00
|
|
|
middle::region::resolve_crate(&sess, krate));
|
2012-01-17 09:42:45 -06:00
|
|
|
|
2014-04-04 18:05:31 -05:00
|
|
|
time(time_passes, "loop checking", (), |_|
|
|
|
|
middle::check_loop::check_crate(&sess, krate));
|
|
|
|
|
2014-02-24 14:45:31 -06:00
|
|
|
let ty_cx = ty::mk_ctxt(sess, def_map, named_region_map, ast_map,
|
|
|
|
freevars, region_map, lang_items);
|
2012-09-04 16:48:32 -05:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
// passes are timed inside typeck
|
2014-04-09 10:18:40 -05:00
|
|
|
typeck::check_crate(&ty_cx, trait_map, krate);
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2014-02-26 12:22:41 -06:00
|
|
|
time(time_passes, "check static items", (), |_|
|
2014-03-05 21:07:47 -06:00
|
|
|
middle::check_static::check_crate(&ty_cx, krate));
|
2014-02-26 12:22:41 -06:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
// These next two const passes can probably be merged
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "const marking", (), |_|
|
2014-03-05 21:07:47 -06:00
|
|
|
middle::const_eval::process_crate(krate, &ty_cx));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "const checking", (), |_|
|
2014-04-09 10:18:40 -05:00
|
|
|
middle::check_const::check_crate(krate, &ty_cx));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
Extract privacy checking from name resolution
This commit is the culmination of my recent effort to refine Rust's notion of
privacy and visibility among crates. The major goals of this commit were to
remove privacy checking from resolve for the sake of sane error messages, and to
attempt a much more rigid and well-tested implementation of visibility
throughout rust. The implemented rules for name visibility are:
1. Everything pub from the root namespace is visible to anyone
2. You may access any private item of your ancestors.
"Accessing a private item" depends on what the item is, so for a function this
means that you can call it, but for a module it means that you can look inside
of it. Once you look inside a private module, any accessed item must be "pub
from the root" where the new root is the private module that you looked into.
These rules required some more analysis results to get propagated from trans to
privacy in the form of a few hash tables.
I added a new test in which my goal was to showcase all of the privacy nuances
of the language, and I hope to place any new bugs into this file to prevent
regressions.
Overall, I was unable to completely remove the notion of privacy from resolve.
One use of privacy is for dealing with glob imports. Essentially a glob import
can only import *public* items from the destination, and because this must be
done at namespace resolution time, resolve must maintain the notion of "what
items are public in a module". There are some sad approximations of privacy, but
I unfortunately can't see clear methods to extract them outside.
The other use case of privacy in resolve now is one that must stick around
regardless of glob imports. When dealing with privacy, checking a private path
needs to know "what the last private thing was" when looking at a path. Resolve
is the only compiler pass which knows the answer to this question, so it
maintains the answer on a per-path resolution basis (works similarly to the
def_map generated).
Closes #8215
2013-10-05 16:37:39 -05:00
|
|
|
let maps = (external_exports, last_private_map);
|
2014-01-07 20:46:16 -06:00
|
|
|
let (exported_items, public_items) =
|
|
|
|
time(time_passes, "privacy checking", maps, |(a, b)|
|
2014-04-09 10:18:40 -05:00
|
|
|
middle::privacy::check_crate(&ty_cx, &exp_map2, a, b, krate));
|
2012-06-30 18:19:07 -05:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "effect checking", (), |_|
|
2014-04-09 10:18:40 -05:00
|
|
|
middle::effect::check_crate(&ty_cx, krate));
|
2013-05-23 21:12:16 -05:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
let middle::moves::MoveMaps {moves_map, moved_variables_set,
|
|
|
|
capture_map} =
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "compute moves", (), |_|
|
2014-04-09 10:18:40 -05:00
|
|
|
middle::moves::compute_moves(&ty_cx, krate));
|
2012-12-04 17:38:04 -06:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "match checking", (), |_|
|
2014-04-09 10:18:40 -05:00
|
|
|
middle::check_match::check_crate(&ty_cx, &moves_map, krate));
|
2012-12-07 21:34:57 -06:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "liveness checking", (), |_|
|
2014-04-09 10:18:40 -05:00
|
|
|
middle::liveness::check_crate(&ty_cx, &capture_map, krate));
|
2012-11-14 20:05:07 -06:00
|
|
|
|
2013-12-30 20:57:48 -06:00
|
|
|
let root_map =
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "borrow checking", (), |_|
|
2014-04-09 10:18:40 -05:00
|
|
|
middle::borrowck::check_crate(&ty_cx, &moves_map,
|
|
|
|
&moved_variables_set,
|
2014-03-15 15:29:34 -05:00
|
|
|
&capture_map, krate));
|
|
|
|
|
|
|
|
drop(moves_map);
|
|
|
|
drop(moved_variables_set);
|
2012-11-14 20:05:07 -06:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "kind checking", (), |_|
|
2014-04-09 10:18:40 -05:00
|
|
|
kind::check_crate(&ty_cx, krate));
|
2013-06-14 00:38:17 -05:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
let reachable_map =
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "reachability checking", (), |_|
|
2014-04-09 10:18:40 -05:00
|
|
|
reachable::find_reachable(&ty_cx, &exported_items));
|
2013-06-14 00:38:17 -05:00
|
|
|
|
2014-03-09 06:42:22 -05:00
|
|
|
time(time_passes, "death checking", (), |_| {
|
|
|
|
middle::dead::check_crate(&ty_cx,
|
|
|
|
&exported_items,
|
|
|
|
&reachable_map,
|
|
|
|
krate)
|
|
|
|
});
|
2013-12-08 01:55:27 -06:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
time(time_passes, "lint checking", (), |_|
|
2014-04-09 10:18:40 -05:00
|
|
|
lint::check_crate(&ty_cx, &exported_items, krate));
|
2013-06-14 20:21:47 -05:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
CrateAnalysis {
|
|
|
|
exp_map2: exp_map2,
|
|
|
|
ty_cx: ty_cx,
|
2013-10-12 16:40:41 -05:00
|
|
|
exported_items: exported_items,
|
2014-01-07 20:46:16 -06:00
|
|
|
public_items: public_items,
|
2013-07-27 01:49:38 -05:00
|
|
|
maps: astencode::Maps {
|
2013-06-14 00:38:17 -05:00
|
|
|
root_map: root_map,
|
2014-03-15 15:29:34 -05:00
|
|
|
capture_map: RefCell::new(capture_map)
|
2013-07-27 01:49:38 -05:00
|
|
|
},
|
|
|
|
reachable: reachable_map
|
|
|
|
}
|
|
|
|
}
|
2013-06-14 00:38:17 -05:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
pub struct CrateTranslation {
|
2014-03-28 12:05:27 -05:00
|
|
|
pub context: ContextRef,
|
|
|
|
pub module: ModuleRef,
|
|
|
|
pub metadata_module: ModuleRef,
|
|
|
|
pub link: LinkMeta,
|
|
|
|
pub metadata: Vec<u8>,
|
|
|
|
pub reachable: Vec<~str>,
|
2013-07-27 01:49:38 -05:00
|
|
|
}
|
2012-02-14 17:21:53 -06:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
/// Run the translation phase to LLVM, after which the AST and analysis can
|
|
|
|
/// be discarded.
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn phase_4_translate_to_llvm(krate: ast::Crate,
|
2014-03-15 15:29:34 -05:00
|
|
|
analysis: CrateAnalysis,
|
|
|
|
outputs: &OutputFilenames) -> (ty::ctxt, CrateTranslation) {
|
|
|
|
// Option dance to work around the lack of stack once closures.
|
|
|
|
let time_passes = analysis.ty_cx.sess.time_passes();
|
|
|
|
let mut analysis = Some(analysis);
|
|
|
|
time(time_passes, "translation", krate, |krate|
|
|
|
|
trans::base::trans_crate(krate, analysis.take_unwrap(), outputs))
|
2013-07-27 01:49:38 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Run LLVM itself, producing a bitcode file, assembly file or object file
|
|
|
|
/// as a side effect.
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn phase_5_run_llvm_passes(sess: &Session,
|
2013-07-27 01:49:38 -05:00
|
|
|
trans: &CrateTranslation,
|
|
|
|
outputs: &OutputFilenames) {
|
2014-02-06 21:57:09 -06:00
|
|
|
if sess.opts.cg.no_integrated_as {
|
2014-01-09 19:42:08 -06:00
|
|
|
let output_type = link::OutputTypeAssembly;
|
2013-03-15 03:32:39 -05:00
|
|
|
|
2013-10-04 12:46:53 -05:00
|
|
|
time(sess.time_passes(), "LLVM passes", (), |_|
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
link::write::run_passes(sess, trans, [output_type], outputs));
|
2013-03-15 03:32:39 -05:00
|
|
|
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
link::write::run_assembler(sess, outputs);
|
2013-08-19 17:21:30 -05:00
|
|
|
|
2013-12-08 22:13:10 -06:00
|
|
|
// Remove assembly source, unless --save-temps was specified
|
2014-02-06 21:57:09 -06:00
|
|
|
if !sess.opts.cg.save_temps {
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
fs::unlink(&outputs.temp_path(link::OutputTypeAssembly)).unwrap();
|
2013-08-19 17:21:30 -05:00
|
|
|
}
|
2013-03-15 03:32:39 -05:00
|
|
|
} else {
|
2013-10-04 12:46:53 -05:00
|
|
|
time(sess.time_passes(), "LLVM passes", (), |_|
|
2013-07-27 01:49:38 -05:00
|
|
|
link::write::run_passes(sess,
|
Store metadata separately in rlib files
Right now whenever an rlib file is linked against, all of the metadata from the
rlib is pulled in to the final staticlib or binary. The reason for this is that
the metadata is currently stored in a section of the object file. Note that this
is intentional for dynamic libraries in order to distribute metadata bundled
with static libraries.
This commit alters the situation for rlib libraries to instead store the
metadata in a separate file in the archive. In doing so, when the archive is
passed to the linker, none of the metadata will get pulled into the result
executable. Furthermore, the metadata file is skipped when assembling rlibs into
an archive.
The snag in this implementation comes with multiple output formats. When
generating a dylib, the metadata needs to be in the object file, but when
generating an rlib this needs to be separate. In order to accomplish this, the
metadata variable is inserted into an entirely separate LLVM Module which is
then codegen'd into a different location (foo.metadata.o). This is then linked
into dynamic libraries and silently ignored for rlib files.
While changing how metadata is inserted into archives, I have also stopped
compressing metadata when inserted into rlib files. We have wanted to stop
compressing metadata, but the sections it creates in object file sections are
apparently too large. Thankfully if it's just an arbitrary file it doesn't
matter how large it is.
I have seen massive reductions in executable sizes, as well as staticlib output
sizes (to confirm that this is all working).
2013-12-03 19:41:01 -06:00
|
|
|
trans,
|
2014-03-08 14:36:22 -06:00
|
|
|
sess.opts.output_types.as_slice(),
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
outputs));
|
2013-03-15 03:32:39 -05:00
|
|
|
}
|
2013-07-27 01:49:38 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2013-07-27 01:49:38 -05:00
|
|
|
/// Run the linker on any artifacts that resulted from the LLVM run.
|
|
|
|
/// This should produce either a finished executable or library.
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn phase_6_link_output(sess: &Session,
|
2013-07-27 01:49:38 -05:00
|
|
|
trans: &CrateTranslation,
|
|
|
|
outputs: &OutputFilenames) {
|
2013-12-26 13:55:10 -06:00
|
|
|
time(sess.time_passes(), "linking", (), |_|
|
2012-09-18 13:46:39 -05:00
|
|
|
link::link_binary(sess,
|
Store metadata separately in rlib files
Right now whenever an rlib file is linked against, all of the metadata from the
rlib is pulled in to the final staticlib or binary. The reason for this is that
the metadata is currently stored in a section of the object file. Note that this
is intentional for dynamic libraries in order to distribute metadata bundled
with static libraries.
This commit alters the situation for rlib libraries to instead store the
metadata in a separate file in the archive. In doing so, when the archive is
passed to the linker, none of the metadata will get pulled into the result
executable. Furthermore, the metadata file is skipped when assembling rlibs into
an archive.
The snag in this implementation comes with multiple output formats. When
generating a dylib, the metadata needs to be in the object file, but when
generating an rlib this needs to be separate. In order to accomplish this, the
metadata variable is inserted into an entirely separate LLVM Module which is
then codegen'd into a different location (foo.metadata.o). This is then linked
into dynamic libraries and silently ignored for rlib files.
While changing how metadata is inserted into archives, I have also stopped
compressing metadata when inserted into rlib files. We have wanted to stop
compressing metadata, but the sections it creates in object file sections are
apparently too large. Thankfully if it's just an arbitrary file it doesn't
matter how large it is.
I have seen massive reductions in executable sizes, as well as staticlib output
sizes (to confirm that this is all working).
2013-12-03 19:41:01 -06:00
|
|
|
trans,
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
outputs,
|
2014-02-24 21:45:20 -06:00
|
|
|
&trans.link.crateid));
|
2013-12-26 13:55:10 -06:00
|
|
|
}
|
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn stop_after_phase_3(sess: &Session) -> bool {
|
2013-12-26 13:55:10 -06:00
|
|
|
if sess.opts.no_trans {
|
|
|
|
debug!("invoked with --no-trans, returning early from compile_input");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn stop_after_phase_1(sess: &Session) -> bool {
|
2013-12-26 13:55:10 -06:00
|
|
|
if sess.opts.parse_only {
|
|
|
|
debug!("invoked with --parse-only, returning early from compile_input");
|
|
|
|
return true;
|
|
|
|
}
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
if sess.show_span() {
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-19 01:27:49 -06:00
|
|
|
return sess.opts.debugging_opts & session::AST_JSON_NOEXPAND != 0;
|
2013-12-26 13:55:10 -06:00
|
|
|
}
|
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn stop_after_phase_2(sess: &Session) -> bool {
|
2013-12-26 16:39:36 -06:00
|
|
|
if sess.opts.no_analysis {
|
|
|
|
debug!("invoked with --no-analysis, returning early from compile_input");
|
|
|
|
return true;
|
|
|
|
}
|
2014-02-19 01:27:49 -06:00
|
|
|
return sess.opts.debugging_opts & session::AST_JSON != 0;
|
2013-12-26 16:39:36 -06:00
|
|
|
}
|
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn stop_after_phase_5(sess: &Session) -> bool {
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
if !sess.opts.output_types.iter().any(|&i| i == link::OutputTypeExe) {
|
2013-12-26 13:55:10 -06:00
|
|
|
debug!("not building executable, returning early from compile_input");
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
fn write_out_deps(sess: &Session,
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
input: &Input,
|
|
|
|
outputs: &OutputFilenames,
|
2014-02-05 15:15:24 -06:00
|
|
|
krate: &ast::Crate) -> io::IoResult<()> {
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
let id = link::find_crate_id(krate.attrs.as_slice(), outputs.out_filestem);
|
2013-12-26 13:55:10 -06:00
|
|
|
|
2014-03-04 12:02:49 -06:00
|
|
|
let mut out_filenames = Vec::new();
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
for output_type in sess.opts.output_types.iter() {
|
|
|
|
let file = outputs.path(*output_type);
|
|
|
|
match *output_type {
|
|
|
|
link::OutputTypeExe => {
|
2014-03-20 21:49:20 -05:00
|
|
|
for output in sess.crate_types.borrow().iter() {
|
2014-03-05 08:36:01 -06:00
|
|
|
let p = link::filename_for_input(sess, *output, &id, &file);
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
out_filenames.push(p);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => { out_filenames.push(file); }
|
|
|
|
}
|
|
|
|
}
|
2013-11-27 21:06:35 -06:00
|
|
|
|
2014-01-29 20:42:19 -06:00
|
|
|
// Write out dependency rules to the dep-info file if requested with
|
|
|
|
// --dep-info
|
2013-12-22 14:38:55 -06:00
|
|
|
let deps_filename = match sess.opts.write_dependency_info {
|
|
|
|
// Use filename from --dep-file argument if given
|
|
|
|
(true, Some(ref filename)) => filename.clone(),
|
2014-01-29 20:42:19 -06:00
|
|
|
// Use default filename: crate source filename with extension replaced
|
|
|
|
// by ".d"
|
2013-12-22 14:38:55 -06:00
|
|
|
(true, None) => match *input {
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
FileInput(..) => outputs.with_extension("d"),
|
2014-01-13 10:31:05 -06:00
|
|
|
StrInput(..) => {
|
2014-01-29 20:42:19 -06:00
|
|
|
sess.warn("can not write --dep-info without a filename \
|
|
|
|
when compiling stdin.");
|
|
|
|
return Ok(());
|
2013-12-22 14:38:55 -06:00
|
|
|
},
|
|
|
|
},
|
2014-01-29 20:42:19 -06:00
|
|
|
_ => return Ok(()),
|
2013-12-22 14:38:55 -06:00
|
|
|
};
|
2013-12-26 13:55:10 -06:00
|
|
|
|
2013-12-22 14:38:55 -06:00
|
|
|
// Build a list of files used to compile the output and
|
|
|
|
// write Makefile-compatible dependency rules
|
2014-03-20 21:49:20 -05:00
|
|
|
let files: Vec<~str> = sess.codemap().files.borrow()
|
2014-03-16 13:56:24 -05:00
|
|
|
.iter().filter_map(|fmap| {
|
2014-03-21 00:10:44 -05:00
|
|
|
if fmap.is_real_file() {
|
|
|
|
Some(fmap.name.clone())
|
2014-03-16 13:56:24 -05:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}).collect();
|
2014-02-19 12:07:49 -06:00
|
|
|
let mut file = try!(io::File::create(&deps_filename));
|
2013-12-26 13:55:10 -06:00
|
|
|
for path in out_filenames.iter() {
|
2014-02-19 12:07:49 -06:00
|
|
|
try!(write!(&mut file as &mut Writer,
|
2014-01-29 20:42:19 -06:00
|
|
|
"{}: {}\n\n", path.display(), files.connect(" ")));
|
2013-07-27 01:49:38 -05:00
|
|
|
}
|
2014-01-29 20:42:19 -06:00
|
|
|
Ok(())
|
2013-01-22 19:19:13 -06:00
|
|
|
}
|
|
|
|
|
2014-01-13 10:31:05 -06:00
|
|
|
pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
|
2013-01-29 17:16:07 -06:00
|
|
|
outdir: &Option<Path>, output: &Option<Path>) {
|
2013-07-28 12:56:05 -05:00
|
|
|
// We need nested scopes here, because the intermediate results can keep
|
|
|
|
// large chunks of memory alive and we want to free them as soon as
|
|
|
|
// possible to keep the peak memory usage low
|
2014-03-05 08:36:01 -06:00
|
|
|
let (outputs, trans, sess) = {
|
|
|
|
let (outputs, expanded_crate, ast_map) = {
|
|
|
|
let krate = phase_1_parse_input(&sess, cfg, input);
|
|
|
|
if stop_after_phase_1(&sess) { return; }
|
|
|
|
let outputs = build_output_filenames(input,
|
|
|
|
outdir,
|
|
|
|
output,
|
|
|
|
krate.attrs.as_slice(),
|
|
|
|
&sess);
|
|
|
|
let loader = &mut Loader::new(&sess);
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
let id = link::find_crate_id(krate.attrs.as_slice(),
|
|
|
|
outputs.out_filestem);
|
2014-03-05 08:36:01 -06:00
|
|
|
let (expanded_crate, ast_map) = phase_2_configure_and_expand(&sess, loader,
|
|
|
|
krate, &id);
|
|
|
|
(outputs, expanded_crate, ast_map)
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
};
|
2014-03-05 08:36:01 -06:00
|
|
|
write_out_deps(&sess, input, &outputs, &expanded_crate).unwrap();
|
2013-12-26 13:55:10 -06:00
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
if stop_after_phase_2(&sess) { return; }
|
2013-12-26 16:39:36 -06:00
|
|
|
|
2014-01-06 06:00:46 -06:00
|
|
|
let analysis = phase_3_run_analysis_passes(sess, &expanded_crate, ast_map);
|
2014-03-05 08:36:01 -06:00
|
|
|
if stop_after_phase_3(&analysis.ty_cx.sess) { return; }
|
2014-03-15 15:29:34 -05:00
|
|
|
let (tcx, trans) = phase_4_translate_to_llvm(expanded_crate,
|
|
|
|
analysis, &outputs);
|
2014-03-08 16:18:58 -06:00
|
|
|
|
|
|
|
// Discard interned strings as they are no longer required.
|
|
|
|
token::get_ident_interner().clear();
|
|
|
|
|
2014-03-15 15:29:34 -05:00
|
|
|
(outputs, trans, tcx.sess)
|
2013-07-28 12:56:05 -05:00
|
|
|
};
|
2014-03-05 08:36:01 -06:00
|
|
|
phase_5_run_llvm_passes(&sess, &trans, &outputs);
|
|
|
|
if stop_after_phase_5(&sess) { return; }
|
|
|
|
phase_6_link_output(&sess, &trans, &outputs);
|
2012-01-17 09:42:45 -06:00
|
|
|
}
|
|
|
|
|
2014-02-06 16:38:33 -06:00
|
|
|
struct IdentifiedAnnotation;
|
2013-07-27 01:49:38 -05:00
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
impl pprust::PpAnn for IdentifiedAnnotation {
|
2014-03-16 13:58:11 -05:00
|
|
|
fn pre(&self,
|
2014-03-18 00:27:37 -05:00
|
|
|
s: &mut pprust::State,
|
2014-03-16 13:58:11 -05:00
|
|
|
node: pprust::AnnNode) -> io::IoResult<()> {
|
2012-08-06 14:34:08 -05:00
|
|
|
match node {
|
2014-03-16 13:58:11 -05:00
|
|
|
pprust::NodeExpr(_) => s.popen(),
|
2014-01-29 20:42:19 -06:00
|
|
|
_ => Ok(())
|
2013-08-29 17:24:33 -05:00
|
|
|
}
|
|
|
|
}
|
2014-03-16 13:58:11 -05:00
|
|
|
fn post(&self,
|
2014-03-18 00:27:37 -05:00
|
|
|
s: &mut pprust::State,
|
2014-03-16 13:58:11 -05:00
|
|
|
node: pprust::AnnNode) -> io::IoResult<()> {
|
2013-08-29 17:24:33 -05:00
|
|
|
match node {
|
2014-03-16 13:58:11 -05:00
|
|
|
pprust::NodeItem(item) => {
|
2014-02-19 12:07:49 -06:00
|
|
|
try!(pp::space(&mut s.s));
|
2014-03-16 13:58:11 -05:00
|
|
|
s.synth_comment(item.id.to_str())
|
2013-08-29 17:24:33 -05:00
|
|
|
}
|
2014-03-16 13:58:11 -05:00
|
|
|
pprust::NodeBlock(blk) => {
|
2014-02-19 12:07:49 -06:00
|
|
|
try!(pp::space(&mut s.s));
|
2014-04-15 20:17:48 -05:00
|
|
|
s.synth_comment("block ".to_owned() + blk.id.to_str())
|
2013-08-29 17:24:33 -05:00
|
|
|
}
|
2014-03-16 13:58:11 -05:00
|
|
|
pprust::NodeExpr(expr) => {
|
2014-02-19 12:07:49 -06:00
|
|
|
try!(pp::space(&mut s.s));
|
2014-03-16 13:58:11 -05:00
|
|
|
try!(s.synth_comment(expr.id.to_str()));
|
|
|
|
s.pclose()
|
2013-08-29 17:24:33 -05:00
|
|
|
}
|
2014-03-16 13:58:11 -05:00
|
|
|
pprust::NodePat(pat) => {
|
2014-02-19 12:07:49 -06:00
|
|
|
try!(pp::space(&mut s.s));
|
2014-04-15 20:17:48 -05:00
|
|
|
s.synth_comment("pat ".to_owned() + pat.id.to_str())
|
2013-08-29 17:24:33 -05:00
|
|
|
}
|
2012-08-03 21:59:04 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
2013-08-29 17:24:33 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct TypedAnnotation {
|
|
|
|
analysis: CrateAnalysis,
|
|
|
|
}
|
|
|
|
|
2014-01-09 07:05:33 -06:00
|
|
|
impl pprust::PpAnn for TypedAnnotation {
|
2014-03-16 13:58:11 -05:00
|
|
|
fn pre(&self,
|
2014-03-18 00:27:37 -05:00
|
|
|
s: &mut pprust::State,
|
2014-03-16 13:58:11 -05:00
|
|
|
node: pprust::AnnNode) -> io::IoResult<()> {
|
2013-08-29 17:24:33 -05:00
|
|
|
match node {
|
2014-03-16 13:58:11 -05:00
|
|
|
pprust::NodeExpr(_) => s.popen(),
|
2014-01-29 20:42:19 -06:00
|
|
|
_ => Ok(())
|
2013-08-29 17:24:33 -05:00
|
|
|
}
|
|
|
|
}
|
2014-03-16 13:58:11 -05:00
|
|
|
fn post(&self,
|
2014-03-18 00:27:37 -05:00
|
|
|
s: &mut pprust::State,
|
2014-03-16 13:58:11 -05:00
|
|
|
node: pprust::AnnNode) -> io::IoResult<()> {
|
2014-03-05 21:07:47 -06:00
|
|
|
let tcx = &self.analysis.ty_cx;
|
2013-08-29 17:24:33 -05:00
|
|
|
match node {
|
2014-03-16 13:58:11 -05:00
|
|
|
pprust::NodeExpr(expr) => {
|
2014-02-19 12:07:49 -06:00
|
|
|
try!(pp::space(&mut s.s));
|
|
|
|
try!(pp::word(&mut s.s, "as"));
|
|
|
|
try!(pp::space(&mut s.s));
|
|
|
|
try!(pp::word(&mut s.s,
|
2014-01-29 20:42:19 -06:00
|
|
|
ppaux::ty_to_str(tcx, ty::expr_ty(tcx, expr))));
|
2014-03-16 13:58:11 -05:00
|
|
|
s.pclose()
|
2013-08-29 17:24:33 -05:00
|
|
|
}
|
2014-03-16 13:58:11 -05:00
|
|
|
_ => Ok(())
|
2013-08-29 17:24:33 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn pretty_print_input(sess: Session,
|
|
|
|
cfg: ast::CrateConfig,
|
2014-01-13 10:31:05 -06:00
|
|
|
input: &Input,
|
2014-04-08 15:07:15 -05:00
|
|
|
ppm: PpMode,
|
|
|
|
ofile: Option<Path>) {
|
2014-03-05 08:36:01 -06:00
|
|
|
let krate = phase_1_parse_input(&sess, cfg, input);
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
let id = link::find_crate_id(krate.attrs.as_slice(), input.filestem());
|
2013-07-27 01:49:38 -05:00
|
|
|
|
2014-02-05 15:15:24 -06:00
|
|
|
let (krate, ast_map, is_expanded) = match ppm {
|
2013-08-31 11:13:04 -05:00
|
|
|
PpmExpanded | PpmExpandedIdentified | PpmTyped => {
|
2014-03-05 08:36:01 -06:00
|
|
|
let loader = &mut Loader::new(&sess);
|
|
|
|
let (krate, ast_map) = phase_2_configure_and_expand(&sess, loader,
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
krate, &id);
|
2014-02-05 15:15:24 -06:00
|
|
|
(krate, Some(ast_map), true)
|
2013-07-27 01:49:38 -05:00
|
|
|
}
|
2014-02-05 15:15:24 -06:00
|
|
|
_ => (krate, None, false)
|
2012-01-17 09:42:45 -06:00
|
|
|
};
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2014-03-16 13:58:11 -05:00
|
|
|
let src_name = source_name(input);
|
2014-03-27 00:46:25 -05:00
|
|
|
let src = Vec::from_slice(sess.codemap().get_filemap(src_name).src.as_bytes());
|
2014-03-16 13:58:11 -05:00
|
|
|
let mut rdr = MemReader::new(src);
|
2014-03-05 08:36:01 -06:00
|
|
|
|
2014-04-08 15:07:15 -05:00
|
|
|
let out = match ofile {
|
|
|
|
None => ~io::stdout() as ~Writer,
|
|
|
|
Some(p) => {
|
|
|
|
let r = io::File::create(&p);
|
|
|
|
match r {
|
|
|
|
Ok(w) => ~w as ~Writer,
|
|
|
|
Err(e) => fail!("print-print failed to open {} due to {}",
|
|
|
|
p.display(), e),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
2014-03-16 13:58:11 -05:00
|
|
|
match ppm {
|
2013-08-31 11:13:04 -05:00
|
|
|
PpmIdentified | PpmExpandedIdentified => {
|
2014-03-16 13:58:11 -05:00
|
|
|
pprust::print_crate(sess.codemap(),
|
|
|
|
sess.diagnostic(),
|
|
|
|
&krate,
|
|
|
|
src_name,
|
|
|
|
&mut rdr,
|
2014-04-08 15:07:15 -05:00
|
|
|
out,
|
2014-03-16 13:58:11 -05:00
|
|
|
&IdentifiedAnnotation,
|
|
|
|
is_expanded)
|
2013-07-27 01:49:38 -05:00
|
|
|
}
|
2013-08-31 11:13:04 -05:00
|
|
|
PpmTyped => {
|
2014-01-06 06:00:46 -06:00
|
|
|
let ast_map = ast_map.expect("--pretty=typed missing ast_map");
|
2014-02-05 15:15:24 -06:00
|
|
|
let analysis = phase_3_run_analysis_passes(sess, &krate, ast_map);
|
2014-03-16 13:58:11 -05:00
|
|
|
let annotation = TypedAnnotation {
|
2013-08-29 17:24:33 -05:00
|
|
|
analysis: analysis
|
2014-03-16 13:58:11 -05:00
|
|
|
};
|
|
|
|
pprust::print_crate(annotation.analysis.ty_cx.sess.codemap(),
|
|
|
|
annotation.analysis.ty_cx.sess.diagnostic(),
|
|
|
|
&krate,
|
|
|
|
src_name,
|
|
|
|
&mut rdr,
|
2014-04-08 15:07:15 -05:00
|
|
|
out,
|
2014-03-16 13:58:11 -05:00
|
|
|
&annotation,
|
|
|
|
is_expanded)
|
2013-07-27 01:49:38 -05:00
|
|
|
}
|
2014-03-16 13:58:11 -05:00
|
|
|
_ => {
|
|
|
|
pprust::print_crate(sess.codemap(),
|
|
|
|
sess.diagnostic(),
|
|
|
|
&krate,
|
|
|
|
src_name,
|
|
|
|
&mut rdr,
|
2014-04-08 15:07:15 -05:00
|
|
|
out,
|
2014-03-16 13:58:11 -05:00
|
|
|
&pprust::NoAnn,
|
|
|
|
is_expanded)
|
|
|
|
}
|
|
|
|
}.unwrap()
|
2013-07-27 01:49:38 -05:00
|
|
|
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2013-11-08 13:06:57 -06:00
|
|
|
pub fn get_os(triple: &str) -> Option<abi::Os> {
|
2013-08-03 11:45:23 -05:00
|
|
|
for &(name, os) in os_names.iter() {
|
2013-06-15 02:43:19 -05:00
|
|
|
if triple.contains(name) { return Some(os) }
|
|
|
|
}
|
|
|
|
None
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
2013-11-08 13:06:57 -06:00
|
|
|
static os_names : &'static [(&'static str, abi::Os)] = &'static [
|
|
|
|
("mingw32", abi::OsWin32),
|
|
|
|
("win32", abi::OsWin32),
|
|
|
|
("darwin", abi::OsMacos),
|
|
|
|
("android", abi::OsAndroid),
|
|
|
|
("linux", abi::OsLinux),
|
|
|
|
("freebsd", abi::OsFreebsd)];
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2013-03-13 21:25:28 -05:00
|
|
|
pub fn get_arch(triple: &str) -> Option<abi::Architecture> {
|
2013-08-03 11:45:23 -05:00
|
|
|
for &(arch, abi) in architecture_abis.iter() {
|
2013-06-15 02:43:19 -05:00
|
|
|
if triple.contains(arch) { return Some(abi) }
|
|
|
|
}
|
|
|
|
None
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
2013-06-15 02:43:19 -05:00
|
|
|
static architecture_abis : &'static [(&'static str, abi::Architecture)] = &'static [
|
|
|
|
("i386", abi::X86),
|
|
|
|
("i486", abi::X86),
|
|
|
|
("i586", abi::X86),
|
|
|
|
("i686", abi::X86),
|
|
|
|
("i786", abi::X86),
|
|
|
|
|
|
|
|
("x86_64", abi::X86_64),
|
|
|
|
|
|
|
|
("arm", abi::Arm),
|
|
|
|
("xscale", abi::Arm),
|
2014-01-21 00:47:14 -06:00
|
|
|
("thumb", abi::Arm),
|
2013-06-15 02:43:19 -05:00
|
|
|
|
|
|
|
("mips", abi::Mips)];
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2014-03-16 13:56:24 -05:00
|
|
|
pub fn build_target_config(sopts: &session::Options) -> session::Config {
|
2012-08-06 14:34:08 -05:00
|
|
|
let os = match get_os(sopts.target_triple) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(os) => os,
|
2014-02-06 16:38:33 -06:00
|
|
|
None => early_error("unknown operating system")
|
2012-01-14 01:03:37 -06:00
|
|
|
};
|
2012-08-06 14:34:08 -05:00
|
|
|
let arch = match get_arch(sopts.target_triple) {
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(arch) => arch,
|
2014-02-06 16:38:33 -06:00
|
|
|
None => early_error("unknown architecture: " + sopts.target_triple)
|
2012-01-14 01:03:37 -06:00
|
|
|
};
|
2013-09-26 01:26:09 -05:00
|
|
|
let (int_type, uint_type) = match arch {
|
2014-01-09 07:05:33 -06:00
|
|
|
abi::X86 => (ast::TyI32, ast::TyU32),
|
|
|
|
abi::X86_64 => (ast::TyI64, ast::TyU64),
|
|
|
|
abi::Arm => (ast::TyI32, ast::TyU32),
|
|
|
|
abi::Mips => (ast::TyI32, ast::TyU32)
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2013-08-24 12:54:42 -05:00
|
|
|
let target_triple = sopts.target_triple.clone();
|
2012-08-06 14:34:08 -05:00
|
|
|
let target_strs = match arch {
|
2013-08-24 12:54:42 -05:00
|
|
|
abi::X86 => x86::get_target_strs(target_triple, os),
|
|
|
|
abi::X86_64 => x86_64::get_target_strs(target_triple, os),
|
|
|
|
abi::Arm => arm::get_target_strs(target_triple, os),
|
|
|
|
abi::Mips => mips::get_target_strs(target_triple, os)
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2014-03-16 13:56:24 -05:00
|
|
|
session::Config {
|
2013-02-19 01:40:42 -06:00
|
|
|
os: os,
|
|
|
|
arch: arch,
|
|
|
|
target_strs: target_strs,
|
|
|
|
int_type: int_type,
|
|
|
|
uint_type: uint_type,
|
2014-03-16 13:56:24 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2013-08-06 23:50:23 -05:00
|
|
|
pub fn host_triple() -> ~str {
|
|
|
|
// Get the host triple out of the build environment. This ensures that our
|
|
|
|
// idea of the host triple is the same as for the set of libraries we've
|
|
|
|
// actually built. We can't just take LLVM's host triple because they
|
|
|
|
// normalize all ix86 architectures to i386.
|
|
|
|
//
|
|
|
|
// Instead of grabbing the host triple (for the current host), we grab (at
|
|
|
|
// compile time) the target triple that this rustc is built with and
|
|
|
|
// calling that (at runtime) the host triple.
|
2014-03-25 21:23:45 -05:00
|
|
|
(env!("CFG_COMPILER_HOST_TRIPLE")).to_owned()
|
2013-08-06 23:50:23 -05:00
|
|
|
}
|
|
|
|
|
2014-03-16 13:58:11 -05:00
|
|
|
pub fn build_session_options(matches: &getopts::Matches) -> session::Options {
|
2014-03-08 14:36:22 -06:00
|
|
|
let mut crate_types: Vec<CrateType> = Vec::new();
|
|
|
|
let unparsed_crate_types = matches.opt_strs("crate-type");
|
|
|
|
for unparsed_crate_type in unparsed_crate_types.iter() {
|
|
|
|
for part in unparsed_crate_type.split(',') {
|
|
|
|
let new_part = match part {
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
"lib" => session::default_lib_output(),
|
|
|
|
"rlib" => session::CrateTypeRlib,
|
|
|
|
"staticlib" => session::CrateTypeStaticlib,
|
|
|
|
"dylib" => session::CrateTypeDylib,
|
|
|
|
"bin" => session::CrateTypeExecutable,
|
2014-02-06 16:38:33 -06:00
|
|
|
_ => early_error(format!("unknown crate type: `{}`", part))
|
2014-03-08 14:36:22 -06:00
|
|
|
};
|
|
|
|
crate_types.push(new_part)
|
|
|
|
}
|
|
|
|
}
|
Add generation of static libraries to rustc
This commit implements the support necessary for generating both intermediate
and result static rust libraries. This is an implementation of my thoughts in
https://mail.mozilla.org/pipermail/rust-dev/2013-November/006686.html.
When compiling a library, we still retain the "lib" option, although now there
are "rlib", "staticlib", and "dylib" as options for crate_type (and these are
stackable). The idea of "lib" is to generate the "compiler default" instead of
having too choose (although all are interchangeable). For now I have left the
"complier default" to be a dynamic library for size reasons.
Of the rust libraries, lib{std,extra,rustuv} will bootstrap with an
rlib/dylib pair, but lib{rustc,syntax,rustdoc,rustpkg} will only be built as a
dynamic object. I chose this for size reasons, but also because you're probably
not going to be embedding the rustc compiler anywhere any time soon.
Other than the options outlined above, there are a few defaults/preferences that
are now opinionated in the compiler:
* If both a .dylib and .rlib are found for a rust library, the compiler will
prefer the .rlib variant. This is overridable via the -Z prefer-dynamic option
* If generating a "lib", the compiler will generate a dynamic library. This is
overridable by explicitly saying what flavor you'd like (rlib, staticlib,
dylib).
* If no options are passed to the command line, and no crate_type is found in
the destination crate, then an executable is generated
With this change, you can successfully build a rust program with 0 dynamic
dependencies on rust libraries. There is still a dynamic dependency on
librustrt, but I plan on removing that in a subsequent commit.
This change includes no tests just yet. Our current testing
infrastructure/harnesses aren't very amenable to doing flavorful things with
linking, so I'm planning on adding a new mode of testing which I believe belongs
as a separate commit.
Closes #552
2013-11-15 16:03:29 -06:00
|
|
|
|
2013-09-17 20:42:23 -05:00
|
|
|
let parse_only = matches.opt_present("parse-only");
|
|
|
|
let no_trans = matches.opt_present("no-trans");
|
2013-12-26 16:39:36 -06:00
|
|
|
let no_analysis = matches.opt_present("no-analysis");
|
2012-04-12 19:30:52 -05:00
|
|
|
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
let lint_levels = [lint::allow, lint::warn,
|
|
|
|
lint::deny, lint::forbid];
|
2014-03-04 12:02:49 -06:00
|
|
|
let mut lint_opts = Vec::new();
|
2012-04-12 19:30:52 -05:00
|
|
|
let lint_dict = lint::get_lint_dict();
|
2013-08-03 11:45:23 -05:00
|
|
|
for level in lint_levels.iter() {
|
2012-09-19 18:55:01 -05:00
|
|
|
let level_name = lint::level_to_str(*level);
|
2013-04-23 04:08:13 -05:00
|
|
|
|
2013-06-11 06:37:22 -05:00
|
|
|
let level_short = level_name.slice_chars(0, 1);
|
2013-11-07 01:59:40 -06:00
|
|
|
let level_short = level_short.to_ascii().to_upper().into_str();
|
2014-03-30 22:53:26 -05:00
|
|
|
let flags = matches.opt_strs(level_short).move_iter().collect::<Vec<_>>().append(
|
2014-03-05 17:28:08 -06:00
|
|
|
matches.opt_strs(level_name).as_slice());
|
2013-08-03 11:45:23 -05:00
|
|
|
for lint_name in flags.iter() {
|
2013-06-11 06:46:40 -05:00
|
|
|
let lint_name = lint_name.replace("-", "_");
|
2013-06-12 12:02:55 -05:00
|
|
|
match lint_dict.find_equiv(&lint_name) {
|
2012-08-20 14:23:37 -05:00
|
|
|
None => {
|
2014-02-06 16:38:33 -06:00
|
|
|
early_error(format!("unknown {} flag: {}",
|
|
|
|
level_name, lint_name));
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
}
|
2012-08-20 14:23:37 -05:00
|
|
|
Some(lint) => {
|
2012-09-26 19:33:34 -05:00
|
|
|
lint_opts.push((lint.lint, *level));
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
}
|
|
|
|
}
|
2012-04-12 19:30:52 -05:00
|
|
|
}
|
Nomenclature fixes in the lint checker. Fewer double-negatives.
New style is allow(foo), warn(foo), deny(foo) and forbid(foo),
mirrored by -A foo, -W foo, -D foo and -F foo on command line.
These replace -W no-foo, -W foo, -W err-foo, respectively.
Forbid is new, and means "deny, and you can't override it".
2012-07-26 19:08:21 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
|
2014-01-20 15:55:10 -06:00
|
|
|
let mut debugging_opts = 0;
|
2013-09-17 20:42:23 -05:00
|
|
|
let debug_flags = matches.opt_strs("Z");
|
2012-05-17 23:53:49 -05:00
|
|
|
let debug_map = session::debugging_opts_map();
|
2013-08-03 11:45:23 -05:00
|
|
|
for debug_flag in debug_flags.iter() {
|
2014-01-20 15:55:10 -06:00
|
|
|
let mut this_bit = 0;
|
2013-08-03 11:45:23 -05:00
|
|
|
for tuple in debug_map.iter() {
|
2013-03-20 00:17:42 -05:00
|
|
|
let (name, bit) = match *tuple { (ref a, _, b) => (a, b) };
|
2013-10-04 12:46:53 -05:00
|
|
|
if *name == *debug_flag { this_bit = bit; break; }
|
2012-05-17 23:53:49 -05:00
|
|
|
}
|
2014-01-20 15:55:10 -06:00
|
|
|
if this_bit == 0 {
|
2014-02-06 16:38:33 -06:00
|
|
|
early_error(format!("unknown debug flag: {}", *debug_flag))
|
2012-05-17 23:53:49 -05:00
|
|
|
}
|
|
|
|
debugging_opts |= this_bit;
|
|
|
|
}
|
2013-08-14 20:41:40 -05:00
|
|
|
|
2014-01-20 15:55:10 -06:00
|
|
|
if debugging_opts & session::DEBUG_LLVM != 0 {
|
2013-11-06 17:16:04 -06:00
|
|
|
unsafe { llvm::LLVMSetDebug(1); }
|
2012-07-25 14:06:03 -05:00
|
|
|
}
|
2012-05-17 23:53:49 -05:00
|
|
|
|
2014-03-08 14:36:22 -06:00
|
|
|
let mut output_types = Vec::new();
|
|
|
|
if !parse_only && !no_trans {
|
|
|
|
let unparsed_output_types = matches.opt_strs("emit");
|
|
|
|
for unparsed_output_type in unparsed_output_types.iter() {
|
|
|
|
for part in unparsed_output_type.split(',') {
|
|
|
|
let output_type = match part.as_slice() {
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
"asm" => link::OutputTypeAssembly,
|
|
|
|
"ir" => link::OutputTypeLlvmAssembly,
|
|
|
|
"bc" => link::OutputTypeBitcode,
|
|
|
|
"obj" => link::OutputTypeObject,
|
|
|
|
"link" => link::OutputTypeExe,
|
2014-02-06 16:38:33 -06:00
|
|
|
_ => early_error(format!("unknown emission type: `{}`", part))
|
2014-03-08 14:36:22 -06:00
|
|
|
};
|
|
|
|
output_types.push(output_type)
|
|
|
|
}
|
|
|
|
}
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
};
|
2014-03-08 14:36:22 -06:00
|
|
|
output_types.as_mut_slice().sort();
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
output_types.dedup();
|
|
|
|
if output_types.len() == 0 {
|
|
|
|
output_types.push(link::OutputTypeExe);
|
|
|
|
}
|
|
|
|
|
2014-03-09 07:24:58 -05:00
|
|
|
let sysroot_opt = matches.opt_str("sysroot").map(|m| Path::new(m));
|
2013-09-17 20:42:23 -05:00
|
|
|
let target = matches.opt_str("target").unwrap_or(host_triple());
|
2012-09-07 14:06:42 -05:00
|
|
|
let opt_level = {
|
2014-01-20 15:55:10 -06:00
|
|
|
if (debugging_opts & session::NO_OPT) != 0 {
|
2012-09-07 14:06:42 -05:00
|
|
|
No
|
2013-09-17 20:42:23 -05:00
|
|
|
} else if matches.opt_present("O") {
|
|
|
|
if matches.opt_present("opt-level") {
|
2014-02-06 16:38:33 -06:00
|
|
|
early_error("-O and --opt-level both provided");
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
2012-08-21 19:22:45 -05:00
|
|
|
Default
|
2013-09-17 20:42:23 -05:00
|
|
|
} else if matches.opt_present("opt-level") {
|
2014-03-10 14:13:19 -05:00
|
|
|
match matches.opt_str("opt-level").as_ref().map(|s| s.as_slice()) {
|
|
|
|
None |
|
|
|
|
Some("0") => No,
|
|
|
|
Some("1") => Less,
|
|
|
|
Some("2") => Default,
|
|
|
|
Some("3") => Aggressive,
|
|
|
|
Some(arg) => {
|
|
|
|
early_error(format!("optimization level needs to be between 0-3 \
|
|
|
|
(instead was `{}`)", arg));
|
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
2014-03-10 14:13:19 -05:00
|
|
|
} else {
|
|
|
|
No
|
|
|
|
}
|
2012-09-07 14:06:42 -05:00
|
|
|
};
|
2014-01-20 15:55:10 -06:00
|
|
|
let gc = debugging_opts & session::GC != 0;
|
2014-03-10 14:13:19 -05:00
|
|
|
let debuginfo = if matches.opt_present("g") {
|
|
|
|
if matches.opt_present("debuginfo") {
|
|
|
|
early_error("-g and --debuginfo both provided");
|
|
|
|
}
|
|
|
|
FullDebugInfo
|
|
|
|
} else if matches.opt_present("debuginfo") {
|
|
|
|
match matches.opt_str("debuginfo").as_ref().map(|s| s.as_slice()) {
|
|
|
|
Some("0") => NoDebugInfo,
|
|
|
|
Some("1") => LimitedDebugInfo,
|
|
|
|
None |
|
|
|
|
Some("2") => FullDebugInfo,
|
|
|
|
Some(arg) => {
|
|
|
|
early_error(format!("optimization level needs to be between 0-3 \
|
|
|
|
(instead was `{}`)", arg));
|
2014-03-05 07:32:30 -06:00
|
|
|
}
|
|
|
|
}
|
2014-03-10 14:13:19 -05:00
|
|
|
} else {
|
|
|
|
NoDebugInfo
|
2014-03-05 02:51:47 -06:00
|
|
|
};
|
2013-08-13 09:31:42 -05:00
|
|
|
|
2014-03-28 14:42:34 -05:00
|
|
|
let addl_lib_search_paths = matches.opt_strs("L").iter().map(|s| {
|
2013-12-03 21:15:12 -06:00
|
|
|
Path::new(s.as_slice())
|
2014-03-28 14:42:34 -05:00
|
|
|
}).collect();
|
2013-04-28 19:57:49 -05:00
|
|
|
|
2014-03-08 14:36:22 -06:00
|
|
|
let cfg = parse_cfgspecs(matches.opt_strs("cfg").move_iter().collect());
|
2013-09-17 20:42:23 -05:00
|
|
|
let test = matches.opt_present("test");
|
2013-12-22 14:38:55 -06:00
|
|
|
let write_dependency_info = (matches.opt_present("dep-info"),
|
|
|
|
matches.opt_str("dep-info").map(|p| Path::new(p)));
|
2013-04-28 21:54:41 -05:00
|
|
|
|
2013-12-19 09:18:37 -06:00
|
|
|
let print_metas = (matches.opt_present("crate-id"),
|
|
|
|
matches.opt_present("crate-name"),
|
|
|
|
matches.opt_present("crate-file-name"));
|
2014-02-06 21:57:09 -06:00
|
|
|
let cg = build_codegen_options(matches);
|
2013-05-29 03:08:20 -05:00
|
|
|
|
2014-03-16 13:56:24 -05:00
|
|
|
session::Options {
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
crate_types: crate_types,
|
2013-02-19 01:40:42 -06:00
|
|
|
gc: gc,
|
|
|
|
optimize: opt_level,
|
|
|
|
debuginfo: debuginfo,
|
|
|
|
lint_opts: lint_opts,
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
output_types: output_types,
|
2014-03-09 07:24:58 -05:00
|
|
|
addl_lib_search_paths: RefCell::new(addl_lib_search_paths),
|
2013-02-19 01:40:42 -06:00
|
|
|
maybe_sysroot: sysroot_opt,
|
|
|
|
target_triple: target,
|
|
|
|
cfg: cfg,
|
|
|
|
test: test,
|
|
|
|
parse_only: parse_only,
|
|
|
|
no_trans: no_trans,
|
2013-12-26 16:39:36 -06:00
|
|
|
no_analysis: no_analysis,
|
2013-03-04 22:12:23 -06:00
|
|
|
debugging_opts: debugging_opts,
|
2013-11-27 21:06:35 -06:00
|
|
|
write_dependency_info: write_dependency_info,
|
2013-12-19 09:18:37 -06:00
|
|
|
print_metas: print_metas,
|
2014-02-06 21:57:09 -06:00
|
|
|
cg: cg,
|
2014-03-09 07:24:58 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2014-02-06 21:57:09 -06:00
|
|
|
pub fn build_codegen_options(matches: &getopts::Matches)
|
|
|
|
-> session::CodegenOptions
|
|
|
|
{
|
|
|
|
let mut cg = session::basic_codegen_options();
|
|
|
|
for option in matches.opt_strs("C").move_iter() {
|
|
|
|
let mut iter = option.splitn('=', 1);
|
|
|
|
let key = iter.next().unwrap();
|
|
|
|
let value = iter.next();
|
|
|
|
let option_to_lookup = key.replace("-", "_");
|
|
|
|
let mut found = false;
|
|
|
|
for &(candidate, setter, _) in session::CG_OPTIONS.iter() {
|
|
|
|
if option_to_lookup.as_slice() != candidate { continue }
|
|
|
|
if !setter(&mut cg, value) {
|
|
|
|
match value {
|
|
|
|
Some(..) => early_error(format!("codegen option `{}` takes \
|
|
|
|
no value", key)),
|
|
|
|
None => early_error(format!("codegen option `{0}` requires \
|
|
|
|
a value (-C {0}=<value>)",
|
|
|
|
key))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if !found {
|
|
|
|
early_error(format!("unknown codegen option: `{}`", key));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cg;
|
|
|
|
}
|
|
|
|
|
2014-03-16 13:56:24 -05:00
|
|
|
pub fn build_session(sopts: session::Options,
|
2014-02-06 16:38:33 -06:00
|
|
|
local_crate_source_file: Option<Path>)
|
2013-08-29 20:34:09 -05:00
|
|
|
-> Session {
|
2014-03-16 13:56:24 -05:00
|
|
|
let codemap = codemap::CodeMap::new();
|
2012-02-17 16:15:09 -06:00
|
|
|
let diagnostic_handler =
|
2014-02-28 13:37:04 -06:00
|
|
|
diagnostic::default_handler();
|
2012-02-17 16:15:09 -06:00
|
|
|
let span_diagnostic_handler =
|
|
|
|
diagnostic::mk_span_handler(diagnostic_handler, codemap);
|
2014-01-27 07:58:40 -06:00
|
|
|
|
2014-03-16 13:56:24 -05:00
|
|
|
build_session_(sopts, local_crate_source_file, span_diagnostic_handler)
|
2012-02-17 16:15:09 -06:00
|
|
|
}
|
|
|
|
|
2014-03-16 13:56:24 -05:00
|
|
|
pub fn build_session_(sopts: session::Options,
|
2014-01-27 07:58:40 -06:00
|
|
|
local_crate_source_file: Option<Path>,
|
2014-03-16 13:56:24 -05:00
|
|
|
span_diagnostic: diagnostic::SpanHandler)
|
2013-08-29 20:34:09 -05:00
|
|
|
-> Session {
|
2014-03-16 13:56:24 -05:00
|
|
|
let target_cfg = build_target_config(&sopts);
|
|
|
|
let p_s = parse::new_parse_sess_special_handler(span_diagnostic);
|
2014-03-09 07:24:58 -05:00
|
|
|
let default_sysroot = match sopts.maybe_sysroot {
|
|
|
|
Some(_) => None,
|
|
|
|
None => Some(filesearch::get_or_default_sysroot())
|
|
|
|
};
|
2014-01-27 07:58:40 -06:00
|
|
|
|
|
|
|
// Make the path absolute, if necessary
|
|
|
|
let local_crate_source_file = local_crate_source_file.map(|path|
|
|
|
|
if path.is_absolute() {
|
|
|
|
path.clone()
|
|
|
|
} else {
|
|
|
|
os::getcwd().join(path.clone())
|
|
|
|
}
|
|
|
|
);
|
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
Session {
|
2013-02-04 16:02:01 -06:00
|
|
|
targ_cfg: target_cfg,
|
|
|
|
opts: sopts,
|
2014-03-09 08:20:44 -05:00
|
|
|
cstore: CStore::new(token::get_ident_interner()),
|
2013-02-04 16:02:01 -06:00
|
|
|
parse_sess: p_s,
|
|
|
|
// For a library crate, this is always none
|
2013-12-21 19:25:27 -06:00
|
|
|
entry_fn: RefCell::new(None),
|
|
|
|
entry_type: Cell::new(None),
|
2014-04-13 13:26:43 -05:00
|
|
|
macro_registrar_fn: Cell::new(None),
|
2014-03-09 07:24:58 -05:00
|
|
|
default_sysroot: default_sysroot,
|
2013-12-22 16:40:03 -06:00
|
|
|
building_library: Cell::new(false),
|
2014-01-27 07:58:40 -06:00
|
|
|
local_crate_source_file: local_crate_source_file,
|
2013-02-04 16:02:01 -06:00
|
|
|
working_dir: os::getcwd(),
|
2014-03-16 13:56:24 -05:00
|
|
|
lints: RefCell::new(NodeMap::new()),
|
2013-12-22 16:36:50 -06:00
|
|
|
node_id: Cell::new(1),
|
2014-03-16 13:56:24 -05:00
|
|
|
crate_types: RefCell::new(Vec::new()),
|
2014-03-06 12:37:24 -06:00
|
|
|
features: front::feature_gate::Features::new(),
|
|
|
|
recursion_limit: Cell::new(64),
|
2013-02-04 16:02:01 -06:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn parse_pretty(sess: &Session, name: &str) -> PpMode {
|
2012-08-06 14:34:08 -05:00
|
|
|
match name {
|
2013-08-31 11:13:04 -05:00
|
|
|
&"normal" => PpmNormal,
|
|
|
|
&"expanded" => PpmExpanded,
|
|
|
|
&"typed" => PpmTyped,
|
|
|
|
&"expanded,identified" => PpmExpandedIdentified,
|
|
|
|
&"identified" => PpmIdentified,
|
2012-08-02 17:42:56 -05:00
|
|
|
_ => {
|
2013-05-19 00:07:44 -05:00
|
|
|
sess.fatal("argument to `pretty` must be one of `normal`, \
|
|
|
|
`expanded`, `typed`, `identified`, \
|
|
|
|
or `expanded,identified`");
|
2012-08-02 17:42:56 -05:00
|
|
|
}
|
2012-03-12 12:19:35 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2012-10-11 18:54:31 -05:00
|
|
|
// rustc command line options
|
2014-03-04 12:02:49 -06:00
|
|
|
pub fn optgroups() -> Vec<getopts::OptGroup> {
|
|
|
|
vec!(
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
optflag("h", "help", "Display this message"),
|
|
|
|
optmulti("", "cfg", "Configure the compilation environment", "SPEC"),
|
|
|
|
optmulti("L", "", "Add a directory to the library search path", "PATH"),
|
2014-03-05 07:32:30 -06:00
|
|
|
optmulti("", "crate-type", "Comma separated list of types of crates for the compiler to emit",
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
"[bin|lib|rlib|dylib|staticlib]"),
|
2014-03-05 07:32:30 -06:00
|
|
|
optmulti("", "emit", "Comma separated list of types of output for the compiler to emit",
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
"[asm|bc|ir|obj|link]"),
|
2013-12-19 09:18:37 -06:00
|
|
|
optflag("", "crate-id", "Output the crate id and exit"),
|
|
|
|
optflag("", "crate-name", "Output the crate name and exit"),
|
|
|
|
optflag("", "crate-file-name", "Output the file(s) that would be written if compilation \
|
|
|
|
continued and exit"),
|
2014-03-10 14:13:19 -05:00
|
|
|
optflag("g", "", "Equivalent to --debuginfo=2"),
|
|
|
|
optopt("", "debuginfo", "Emit DWARF debug info to the objects created:
|
|
|
|
0 = no debug info,
|
|
|
|
1 = line-tables only (for stacktraces and breakpoints),
|
|
|
|
2 = full debug info with variable and type information (same as -g)", "LEVEL"),
|
2014-03-05 07:32:30 -06:00
|
|
|
optflag("", "no-trans", "Run all passes except translation; no output"),
|
2014-04-15 22:33:14 -05:00
|
|
|
optflag("", "no-analysis",
|
|
|
|
"Parse and expand the source, but run no analysis and produce no output"),
|
2014-03-05 07:32:30 -06:00
|
|
|
optflag("O", "", "Equivalent to --opt-level=2"),
|
|
|
|
optopt("o", "", "Write output to <filename>", "FILENAME"),
|
|
|
|
optopt("", "opt-level", "Optimize with possible levels 0-3", "LEVEL"),
|
|
|
|
optopt( "", "out-dir", "Write output to compiler-chosen filename in <dir>", "DIR"),
|
|
|
|
optflag("", "parse-only", "Parse only; do not compile, assemble, or link"),
|
2013-04-28 19:57:49 -05:00
|
|
|
optflagopt("", "pretty",
|
2014-03-05 07:32:30 -06:00
|
|
|
"Pretty-print the input instead of compiling;
|
|
|
|
valid types are: normal (un-annotated source),
|
|
|
|
expanded (crates expanded),
|
|
|
|
typed (crates expanded, with type annotations),
|
|
|
|
or identified (fully parenthesized,
|
|
|
|
AST nodes and blocks with IDs)", "TYPE"),
|
2014-04-15 22:33:14 -05:00
|
|
|
optflagopt("", "dep-info",
|
|
|
|
"Output dependency info to <filename> after compiling, \
|
|
|
|
in a format suitable for use by Makefiles", "FILENAME"),
|
2014-03-05 07:32:30 -06:00
|
|
|
optopt("", "sysroot", "Override the system root", "PATH"),
|
2013-04-28 19:57:49 -05:00
|
|
|
optflag("", "test", "Build a test harness"),
|
2014-03-05 07:32:30 -06:00
|
|
|
optopt("", "target", "Target triple cpu-manufacturer-kernel[-os]
|
|
|
|
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
|
|
|
|
for details)", "TRIPLE"),
|
|
|
|
optmulti("W", "warn", "Set lint warnings", "OPT"),
|
|
|
|
optmulti("A", "allow", "Set lint allowed", "OPT"),
|
|
|
|
optmulti("D", "deny", "Set lint denied", "OPT"),
|
|
|
|
optmulti("F", "forbid", "Set lint forbidden", "OPT"),
|
|
|
|
optmulti("C", "codegen", "Set a codegen option", "OPT[=VALUE]"),
|
|
|
|
optmulti("Z", "", "Set internal debugging options", "FLAG"),
|
2014-03-04 12:02:49 -06:00
|
|
|
optflag( "v", "version", "Print version info and exit"))
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2013-02-19 01:40:42 -06:00
|
|
|
pub struct OutputFilenames {
|
2014-03-28 12:05:27 -05:00
|
|
|
pub out_directory: Path,
|
|
|
|
pub out_filestem: ~str,
|
|
|
|
pub single_output_file: Option<Path>,
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
impl OutputFilenames {
|
|
|
|
pub fn path(&self, flavor: link::OutputType) -> Path {
|
|
|
|
match self.single_output_file {
|
|
|
|
Some(ref path) => return path.clone(),
|
|
|
|
None => {}
|
|
|
|
}
|
|
|
|
self.temp_path(flavor)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn temp_path(&self, flavor: link::OutputType) -> Path {
|
|
|
|
let base = self.out_directory.join(self.out_filestem.as_slice());
|
|
|
|
match flavor {
|
|
|
|
link::OutputTypeBitcode => base.with_extension("bc"),
|
|
|
|
link::OutputTypeAssembly => base.with_extension("s"),
|
|
|
|
link::OutputTypeLlvmAssembly => base.with_extension("ll"),
|
|
|
|
link::OutputTypeObject => base.with_extension("o"),
|
|
|
|
link::OutputTypeExe => base,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_extension(&self, extension: &str) -> Path {
|
|
|
|
let stem = self.out_filestem.as_slice();
|
|
|
|
self.out_directory.join(stem).with_extension(extension)
|
|
|
|
}
|
2013-02-19 01:40:42 -06:00
|
|
|
}
|
2012-01-17 09:42:45 -06:00
|
|
|
|
2014-01-13 10:31:05 -06:00
|
|
|
pub fn build_output_filenames(input: &Input,
|
2013-01-29 17:16:07 -06:00
|
|
|
odir: &Option<Path>,
|
|
|
|
ofile: &Option<Path>,
|
2013-07-19 06:51:37 -05:00
|
|
|
attrs: &[ast::Attribute],
|
2014-03-05 08:36:01 -06:00
|
|
|
sess: &Session)
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
-> OutputFilenames {
|
2012-08-24 17:28:43 -05:00
|
|
|
match *ofile {
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
None => {
|
|
|
|
// "-" as input file will cause the parser to read from stdin so we
|
|
|
|
// have to make up a name
|
|
|
|
// We want to toss everything after the final '.'
|
|
|
|
let dirpath = match *odir {
|
|
|
|
Some(ref d) => d.clone(),
|
2014-02-10 23:06:01 -06:00
|
|
|
None => Path::new(".")
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
};
|
|
|
|
|
log: Introduce liblog, the old std::logging
This commit moves all logging out of the standard library into an external
crate. This crate is the new crate which is responsible for all logging macros
and logging implementation. A few reasons for this change are:
* The crate map has always been a bit of a code smell among rust programs. It
has difficulty being loaded on almost all platforms, and it's used almost
exclusively for logging and only logging. Removing the crate map is one of the
end goals of this movement.
* The compiler has a fair bit of special support for logging. It has the
__log_level() expression as well as generating a global word per module
specifying the log level. This is unfairly favoring the built-in logging
system, and is much better done purely in libraries instead of the compiler
itself.
* Initialization of logging is much easier to do if there is no reliance on a
magical crate map being available to set module log levels.
* If the logging library can be written outside of the standard library, there's
no reason that it shouldn't be. It's likely that we're not going to build the
highest quality logging library of all time, so third-party libraries should
be able to provide just as high-quality logging systems as the default one
provided in the rust distribution.
With a migration such as this, the change does not come for free. There are some
subtle changes in the behavior of liblog vs the previous logging macros:
* The core change of this migration is that there is no longer a physical
log-level per module. This concept is still emulated (it is quite useful), but
there is now only a global log level, not a local one. This global log level
is a reflection of the maximum of all log levels specified. The previously
generated logging code looked like:
if specified_level <= __module_log_level() {
println!(...)
}
The newly generated code looks like:
if specified_level <= ::log::LOG_LEVEL {
if ::log::module_enabled(module_path!()) {
println!(...)
}
}
Notably, the first layer of checking is still intended to be "super fast" in
that it's just a load of a global word and a compare. The second layer of
checking is executed to determine if the current module does indeed have
logging turned on.
This means that if any module has a debug log level turned on, all modules
with debug log levels get a little bit slower (they all do more expensive
dynamic checks to determine if they're turned on or not).
Semantically, this migration brings no change in this respect, but
runtime-wise, this will have a perf impact on some code.
* A `RUST_LOG=::help` directive will no longer print out a list of all modules
that can be logged. This is because the crate map will no longer specify the
log levels of all modules, so the list of modules is not known. Additionally,
warnings can no longer be provided if a malformed logging directive was
supplied.
The new "hello world" for logging looks like:
#[phase(syntax, link)]
extern crate log;
fn main() {
debug!("Hello, world!");
}
2014-03-09 00:11:44 -06:00
|
|
|
let mut stem = input.filestem();
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
|
|
|
|
// If a crateid is present, we use it as the link name
|
|
|
|
let crateid = attr::find_crateid(attrs);
|
|
|
|
match crateid {
|
|
|
|
None => {}
|
|
|
|
Some(crateid) => stem = crateid.name.to_str(),
|
|
|
|
}
|
|
|
|
OutputFilenames {
|
|
|
|
out_directory: dirpath,
|
|
|
|
out_filestem: stem,
|
|
|
|
single_output_file: None,
|
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
Redesign output flags for rustc
This commit removes the -c, --emit-llvm, -s, --rlib, --dylib, --staticlib,
--lib, and --bin flags from rustc, adding the following flags:
* --emit=[asm,ir,bc,obj,link]
* --crate-type=[dylib,rlib,staticlib,bin,lib]
The -o option has also been redefined to be used for *all* flavors of outputs.
This means that we no longer ignore it for libraries. The --out-dir remains the
same as before.
The new logic for files that rustc emits is as follows:
1. Output types are dictated by the --emit flag. The default value is
--emit=link, and this option can be passed multiple times and have all
options stacked on one another.
2. Crate types are dictated by the --crate-type flag and the #[crate_type]
attribute. The flags can be passed many times and stack with the crate
attribute.
3. If the -o flag is specified, and only one output type is specified, the
output will be emitted at this location. If more than one output type is
specified, then the filename of -o is ignored, and all output goes in the
directory that -o specifies. The -o option always ignores the --out-dir
option.
4. If the --out-dir flag is specified, all output goes in this directory.
5. If -o and --out-dir are both not present, all output goes in the current
directory of the process.
6. When multiple output types are specified, the filestem of all output is the
same as the name of the CrateId (derived from a crate attribute or from the
filestem of the crate file).
Closes #7791
Closes #11056
Closes #11667
2014-02-03 17:27:54 -06:00
|
|
|
Some(ref out_file) => {
|
|
|
|
let ofile = if sess.opts.output_types.len() > 1 {
|
|
|
|
sess.warn("ignoring specified output filename because multiple \
|
|
|
|
outputs were requested");
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
Some(out_file.clone())
|
|
|
|
};
|
|
|
|
if *odir != None {
|
|
|
|
sess.warn("ignoring --out-dir flag due to -o flag.");
|
|
|
|
}
|
|
|
|
OutputFilenames {
|
|
|
|
out_directory: out_file.dir_path(),
|
|
|
|
out_filestem: out_file.filestem_str().unwrap().to_str(),
|
|
|
|
single_output_file: ofile,
|
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
2013-02-19 01:40:42 -06:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2014-02-06 16:38:33 -06:00
|
|
|
pub fn early_error(msg: &str) -> ! {
|
2014-02-28 13:37:04 -06:00
|
|
|
let mut emitter = diagnostic::EmitterWriter::stderr();
|
|
|
|
emitter.emit(None, msg, diagnostic::Fatal);
|
2014-01-22 17:48:55 -06:00
|
|
|
fail!(diagnostic::FatalError);
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
pub fn list_metadata(sess: &Session, path: &Path,
|
2014-01-29 20:42:19 -06:00
|
|
|
out: &mut io::Writer) -> io::IoResult<()> {
|
2012-05-22 19:16:26 -05:00
|
|
|
metadata::loader::list_file_metadata(
|
2014-01-29 20:42:19 -06:00
|
|
|
session::sess_os_to_meta_os(sess.targ_cfg.os), path, out)
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
2013-04-15 10:08:52 -05:00
|
|
|
mod test {
|
2013-05-22 21:59:22 -05:00
|
|
|
|
2013-01-08 21:37:25 -06:00
|
|
|
use driver::driver::{build_configuration, build_session};
|
2013-08-13 19:06:27 -05:00
|
|
|
use driver::driver::{build_session_options, optgroups};
|
2013-01-08 21:37:25 -06:00
|
|
|
|
2014-02-03 21:14:40 -06:00
|
|
|
use getopts::getopts;
|
2012-12-27 17:49:26 -06:00
|
|
|
use syntax::attr;
|
2014-01-07 02:57:12 -06:00
|
|
|
use syntax::attr::AttrMetaMethods;
|
2012-12-27 17:49:26 -06:00
|
|
|
|
2011-12-20 04:17:13 -06:00
|
|
|
// When the user supplies --test we should implicitly supply --cfg test
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_switch_implies_cfg_test() {
|
2012-07-31 18:38:41 -05:00
|
|
|
let matches =
|
2014-04-15 20:17:48 -05:00
|
|
|
&match getopts(["--test".to_owned()], optgroups().as_slice()) {
|
2013-05-29 18:59:33 -05:00
|
|
|
Ok(m) => m,
|
2013-10-21 15:08:31 -05:00
|
|
|
Err(f) => fail!("test_switch_implies_cfg_test: {}", f.to_err_msg())
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2014-02-10 10:10:26 -06:00
|
|
|
let sessopts = build_session_options(matches);
|
2014-02-06 16:38:33 -06:00
|
|
|
let sess = build_session(sessopts, None);
|
2014-03-17 02:55:41 -05:00
|
|
|
let cfg = build_configuration(&sess);
|
2014-02-28 17:25:15 -06:00
|
|
|
assert!((attr::contains_name(cfg.as_slice(), "test")));
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
// When the user supplies --test and --cfg test, don't implicitly add
|
|
|
|
// another --cfg test
|
|
|
|
#[test]
|
2013-04-15 10:08:52 -05:00
|
|
|
fn test_switch_implies_cfg_test_unless_cfg_test() {
|
2012-07-31 18:38:41 -05:00
|
|
|
let matches =
|
2014-04-15 20:17:48 -05:00
|
|
|
&match getopts(["--test".to_owned(), "--cfg=test".to_owned()],
|
2014-03-08 14:36:22 -06:00
|
|
|
optgroups().as_slice()) {
|
2013-05-29 18:59:33 -05:00
|
|
|
Ok(m) => m,
|
|
|
|
Err(f) => {
|
2013-10-21 15:08:31 -05:00
|
|
|
fail!("test_switch_implies_cfg_test_unless_cfg_test: {}",
|
2013-09-28 00:38:08 -05:00
|
|
|
f.to_err_msg());
|
2012-07-14 00:57:48 -05:00
|
|
|
}
|
2011-12-20 04:17:13 -06:00
|
|
|
};
|
2014-02-10 10:10:26 -06:00
|
|
|
let sessopts = build_session_options(matches);
|
2014-02-06 16:38:33 -06:00
|
|
|
let sess = build_session(sessopts, None);
|
2014-03-17 02:55:41 -05:00
|
|
|
let cfg = build_configuration(&sess);
|
2014-02-01 09:19:55 -06:00
|
|
|
let mut test_items = cfg.iter().filter(|m| m.name().equiv(&("test")));
|
2013-07-19 06:51:37 -05:00
|
|
|
assert!(test_items.next().is_some());
|
|
|
|
assert!(test_items.next().is_none());
|
2011-12-20 04:17:13 -06:00
|
|
|
}
|
|
|
|
}
|