2013-02-28 07:15:32 -06: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.
|
|
|
|
|
2014-01-07 23:17:52 -06:00
|
|
|
/*!
|
|
|
|
|
|
|
|
The Rust compiler.
|
|
|
|
|
|
|
|
# Note
|
|
|
|
|
|
|
|
This API is completely unstable and subject to change.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
2014-04-03 18:28:46 -05:00
|
|
|
#![crate_id = "rustc#0.11-pre"]
|
2014-03-21 20:05:05 -05:00
|
|
|
#![comment = "The Rust compiler"]
|
|
|
|
#![license = "MIT/ASL2"]
|
|
|
|
#![crate_type = "dylib"]
|
|
|
|
#![crate_type = "rlib"]
|
|
|
|
#![doc(html_logo_url = "http://www.rust-lang.org/logos/rust-logo-128x128-blk-v2.png",
|
2014-01-07 23:17:52 -06:00
|
|
|
html_favicon_url = "http://www.rust-lang.org/favicon.ico",
|
2014-03-21 20:05:05 -05:00
|
|
|
html_root_url = "http://static.rust-lang.org/doc/master")]
|
2011-05-05 21:44:00 -05:00
|
|
|
|
2014-03-21 20:05:05 -05:00
|
|
|
#![allow(deprecated)]
|
|
|
|
#![feature(macro_rules, globs, struct_variant, managed_boxes, quote,
|
|
|
|
default_type_params, phase)]
|
2013-08-14 20:41:40 -05:00
|
|
|
|
2014-02-14 12:10:06 -06:00
|
|
|
extern crate flate;
|
|
|
|
extern crate arena;
|
|
|
|
extern crate syntax;
|
|
|
|
extern crate serialize;
|
|
|
|
extern crate sync;
|
|
|
|
extern crate getopts;
|
|
|
|
extern crate collections;
|
2014-02-19 21:08:12 -06:00
|
|
|
extern crate time;
|
2014-02-26 11:58:41 -06:00
|
|
|
extern crate libc;
|
|
|
|
|
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
|
|
|
#[phase(syntax, link)]
|
|
|
|
extern crate log;
|
2013-03-26 21:53:33 -05:00
|
|
|
|
2013-12-19 14:23:39 -06:00
|
|
|
use back::link;
|
2013-03-26 21:53:33 -05:00
|
|
|
use driver::session;
|
|
|
|
use middle::lint;
|
|
|
|
|
2013-12-19 14:23:39 -06:00
|
|
|
use d = driver::driver;
|
|
|
|
|
2014-03-02 18:01:13 -06:00
|
|
|
use std::any::AnyRefExt;
|
2014-02-06 01:34:33 -06:00
|
|
|
use std::cmp;
|
2013-11-11 00:46:32 -06:00
|
|
|
use std::io;
|
2013-06-28 17:32:26 -05:00
|
|
|
use std::os;
|
|
|
|
use std::str;
|
|
|
|
use std::task;
|
2013-12-19 14:23:39 -06:00
|
|
|
use syntax::ast;
|
2013-08-29 20:34:09 -05:00
|
|
|
use syntax::diagnostic::Emitter;
|
2013-03-26 21:53:33 -05:00
|
|
|
use syntax::diagnostic;
|
2013-12-19 14:23:39 -06:00
|
|
|
use syntax::parse;
|
2013-03-26 21:53:33 -05:00
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod middle {
|
2013-06-12 18:18:58 -05:00
|
|
|
pub mod trans;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod ty;
|
2013-10-29 05:03:32 -05:00
|
|
|
pub mod ty_fold;
|
Cleanup substitutions and treatment of generics around traits in a number of ways.
- In a TraitRef, use the self type consistently to refer to the Self type:
- trait ref in `impl Trait<A,B,C> for S` has a self type of `S`.
- trait ref in `A:Trait` has the self type `A`
- trait ref associated with a trait decl has self type `Self`
- trait ref associated with a supertype has self type `Self`
- trait ref in an object type `@Trait` has no self type
- Rewrite `each_bound_traits_and_supertraits` to perform
substitutions as it goes, and thus yield a series of trait refs
that are always in the same 'namespace' as the type parameter
bound given as input. Before, we left this to the caller, but
this doesn't work because the caller lacks adequare information
to perform the type substitutions correctly.
- For provided methods, substitute the generics involved in the provided
method correctly.
- Introduce TypeParameterDef, which tracks the bounds declared on a type
parameter and brings them together with the def_id and (in the future)
other information (maybe even the parameter's name!).
- Introduce Subst trait, which helps to cleanup a lot of the
repetitive code involved with doing type substitution.
- Introduce Repr trait, which makes debug printouts far more convenient.
Fixes #4183. Needed for #5656.
2013-04-09 00:54:49 -05:00
|
|
|
pub mod subst;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod resolve;
|
2013-10-29 05:03:32 -05:00
|
|
|
pub mod resolve_lifetime;
|
2012-11-28 14:33:00 -06:00
|
|
|
pub mod typeck;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod check_loop;
|
|
|
|
pub mod check_match;
|
|
|
|
pub mod check_const;
|
2014-02-26 12:22:41 -06:00
|
|
|
pub mod check_static;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod lint;
|
2012-12-13 15:05:22 -06:00
|
|
|
pub mod borrowck;
|
2013-04-17 17:05:17 -05:00
|
|
|
pub mod dataflow;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod mem_categorization;
|
|
|
|
pub mod liveness;
|
|
|
|
pub mod kind;
|
|
|
|
pub mod freevars;
|
|
|
|
pub mod pat_util;
|
|
|
|
pub mod region;
|
|
|
|
pub mod const_eval;
|
|
|
|
pub mod astencode;
|
|
|
|
pub mod lang_items;
|
|
|
|
pub mod privacy;
|
2013-01-10 12:59:58 -06:00
|
|
|
pub mod moves;
|
2013-04-29 16:56:05 -05:00
|
|
|
pub mod entry;
|
2013-05-23 21:12:16 -05:00
|
|
|
pub mod effect;
|
2013-06-14 20:21:47 -05:00
|
|
|
pub mod reachable;
|
2013-05-09 10:29:17 -05:00
|
|
|
pub mod graph;
|
2013-05-10 12:10:35 -05:00
|
|
|
pub mod cfg;
|
2013-12-08 01:55:27 -06:00
|
|
|
pub mod dead;
|
2011-04-19 18:40:46 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod front {
|
|
|
|
pub mod config;
|
|
|
|
pub mod test;
|
2013-05-17 15:12:42 -05:00
|
|
|
pub mod std_inject;
|
2014-01-06 06:00:46 -06:00
|
|
|
pub mod assign_node_ids_and_map;
|
2013-10-02 20:10:16 -05:00
|
|
|
pub mod feature_gate;
|
2014-02-07 04:50:07 -06:00
|
|
|
pub mod show_span;
|
2010-06-23 23:03:09 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod back {
|
|
|
|
pub mod abi;
|
2014-02-24 21:45:20 -06:00
|
|
|
pub mod archive;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod arm;
|
2014-02-24 21:45:20 -06:00
|
|
|
pub mod link;
|
|
|
|
pub mod lto;
|
2013-01-29 08:28:08 -06:00
|
|
|
pub mod mips;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod rpath;
|
2014-02-24 21:45:20 -06:00
|
|
|
pub mod svh;
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod target_strs;
|
2014-02-24 21:45:20 -06:00
|
|
|
pub mod x86;
|
|
|
|
pub mod x86_64;
|
2010-09-23 17:46:31 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod metadata;
|
2011-06-27 18:38:57 -05:00
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod driver;
|
2010-06-23 23:03:09 -05:00
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod util {
|
|
|
|
pub mod common;
|
|
|
|
pub mod ppaux;
|
2013-12-09 15:56:53 -06:00
|
|
|
pub mod sha2;
|
2014-02-28 16:34:26 -06:00
|
|
|
pub mod nodemap;
|
2014-04-08 12:06:11 -05:00
|
|
|
pub mod fs;
|
2010-08-18 13:34:47 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub mod lib {
|
|
|
|
pub mod llvm;
|
2013-11-30 22:52:21 -06:00
|
|
|
pub mod llvmdeps;
|
2010-07-12 19:47:40 -05:00
|
|
|
}
|
|
|
|
|
2014-03-13 18:00:07 -05:00
|
|
|
static BUG_REPORT_URL: &'static str =
|
|
|
|
"http://static.rust-lang.org/doc/master/complement-bugreport.html";
|
|
|
|
|
2013-08-06 23:50:23 -05:00
|
|
|
pub fn version(argv0: &str) {
|
|
|
|
let vers = match option_env!("CFG_VERSION") {
|
|
|
|
Some(vers) => vers,
|
|
|
|
None => "unknown version"
|
|
|
|
};
|
2013-09-25 00:16:43 -05:00
|
|
|
println!("{} {}", argv0, vers);
|
2013-12-19 14:23:39 -06:00
|
|
|
println!("host: {}", d::host_triple());
|
2013-08-06 23:50:23 -05:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub fn usage(argv0: &str) {
|
2013-09-28 00:38:08 -05:00
|
|
|
let message = format!("Usage: {} [OPTIONS] INPUT", argv0);
|
2013-09-25 00:16:43 -05:00
|
|
|
println!("{}\n\
|
2013-06-21 18:08:37 -05:00
|
|
|
Additional help:
|
2014-02-10 09:54:00 -06:00
|
|
|
-C help Print codegen options
|
2013-06-21 18:08:37 -05:00
|
|
|
-W help Print 'lint' options and default settings
|
|
|
|
-Z help Print internal options for debugging rustc\n",
|
2014-03-08 14:36:22 -06:00
|
|
|
getopts::usage(message, d::optgroups().as_slice()));
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub fn describe_warnings() {
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("
|
2012-11-28 14:33:00 -06:00
|
|
|
Available lint options:
|
|
|
|
-W <foo> Warn about <foo>
|
|
|
|
-A <foo> Allow <foo>
|
|
|
|
-D <foo> Deny <foo>
|
|
|
|
-F <foo> Forbid <foo> (deny, and deny all overrides)
|
2013-07-22 11:03:39 -05:00
|
|
|
");
|
2012-11-28 14:33:00 -06:00
|
|
|
|
|
|
|
let lint_dict = lint::get_lint_dict();
|
2013-08-07 21:21:36 -05:00
|
|
|
let mut lint_dict = lint_dict.move_iter()
|
2013-08-09 22:09:47 -05:00
|
|
|
.map(|(k, v)| (v, k))
|
2014-03-04 12:02:49 -06:00
|
|
|
.collect::<Vec<(lint::LintSpec, &'static str)> >();
|
2014-03-08 14:36:22 -06:00
|
|
|
lint_dict.as_mut_slice().sort();
|
2013-07-16 23:12:16 -05:00
|
|
|
|
2012-11-28 14:33:00 -06:00
|
|
|
let mut max_key = 0;
|
2013-08-03 11:45:23 -05:00
|
|
|
for &(_, name) in lint_dict.iter() {
|
2014-02-06 01:34:33 -06:00
|
|
|
max_key = cmp::max(name.len(), max_key);
|
2013-07-16 23:12:16 -05:00
|
|
|
}
|
2012-11-28 14:33:00 -06:00
|
|
|
fn padded(max: uint, s: &str) -> ~str {
|
2013-11-28 06:52:11 -06:00
|
|
|
" ".repeat(max - s.len()) + s
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
2014-02-06 21:57:09 -06:00
|
|
|
println!("\nAvailable lint checks:\n");
|
2013-09-25 00:16:43 -05:00
|
|
|
println!(" {} {:7.7s} {}",
|
|
|
|
padded(max_key, "name"), "default", "meaning");
|
|
|
|
println!(" {} {:7.7s} {}\n",
|
|
|
|
padded(max_key, "----"), "-------", "-------");
|
2013-08-07 21:21:36 -05:00
|
|
|
for (spec, name) in lint_dict.move_iter() {
|
2013-07-16 23:12:16 -05:00
|
|
|
let name = name.replace("_", "-");
|
2013-09-25 00:16:43 -05:00
|
|
|
println!(" {} {:7.7s} {}",
|
|
|
|
padded(max_key, name),
|
|
|
|
lint::level_to_str(spec.default),
|
|
|
|
spec.desc);
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
2014-01-09 04:06:55 -06:00
|
|
|
println!("");
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub fn describe_debug_flags() {
|
2014-02-06 21:57:09 -06:00
|
|
|
println!("\nAvailable debug options:\n");
|
2013-06-21 07:29:53 -05:00
|
|
|
let r = session::debugging_opts_map();
|
2013-08-03 11:45:23 -05:00
|
|
|
for tuple in r.iter() {
|
2013-07-02 14:47:32 -05:00
|
|
|
match *tuple {
|
|
|
|
(ref name, ref desc, _) => {
|
2013-09-25 00:16:43 -05:00
|
|
|
println!(" -Z {:>20s} -- {}", *name, *desc);
|
2013-07-02 14:47:32 -05:00
|
|
|
}
|
|
|
|
}
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-06 21:57:09 -06:00
|
|
|
pub fn describe_codegen_flags() {
|
|
|
|
println!("\nAvailable codegen options:\n");
|
|
|
|
let mut cg = session::basic_codegen_options();
|
|
|
|
for &(name, parser, desc) in session::CG_OPTIONS.iter() {
|
|
|
|
// we invoke the parser function on `None` to see if this option needs
|
|
|
|
// an argument or not.
|
|
|
|
let (width, extra) = if parser(&mut cg, None) {
|
|
|
|
(25, "")
|
|
|
|
} else {
|
|
|
|
(21, "=val")
|
|
|
|
};
|
|
|
|
println!(" -C {:>width$s}{} -- {}", name.replace("_", "-"),
|
|
|
|
extra, desc, width=width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-06 16:38:33 -06:00
|
|
|
pub fn run_compiler(args: &[~str]) {
|
2013-08-22 04:41:33 -05:00
|
|
|
let mut args = args.to_owned();
|
2013-12-23 09:40:42 -06:00
|
|
|
let binary = args.shift().unwrap();
|
2012-11-28 14:33:00 -06:00
|
|
|
|
2013-06-12 12:02:55 -05:00
|
|
|
if args.is_empty() { usage(binary); return; }
|
2012-11-28 14:33:00 -06:00
|
|
|
|
|
|
|
let matches =
|
2014-03-08 14:36:22 -06:00
|
|
|
&match getopts::getopts(args, d::optgroups().as_slice()) {
|
2013-01-10 12:59:58 -06:00
|
|
|
Ok(m) => m,
|
|
|
|
Err(f) => {
|
2014-02-06 16:38:33 -06:00
|
|
|
d::early_error(f.to_err_msg());
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-09-17 20:42:23 -05:00
|
|
|
if matches.opt_present("h") || matches.opt_present("help") {
|
2013-06-12 12:02:55 -05:00
|
|
|
usage(binary);
|
2012-11-28 14:33:00 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-03-30 22:53:26 -05:00
|
|
|
let lint_flags = matches.opt_strs("W").move_iter().collect::<Vec<_>>().append(
|
2014-03-05 17:28:08 -06:00
|
|
|
matches.opt_strs("warn").as_slice());
|
2014-01-15 11:31:48 -06:00
|
|
|
if lint_flags.iter().any(|x| x == &~"help") {
|
2012-11-28 14:33:00 -06:00
|
|
|
describe_warnings();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-17 20:42:23 -05:00
|
|
|
let r = matches.opt_strs("Z");
|
2013-07-04 21:13:26 -05:00
|
|
|
if r.iter().any(|x| x == &~"help") {
|
2012-11-28 14:33:00 -06:00
|
|
|
describe_debug_flags();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-02-06 21:57:09 -06:00
|
|
|
let cg_flags = matches.opt_strs("C");
|
|
|
|
if cg_flags.iter().any(|x| x == &~"help") {
|
|
|
|
describe_codegen_flags();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if cg_flags.contains(&~"passes=list") {
|
2013-08-22 22:58:42 -05:00
|
|
|
unsafe { lib::llvm::llvm::LLVMRustPrintPasses(); }
|
2013-05-29 03:08:20 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-17 20:42:23 -05:00
|
|
|
if matches.opt_present("v") || matches.opt_present("version") {
|
2013-06-12 12:02:55 -05:00
|
|
|
version(binary);
|
2012-11-28 14:33:00 -06:00
|
|
|
return;
|
|
|
|
}
|
2014-01-27 07:58:40 -06:00
|
|
|
let (input, input_file_path) = match matches.free.len() {
|
2014-02-06 16:38:33 -06:00
|
|
|
0u => d::early_error("no input filename given"),
|
2012-11-28 14:33:00 -06:00
|
|
|
1u => {
|
2014-03-05 17:28:08 -06:00
|
|
|
let ifile = matches.free.get(0).as_slice();
|
2014-01-21 12:08:10 -06:00
|
|
|
if ifile == "-" {
|
2014-02-01 13:24:42 -06:00
|
|
|
let contents = io::stdin().read_to_end().unwrap();
|
2014-03-26 11:24:16 -05:00
|
|
|
let src = str::from_utf8(contents.as_slice()).unwrap().to_owned();
|
2014-01-15 18:26:20 -06:00
|
|
|
(d::StrInput(src), None)
|
2012-11-28 14:33:00 -06:00
|
|
|
} else {
|
2014-01-27 07:58:40 -06:00
|
|
|
(d::FileInput(Path::new(ifile)), Some(Path::new(ifile)))
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
}
|
2014-02-06 16:38:33 -06:00
|
|
|
_ => d::early_error("multiple input filenames provided")
|
2012-11-28 14:33:00 -06:00
|
|
|
};
|
|
|
|
|
2014-02-10 10:10:26 -06:00
|
|
|
let sopts = d::build_session_options(matches);
|
2014-02-06 16:38:33 -06:00
|
|
|
let sess = d::build_session(sopts, input_file_path);
|
2013-12-03 21:15:12 -06:00
|
|
|
let odir = matches.opt_str("out-dir").map(|o| Path::new(o));
|
|
|
|
let ofile = matches.opt_str("o").map(|o| Path::new(o));
|
2014-03-05 08:36:01 -06:00
|
|
|
let cfg = d::build_configuration(&sess);
|
2013-11-21 17:42:55 -06:00
|
|
|
let pretty = matches.opt_default("pretty", "normal").map(|a| {
|
2014-03-05 08:36:01 -06:00
|
|
|
d::parse_pretty(&sess, a)
|
2013-11-21 17:42:55 -06:00
|
|
|
});
|
2012-11-28 14:33:00 -06:00
|
|
|
match pretty {
|
2014-03-16 13:56:24 -05:00
|
|
|
Some::<d::PpMode>(ppm) => {
|
2014-04-08 15:07:15 -05:00
|
|
|
d::pretty_print_input(sess, cfg, &input, ppm, ofile);
|
2014-03-16 13:56:24 -05:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
None::<d::PpMode> => {/* continue */ }
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
2013-09-17 20:42:23 -05:00
|
|
|
let ls = matches.opt_present("ls");
|
2012-11-28 14:33:00 -06:00
|
|
|
if ls {
|
|
|
|
match input {
|
2014-03-16 13:56:24 -05:00
|
|
|
d::FileInput(ref ifile) => {
|
|
|
|
let mut stdout = io::stdout();
|
|
|
|
d::list_metadata(&sess, &(*ifile), &mut stdout).unwrap();
|
|
|
|
}
|
|
|
|
d::StrInput(_) => {
|
|
|
|
d::early_error("can not list metadata for stdin");
|
|
|
|
}
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
2014-03-16 13:56:24 -05:00
|
|
|
let (crate_id, crate_name, crate_file_name) = sess.opts.print_metas;
|
2013-12-19 14:23:39 -06:00
|
|
|
// these nasty nested conditions are to avoid doing extra work
|
|
|
|
if crate_id || crate_name || crate_file_name {
|
2014-03-05 08:36:01 -06:00
|
|
|
let attrs = parse_crate_attrs(&sess, &input);
|
2013-12-19 14:23:39 -06:00
|
|
|
let t_outputs = d::build_output_filenames(&input, &odir, &ofile,
|
2014-03-05 08:36:01 -06:00
|
|
|
attrs.as_slice(), &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(attrs.as_slice(), t_outputs.out_filestem);
|
2012-11-28 14:33:00 -06:00
|
|
|
|
2014-02-24 21:45:20 -06:00
|
|
|
if crate_id {
|
|
|
|
println!("{}", id.to_str());
|
|
|
|
}
|
|
|
|
if crate_name {
|
|
|
|
println!("{}", id.name);
|
|
|
|
}
|
2013-12-19 14:23:39 -06:00
|
|
|
if crate_file_name {
|
2014-03-08 14:36:22 -06:00
|
|
|
let crate_types = session::collect_crate_types(&sess,
|
|
|
|
attrs.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
|
|
|
for &style in crate_types.iter() {
|
2014-02-24 21:45:20 -06:00
|
|
|
let fname = link::filename_for_input(&sess, style, &id,
|
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
|
|
|
&t_outputs.with_extension(""));
|
2013-12-19 14:23:39 -06:00
|
|
|
println!("{}", fname.filename_display());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
d::compile_input(sess, cfg, &input, &odir, &ofile);
|
|
|
|
}
|
|
|
|
|
2014-03-05 08:36:01 -06:00
|
|
|
fn parse_crate_attrs(sess: &session::Session, input: &d::Input) ->
|
2014-03-04 12:02:49 -06:00
|
|
|
Vec<ast::Attribute> {
|
2014-02-28 17:25:15 -06:00
|
|
|
let result = match *input {
|
2014-01-13 10:31:05 -06:00
|
|
|
d::FileInput(ref ifile) => {
|
2014-02-28 17:25:15 -06:00
|
|
|
parse::parse_crate_attrs_from_file(ifile,
|
|
|
|
Vec::new(),
|
2014-03-09 09:54:34 -05:00
|
|
|
&sess.parse_sess)
|
2013-12-19 14:23:39 -06:00
|
|
|
}
|
2014-01-15 18:26:20 -06:00
|
|
|
d::StrInput(ref src) => {
|
|
|
|
parse::parse_crate_attrs_from_source_str(d::anon_src(),
|
|
|
|
(*src).clone(),
|
2014-02-28 17:25:15 -06:00
|
|
|
Vec::new(),
|
2014-03-09 09:54:34 -05:00
|
|
|
&sess.parse_sess)
|
2013-12-19 14:23:39 -06:00
|
|
|
}
|
2014-02-28 17:25:15 -06:00
|
|
|
};
|
|
|
|
result.move_iter().collect()
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
|
2014-01-17 14:12:46 -06:00
|
|
|
/// Run a procedure which will detect failures in the compiler and print nicer
|
|
|
|
/// error messages rather than just failing the test.
|
|
|
|
///
|
|
|
|
/// The diagnostic emitter yielded to the procedure should be used for reporting
|
|
|
|
/// errors of the compiler.
|
2014-04-07 15:30:48 -05:00
|
|
|
pub fn monitor(f: proc():Send) {
|
2014-01-26 02:43:42 -06:00
|
|
|
// FIXME: This is a hack for newsched since it doesn't support split stacks.
|
2013-10-17 03:40:33 -05:00
|
|
|
// rustc needs a lot of stack! When optimizations are disabled, it needs
|
|
|
|
// even *more* stack than usual as well.
|
|
|
|
#[cfg(rtopt)]
|
|
|
|
static STACK_SIZE: uint = 6000000; // 6MB
|
|
|
|
#[cfg(not(rtopt))]
|
|
|
|
static STACK_SIZE: uint = 20000000; // 20MB
|
2013-08-05 15:10:34 -05:00
|
|
|
|
2014-02-13 00:03:36 -06:00
|
|
|
let mut task_builder = task::task().named("rustc");
|
2013-08-09 19:28:27 -05:00
|
|
|
|
2014-01-26 02:43:42 -06:00
|
|
|
// FIXME: Hacks on hacks. If the env is trying to override the stack size
|
2013-08-09 19:28:27 -05:00
|
|
|
// then *don't* set it explicitly.
|
|
|
|
if os::getenv("RUST_MIN_STACK").is_none() {
|
|
|
|
task_builder.opts.stack_size = Some(STACK_SIZE);
|
|
|
|
}
|
|
|
|
|
2014-03-09 16:58:32 -05:00
|
|
|
let (tx, rx) = channel();
|
|
|
|
let w = io::ChanWriter::new(tx);
|
|
|
|
let mut r = io::ChanReader::new(rx);
|
2013-02-27 18:13:53 -06:00
|
|
|
|
2014-01-17 14:12:46 -06:00
|
|
|
match task_builder.try(proc() {
|
2014-03-08 20:21:49 -06:00
|
|
|
io::stdio::set_stderr(~w);
|
2014-02-06 16:38:33 -06:00
|
|
|
f()
|
2013-11-21 17:42:55 -06:00
|
|
|
}) {
|
2014-01-17 14:12:46 -06:00
|
|
|
Ok(()) => { /* fallthrough */ }
|
|
|
|
Err(value) => {
|
2012-11-28 14:33:00 -06:00
|
|
|
// Task failed without emitting a fatal diagnostic
|
2014-01-17 14:12:46 -06:00
|
|
|
if !value.is::<diagnostic::FatalError>() {
|
2014-02-28 13:37:04 -06:00
|
|
|
let mut emitter = diagnostic::EmitterWriter::stderr();
|
2014-03-13 18:00:07 -05:00
|
|
|
|
|
|
|
// a .span_bug or .bug call has already printed what
|
|
|
|
// it wants to print.
|
|
|
|
if !value.is::<diagnostic::ExplicitBug>() {
|
|
|
|
emitter.emit(
|
|
|
|
None,
|
|
|
|
"unexpected failure",
|
|
|
|
diagnostic::Bug);
|
|
|
|
}
|
2012-11-28 14:33:00 -06:00
|
|
|
|
2013-06-21 07:29:53 -05:00
|
|
|
let xs = [
|
2014-03-13 18:00:07 -05:00
|
|
|
~"the compiler hit an unexpected failure path. this is a bug.",
|
|
|
|
"we would appreciate a bug report: " + BUG_REPORT_URL,
|
2014-03-13 01:34:31 -05:00
|
|
|
~"run with `RUST_BACKTRACE=1` for a backtrace",
|
2013-06-21 07:29:53 -05:00
|
|
|
];
|
2013-08-03 11:45:23 -05:00
|
|
|
for note in xs.iter() {
|
2014-02-28 13:37:04 -06:00
|
|
|
emitter.emit(None, *note, diagnostic::Note)
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
2014-01-17 14:12:46 -06:00
|
|
|
|
2014-03-13 18:00:07 -05:00
|
|
|
match r.read_to_str() {
|
|
|
|
Ok(s) => println!("{}", s),
|
|
|
|
Err(e) => emitter.emit(None,
|
|
|
|
format!("failed to read internal stderr: {}", e),
|
|
|
|
diagnostic::Error),
|
|
|
|
}
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
2014-01-17 14:12:46 -06:00
|
|
|
|
|
|
|
// Fail so the process returns a failure code, but don't pollute the
|
|
|
|
// output with some unnecessary failure messages, we've already
|
|
|
|
// printed everything that we needed to.
|
2014-03-08 20:21:49 -06:00
|
|
|
io::stdio::set_stderr(~io::util::NullWriter);
|
2013-10-21 15:08:31 -05:00
|
|
|
fail!();
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-29 17:16:07 -06:00
|
|
|
pub fn main() {
|
2013-09-24 18:34:23 -05:00
|
|
|
std::os::set_exit_status(main_args(std::os::args()));
|
2013-08-22 04:41:33 -05:00
|
|
|
}
|
|
|
|
|
2013-09-24 18:34:23 -05:00
|
|
|
pub fn main_args(args: &[~str]) -> int {
|
2013-08-22 04:41:33 -05:00
|
|
|
let owned_args = args.to_owned();
|
2014-02-06 16:38:33 -06:00
|
|
|
monitor(proc() run_compiler(owned_args));
|
2013-11-21 17:42:55 -06:00
|
|
|
0
|
2012-11-28 14:33:00 -06:00
|
|
|
}
|