From edb2c2d291811f9b21ed8bd1499648a0614f6fc8 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Tue, 26 Sep 2017 21:16:59 -0400 Subject: [PATCH 01/42] Remove uses of mem::transmute in Box methods Makes use of conversions via Unique. --- src/liballoc/boxed.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 4341b0b2975..512c7194fe3 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -269,7 +269,7 @@ impl Box { #[stable(feature = "box_raw", since = "1.4.0")] #[inline] pub unsafe fn from_raw(raw: *mut T) -> Self { - mem::transmute(raw) + Box(Unique::new_unchecked(raw)) } /// Consumes the `Box`, returning the wrapped raw pointer. @@ -295,7 +295,7 @@ impl Box { #[stable(feature = "box_raw", since = "1.4.0")] #[inline] pub fn into_raw(b: Box) -> *mut T { - unsafe { mem::transmute(b) } + Box::into_unique(b).as_ptr() } /// Consumes the `Box`, returning the wrapped pointer as `Unique`. @@ -326,7 +326,9 @@ impl Box { issue = "27730")] #[inline] pub fn into_unique(b: Box) -> Unique { - unsafe { mem::transmute(b) } + let u = b.0; + mem::forget(b); + u } } From 8ef54478157adb980598104af0ce571cb6637931 Mon Sep 17 00:00:00 2001 From: Corey Farwell Date: Mon, 25 Sep 2017 00:14:56 -0400 Subject: [PATCH 02/42] Migrate to eprint/eprintln macros where appropriate. --- src/bootstrap/bin/rustc.rs | 4 +--- src/librustc_driver/lib.rs | 2 +- src/librustdoc/externalfiles.rs | 9 ++------- src/librustdoc/markdown.rs | 14 +++----------- src/librustdoc/test.rs | 9 ++++----- src/libstd/process.rs | 4 +--- src/test/run-fail/mir_drop_panics.rs | 3 +-- src/test/run-fail/mir_dynamic_drops_1.rs | 5 ++--- src/test/run-fail/mir_dynamic_drops_2.rs | 5 ++--- src/test/run-fail/mir_dynamic_drops_3.rs | 5 ++--- .../run-fail/mir_trans_calls_converging_drops.rs | 6 ++---- .../run-fail/mir_trans_calls_converging_drops_2.rs | 6 ++---- .../run-fail/mir_trans_calls_diverging_drops.rs | 4 +--- src/test/run-fail/panic-set-handler.rs | 3 +-- src/test/run-fail/panic-set-unset-handler.rs | 3 +-- src/test/run-pass/backtrace-debuginfo.rs | 4 +--- src/tools/tidy/src/lib.rs | 5 ++--- src/tools/tidy/src/main.rs | 3 +-- 18 files changed, 30 insertions(+), 64 deletions(-) diff --git a/src/bootstrap/bin/rustc.rs b/src/bootstrap/bin/rustc.rs index 848b10d312c..54a3dbafe27 100644 --- a/src/bootstrap/bin/rustc.rs +++ b/src/bootstrap/bin/rustc.rs @@ -31,8 +31,6 @@ extern crate bootstrap; use std::env; use std::ffi::OsString; -use std::io; -use std::io::prelude::*; use std::str::FromStr; use std::path::PathBuf; use std::process::{Command, ExitStatus}; @@ -270,7 +268,7 @@ fn main() { } if verbose > 1 { - writeln!(&mut io::stderr(), "rustc command: {:?}", cmd).unwrap(); + eprintln!("rustc command: {:?}", cmd); } // Actually run the compiler! diff --git a/src/librustc_driver/lib.rs b/src/librustc_driver/lib.rs index 044f4a5eaf5..29d15188500 100644 --- a/src/librustc_driver/lib.rs +++ b/src/librustc_driver/lib.rs @@ -1307,7 +1307,7 @@ pub fn monitor(f: F) { errors::Level::Note); } - writeln!(io::stderr(), "{}", str::from_utf8(&data.lock().unwrap()).unwrap()).unwrap(); + eprintln!("{}", str::from_utf8(&data.lock().unwrap()).unwrap()); } exit_on_err(); diff --git a/src/librustdoc/externalfiles.rs b/src/librustdoc/externalfiles.rs index 111ae4ede27..2f7bd5e39a1 100644 --- a/src/librustdoc/externalfiles.rs +++ b/src/librustdoc/externalfiles.rs @@ -10,7 +10,6 @@ use std::fs::File; use std::io::prelude::*; -use std::io; use std::path::Path; use std::str; use html::markdown::{Markdown, RenderType}; @@ -70,17 +69,13 @@ pub fn load_string>(file_path: P) -> Result Ok(s.to_string()), Err(_) => { - let _ = writeln!(&mut io::stderr(), - "error reading `{}`: not UTF-8", - file_path.display()); + eprintln!("error reading `{}`: not UTF-8", file_path.display()); Err(LoadStringError::BadUtf8) } } diff --git a/src/librustdoc/markdown.rs b/src/librustdoc/markdown.rs index 57e8e88cd13..484285e91f6 100644 --- a/src/librustdoc/markdown.rs +++ b/src/librustdoc/markdown.rs @@ -11,7 +11,6 @@ use std::default::Default; use std::fs::File; use std::io::prelude::*; -use std::io; use std::path::{PathBuf, Path}; use getopts; @@ -75,9 +74,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches, let mut out = match File::create(&output) { Err(e) => { - let _ = writeln!(&mut io::stderr(), - "rustdoc: {}: {}", - output.display(), e); + eprintln!("rustdoc: {}: {}", output.display(), e); return 4; } Ok(f) => f @@ -85,10 +82,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches, let (metadata, text) = extract_leading_metadata(&input_str); if metadata.is_empty() { - let _ = writeln!( - &mut io::stderr(), - "rustdoc: invalid markdown file: no initial lines starting with `# ` or `%`" - ); + eprintln!("rustdoc: invalid markdown file: no initial lines starting with `# ` or `%`"); return 5; } let title = metadata[0]; @@ -138,9 +132,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches, match err { Err(e) => { - let _ = writeln!(&mut io::stderr(), - "rustdoc: cannot write to `{}`: {}", - output.display(), e); + eprintln!("rustdoc: cannot write to `{}`: {}", output.display(), e); 6 } Ok(_) => 0 diff --git a/src/librustdoc/test.rs b/src/librustdoc/test.rs index f9cb4b84545..5f6ccb8a75e 100644 --- a/src/librustdoc/test.rs +++ b/src/librustdoc/test.rs @@ -479,11 +479,10 @@ impl Collector { found = entry.remove_item(&test).is_some(); } if !found { - let _ = writeln!(&mut io::stderr(), - "WARNING: {} Code block is not currently run as a test, but will \ - in future versions of rustdoc. Please ensure this code block is \ - a runnable test, or use the `ignore` directive.", - name); + eprintln!("WARNING: {} Code block is not currently run as a test, but will \ + in future versions of rustdoc. Please ensure this code block is \ + a runnable test, or use the `ignore` directive.", + name); return } } diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 1869ad3ed70..015f859b5cc 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -1083,8 +1083,6 @@ impl Child { /// function and compute the exit code from its return value: /// /// ``` -/// use std::io::{self, Write}; -/// /// fn run_app() -> Result<(), ()> { /// // Application logic here /// Ok(()) @@ -1094,7 +1092,7 @@ impl Child { /// ::std::process::exit(match run_app() { /// Ok(_) => 0, /// Err(err) => { -/// writeln!(io::stderr(), "error: {:?}", err).unwrap(); +/// eprintln!("error: {:?}", err); /// 1 /// } /// }); diff --git a/src/test/run-fail/mir_drop_panics.rs b/src/test/run-fail/mir_drop_panics.rs index 98311525ad0..51191dd7087 100644 --- a/src/test/run-fail/mir_drop_panics.rs +++ b/src/test/run-fail/mir_drop_panics.rs @@ -10,7 +10,6 @@ // error-pattern:panic 1 // error-pattern:drop 2 -use std::io::{self, Write}; struct Droppable(u32); impl Drop for Droppable { @@ -18,7 +17,7 @@ impl Drop for Droppable { if self.0 == 1 { panic!("panic 1"); } else { - write!(io::stderr(), "drop {}", self.0); + eprint!("drop {}", self.0); } } } diff --git a/src/test/run-fail/mir_dynamic_drops_1.rs b/src/test/run-fail/mir_dynamic_drops_1.rs index 6cf2851d93d..69f934272b7 100644 --- a/src/test/run-fail/mir_dynamic_drops_1.rs +++ b/src/test/run-fail/mir_dynamic_drops_1.rs @@ -9,7 +9,6 @@ // except according to those terms. // error-pattern:drop 1 // error-pattern:drop 2 -use std::io::{self, Write}; /// Structure which will not allow to be dropped twice. @@ -17,10 +16,10 @@ struct Droppable<'a>(&'a mut bool, u32); impl<'a> Drop for Droppable<'a> { fn drop(&mut self) { if *self.0 { - writeln!(io::stderr(), "{} dropped twice", self.1); + eprintln!("{} dropped twice", self.1); ::std::process::exit(1); } - writeln!(io::stderr(), "drop {}", self.1); + eprintln!("drop {}", self.1); *self.0 = true; } } diff --git a/src/test/run-fail/mir_dynamic_drops_2.rs b/src/test/run-fail/mir_dynamic_drops_2.rs index 7a90298e422..d2fe50401ab 100644 --- a/src/test/run-fail/mir_dynamic_drops_2.rs +++ b/src/test/run-fail/mir_dynamic_drops_2.rs @@ -9,7 +9,6 @@ // except according to those terms. // error-pattern:drop 1 -use std::io::{self, Write}; /// Structure which will not allow to be dropped twice. @@ -17,10 +16,10 @@ struct Droppable<'a>(&'a mut bool, u32); impl<'a> Drop for Droppable<'a> { fn drop(&mut self) { if *self.0 { - writeln!(io::stderr(), "{} dropped twice", self.1); + eprintln!("{} dropped twice", self.1); ::std::process::exit(1); } - writeln!(io::stderr(), "drop {}", self.1); + eprintln!("drop {}", self.1); *self.0 = true; } } diff --git a/src/test/run-fail/mir_dynamic_drops_3.rs b/src/test/run-fail/mir_dynamic_drops_3.rs index 79ecbbb35bc..ecc35ee9b24 100644 --- a/src/test/run-fail/mir_dynamic_drops_3.rs +++ b/src/test/run-fail/mir_dynamic_drops_3.rs @@ -12,7 +12,6 @@ // error-pattern:drop 3 // error-pattern:drop 2 // error-pattern:drop 1 -use std::io::{self, Write}; /// Structure which will not allow to be dropped twice. @@ -20,10 +19,10 @@ struct Droppable<'a>(&'a mut bool, u32); impl<'a> Drop for Droppable<'a> { fn drop(&mut self) { if *self.0 { - writeln!(io::stderr(), "{} dropped twice", self.1); + eprintln!("{} dropped twice", self.1); ::std::process::exit(1); } - writeln!(io::stderr(), "drop {}", self.1); + eprintln!("drop {}", self.1); *self.0 = true; } } diff --git a/src/test/run-fail/mir_trans_calls_converging_drops.rs b/src/test/run-fail/mir_trans_calls_converging_drops.rs index 7a7526c5fc1..9c851eb7346 100644 --- a/src/test/run-fail/mir_trans_calls_converging_drops.rs +++ b/src/test/run-fail/mir_trans_calls_converging_drops.rs @@ -12,17 +12,15 @@ // error-pattern:0 dropped // error-pattern:exit -use std::io::{self, Write}; - struct Droppable(u8); impl Drop for Droppable { fn drop(&mut self) { - write!(io::stderr(), "{} dropped\n", self.0); + eprintln!("{} dropped", self.0); } } fn converging_fn() { - write!(io::stderr(), "converging_fn called\n"); + eprintln!("converging_fn called"); } fn mir(d: Droppable) { diff --git a/src/test/run-fail/mir_trans_calls_converging_drops_2.rs b/src/test/run-fail/mir_trans_calls_converging_drops_2.rs index 1301630cc85..6f105211556 100644 --- a/src/test/run-fail/mir_trans_calls_converging_drops_2.rs +++ b/src/test/run-fail/mir_trans_calls_converging_drops_2.rs @@ -12,18 +12,16 @@ // error-pattern:dropped // error-pattern:exit -use std::io::{self, Write}; - struct Droppable; impl Drop for Droppable { fn drop(&mut self) { - write!(io::stderr(), "dropped\n"); + eprintln!("dropped"); } } // return value of this function is copied into the return slot fn complex() -> u64 { - write!(io::stderr(), "complex called\n"); + eprintln!("complex called"); 42 } diff --git a/src/test/run-fail/mir_trans_calls_diverging_drops.rs b/src/test/run-fail/mir_trans_calls_diverging_drops.rs index c1918704929..f8fbe8f79cc 100644 --- a/src/test/run-fail/mir_trans_calls_diverging_drops.rs +++ b/src/test/run-fail/mir_trans_calls_diverging_drops.rs @@ -11,12 +11,10 @@ // error-pattern:diverging_fn called // error-pattern:0 dropped -use std::io::{self, Write}; - struct Droppable(u8); impl Drop for Droppable { fn drop(&mut self) { - write!(io::stderr(), "{} dropped", self.0); + eprintln!("{} dropped", self.0); } } diff --git a/src/test/run-fail/panic-set-handler.rs b/src/test/run-fail/panic-set-handler.rs index b589544ae15..68f1c4ed0bc 100644 --- a/src/test/run-fail/panic-set-handler.rs +++ b/src/test/run-fail/panic-set-handler.rs @@ -13,11 +13,10 @@ #![feature(panic_handler)] use std::panic; -use std::io::{self, Write}; fn main() { panic::set_hook(Box::new(|i| { - write!(io::stderr(), "greetings from the panic handler"); + eprint!("greetings from the panic handler"); })); panic!("foobar"); } diff --git a/src/test/run-fail/panic-set-unset-handler.rs b/src/test/run-fail/panic-set-unset-handler.rs index 6741c2d9c2c..072139a8c9b 100644 --- a/src/test/run-fail/panic-set-unset-handler.rs +++ b/src/test/run-fail/panic-set-unset-handler.rs @@ -13,11 +13,10 @@ #![feature(panic_handler)] use std::panic; -use std::io::{self, Write}; fn main() { panic::set_hook(Box::new(|i| { - write!(io::stderr(), "greetings from the panic handler"); + eprint!("greetings from the panic handler"); })); panic::take_hook(); panic!("foobar"); diff --git a/src/test/run-pass/backtrace-debuginfo.rs b/src/test/run-pass/backtrace-debuginfo.rs index f81352e1773..f9233026a1e 100644 --- a/src/test/run-pass/backtrace-debuginfo.rs +++ b/src/test/run-pass/backtrace-debuginfo.rs @@ -19,8 +19,6 @@ // ignore-pretty issue #37195 // ignore-emscripten spawning processes is not supported -use std::io; -use std::io::prelude::*; use std::env; #[path = "backtrace-debuginfo-aux.rs"] mod aux; @@ -163,7 +161,7 @@ fn main() { let args: Vec = env::args().collect(); if args.len() >= 2 { let case = args[1].parse().unwrap(); - writeln!(&mut io::stderr(), "test case {}", case).unwrap(); + eprintln!("test case {}", case); outer(case, pos!()); println!("done."); } else { diff --git a/src/tools/tidy/src/lib.rs b/src/tools/tidy/src/lib.rs index 90bf7a5e0a6..c316ec46762 100644 --- a/src/tools/tidy/src/lib.rs +++ b/src/tools/tidy/src/lib.rs @@ -33,10 +33,9 @@ macro_rules! t { macro_rules! tidy_error { ($bad:expr, $fmt:expr, $($arg:tt)*) => ({ - use std::io::Write; *$bad = true; - write!(::std::io::stderr(), "tidy error: ").expect("could not write to stderr"); - writeln!(::std::io::stderr(), $fmt, $($arg)*).expect("could not write to stderr"); + eprint!("tidy error: "); + eprintln!($fmt, $($arg)*); }); } diff --git a/src/tools/tidy/src/main.rs b/src/tools/tidy/src/main.rs index 433192a21ec..f6640c902bc 100644 --- a/src/tools/tidy/src/main.rs +++ b/src/tools/tidy/src/main.rs @@ -22,7 +22,6 @@ use tidy::*; use std::process; use std::path::PathBuf; use std::env; -use std::io::{self, Write}; fn main() { let path = env::args_os().skip(1).next().expect("need an argument"); @@ -44,7 +43,7 @@ fn main() { } if bad { - writeln!(io::stderr(), "some tidy checks failed").expect("could not write to stderr"); + eprintln!("some tidy checks failed"); process::exit(1); } } From ac25a4ac329a083a9693fe5d9d1600024db9b35c Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Thu, 5 Oct 2017 01:02:25 +0300 Subject: [PATCH 03/42] rustc_trans: do not set NoCapture for anonymous lifetime &T arguments. --- src/librustc_trans/abi.rs | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/librustc_trans/abi.rs b/src/librustc_trans/abi.rs index 2aecc016a5c..1f72ae849e6 100644 --- a/src/librustc_trans/abi.rs +++ b/src/librustc_trans/abi.rs @@ -750,9 +750,7 @@ impl<'a, 'tcx> FnType<'tcx> { Some(ty.boxed_ty()) } - ty::TyRef(b, mt) => { - use rustc::ty::{BrAnon, ReLateBound}; - + ty::TyRef(_, mt) => { // `&mut` pointer parameters never alias other parameters, or mutable global data // // `&T` where `T` contains no `UnsafeCell` is immutable, and can be marked as @@ -768,13 +766,6 @@ impl<'a, 'tcx> FnType<'tcx> { arg.attrs.set(ArgAttribute::ReadOnly); } - // When a reference in an argument has no named lifetime, it's - // impossible for that reference to escape this function - // (returned or stored beyond the call by a closure). - if let ReLateBound(_, BrAnon(_)) = *b { - arg.attrs.set(ArgAttribute::NoCapture); - } - Some(mt.ty) } _ => None From 17a2a766ac61762fdec7e89c80ce9f8ac97bf654 Mon Sep 17 00:00:00 2001 From: James Tucker Date: Wed, 4 Oct 2017 14:08:53 -0700 Subject: [PATCH 04/42] zircon: the type of zx_handle_t is now unsigned This is a kernel ABI change that landed today. I noticed some other ABI issues and have left a note to cleanup once they are better defined. --- src/libstd/sys/unix/process/zircon.rs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/libstd/sys/unix/process/zircon.rs b/src/libstd/sys/unix/process/zircon.rs index b5ec11b40fd..8d0ad30f9c8 100644 --- a/src/libstd/sys/unix/process/zircon.rs +++ b/src/libstd/sys/unix/process/zircon.rs @@ -17,11 +17,16 @@ use u64; use libc::{c_int, c_void}; -pub type zx_handle_t = i32; +pub type zx_handle_t = u32; pub type zx_vaddr_t = usize; pub type zx_rights_t = u32; pub type zx_status_t = i32; +// TODO(raggi): zx_size_t was removed from Zircon. various syscall API docs use size_t here, but +// don't define that well at the ABI level yet, as the C spec definition of size_t isn't what is +// meant. In the future Zirocn will define size_t more strictly for it's ABI. At that time, +// zx_size_t should be removed here, and replaced with an appropriately sized type with a +// sufficiently strict definition. pub type zx_size_t = usize; pub const ZX_HANDLE_INVALID: zx_handle_t = 0; From fb03bb72b9c5e46d98726ba520ba08fe8ba2082f Mon Sep 17 00:00:00 2001 From: James Tucker Date: Wed, 4 Oct 2017 15:29:01 -0700 Subject: [PATCH 05/42] zircon: update some more zx and lp constants * Use size_t where size_t is used, while it's not critical on our specifically supported architectures, this is more accurate. * Update HND_SPECIAL_COUNT to the correct value, and give it the size that enum is likely to be. --- .../sys/unix/process/process_fuchsia.rs | 10 +++---- src/libstd/sys/unix/process/zircon.rs | 28 ++++++++----------- 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/libstd/sys/unix/process/process_fuchsia.rs b/src/libstd/sys/unix/process/process_fuchsia.rs index 5d34da04446..a7a67ed36e8 100644 --- a/src/libstd/sys/unix/process/process_fuchsia.rs +++ b/src/libstd/sys/unix/process/process_fuchsia.rs @@ -9,7 +9,7 @@ // except according to those terms. use io; -use libc; +use libc::{self, size_t}; use mem; use ptr; @@ -148,8 +148,8 @@ impl Process { use sys::process::zircon::*; let mut proc_info: zx_info_process_t = Default::default(); - let mut actual: zx_size_t = 0; - let mut avail: zx_size_t = 0; + let mut actual: size_t = 0; + let mut avail: size_t = 0; unsafe { zx_cvt(zx_object_wait_one(self.handle.raw(), ZX_TASK_TERMINATED, @@ -171,8 +171,8 @@ impl Process { use sys::process::zircon::*; let mut proc_info: zx_info_process_t = Default::default(); - let mut actual: zx_size_t = 0; - let mut avail: zx_size_t = 0; + let mut actual: size_t = 0; + let mut avail: size_t = 0; unsafe { let status = zx_object_wait_one(self.handle.raw(), ZX_TASK_TERMINATED, diff --git a/src/libstd/sys/unix/process/zircon.rs b/src/libstd/sys/unix/process/zircon.rs index 8d0ad30f9c8..90864e6ef3f 100644 --- a/src/libstd/sys/unix/process/zircon.rs +++ b/src/libstd/sys/unix/process/zircon.rs @@ -15,20 +15,13 @@ use io; use os::raw::c_char; use u64; -use libc::{c_int, c_void}; +use libc::{c_int, c_void, size_t}; pub type zx_handle_t = u32; pub type zx_vaddr_t = usize; pub type zx_rights_t = u32; pub type zx_status_t = i32; -// TODO(raggi): zx_size_t was removed from Zircon. various syscall API docs use size_t here, but -// don't define that well at the ABI level yet, as the C spec definition of size_t isn't what is -// meant. In the future Zirocn will define size_t more strictly for it's ABI. At that time, -// zx_size_t should be removed here, and replaced with an appropriately sized type with a -// sufficiently strict definition. -pub type zx_size_t = usize; - pub const ZX_HANDLE_INVALID: zx_handle_t = 0; pub type zx_time_t = u64; @@ -120,36 +113,37 @@ extern { pending: *mut zx_signals_t) -> zx_status_t; pub fn zx_object_get_info(handle: zx_handle_t, topic: u32, buffer: *mut c_void, - buffer_size: zx_size_t, actual_size: *mut zx_size_t, - avail: *mut zx_size_t) -> zx_status_t; + buffer_size: size_t, actual_size: *mut size_t, + avail: *mut size_t) -> zx_status_t; } // From `enum special_handles` in system/ulib/launchpad/launchpad.c // HND_LOADER_SVC = 0 // HND_EXEC_VMO = 1 -pub const HND_SPECIAL_COUNT: usize = 2; +// HND_SEGMENTS_VMAR = 2 +const HND_SPECIAL_COUNT: c_int = 3; #[repr(C)] pub struct launchpad_t { argc: u32, envc: u32, args: *const c_char, - args_len: usize, + args_len: size_t, env: *const c_char, - env_len: usize, + env_len: size_t, handles: *mut zx_handle_t, handles_info: *mut u32, - handle_count: usize, - handle_alloc: usize, + handle_count: size_t, + handle_alloc: size_t, entry: zx_vaddr_t, base: zx_vaddr_t, vdso_base: zx_vaddr_t, - stack_size: usize, + stack_size: size_t, - special_handles: [zx_handle_t; HND_SPECIAL_COUNT], + special_handles: [zx_handle_t; HND_SPECIAL_COUNT as usize], loader_message: bool, } From a70c5cb68f84e576b16fbca86453240290e7cc22 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Wed, 4 Oct 2017 16:21:38 -0700 Subject: [PATCH 06/42] rustc: Don't create empty codegen units This'll end up just creating a bunch of object files that otherwise wouldn't exist, so skip that extra work if possible. --- src/librustc_trans/base.rs | 3 --- src/librustc_trans/partitioning.rs | 9 --------- 2 files changed, 12 deletions(-) diff --git a/src/librustc_trans/base.rs b/src/librustc_trans/base.rs index 0568bd2f3ca..94e1d238c64 100644 --- a/src/librustc_trans/base.rs +++ b/src/librustc_trans/base.rs @@ -1178,9 +1178,6 @@ fn collect_and_partition_translation_items<'a, 'tcx>( .collect::>() }); - assert!(tcx.sess.opts.codegen_units == codegen_units.len() || - tcx.sess.opts.debugging_opts.incremental.is_some()); - let translation_items: DefIdSet = items.iter().filter_map(|trans_item| { match *trans_item { TransItem::Fn(ref instance) => Some(instance.def_id()), diff --git a/src/librustc_trans/partitioning.rs b/src/librustc_trans/partitioning.rs index 7c29186f465..a84bfd15402 100644 --- a/src/librustc_trans/partitioning.rs +++ b/src/librustc_trans/partitioning.rs @@ -407,15 +407,6 @@ fn merge_codegen_units<'tcx>(initial_partitioning: &mut PreInliningPartitioning< for (index, cgu) in codegen_units.iter_mut().enumerate() { cgu.set_name(numbered_codegen_unit_name(crate_name, index)); } - - // If the initial partitioning contained less than target_cgu_count to begin - // with, we won't have enough codegen units here, so add a empty units until - // we reach the target count - while codegen_units.len() < target_cgu_count { - let index = codegen_units.len(); - let name = numbered_codegen_unit_name(crate_name, index); - codegen_units.push(CodegenUnit::new(name)); - } } fn place_inlined_translation_items<'tcx>(initial_partitioning: PreInliningPartitioning<'tcx>, From 6f7dd654cdf5aeec714914ec0848fb711662fa11 Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 5 Oct 2017 05:01:02 +0200 Subject: [PATCH 07/42] Remove nacl from librustc_llvm --- src/librustc_llvm/build.rs | 2 +- src/librustc_llvm/lib.rs | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/src/librustc_llvm/build.rs b/src/librustc_llvm/build.rs index dde7a38efc7..12d57e78c69 100644 --- a/src/librustc_llvm/build.rs +++ b/src/librustc_llvm/build.rs @@ -88,7 +88,7 @@ fn main() { let is_crossed = target != host; let mut optional_components = - vec!["x86", "arm", "aarch64", "mips", "powerpc", "pnacl", + vec!["x86", "arm", "aarch64", "mips", "powerpc", "systemz", "jsbackend", "webassembly", "msp430", "sparc", "nvptx"]; let mut version_cmd = Command::new(&llvm_config); diff --git a/src/librustc_llvm/lib.rs b/src/librustc_llvm/lib.rs index 9be5f5b5486..98172bca177 100644 --- a/src/librustc_llvm/lib.rs +++ b/src/librustc_llvm/lib.rs @@ -346,10 +346,6 @@ pub fn initialize_available_targets() { LLVMInitializePowerPCTargetMC, LLVMInitializePowerPCAsmPrinter, LLVMInitializePowerPCAsmParser); - init_target!(llvm_component = "pnacl", - LLVMInitializePNaClTargetInfo, - LLVMInitializePNaClTarget, - LLVMInitializePNaClTargetMC); init_target!(llvm_component = "systemz", LLVMInitializeSystemZTargetInfo, LLVMInitializeSystemZTarget, From b8fad2d21961307ec908ced9d3e2a64595eb5deb Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 5 Oct 2017 05:01:19 +0200 Subject: [PATCH 08/42] Remove nacl from librustc_back --- src/librustc_back/target/le32_unknown_nacl.rs | 51 ------------------- src/librustc_back/target/mod.rs | 1 - 2 files changed, 52 deletions(-) delete mode 100644 src/librustc_back/target/le32_unknown_nacl.rs diff --git a/src/librustc_back/target/le32_unknown_nacl.rs b/src/librustc_back/target/le32_unknown_nacl.rs deleted file mode 100644 index 9af4606f1f1..00000000000 --- a/src/librustc_back/target/le32_unknown_nacl.rs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -use LinkerFlavor; -use super::{LinkArgs, Target, TargetOptions, TargetResult}; - -pub fn target() -> TargetResult { - let mut pre_link_args = LinkArgs::new(); - pre_link_args.insert(LinkerFlavor::Gcc, - vec!["--pnacl-exceptions=sjlj".to_string(), - "--target=le32-unknown-nacl".to_string(), - "-Wl,--start-group".to_string()]); - let mut post_link_args = LinkArgs::new(); - post_link_args.insert(LinkerFlavor::Gcc, - vec!["-Wl,--end-group".to_string()]); - - let opts = TargetOptions { - linker: "pnacl-clang".to_string(), - ar: "pnacl-ar".to_string(), - - pre_link_args, - post_link_args, - dynamic_linking: false, - executables: true, - exe_suffix: ".pexe".to_string(), - linker_is_gnu: true, - allow_asm: false, - max_atomic_width: Some(32), - .. Default::default() - }; - Ok(Target { - llvm_target: "le32-unknown-nacl".to_string(), - target_endian: "little".to_string(), - target_pointer_width: "32".to_string(), - target_c_int_width: "32".to_string(), - target_os: "nacl".to_string(), - target_env: "newlib".to_string(), - target_vendor: "unknown".to_string(), - data_layout: "e-i64:64:64-p:32:32:32-v128:32:32".to_string(), - arch: "le32".to_string(), - linker_flavor: LinkerFlavor::Gcc, - options: opts, - }) -} diff --git a/src/librustc_back/target/mod.rs b/src/librustc_back/target/mod.rs index b1b208d2de4..039e0153656 100644 --- a/src/librustc_back/target/mod.rs +++ b/src/librustc_back/target/mod.rs @@ -215,7 +215,6 @@ supported_targets! { ("i686-pc-windows-msvc", i686_pc_windows_msvc), ("i586-pc-windows-msvc", i586_pc_windows_msvc), - ("le32-unknown-nacl", le32_unknown_nacl), ("asmjs-unknown-emscripten", asmjs_unknown_emscripten), ("wasm32-unknown-emscripten", wasm32_unknown_emscripten), ("wasm32-experimental-emscripten", wasm32_experimental_emscripten), From aad1c998c7a08dd06719845dd5b3b962dfcb0be7 Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 5 Oct 2017 05:01:41 +0200 Subject: [PATCH 09/42] Remove nacl from libstd --- src/libstd/os/mod.rs | 1 - src/libstd/os/nacl/fs.rs | 128 ------------------ src/libstd/os/nacl/mod.rs | 16 --- src/libstd/os/nacl/raw.rs | 56 -------- src/libstd/sys/unix/env.rs | 21 --- src/libstd/sys/unix/mod.rs | 5 +- src/libstd/sys/unix/os.rs | 2 - src/libstd/sys/unix/process/process_common.rs | 1 - src/libstd/sys/unix/process/process_unix.rs | 4 +- src/libstd/sys_common/backtrace.rs | 2 - 10 files changed, 4 insertions(+), 232 deletions(-) delete mode 100644 src/libstd/os/nacl/fs.rs delete mode 100644 src/libstd/os/nacl/mod.rs delete mode 100644 src/libstd/os/nacl/raw.rs diff --git a/src/libstd/os/mod.rs b/src/libstd/os/mod.rs index b460bd90f17..122f15d1d4c 100644 --- a/src/libstd/os/mod.rs +++ b/src/libstd/os/mod.rs @@ -38,7 +38,6 @@ pub mod linux; #[cfg(all(not(dox), target_os = "haiku"))] pub mod haiku; #[cfg(all(not(dox), target_os = "ios"))] pub mod ios; #[cfg(all(not(dox), target_os = "macos"))] pub mod macos; -#[cfg(all(not(dox), target_os = "nacl"))] pub mod nacl; #[cfg(all(not(dox), target_os = "netbsd"))] pub mod netbsd; #[cfg(all(not(dox), target_os = "openbsd"))] pub mod openbsd; #[cfg(all(not(dox), target_os = "solaris"))] pub mod solaris; diff --git a/src/libstd/os/nacl/fs.rs b/src/libstd/os/nacl/fs.rs deleted file mode 100644 index 3e0fb44b01e..00000000000 --- a/src/libstd/os/nacl/fs.rs +++ /dev/null @@ -1,128 +0,0 @@ -// Copyright 2016 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -#![stable(feature = "metadata_ext", since = "1.1.0")] - -use libc; - -use fs::Metadata; -use sys_common::AsInner; - -#[allow(deprecated)] -use os::nacl::raw; - -/// OS-specific extension methods for `fs::Metadata` -#[stable(feature = "metadata_ext", since = "1.1.0")] -pub trait MetadataExt { - /// Gain a reference to the underlying `stat` structure which contains - /// the raw information returned by the OS. - /// - /// The contents of the returned `stat` are **not** consistent across - /// Unix platforms. The `os::unix::fs::MetadataExt` trait contains the - /// cross-Unix abstractions contained within the raw stat. - #[stable(feature = "metadata_ext", since = "1.1.0")] - #[rustc_deprecated(since = "1.8.0", - reason = "deprecated in favor of the accessor \ - methods of this trait")] - #[allow(deprecated)] - fn as_raw_stat(&self) -> &raw::stat; - - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_dev(&self) -> u64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_ino(&self) -> u64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_mode(&self) -> u32; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_nlink(&self) -> u64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_uid(&self) -> u32; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_gid(&self) -> u32; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_rdev(&self) -> u64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_size(&self) -> u64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_atime(&self) -> i64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_atime_nsec(&self) -> i64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_mtime(&self) -> i64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_mtime_nsec(&self) -> i64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_ctime(&self) -> i64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_ctime_nsec(&self) -> i64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_blksize(&self) -> u64; - #[stable(feature = "metadata_ext2", since = "1.8.0")] - fn st_blocks(&self) -> u64; -} - -#[stable(feature = "metadata_ext", since = "1.1.0")] -impl MetadataExt for Metadata { - #[allow(deprecated)] - fn as_raw_stat(&self) -> &raw::stat { - unsafe { - &*(self.as_inner().as_inner() as *const libc::stat64 - as *const raw::stat) - } - } - fn st_dev(&self) -> u64 { - self.as_inner().as_inner().st_dev as u64 - } - fn st_ino(&self) -> u64 { - self.as_inner().as_inner().st_ino as u64 - } - fn st_mode(&self) -> u32 { - self.as_inner().as_inner().st_mode as u32 - } - fn st_nlink(&self) -> u64 { - self.as_inner().as_inner().st_nlink as u64 - } - fn st_uid(&self) -> u32 { - self.as_inner().as_inner().st_uid as u32 - } - fn st_gid(&self) -> u32 { - self.as_inner().as_inner().st_gid as u32 - } - fn st_rdev(&self) -> u64 { - self.as_inner().as_inner().st_rdev as u64 - } - fn st_size(&self) -> u64 { - self.as_inner().as_inner().st_size as u64 - } - fn st_atime(&self) -> i64 { - self.as_inner().as_inner().st_atime as i64 - } - fn st_atime_nsec(&self) -> i64 { - self.as_inner().as_inner().st_atime_nsec as i64 - } - fn st_mtime(&self) -> i64 { - self.as_inner().as_inner().st_mtime as i64 - } - fn st_mtime_nsec(&self) -> i64 { - self.as_inner().as_inner().st_mtime_nsec as i64 - } - fn st_ctime(&self) -> i64 { - self.as_inner().as_inner().st_ctime as i64 - } - fn st_ctime_nsec(&self) -> i64 { - self.as_inner().as_inner().st_ctime_nsec as i64 - } - fn st_blksize(&self) -> u64 { - self.as_inner().as_inner().st_blksize as u64 - } - fn st_blocks(&self) -> u64 { - self.as_inner().as_inner().st_blocks as u64 - } -} diff --git a/src/libstd/os/nacl/mod.rs b/src/libstd/os/nacl/mod.rs deleted file mode 100644 index 7dfa2eabe3e..00000000000 --- a/src/libstd/os/nacl/mod.rs +++ /dev/null @@ -1,16 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Nacl-specific definitions - -#![stable(feature = "raw_ext", since = "1.1.0")] - -pub mod raw; -pub mod fs; diff --git a/src/libstd/os/nacl/raw.rs b/src/libstd/os/nacl/raw.rs deleted file mode 100644 index 3c3d4410a2a..00000000000 --- a/src/libstd/os/nacl/raw.rs +++ /dev/null @@ -1,56 +0,0 @@ -// Copyright 2015 The Rust Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution and at -// http://rust-lang.org/COPYRIGHT. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - -//! Nacl-specific raw type definitions - -#![stable(feature = "raw_ext", since = "1.1.0")] -#![rustc_deprecated(since = "1.8.0", - reason = "these type aliases are no longer supported by \ - the standard library, the `libc` crate on \ - crates.io should be used instead for the correct \ - definitions")] -#![allow(deprecated)] - -#[stable(feature = "raw_ext", since = "1.1.0")] pub type time_t = i64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type off_t = u64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type dev_t = u64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type ino_t = u64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type pid_t = i32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type uid_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type gid_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type mode_t = u32; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type nlink_t = u64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blksize_t = u64; -#[stable(feature = "raw_ext", since = "1.1.0")] pub type blkcnt_t = u64; - -#[stable(feature = "pthread_t", since = "1.8.0")] -pub type pthread_t = usize; - -#[repr(C)] -#[derive(Copy, Clone)] -#[stable(feature = "raw_ext", since = "1.1.0")] -pub struct stat { - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_dev: dev_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ino: ino_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mode: mode_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_nlink: nlink_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_uid: uid_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_gid: gid_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_rdev: dev_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_size: off_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_blksize: blksize_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_blocks: blkcnt_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime: time_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_atime_nsec: i64, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime: time_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_mtime_nsec: i64, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime: time_t, - #[stable(feature = "raw_ext", since = "1.1.0")] pub st_ctime_nsec: i64, -} diff --git a/src/libstd/sys/unix/env.rs b/src/libstd/sys/unix/env.rs index 3d9a06bedd5..00cf7eca75d 100644 --- a/src/libstd/sys/unix/env.rs +++ b/src/libstd/sys/unix/env.rs @@ -118,27 +118,6 @@ pub mod os { pub const EXE_EXTENSION: &'static str = ""; } -#[cfg(all(target_os = "nacl", not(target_arch = "le32")))] -pub mod os { - pub const FAMILY: &'static str = "unix"; - pub const OS: &'static str = "nacl"; - pub const DLL_PREFIX: &'static str = "lib"; - pub const DLL_SUFFIX: &'static str = ".so"; - pub const DLL_EXTENSION: &'static str = "so"; - pub const EXE_SUFFIX: &'static str = ".nexe"; - pub const EXE_EXTENSION: &'static str = "nexe"; -} -#[cfg(all(target_os = "nacl", target_arch = "le32"))] -pub mod os { - pub const FAMILY: &'static str = "unix"; - pub const OS: &'static str = "pnacl"; - pub const DLL_PREFIX: &'static str = "lib"; - pub const DLL_SUFFIX: &'static str = ".pso"; - pub const DLL_EXTENSION: &'static str = "pso"; - pub const EXE_SUFFIX: &'static str = ".pexe"; - pub const EXE_EXTENSION: &'static str = "pexe"; -} - #[cfg(target_os = "haiku")] pub mod os { pub const FAMILY: &'static str = "unix"; diff --git a/src/libstd/sys/unix/mod.rs b/src/libstd/sys/unix/mod.rs index 1b3f1000b77..c2772e2e2cc 100644 --- a/src/libstd/sys/unix/mod.rs +++ b/src/libstd/sys/unix/mod.rs @@ -22,7 +22,6 @@ use libc; #[cfg(all(not(dox), target_os = "haiku"))] pub use os::haiku as platform; #[cfg(all(not(dox), target_os = "ios"))] pub use os::ios as platform; #[cfg(all(not(dox), target_os = "macos"))] pub use os::macos as platform; -#[cfg(all(not(dox), target_os = "nacl"))] pub use os::nacl as platform; #[cfg(all(not(dox), target_os = "netbsd"))] pub use os::netbsd as platform; #[cfg(all(not(dox), target_os = "openbsd"))] pub use os::openbsd as platform; #[cfg(all(not(dox), target_os = "solaris"))] pub use os::solaris as platform; @@ -77,11 +76,11 @@ pub fn init() { reset_sigpipe(); } - #[cfg(not(any(target_os = "nacl", target_os = "emscripten", target_os="fuchsia")))] + #[cfg(not(any(target_os = "emscripten", target_os="fuchsia")))] unsafe fn reset_sigpipe() { assert!(signal(libc::SIGPIPE, libc::SIG_IGN) != libc::SIG_ERR); } - #[cfg(any(target_os = "nacl", target_os = "emscripten", target_os="fuchsia"))] + #[cfg(any(target_os = "emscripten", target_os="fuchsia"))] unsafe fn reset_sigpipe() {} } diff --git a/src/libstd/sys/unix/os.rs b/src/libstd/sys/unix/os.rs index 5ef98d24710..d8c30534eed 100644 --- a/src/libstd/sys/unix/os.rs +++ b/src/libstd/sys/unix/os.rs @@ -483,12 +483,10 @@ pub fn home_dir() -> Option { #[cfg(any(target_os = "android", target_os = "ios", - target_os = "nacl", target_os = "emscripten"))] unsafe fn fallback() -> Option { None } #[cfg(not(any(target_os = "android", target_os = "ios", - target_os = "nacl", target_os = "emscripten")))] unsafe fn fallback() -> Option { let amt = match libc::sysconf(libc::_SC_GETPW_R_SIZE_MAX) { diff --git a/src/libstd/sys/unix/process/process_common.rs b/src/libstd/sys/unix/process/process_common.rs index 689ccd78524..383434b1cd8 100644 --- a/src/libstd/sys/unix/process/process_common.rs +++ b/src/libstd/sys/unix/process/process_common.rs @@ -464,7 +464,6 @@ mod tests { // test from being flaky we ignore it on macOS. #[test] #[cfg_attr(target_os = "macos", ignore)] - #[cfg_attr(target_os = "nacl", ignore)] // no signals on NaCl. // When run under our current QEMU emulation test suite this test fails, // although the reason isn't very clear as to why. For now this test is // ignored there. diff --git a/src/libstd/sys/unix/process/process_unix.rs b/src/libstd/sys/unix/process/process_unix.rs index 870db820027..743c458d580 100644 --- a/src/libstd/sys/unix/process/process_unix.rs +++ b/src/libstd/sys/unix/process/process_unix.rs @@ -184,8 +184,8 @@ impl Command { *sys::os::environ() = envp.as_ptr(); } - // NaCl has no signal support. - #[cfg(not(any(target_os = "nacl", target_os = "emscripten")))] + // emscripten has no signal support. + #[cfg(not(any(target_os = "emscripten")))] { use mem; // Reset signal handling so the child process starts in a diff --git a/src/libstd/sys_common/backtrace.rs b/src/libstd/sys_common/backtrace.rs index 617218fe7a5..8f78c2e6f59 100644 --- a/src/libstd/sys_common/backtrace.rs +++ b/src/libstd/sys_common/backtrace.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#![cfg_attr(target_os = "nacl", allow(dead_code))] - /// Common code for printing the backtrace in the same way across the different /// supported platforms. From 329b901b50639232ca59fe839beda89cecbe1c85 Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 5 Oct 2017 05:04:40 +0200 Subject: [PATCH 10/42] Remove nacl from libtest --- src/libtest/lib.rs | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/libtest/lib.rs b/src/libtest/lib.rs index 642eb285564..e8a1242c814 100644 --- a/src/libtest/lib.rs +++ b/src/libtest/lib.rs @@ -1554,16 +1554,14 @@ impl MetricMap { /// elimination. /// /// This function is a no-op, and does not even read from `dummy`. -#[cfg(not(any(all(target_os = "nacl", target_arch = "le32"), - target_arch = "asmjs", target_arch = "wasm32")))] +#[cfg(not(any(target_arch = "asmjs", target_arch = "wasm32")))] pub fn black_box(dummy: T) -> T { // we need to "use" the argument in some way LLVM can't // introspect. unsafe { asm!("" : : "r"(&dummy)) } dummy } -#[cfg(any(all(target_os = "nacl", target_arch = "le32"), - target_arch = "asmjs", target_arch = "wasm32"))] +#[cfg(any(target_arch = "asmjs", target_arch = "wasm32"))] #[inline(never)] pub fn black_box(dummy: T) -> T { dummy From 327116a423c71754192945a319eef64947fd59df Mon Sep 17 00:00:00 2001 From: est31 Date: Thu, 5 Oct 2017 05:04:50 +0200 Subject: [PATCH 11/42] Remove nacl from librustdoc --- src/librustdoc/clean/cfg.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/librustdoc/clean/cfg.rs b/src/librustdoc/clean/cfg.rs index da8c3a5cf20..e3ce403f3c1 100644 --- a/src/librustdoc/clean/cfg.rs +++ b/src/librustdoc/clean/cfg.rs @@ -337,7 +337,6 @@ impl<'a> fmt::Display for Html<'a> { "l4re" => "L4Re", "linux" => "Linux", "macos" => "macOS", - "nacl" => "NaCl", "netbsd" => "NetBSD", "openbsd" => "OpenBSD", "redox" => "Redox", @@ -886,4 +885,4 @@ mod test { only." ); } -} \ No newline at end of file +} From 19884470076efdeaa03af634b27f306fffc92289 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 6 Oct 2017 07:06:30 -0700 Subject: [PATCH 12/42] rustc: Reduce default CGUs to 16 Rationale explained in the included comment as well as #44941 --- src/librustc/session/config.rs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 7c1d457a6ee..ca9603277a7 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1716,7 +1716,7 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches) let codegen_units = codegen_units.unwrap_or_else(|| { match opt_level { - // If we're compiling at `-O0` then default to 32 codegen units. + // If we're compiling at `-O0` then default to 16 codegen units. // The number here shouldn't matter too too much as debug mode // builds don't rely on performance at all, meaning that lost // opportunities for inlining through multiple codegen units is @@ -1734,7 +1734,21 @@ pub fn build_session_options_and_crate_config(matches: &getopts::Matches) // unit takes *too* long to build we'll be guaranteed that all // cpus will finish pretty closely to one another and we should // make relatively optimal use of system resources - OptLevel::No => 32, + // + // Another note worth mentioning here, however, is that this number + // isn't *too* high. When codegen units are increased that means we + // currently have to codegen `#[inline]` functions into each codegen + // unit, which means the more codegen units we're using the more we + // may be generating. In other words, increasing codegen units may + // increase the overall work the compiler does. If we don't have + // enough cores to make up for this loss then increasing the number + // of codegen units could become an overall loss! + // + // As a result we choose a hopefully conservative value 16, which + // should be more than the number of cpus of most hardware compiling + // Rust but also not too much for 2-4 core machines to have too much + // loss of compile time. + OptLevel::No => 16, // All other optimization levels default use one codegen unit, // the historical default in Rust for a Long Time. From 904133e1e28b690e2bbd101b719509aa897539a0 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Fri, 6 Oct 2017 16:39:01 -0400 Subject: [PATCH 13/42] Revert to using mem::transmute in Box::into_unique Seems to cause this error: "Cannot handle boxed::Box<[u8]> represented as TyLayout". --- src/liballoc/boxed.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 512c7194fe3..6b92da11079 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -326,9 +326,7 @@ impl Box { issue = "27730")] #[inline] pub fn into_unique(b: Box) -> Unique { - let u = b.0; - mem::forget(b); - u + unsafe { mem::transmute(b) } } } From 452b71a07be066432d93a93c1f9e7f10e18d7c96 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Fri, 6 Oct 2017 17:01:50 -0400 Subject: [PATCH 14/42] Revert to using mem::transmute in Box::from_raw Same reasons as commit 904133e1e28b690e2bbd101b719509aa897539a0. --- src/liballoc/boxed.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 6b92da11079..2e77b1b390c 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -269,7 +269,7 @@ impl Box { #[stable(feature = "box_raw", since = "1.4.0")] #[inline] pub unsafe fn from_raw(raw: *mut T) -> Self { - Box(Unique::new_unchecked(raw)) + mem::transmute(raw) } /// Consumes the `Box`, returning the wrapped raw pointer. From 5ce5b2fe76802385e2974bdec8d82117fb55d0ea Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Fri, 6 Oct 2017 17:29:49 -0400 Subject: [PATCH 15/42] Create Box::from_unique function Provides a reasonable interface for Box::from_raw implementation. Does not get around the requirement of mem::transmute for converting back and forth between Unique and Box. --- src/liballoc/boxed.rs | 38 +++++++++++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 3 deletions(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 2e77b1b390c..53d643e7288 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -269,7 +269,34 @@ impl Box { #[stable(feature = "box_raw", since = "1.4.0")] #[inline] pub unsafe fn from_raw(raw: *mut T) -> Self { - mem::transmute(raw) + Box::from_unique(Unique::new_unchecked(raw)) + } + + /// Constructs a `Box` from a `Unique` pointer. + /// + /// After calling this function, the memory is owned by a `Box` and `T` then + /// be destroyed and released upon drop. + /// + /// # Safety + /// + /// A `Unique` can be safely created via [`Unique::new`] and thus doesn't + /// necessarily own the data pointed to nor is the data guaranteed to live + /// as long as the pointer. + /// + /// [`Unique::new`]: ../../core/ptr/struct.Unique.html#method.new + /// + /// # Examples + /// + /// ``` + /// let x = Box::new(5); + /// let ptr = Box::into_unique(x); + /// let x = unsafe { Box::from_unique(ptr) }; + /// ``` + #[unstable(feature = "unique", reason = "needs an RFC to flesh out design", + issue = "27730")] + #[inline] + pub unsafe fn from_unique(u: Unique) -> Self { + mem::transmute(u) } /// Consumes the `Box`, returning the wrapped raw pointer. @@ -303,13 +330,18 @@ impl Box { /// After calling this function, the caller is responsible for the /// memory previously managed by the `Box`. In particular, the /// caller should properly destroy `T` and release the memory. The - /// proper way to do so is to convert the raw pointer back into a - /// `Box` with the [`Box::from_raw`] function. + /// proper way to do so is to either convert the `Unique` pointer: + /// + /// - Into a `Box` with the [`Box::from_unique`] function. + /// + /// - Into a raw pointer and back into a `Box` with the [`Box::from_raw`] + /// function. /// /// Note: this is an associated function, which means that you have /// to call it as `Box::into_unique(b)` instead of `b.into_unique()`. This /// is so that there is no conflict with a method on the inner type. /// + /// [`Box::from_unique`]: struct.Box.html#method.from_unique /// [`Box::from_raw`]: struct.Box.html#method.from_raw /// /// # Examples From 5af88ee9969320ef900190e1e6a8247d800b7fe6 Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Fri, 6 Oct 2017 17:39:38 -0400 Subject: [PATCH 16/42] Add missing word in Box::from_unique docs --- src/liballoc/boxed.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 53d643e7288..2c14dfb1dd0 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -274,8 +274,8 @@ impl Box { /// Constructs a `Box` from a `Unique` pointer. /// - /// After calling this function, the memory is owned by a `Box` and `T` then - /// be destroyed and released upon drop. + /// After calling this function, the memory is owned by a `Box` and `T` can + /// then be destroyed and released upon drop. /// /// # Safety /// From 22298b8240d40ed9b3dbdf570bccce56dfbfcd2c Mon Sep 17 00:00:00 2001 From: Nikolai Vazquez Date: Fri, 6 Oct 2017 19:21:22 -0400 Subject: [PATCH 17/42] Add unique feature in Box::from_unique docs --- src/liballoc/boxed.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/liballoc/boxed.rs b/src/liballoc/boxed.rs index 2c14dfb1dd0..0d19b74ebae 100644 --- a/src/liballoc/boxed.rs +++ b/src/liballoc/boxed.rs @@ -288,9 +288,13 @@ impl Box { /// # Examples /// /// ``` - /// let x = Box::new(5); - /// let ptr = Box::into_unique(x); - /// let x = unsafe { Box::from_unique(ptr) }; + /// #![feature(unique)] + /// + /// fn main() { + /// let x = Box::new(5); + /// let ptr = Box::into_unique(x); + /// let x = unsafe { Box::from_unique(ptr) }; + /// } /// ``` #[unstable(feature = "unique", reason = "needs an RFC to flesh out design", issue = "27730")] From 7d1c14a32d9b09681d8050b30e35c30c7058d8b7 Mon Sep 17 00:00:00 2001 From: Robin Kruppe Date: Sat, 7 Oct 2017 18:04:23 +0200 Subject: [PATCH 18/42] Fix typo in codegen test --- src/test/codegen/float_math.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/codegen/float_math.rs b/src/test/codegen/float_math.rs index bc458d45446..6a6d6f90b2e 100644 --- a/src/test/codegen/float_math.rs +++ b/src/test/codegen/float_math.rs @@ -19,7 +19,7 @@ use std::intrinsics::{fadd_fast, fsub_fast, fmul_fast, fdiv_fast, frem_fast}; #[no_mangle] pub fn add(x: f32, y: f32) -> f32 { // CHECK: fadd float -// CHECK-NOT fast +// CHECK-NOT: fast x + y } From 07b189977d88d1de595601e7137275e4f4ccd8a2 Mon Sep 17 00:00:00 2001 From: kennytm Date: Sun, 8 Oct 2017 01:39:27 +0800 Subject: [PATCH 19/42] debuginfo-test: Fix #45086. LLDB's output may be None instead of '', and that will cause type mismatch when normalize_whitespace() expects a string instead of None. This commit simply ensures we do pass '' even if the output is None. --- src/etc/lldb_batchmode.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/etc/lldb_batchmode.py b/src/etc/lldb_batchmode.py index 4952cf4f82c..24a0ce0ac36 100644 --- a/src/etc/lldb_batchmode.py +++ b/src/etc/lldb_batchmode.py @@ -81,7 +81,7 @@ def execute_command(command_interpreter, command): if res.Succeeded(): if res.HasResult(): - print(normalize_whitespace(res.GetOutput()), end='\n') + print(normalize_whitespace(res.GetOutput() or ''), end='\n') # If the command introduced any breakpoints, make sure to register # them with the breakpoint From 3fff2d95bf90514e66892ca9be666c35eeae9165 Mon Sep 17 00:00:00 2001 From: Ulrik Sverdrup Date: Sat, 7 Oct 2017 21:33:36 +0200 Subject: [PATCH 20/42] core: Ensure std::mem::Discriminant is Send + Sync `PhantomData<*const T>` has the implication of Send / Syncness following the *const T type, but the discriminant should always be Send and Sync. Use `PhantomData T>` which has the same variance in T, but is Send + Sync --- src/libcore/mem.rs | 2 +- src/libcore/tests/mem.rs | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/libcore/mem.rs b/src/libcore/mem.rs index e085d427b8c..680a0f5b2c0 100644 --- a/src/libcore/mem.rs +++ b/src/libcore/mem.rs @@ -836,7 +836,7 @@ pub unsafe fn transmute_copy(src: &T) -> U { /// /// See the `discriminant` function in this module for more information. #[stable(feature = "discriminant_value", since = "1.21.0")] -pub struct Discriminant(u64, PhantomData<*const T>); +pub struct Discriminant(u64, PhantomData T>); // N.B. These trait implementations cannot be derived because we don't want any bounds on T. diff --git a/src/libcore/tests/mem.rs b/src/libcore/tests/mem.rs index 86e59c736ba..f55a1c81463 100644 --- a/src/libcore/tests/mem.rs +++ b/src/libcore/tests/mem.rs @@ -121,3 +121,19 @@ fn test_transmute() { } } +#[test] +#[allow(dead_code)] +fn test_discriminant_send_sync() { + enum Regular { + A, + B(i32) + } + enum NotSendSync { + A(*const i32) + } + + fn is_send_sync() { } + + is_send_sync::>(); + is_send_sync::>(); +} From 4b2bdf7b543df0ae28ce27db700ad46d9be59eed Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 6 Oct 2017 14:59:33 -0700 Subject: [PATCH 21/42] rustc: Don't inline in CGUs at -O0 This commit tweaks the behavior of inlining functions into multiple codegen units when rustc is compiling in debug mode. Today rustc will unconditionally treat `#[inline]` functions by translating them into all codegen units that they're needed within, marking the linkage as `internal`. This commit changes the behavior so that in debug mode (compiling at `-O0`) rustc will instead only translate `#[inline]` functions into *one* codegen unit, forcing all other codegen units to reference this one copy. The goal here is to improve debug compile times by reducing the amount of translation that happens on behalf of multiple codegen units. It was discovered in #44941 that increasing the number of codegen units had the adverse side effect of increasing the overal work done by the compiler, and the suspicion here was that the compiler was inlining, translating, and codegen'ing more functions with more codegen units (for example `String` would be basically inlined into all codegen units if used). The strategy in this commit should reduce the cost of `#[inline]` functions to being equivalent to one codegen unit, which is only translating and codegen'ing inline functions once. Collected [data] shows that this does indeed improve the situation from [before] as the overall cpu-clock time increases at a much slower rate and when pinned to one core rustc does not consume significantly more wall clock time than with one codegen unit. One caveat of this commit is that the symbol names for inlined functions that are only translated once needed some slight tweaking. These inline functions could be translated into multiple crates and we need to make sure the symbols don't collideA so the crate name/disambiguator is mixed in to the symbol name hash in these situations. [data]: https://github.com/rust-lang/rust/issues/44941#issuecomment-334880911 [before]: https://github.com/rust-lang/rust/issues/44941#issuecomment-334583384 --- src/librustc/session/config.rs | 2 + src/librustc_trans/back/symbol_names.rs | 52 +++++--- src/librustc_trans/collector.rs | 6 +- src/librustc_trans/partitioning.rs | 111 +++++++++--------- src/librustc_trans/trans_item.rs | 37 +++++- .../drop_in_place_intrinsic.rs | 1 + .../item-collection/generic-drop-glue.rs | 1 + .../instantiation-through-vtable.rs | 1 + .../item-collection/non-generic-drop-glue.rs | 1 + .../item-collection/transitive-drop-glue.rs | 1 + .../item-collection/tuple-drop-glue.rs | 1 + .../codegen-units/item-collection/unsizing.rs | 1 + .../partitioning/extern-drop-glue.rs | 1 + .../inlining-from-extern-crate.rs | 1 + .../partitioning/local-drop-glue.rs | 1 + .../local-inlining-but-not-all.rs | 54 +++++++++ .../partitioning/local-inlining.rs | 1 + .../partitioning/local-transitive-inlining.rs | 1 + .../partitioning/vtable-through-const.rs | 1 + src/test/run-make/sepcomp-cci-copies/Makefile | 3 +- src/test/run-make/sepcomp-inlining/Makefile | 3 +- 21 files changed, 200 insertions(+), 81 deletions(-) create mode 100644 src/test/codegen-units/partitioning/local-inlining-but-not-all.rs diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index 6ef64ef3d96..44dc04f0895 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1097,6 +1097,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "generate a graphical HTML report of time spent in trans and LLVM"), thinlto: bool = (false, parse_bool, [TRACKED], "enable ThinLTO when possible"), + inline_in_all_cgus: Option = (None, parse_opt_bool, [TRACKED], + "control whether #[inline] functions are in all cgus"), } pub fn default_lib_output() -> CrateType { diff --git a/src/librustc_trans/back/symbol_names.rs b/src/librustc_trans/back/symbol_names.rs index 306071223fc..66a27f1c4a9 100644 --- a/src/librustc_trans/back/symbol_names.rs +++ b/src/librustc_trans/back/symbol_names.rs @@ -98,8 +98,10 @@ //! DefPaths which are much more robust in the face of changes to the code base. use monomorphize::Instance; +use trans_item::{TransItemExt, InstantiationMode}; use rustc::middle::weak_lang_items; +use rustc::middle::trans::TransItem; use rustc::hir::def_id::DefId; use rustc::hir::map as hir_map; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; @@ -150,7 +152,10 @@ pub fn provide(providers: &mut Providers) { fn get_symbol_hash<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // the DefId of the item this name is for - def_id: Option, + def_id: DefId, + + // instance this name will be for + instance: Instance<'tcx>, // type of the item, without any generic // parameters substituted; this is @@ -160,7 +165,7 @@ fn get_symbol_hash<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // values for generic type parameters, // if any. - substs: Option<&'tcx Substs<'tcx>>) + substs: &'tcx Substs<'tcx>) -> u64 { debug!("get_symbol_hash(def_id={:?}, parameters={:?})", def_id, substs); @@ -170,7 +175,7 @@ fn get_symbol_hash<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, // the main symbol name is not necessarily unique; hash in the // compiler's internal def-path, guaranteeing each symbol has a // truly unique path - hasher.hash(def_id.map(|def_id| tcx.def_path_hash(def_id))); + hasher.hash(tcx.def_path_hash(def_id)); // Include the main item-type. Note that, in this case, the // assertions about `needs_subst` may not hold, but this item-type @@ -186,19 +191,36 @@ fn get_symbol_hash<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } // also include any type parameters (for generic items) - if let Some(substs) = substs { - assert!(!substs.has_erasable_regions()); - assert!(!substs.needs_subst()); - substs.visit_with(&mut hasher); + assert!(!substs.has_erasable_regions()); + assert!(!substs.needs_subst()); + substs.visit_with(&mut hasher); - // If this is an instance of a generic function, we also hash in - // the ID of the instantiating crate. This avoids symbol conflicts - // in case the same instances is emitted in two crates of the same - // project. - if substs.types().next().is_some() { - hasher.hash(tcx.crate_name.as_str()); - hasher.hash(tcx.sess.local_crate_disambiguator().as_str()); + let mut avoid_cross_crate_conflicts = false; + + // If this is an instance of a generic function, we also hash in + // the ID of the instantiating crate. This avoids symbol conflicts + // in case the same instances is emitted in two crates of the same + // project. + if substs.types().next().is_some() { + avoid_cross_crate_conflicts = true; + } + + // If we're dealing with an instance of a function that's inlined from + // another crate but we're marking it as globally shared to our + // compliation (aka we're not making an internal copy in each of our + // codegen units) then this symbol may become an exported (but hidden + // visibility) symbol. This means that multiple crates may do the same + // and we want to be sure to avoid any symbol conflicts here. + match TransItem::Fn(instance).instantiation_mode(tcx) { + InstantiationMode::GloballyShared { may_conflict: true } => { + avoid_cross_crate_conflicts = true; } + _ => {} + } + + if avoid_cross_crate_conflicts { + hasher.hash(tcx.crate_name.as_str()); + hasher.hash(tcx.sess.local_crate_disambiguator().as_str()); } }); @@ -309,7 +331,7 @@ fn compute_symbol_name<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, instance: Instance // and should not matter anyhow. let instance_ty = tcx.erase_regions(&instance_ty); - let hash = get_symbol_hash(tcx, Some(def_id), instance_ty, Some(substs)); + let hash = get_symbol_hash(tcx, def_id, instance, instance_ty, substs); SymbolPathBuffer::from_interned(tcx.def_symbol_name(def_id)).finish(hash) } diff --git a/src/librustc_trans/collector.rs b/src/librustc_trans/collector.rs index 73df1b45c59..9d1e36fa581 100644 --- a/src/librustc_trans/collector.rs +++ b/src/librustc_trans/collector.rs @@ -401,9 +401,9 @@ fn collect_items_rec<'a, 'tcx: 'a>(tcx: TyCtxt<'a, 'tcx, 'tcx>, } fn record_accesses<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, - caller: TransItem<'tcx>, - callees: &[TransItem<'tcx>], - inlining_map: &mut InliningMap<'tcx>) { + caller: TransItem<'tcx>, + callees: &[TransItem<'tcx>], + inlining_map: &mut InliningMap<'tcx>) { let is_inlining_candidate = |trans_item: &TransItem<'tcx>| { trans_item.instantiation_mode(tcx) == InstantiationMode::LocalCopy }; diff --git a/src/librustc_trans/partitioning.rs b/src/librustc_trans/partitioning.rs index 82ec1aaa413..e4bfd994868 100644 --- a/src/librustc_trans/partitioning.rs +++ b/src/librustc_trans/partitioning.rs @@ -279,75 +279,74 @@ fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>, let mut internalization_candidates = FxHashSet(); for trans_item in trans_items { - let is_root = trans_item.instantiation_mode(tcx) == InstantiationMode::GloballyShared; + match trans_item.instantiation_mode(tcx) { + InstantiationMode::GloballyShared { .. } => {} + InstantiationMode::LocalCopy => continue, + } - if is_root { - let characteristic_def_id = characteristic_def_id_of_trans_item(tcx, trans_item); - let is_volatile = is_incremental_build && - trans_item.is_generic_fn(); + let characteristic_def_id = characteristic_def_id_of_trans_item(tcx, trans_item); + let is_volatile = is_incremental_build && + trans_item.is_generic_fn(); - let codegen_unit_name = match characteristic_def_id { - Some(def_id) => compute_codegen_unit_name(tcx, def_id, is_volatile), - None => Symbol::intern(FALLBACK_CODEGEN_UNIT).as_str(), - }; + let codegen_unit_name = match characteristic_def_id { + Some(def_id) => compute_codegen_unit_name(tcx, def_id, is_volatile), + None => Symbol::intern(FALLBACK_CODEGEN_UNIT).as_str(), + }; - let make_codegen_unit = || { - CodegenUnit::new(codegen_unit_name.clone()) - }; + let make_codegen_unit = || { + CodegenUnit::new(codegen_unit_name.clone()) + }; - let codegen_unit = codegen_units.entry(codegen_unit_name.clone()) - .or_insert_with(make_codegen_unit); + let codegen_unit = codegen_units.entry(codegen_unit_name.clone()) + .or_insert_with(make_codegen_unit); - let (linkage, visibility) = match trans_item.explicit_linkage(tcx) { - Some(explicit_linkage) => (explicit_linkage, Visibility::Default), - None => { - match trans_item { - TransItem::Fn(ref instance) => { - let visibility = match instance.def { - InstanceDef::Item(def_id) => { - if def_id.is_local() { - if tcx.is_exported_symbol(def_id) { - Visibility::Default - } else { - internalization_candidates.insert(trans_item); - Visibility::Hidden - } + let (linkage, visibility) = match trans_item.explicit_linkage(tcx) { + Some(explicit_linkage) => (explicit_linkage, Visibility::Default), + None => { + match trans_item { + TransItem::Fn(ref instance) => { + let visibility = match instance.def { + InstanceDef::Item(def_id) => { + if def_id.is_local() { + if tcx.is_exported_symbol(def_id) { + Visibility::Default } else { - internalization_candidates.insert(trans_item); Visibility::Hidden } + } else { + Visibility::Hidden } - InstanceDef::FnPtrShim(..) | - InstanceDef::Virtual(..) | - InstanceDef::Intrinsic(..) | - InstanceDef::ClosureOnceShim { .. } | - InstanceDef::DropGlue(..) | - InstanceDef::CloneShim(..) => { - bug!("partitioning: Encountered unexpected - root translation item: {:?}", - trans_item) - } - }; - (Linkage::External, visibility) - } - TransItem::Static(node_id) | - TransItem::GlobalAsm(node_id) => { - let def_id = tcx.hir.local_def_id(node_id); - let visibility = if tcx.is_exported_symbol(def_id) { - Visibility::Default - } else { - internalization_candidates.insert(trans_item); + } + InstanceDef::FnPtrShim(..) | + InstanceDef::Virtual(..) | + InstanceDef::Intrinsic(..) | + InstanceDef::ClosureOnceShim { .. } | + InstanceDef::DropGlue(..) | + InstanceDef::CloneShim(..) => { Visibility::Hidden - }; - (Linkage::External, visibility) - } + } + }; + (Linkage::External, visibility) + } + TransItem::Static(node_id) | + TransItem::GlobalAsm(node_id) => { + let def_id = tcx.hir.local_def_id(node_id); + let visibility = if tcx.is_exported_symbol(def_id) { + Visibility::Default + } else { + Visibility::Hidden + }; + (Linkage::External, visibility) } } - }; - - codegen_unit.items_mut().insert(trans_item, (linkage, visibility)); - roots.insert(trans_item); + } + }; + if visibility == Visibility::Hidden { + internalization_candidates.insert(trans_item); } + + codegen_unit.items_mut().insert(trans_item, (linkage, visibility)); + roots.insert(trans_item); } // always ensure we have at least one CGU; otherwise, if we have a diff --git a/src/librustc_trans/trans_item.rs b/src/librustc_trans/trans_item.rs index 526b61303e1..e40b1617d0a 100644 --- a/src/librustc_trans/trans_item.rs +++ b/src/librustc_trans/trans_item.rs @@ -26,6 +26,7 @@ use monomorphize::Instance; use rustc::hir; use rustc::hir::def_id::DefId; use rustc::middle::trans::{Linkage, Visibility}; +use rustc::session::config::OptLevel; use rustc::traits; use rustc::ty::{self, Ty, TyCtxt, TypeFoldable}; use rustc::ty::subst::{Subst, Substs}; @@ -44,7 +45,20 @@ pub use rustc::middle::trans::TransItem; pub enum InstantiationMode { /// There will be exactly one instance of the given TransItem. It will have /// external linkage so that it can be linked to from other codegen units. - GloballyShared, + GloballyShared { + /// In some compilation scenarios we may decide to take functions that + /// are typically `LocalCopy` and instead move them to `GloballyShared` + /// to avoid translating them a bunch of times. In this situation, + /// however, our local copy may conflict with other crates also + /// inlining the same function. + /// + /// This flag indicates that this situation is occuring, and informs + /// symbol name calculation that some extra mangling is needed to + /// avoid conflicts. Note that this may eventually go away entirely if + /// ThinLTO enables us to *always* have a globally shared instance of a + /// function within one crate's compilation. + may_conflict: bool, + }, /// Each codegen unit containing a reference to the given TransItem will /// have its own private copy of the function (with internal linkage). @@ -154,18 +168,31 @@ pub trait TransItemExt<'a, 'tcx>: fmt::Debug { fn instantiation_mode(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>) -> InstantiationMode { + let inline_in_all_cgus = + tcx.sess.opts.debugging_opts.inline_in_all_cgus.unwrap_or_else(|| { + tcx.sess.opts.optimize != OptLevel::No + }); + match *self.as_trans_item() { TransItem::Fn(ref instance) => { if self.explicit_linkage(tcx).is_none() && common::requests_inline(tcx, instance) { - InstantiationMode::LocalCopy + if inline_in_all_cgus { + InstantiationMode::LocalCopy + } else { + InstantiationMode::GloballyShared { may_conflict: true } + } } else { - InstantiationMode::GloballyShared + InstantiationMode::GloballyShared { may_conflict: false } } } - TransItem::Static(..) => InstantiationMode::GloballyShared, - TransItem::GlobalAsm(..) => InstantiationMode::GloballyShared, + TransItem::Static(..) => { + InstantiationMode::GloballyShared { may_conflict: false } + } + TransItem::GlobalAsm(..) => { + InstantiationMode::GloballyShared { may_conflict: false } + } } } diff --git a/src/test/codegen-units/item-collection/drop_in_place_intrinsic.rs b/src/test/codegen-units/item-collection/drop_in_place_intrinsic.rs index bd1325e7501..b8033b88fb7 100644 --- a/src/test/codegen-units/item-collection/drop_in_place_intrinsic.rs +++ b/src/test/codegen-units/item-collection/drop_in_place_intrinsic.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // compile-flags:-Zprint-trans-items=eager +// compile-flags:-Zinline-in-all-cgus //~ TRANS_ITEM fn core::ptr[0]::drop_in_place[0] @@ drop_in_place_intrinsic0[Internal] struct StructWithDtor(u32); diff --git a/src/test/codegen-units/item-collection/generic-drop-glue.rs b/src/test/codegen-units/item-collection/generic-drop-glue.rs index 108a8b570de..65936d12e31 100644 --- a/src/test/codegen-units/item-collection/generic-drop-glue.rs +++ b/src/test/codegen-units/item-collection/generic-drop-glue.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // compile-flags:-Zprint-trans-items=eager +// compile-flags:-Zinline-in-all-cgus #![deny(dead_code)] diff --git a/src/test/codegen-units/item-collection/instantiation-through-vtable.rs b/src/test/codegen-units/item-collection/instantiation-through-vtable.rs index 875cacb3907..e32366d15c3 100644 --- a/src/test/codegen-units/item-collection/instantiation-through-vtable.rs +++ b/src/test/codegen-units/item-collection/instantiation-through-vtable.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // compile-flags:-Zprint-trans-items=eager +// compile-flags:-Zinline-in-all-cgus #![deny(dead_code)] diff --git a/src/test/codegen-units/item-collection/non-generic-drop-glue.rs b/src/test/codegen-units/item-collection/non-generic-drop-glue.rs index a6081b2c5eb..5765f230e8b 100644 --- a/src/test/codegen-units/item-collection/non-generic-drop-glue.rs +++ b/src/test/codegen-units/item-collection/non-generic-drop-glue.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // compile-flags:-Zprint-trans-items=eager +// compile-flags:-Zinline-in-all-cgus #![deny(dead_code)] diff --git a/src/test/codegen-units/item-collection/transitive-drop-glue.rs b/src/test/codegen-units/item-collection/transitive-drop-glue.rs index 8eef5f00f2a..be560690e51 100644 --- a/src/test/codegen-units/item-collection/transitive-drop-glue.rs +++ b/src/test/codegen-units/item-collection/transitive-drop-glue.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // compile-flags:-Zprint-trans-items=eager +// compile-flags:-Zinline-in-all-cgus #![deny(dead_code)] diff --git a/src/test/codegen-units/item-collection/tuple-drop-glue.rs b/src/test/codegen-units/item-collection/tuple-drop-glue.rs index 7edb1c14525..ad1475a73f7 100644 --- a/src/test/codegen-units/item-collection/tuple-drop-glue.rs +++ b/src/test/codegen-units/item-collection/tuple-drop-glue.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // compile-flags:-Zprint-trans-items=eager +// compile-flags:-Zinline-in-all-cgus #![deny(dead_code)] diff --git a/src/test/codegen-units/item-collection/unsizing.rs b/src/test/codegen-units/item-collection/unsizing.rs index cf0c6643238..d7e457cde8a 100644 --- a/src/test/codegen-units/item-collection/unsizing.rs +++ b/src/test/codegen-units/item-collection/unsizing.rs @@ -10,6 +10,7 @@ // ignore-tidy-linelength // compile-flags:-Zprint-trans-items=eager +// compile-flags:-Zinline-in-all-cgus #![deny(dead_code)] #![feature(coerce_unsized)] diff --git a/src/test/codegen-units/partitioning/extern-drop-glue.rs b/src/test/codegen-units/partitioning/extern-drop-glue.rs index 4e6ae167024..29528644ed0 100644 --- a/src/test/codegen-units/partitioning/extern-drop-glue.rs +++ b/src/test/codegen-units/partitioning/extern-drop-glue.rs @@ -13,6 +13,7 @@ // We specify -Z incremental here because we want to test the partitioning for // incremental compilation // compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/extern-drop-glue +// compile-flags:-Zinline-in-all-cgus #![allow(dead_code)] #![crate_type="lib"] diff --git a/src/test/codegen-units/partitioning/inlining-from-extern-crate.rs b/src/test/codegen-units/partitioning/inlining-from-extern-crate.rs index 20920c9ebe4..4bfd35b59bc 100644 --- a/src/test/codegen-units/partitioning/inlining-from-extern-crate.rs +++ b/src/test/codegen-units/partitioning/inlining-from-extern-crate.rs @@ -12,6 +12,7 @@ // We specify -Z incremental here because we want to test the partitioning for // incremental compilation // compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/inlining-from-extern-crate +// compile-flags:-Zinline-in-all-cgus #![crate_type="lib"] diff --git a/src/test/codegen-units/partitioning/local-drop-glue.rs b/src/test/codegen-units/partitioning/local-drop-glue.rs index d2ce847e108..65e91343ccf 100644 --- a/src/test/codegen-units/partitioning/local-drop-glue.rs +++ b/src/test/codegen-units/partitioning/local-drop-glue.rs @@ -12,6 +12,7 @@ // We specify -Z incremental here because we want to test the partitioning for // incremental compilation // compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/local-drop-glue +// compile-flags:-Zinline-in-all-cgus #![allow(dead_code)] #![crate_type="lib"] diff --git a/src/test/codegen-units/partitioning/local-inlining-but-not-all.rs b/src/test/codegen-units/partitioning/local-inlining-but-not-all.rs new file mode 100644 index 00000000000..ccc8f03a40f --- /dev/null +++ b/src/test/codegen-units/partitioning/local-inlining-but-not-all.rs @@ -0,0 +1,54 @@ +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// ignore-tidy-linelength +// We specify -Z incremental here because we want to test the partitioning for +// incremental compilation +// compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/local-inlining-but-not-all +// compile-flags:-Zinline-in-all-cgus=no + +#![allow(dead_code)] +#![crate_type="lib"] + +mod inline { + + //~ TRANS_ITEM fn local_inlining_but_not_all::inline[0]::inlined_function[0] @@ local_inlining_but_not_all-inline[External] + #[inline(always)] + pub fn inlined_function() + { + + } +} + +mod user1 { + use super::inline; + + //~ TRANS_ITEM fn local_inlining_but_not_all::user1[0]::foo[0] @@ local_inlining_but_not_all-user1[Internal] + fn foo() { + inline::inlined_function(); + } +} + +mod user2 { + use super::inline; + + //~ TRANS_ITEM fn local_inlining_but_not_all::user2[0]::bar[0] @@ local_inlining_but_not_all-user2[Internal] + fn bar() { + inline::inlined_function(); + } +} + +mod non_user { + + //~ TRANS_ITEM fn local_inlining_but_not_all::non_user[0]::baz[0] @@ local_inlining_but_not_all-non_user[Internal] + fn baz() { + + } +} diff --git a/src/test/codegen-units/partitioning/local-inlining.rs b/src/test/codegen-units/partitioning/local-inlining.rs index a4d9e60d228..f3176191241 100644 --- a/src/test/codegen-units/partitioning/local-inlining.rs +++ b/src/test/codegen-units/partitioning/local-inlining.rs @@ -12,6 +12,7 @@ // We specify -Z incremental here because we want to test the partitioning for // incremental compilation // compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/local-inlining +// compile-flags:-Zinline-in-all-cgus #![allow(dead_code)] #![crate_type="lib"] diff --git a/src/test/codegen-units/partitioning/local-transitive-inlining.rs b/src/test/codegen-units/partitioning/local-transitive-inlining.rs index 1beaa186d9e..bda76a8789f 100644 --- a/src/test/codegen-units/partitioning/local-transitive-inlining.rs +++ b/src/test/codegen-units/partitioning/local-transitive-inlining.rs @@ -12,6 +12,7 @@ // We specify -Z incremental here because we want to test the partitioning for // incremental compilation // compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/local-transitive-inlining +// compile-flags:-Zinline-in-all-cgus #![allow(dead_code)] #![crate_type="lib"] diff --git a/src/test/codegen-units/partitioning/vtable-through-const.rs b/src/test/codegen-units/partitioning/vtable-through-const.rs index 74f2f843567..302f9312b57 100644 --- a/src/test/codegen-units/partitioning/vtable-through-const.rs +++ b/src/test/codegen-units/partitioning/vtable-through-const.rs @@ -13,6 +13,7 @@ // We specify -Z incremental here because we want to test the partitioning for // incremental compilation // compile-flags:-Zprint-trans-items=lazy -Zincremental=tmp/partitioning-tests/vtable-through-const +// compile-flags:-Zinline-in-all-cgus // This test case makes sure, that references made through constants are // recorded properly in the InliningMap. diff --git a/src/test/run-make/sepcomp-cci-copies/Makefile b/src/test/run-make/sepcomp-cci-copies/Makefile index 8324a074d6c..ccd4e1b0e71 100644 --- a/src/test/run-make/sepcomp-cci-copies/Makefile +++ b/src/test/run-make/sepcomp-cci-copies/Makefile @@ -5,5 +5,6 @@ all: $(RUSTC) cci_lib.rs - $(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3 + $(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3 \ + -Z inline-in-all-cgus [ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ .*cci_fn)" -eq "2" ] diff --git a/src/test/run-make/sepcomp-inlining/Makefile b/src/test/run-make/sepcomp-inlining/Makefile index 6dc837b8a78..1d20d940000 100644 --- a/src/test/run-make/sepcomp-inlining/Makefile +++ b/src/test/run-make/sepcomp-inlining/Makefile @@ -7,7 +7,8 @@ # in only one compilation unit. all: - $(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3 + $(RUSTC) foo.rs --emit=llvm-ir -C codegen-units=3 \ + -Z inline-in-all-cgus [ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ i32\ .*inlined)" -eq "0" ] [ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ internal\ i32\ .*inlined)" -eq "2" ] [ "$$(cat "$(TMPDIR)"/foo.*.ll | grep -c define\ hidden\ i32\ .*normal)" -eq "1" ] From 6f4e942ef96f92e61f40c0d1bd889e66b0de3cfd Mon Sep 17 00:00:00 2001 From: Michael Hewson Date: Sat, 7 Oct 2017 23:51:43 -0400 Subject: [PATCH 22/42] update comments referring to old check_method_self_type - function has been renamed to check_method_receiver --- src/librustc_typeck/astconv.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustc_typeck/astconv.rs b/src/librustc_typeck/astconv.rs index af8cc2c806a..6b7a5b3af96 100644 --- a/src/librustc_typeck/astconv.rs +++ b/src/librustc_typeck/astconv.rs @@ -1464,7 +1464,7 @@ impl<'tcx> ExplicitSelf<'tcx> { /// declaration like `self: SomeType` into either `self`, /// `&self`, `&mut self`, or `Box`. We do this here /// by some simple pattern matching. A more precise check - /// is done later in `check_method_self_type()`. + /// is done later in `check_method_receiver()`. /// /// Examples: /// @@ -1475,7 +1475,7 @@ impl<'tcx> ExplicitSelf<'tcx> { /// fn method2(self: &T); // ExplicitSelf::ByValue /// fn method3(self: Box<&T>); // ExplicitSelf::ByBox /// - /// // Invalid cases will be caught later by `check_method_self_type`: + /// // Invalid cases will be caught later by `check_method_receiver`: /// fn method_err1(self: &mut T); // ExplicitSelf::ByReference /// } /// ``` From f108fce21cd025ead58ced8c21a8156fe339e26f Mon Sep 17 00:00:00 2001 From: Chris Wong Date: Sun, 8 Oct 2017 21:42:33 +1300 Subject: [PATCH 23/42] Make the result of `Literal::string()` more readable Closes #45076 --- src/libproc_macro/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libproc_macro/lib.rs b/src/libproc_macro/lib.rs index e6307f10c13..cf30966fa89 100644 --- a/src/libproc_macro/lib.rs +++ b/src/libproc_macro/lib.rs @@ -488,7 +488,7 @@ impl Literal { pub fn string(string: &str) -> Literal { let mut escaped = String::new(); for ch in string.chars() { - escaped.extend(ch.escape_unicode()); + escaped.extend(ch.escape_debug()); } Literal(token::Literal(token::Lit::Str_(Symbol::intern(&escaped)), None)) } From b5b7666120658e332c1ea26e8bb3944aefde31ca Mon Sep 17 00:00:00 2001 From: Jake Goulding Date: Sun, 1 Oct 2017 14:55:58 -0400 Subject: [PATCH 24/42] Don't encourage people to ignore threading errors in the docs --- src/libstd/thread/mod.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/libstd/thread/mod.rs b/src/libstd/thread/mod.rs index 30887b16c60..07bbddc62b9 100644 --- a/src/libstd/thread/mod.rs +++ b/src/libstd/thread/mod.rs @@ -485,15 +485,17 @@ impl Builder { /// let (tx, rx) = channel(); /// /// let sender = thread::spawn(move || { -/// let _ = tx.send("Hello, thread".to_owned()); +/// tx.send("Hello, thread".to_owned()) +/// .expect("Unable to send on channel"); /// }); /// /// let receiver = thread::spawn(move || { -/// println!("{}", rx.recv().unwrap()); +/// let value = rx.recv().expect("Unable to receive from channel"); +/// println!("{}", value); /// }); /// -/// let _ = sender.join(); -/// let _ = receiver.join(); +/// sender.join().expect("The sender thread has panicked"); +/// receiver.join().expect("The receiver thread has panicked"); /// ``` /// /// A thread can also return a value through its [`JoinHandle`], you can use @@ -1192,7 +1194,7 @@ impl JoinInner { /// }); /// }); /// -/// let _ = original_thread.join(); +/// original_thread.join().expect("The thread being joined has panicked"); /// println!("Original thread is joined."); /// /// // We make sure that the new thread has time to run, before the main From 19029d5627218aa01f52c68b27dec71d39974cd7 Mon Sep 17 00:00:00 2001 From: Pirh Date: Sun, 8 Oct 2017 17:12:14 +0100 Subject: [PATCH 25/42] Add links and examples for std::process::Stdio As per #29370 --- src/libstd/process.rs | 109 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 108 insertions(+), 1 deletion(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index dbb58991215..2b3f49ee3f7 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -742,21 +742,128 @@ impl fmt::Debug for Output { } } -/// Describes what to do with a standard I/O stream for a child process. +/// Describes what to do with a standard I/O stream for a child process when +/// passed to the [`stdin`], [`stdout`], and [`stderr`] methods of [`Command`]. +/// +/// [`stdin`]: ./struct.Command.html#method.stdin +/// [`stdout`]: ./struct.Command.html#method.stdout +/// [`stderr`]: ./struct.Command.html#method.stderr +/// [`Command`]: ./struct.Command.html #[stable(feature = "process", since = "1.0.0")] pub struct Stdio(imp::Stdio); impl Stdio { /// A new pipe should be arranged to connect the parent and child processes. + /// + /// # Examples + /// + /// With stdout: + /// + /// ```no_run + /// use std::process::{Command, Stdio}; + /// + /// let output = Command::new("echo") + /// .arg("Hello, world!") + /// .stdout(Stdio::piped()) + /// .output() + /// .expect("Failed to execute command"); + /// + /// assert_eq!(String::from_utf8_lossy(&output.stdout), "Hello, world!\n"); + /// // Nothing echoed to console + /// ``` + /// + /// With stdin: + /// + /// ```no_run + /// use std::io::Write; + /// use std::process::{Command, Stdio}; + /// + /// let mut child = Command::new("rev") + /// .stdin(Stdio::piped()) + /// .stdout(Stdio::piped()) + /// .spawn() + /// .expect("Failed to spawn child process"); + /// + /// { + /// let mut stdin = child.stdin.as_mut().expect("Failed to open stdin"); + /// stdin.write_all("Hello, world!".as_bytes()).expect("Failed to write to stdin"); + /// } + /// + /// let output = child.wait_with_output().expect("Failed to read stdout"); + /// assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH\n"); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn piped() -> Stdio { Stdio(imp::Stdio::MakePipe) } /// The child inherits from the corresponding parent descriptor. + /// + /// # Examples + /// + /// With stdout: + /// + /// ```no_run + /// use std::process::{Command, Stdio}; + /// + /// let output = Command::new("echo") + /// .arg("Hello, world!") + /// .stdout(Stdio::inherit()) + /// .output() + /// .expect("Failed to execute command"); + /// + /// assert_eq!(String::from_utf8_lossy(&output.stdout), ""); + /// // "Hello, world!" echoed to console + /// ``` + /// + /// With stdin: + /// + /// ```no_run + /// use std::process::{Command, Stdio}; + /// + /// let output = Command::new("rev") + /// .stdin(Stdio::inherit()) + /// .stdout(Stdio::piped()) + /// .output() + /// .expect("Failed to execute command"); + /// + /// println!("You piped in the reverse of: {}", String::from_utf8_lossy(&output.stdout)); + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn inherit() -> Stdio { Stdio(imp::Stdio::Inherit) } /// This stream will be ignored. This is the equivalent of attaching the /// stream to `/dev/null` + /// + /// # Examples + /// + /// With stdout: + /// + /// ```no_run + /// use std::process::{Command, Stdio}; + /// + /// let output = Command::new("echo") + /// .arg("Hello, world!") + /// .stdout(Stdio::null()) + /// .output() + /// .expect("Failed to execute command"); + /// + /// assert_eq!(String::from_utf8_lossy(&output.stdout), ""); + /// // Nothing echoed to console + /// ``` + /// + /// With stdin: + /// + /// ```no_run + /// use std::process::{Command, Stdio}; + /// + /// let output = Command::new("rev") + /// .stdin(Stdio::null()) + /// .stdout(Stdio::piped()) + /// .output() + /// .expect("Failed to execute command"); + /// + /// assert_eq!(String::from_utf8_lossy(&output.stdout), ""); + /// // Ignores any piped-in input + /// ``` #[stable(feature = "process", since = "1.0.0")] pub fn null() -> Stdio { Stdio(imp::Stdio::Null) } } From e8ba32e7a07dbcba124cceeee8c75535309084aa Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Sun, 8 Oct 2017 18:19:51 +0200 Subject: [PATCH 26/42] Fix data-layout field The value was generated according to [this comment by @japaric](https://github.com/rust-lang/rust/issues/31367#issuecomment-213595571). --- src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json b/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json index c1dd0cf4063..3ae01d72fcc 100644 --- a/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json +++ b/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json @@ -1,6 +1,6 @@ { "pre-link-args": ["-m64"], - "data-layout": "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128", + "data-layout": "e-m:e-i64:64-f80:128-n8:16:32:64-S128", "linker-flavor": "gcc", "llvm-target": "x86_64-unknown-linux-gnu", "target-endian": "little", From 977200310abe3ca6c71d467e585654537b5309c2 Mon Sep 17 00:00:00 2001 From: Pirh Date: Sun, 8 Oct 2017 19:09:16 +0100 Subject: [PATCH 27/42] Remove ./ prefix from relative URLs Also remove trailing whitespace to pass tidy checks. --- src/libstd/process.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/libstd/process.rs b/src/libstd/process.rs index 2b3f49ee3f7..af64e681820 100644 --- a/src/libstd/process.rs +++ b/src/libstd/process.rs @@ -745,10 +745,10 @@ impl fmt::Debug for Output { /// Describes what to do with a standard I/O stream for a child process when /// passed to the [`stdin`], [`stdout`], and [`stderr`] methods of [`Command`]. /// -/// [`stdin`]: ./struct.Command.html#method.stdin -/// [`stdout`]: ./struct.Command.html#method.stdout -/// [`stderr`]: ./struct.Command.html#method.stderr -/// [`Command`]: ./struct.Command.html +/// [`stdin`]: struct.Command.html#method.stdin +/// [`stdout`]: struct.Command.html#method.stdout +/// [`stderr`]: struct.Command.html#method.stderr +/// [`Command`]: struct.Command.html #[stable(feature = "process", since = "1.0.0")] pub struct Stdio(imp::Stdio); @@ -783,12 +783,12 @@ impl Stdio { /// .stdout(Stdio::piped()) /// .spawn() /// .expect("Failed to spawn child process"); - /// + /// /// { /// let mut stdin = child.stdin.as_mut().expect("Failed to open stdin"); /// stdin.write_all("Hello, world!".as_bytes()).expect("Failed to write to stdin"); /// } - /// + /// /// let output = child.wait_with_output().expect("Failed to read stdout"); /// assert_eq!(String::from_utf8_lossy(&output.stdout), "!dlrow ,olleH\n"); /// ``` @@ -818,13 +818,13 @@ impl Stdio { /// /// ```no_run /// use std::process::{Command, Stdio}; - /// + /// /// let output = Command::new("rev") /// .stdin(Stdio::inherit()) /// .stdout(Stdio::piped()) /// .output() /// .expect("Failed to execute command"); - /// + /// /// println!("You piped in the reverse of: {}", String::from_utf8_lossy(&output.stdout)); /// ``` #[stable(feature = "process", since = "1.0.0")] @@ -854,13 +854,13 @@ impl Stdio { /// /// ```no_run /// use std::process::{Command, Stdio}; - /// + /// /// let output = Command::new("rev") /// .stdin(Stdio::null()) /// .stdout(Stdio::piped()) /// .output() /// .expect("Failed to execute command"); - /// + /// /// assert_eq!(String::from_utf8_lossy(&output.stdout), ""); /// // Ignores any piped-in input /// ``` From 911d95bfe3076f2ed61798a1cf7373db9852c64f Mon Sep 17 00:00:00 2001 From: Aidan Hobson Sayers Date: Sun, 8 Oct 2017 21:57:03 +0100 Subject: [PATCH 28/42] Don't panic in the coordinator thread, bubble up the failure Fixes #43402 (take 2) --- src/librustc_trans/back/write.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index 1988b9f76e4..de07ee8b36f 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -1192,7 +1192,7 @@ fn start_executing_work(tcx: TyCtxt, modules_config: Arc, metadata_config: Arc, allocator_config: Arc) - -> thread::JoinHandle { + -> thread::JoinHandle> { let coordinator_send = tcx.tx_to_llvm_workers.clone(); let mut exported_symbols = FxHashMap(); exported_symbols.insert(LOCAL_CRATE, tcx.exported_symbols(LOCAL_CRATE)); @@ -1638,7 +1638,7 @@ fn start_executing_work(tcx: TyCtxt, Message::Done { result: Err(()), worker_id: _ } => { shared_emitter.fatal("aborting due to worker thread failure"); // Exit the coordinator thread - panic!("aborting due to worker thread failure") + return Err(()) } Message::TranslateItem => { bug!("the coordinator should not receive translation requests") @@ -1664,11 +1664,11 @@ fn start_executing_work(tcx: TyCtxt, let compiled_metadata_module = compiled_metadata_module .expect("Metadata module not compiled?"); - CompiledModules { + Ok(CompiledModules { modules: compiled_modules, metadata_module: compiled_metadata_module, allocator_module: compiled_allocator_module, - } + }) }); // A heuristic that determines if we have enough LLVM WorkItems in the @@ -1960,7 +1960,7 @@ pub struct OngoingCrateTranslation { coordinator_send: Sender>, trans_worker_receive: Receiver, shared_emitter_main: SharedEmitterMain, - future: thread::JoinHandle, + future: thread::JoinHandle>, output_filenames: Arc, } @@ -1968,7 +1968,11 @@ impl OngoingCrateTranslation { pub fn join(self, sess: &Session, dep_graph: &DepGraph) -> CrateTranslation { self.shared_emitter_main.check(sess, true); let compiled_modules = match self.future.join() { - Ok(compiled_modules) => compiled_modules, + Ok(Ok(compiled_modules)) => compiled_modules, + Ok(Err(())) => { + sess.abort_if_errors(); + panic!("expected abort due to worker thread errors") + }, Err(_) => { sess.fatal("Error during translation/LLVM phase."); } From 1c4add9c7cebc1220cb3c05da88b11830bb16ecd Mon Sep 17 00:00:00 2001 From: johnthagen Date: Sun, 8 Oct 2017 19:11:34 -0400 Subject: [PATCH 29/42] Fix typo in comment --- src/bootstrap/configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 67337bf4421..29eee0442e2 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -346,7 +346,7 @@ for target in configured_targets: targets[target][0] = targets[target][0].replace("x86_64-unknown-linux-gnu", target) # Here we walk through the constructed configuration we have from the parsed -# command line arguemnts. We then apply each piece of configuration by +# command line arguments. We then apply each piece of configuration by # basically just doing a `sed` to change the various configuration line to what # we've got configure. def to_toml(value): From 9e569d7671339ceaecfde6e0c86f9494cf1f3d04 Mon Sep 17 00:00:00 2001 From: johnthagen Date: Sun, 8 Oct 2017 19:15:17 -0400 Subject: [PATCH 30/42] Fix typo in README --- src/bootstrap/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/README.md b/src/bootstrap/README.md index e543b8c070b..ebacc62b0fd 100644 --- a/src/bootstrap/README.md +++ b/src/bootstrap/README.md @@ -39,7 +39,7 @@ The script accepts commands, flags, and arguments to determine what to do: ``` If files are dirty that would normally be rebuilt from stage 0, that can be - overidden using `--keep-stage 0`. Using `--keep-stage n` will skip all steps + overridden using `--keep-stage 0`. Using `--keep-stage n` will skip all steps that belong to stage n or earlier: ``` From dee517a286de6387ad75291f3f8068ada99f2a92 Mon Sep 17 00:00:00 2001 From: johnthagen Date: Sun, 8 Oct 2017 19:28:21 -0400 Subject: [PATCH 31/42] Fix trying to raise a bare str as an exception. This has been deprecated since Python 2.5 --- src/bootstrap/configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 67337bf4421..176e9435528 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -360,7 +360,7 @@ def to_toml(value): elif isinstance(value, str): return "'" + value + "'" else: - raise 'no toml' + raise RuntimeError('no toml') def configure_section(lines, config): for key in config: From 430e875b262b5e14870057004ea9abb4c3a9762d Mon Sep 17 00:00:00 2001 From: johnthagen Date: Sun, 8 Oct 2017 19:36:37 -0400 Subject: [PATCH 32/42] Fix variable name reference --- src/bootstrap/configure.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/configure.py b/src/bootstrap/configure.py index 67337bf4421..0a8e57e6225 100755 --- a/src/bootstrap/configure.py +++ b/src/bootstrap/configure.py @@ -378,7 +378,7 @@ def configure_section(lines, config): for section_key in config: section_config = config[section_key] if not section_key in sections: - raise RuntimeError("config key {} not in sections".format(key)) + raise RuntimeError("config key {} not in sections".format(section_key)) if section_key == 'target': for target in section_config: From d9e67038346d0b3f6509c7d881f1dc63b04cd160 Mon Sep 17 00:00:00 2001 From: johnthagen Date: Sun, 8 Oct 2017 19:46:58 -0400 Subject: [PATCH 33/42] Use identity operator `is` when comparing to None --- src/bootstrap/bootstrap.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bootstrap/bootstrap.py b/src/bootstrap/bootstrap.py index 4a8c3dcebcb..25768867439 100644 --- a/src/bootstrap/bootstrap.py +++ b/src/bootstrap/bootstrap.py @@ -498,7 +498,7 @@ class RustBuild(object): If the key does not exists, the result is None: - >>> rb.get_toml("key3") == None + >>> rb.get_toml("key3") is None True """ for line in self.config_toml.splitlines(): From 8240b872e42f066dc57ac7c59e2970f7a5456c32 Mon Sep 17 00:00:00 2001 From: Brian Leibig Date: Sun, 8 Oct 2017 18:46:42 -0700 Subject: [PATCH 34/42] Update grammar to parse current rust syntax --- src/grammar/lexer.l | 73 +++++--- src/grammar/parser-lalr.y | 366 ++++++++++++++++++++++---------------- src/grammar/tokens.h | 18 ++ 3 files changed, 271 insertions(+), 186 deletions(-) diff --git a/src/grammar/lexer.l b/src/grammar/lexer.l index 91652bfdf24..2f282c8281d 100644 --- a/src/grammar/lexer.l +++ b/src/grammar/lexer.l @@ -85,16 +85,23 @@ ident [a-zA-Z\x80-\xff_][a-zA-Z0-9\x80-\xff_]* (.|\n) { } _ { return UNDERSCORE; } +abstract { return ABSTRACT; } +alignof { return ALIGNOF; } as { return AS; } +become { return BECOME; } box { return BOX; } break { return BREAK; } +catch { return CATCH; } const { return CONST; } continue { return CONTINUE; } crate { return CRATE; } +default { return DEFAULT; } +do { return DO; } else { return ELSE; } enum { return ENUM; } extern { return EXTERN; } false { return FALSE; } +final { return FINAL; } fn { return FN; } for { return FOR; } if { return IF; } @@ -102,26 +109,36 @@ impl { return IMPL; } in { return IN; } let { return LET; } loop { return LOOP; } +macro { return MACRO; } match { return MATCH; } mod { return MOD; } move { return MOVE; } mut { return MUT; } +offsetof { return OFFSETOF; } +override { return OVERRIDE; } priv { return PRIV; } proc { return PROC; } +pure { return PURE; } pub { return PUB; } ref { return REF; } return { return RETURN; } self { return SELF; } +sizeof { return SIZEOF; } static { return STATIC; } struct { return STRUCT; } +super { return SUPER; } trait { return TRAIT; } true { return TRUE; } type { return TYPE; } typeof { return TYPEOF; } +union { return UNION; } unsafe { return UNSAFE; } +unsized { return UNSIZED; } use { return USE; } +virtual { return VIRTUAL; } where { return WHERE; } while { return WHILE; } +yield { return YIELD; } {ident} { return IDENT; } @@ -189,25 +206,25 @@ while { return WHILE; } \>\>= { return SHREQ; } \> { return '>'; } -\x27 { BEGIN(ltorchar); yymore(); } -static { BEGIN(INITIAL); return STATIC_LIFETIME; } -{ident} { BEGIN(INITIAL); return LIFETIME; } -\\[nrt\\\x27\x220]\x27 { BEGIN(suffix); return LIT_CHAR; } -\\x[0-9a-fA-F]{2}\x27 { BEGIN(suffix); return LIT_CHAR; } -\\u\{[0-9a-fA-F]?{6}\}\x27 { BEGIN(suffix); return LIT_CHAR; } -.\x27 { BEGIN(suffix); return LIT_CHAR; } -[\x80-\xff]{2,4}\x27 { BEGIN(suffix); return LIT_CHAR; } -<> { BEGIN(INITIAL); return -1; } +\x27 { BEGIN(ltorchar); yymore(); } +static { BEGIN(INITIAL); return STATIC_LIFETIME; } +{ident} { BEGIN(INITIAL); return LIFETIME; } +\\[nrt\\\x27\x220]\x27 { BEGIN(suffix); return LIT_CHAR; } +\\x[0-9a-fA-F]{2}\x27 { BEGIN(suffix); return LIT_CHAR; } +\\u\{([0-9a-fA-F]_*){1,6}\}\x27 { BEGIN(suffix); return LIT_CHAR; } +.\x27 { BEGIN(suffix); return LIT_CHAR; } +[\x80-\xff]{2,4}\x27 { BEGIN(suffix); return LIT_CHAR; } +<> { BEGIN(INITIAL); return -1; } b\x22 { BEGIN(bytestr); yymore(); } \x22 { BEGIN(suffix); return LIT_BYTE_STR; } -<> { return -1; } -\\[n\nrt\\\x27\x220] { yymore(); } -\\x[0-9a-fA-F]{2} { yymore(); } -\\u\{[0-9a-fA-F]?{6}\} { yymore(); } -\\[^n\nrt\\\x27\x220] { return -1; } -(.|\n) { yymore(); } +<> { return -1; } +\\[n\nrt\\\x27\x220] { yymore(); } +\\x[0-9a-fA-F]{2} { yymore(); } +\\u\{([0-9a-fA-F]_*){1,6}\} { yymore(); } +\\[^n\nrt\\\x27\x220] { return -1; } +(.|\n) { yymore(); } br\x22 { BEGIN(rawbytestr_nohash); yymore(); } \x22 { BEGIN(suffix); return LIT_BYTE_STR_RAW; } @@ -252,13 +269,13 @@ br/# { } <> { return -1; } -b\x27 { BEGIN(byte); yymore(); } -\\[nrt\\\x27\x220]\x27 { BEGIN(INITIAL); return LIT_BYTE; } -\\x[0-9a-fA-F]{2}\x27 { BEGIN(INITIAL); return LIT_BYTE; } -\\u[0-9a-fA-F]{4}\x27 { BEGIN(INITIAL); return LIT_BYTE; } -\\U[0-9a-fA-F]{8}\x27 { BEGIN(INITIAL); return LIT_BYTE; } -.\x27 { BEGIN(INITIAL); return LIT_BYTE; } -<> { BEGIN(INITIAL); return -1; } +b\x27 { BEGIN(byte); yymore(); } +\\[nrt\\\x27\x220]\x27 { BEGIN(INITIAL); return LIT_BYTE; } +\\x[0-9a-fA-F]{2}\x27 { BEGIN(INITIAL); return LIT_BYTE; } +\\u([0-9a-fA-F]_*){4}\x27 { BEGIN(INITIAL); return LIT_BYTE; } +\\U([0-9a-fA-F]_*){8}\x27 { BEGIN(INITIAL); return LIT_BYTE; } +.\x27 { BEGIN(INITIAL); return LIT_BYTE; } +<> { BEGIN(INITIAL); return -1; } r\x22 { BEGIN(rawstr); yymore(); } \x22 { BEGIN(suffix); return LIT_STR_RAW; } @@ -310,12 +327,12 @@ r/# { \x22 { BEGIN(str); yymore(); } \x22 { BEGIN(suffix); return LIT_STR; } -<> { return -1; } -\\[n\nr\rt\\\x27\x220] { yymore(); } -\\x[0-9a-fA-F]{2} { yymore(); } -\\u\{[0-9a-fA-F]?{6}\} { yymore(); } -\\[^n\nrt\\\x27\x220] { return -1; } -(.|\n) { yymore(); } +<> { return -1; } +\\[n\nr\rt\\\x27\x220] { yymore(); } +\\x[0-9a-fA-F]{2} { yymore(); } +\\u\{([0-9a-fA-F]_*){1,6}\} { yymore(); } +\\[^n\nrt\\\x27\x220] { return -1; } +(.|\n) { yymore(); } \<- { return LARROW; } -\> { return RARROW; } diff --git a/src/grammar/parser-lalr.y b/src/grammar/parser-lalr.y index c9fcdf7647b..de1f96aac50 100644 --- a/src/grammar/parser-lalr.y +++ b/src/grammar/parser-lalr.y @@ -62,13 +62,19 @@ extern char *yytext; // keywords %token SELF %token STATIC +%token ABSTRACT +%token ALIGNOF %token AS +%token BECOME %token BREAK +%token CATCH %token CRATE +%token DO %token ELSE %token ENUM %token EXTERN %token FALSE +%token FINAL %token FN %token FOR %token IF @@ -76,19 +82,29 @@ extern char *yytext; %token IN %token LET %token LOOP +%token MACRO %token MATCH %token MOD %token MOVE %token MUT +%token OFFSETOF +%token OVERRIDE %token PRIV %token PUB +%token PURE %token REF %token RETURN +%token SIZEOF %token STRUCT +%token SUPER +%token UNION +%token UNSIZED %token TRUE %token TRAIT %token TYPE %token UNSAFE +%token VIRTUAL +%token YIELD %token DEFAULT %token USE %token WHILE @@ -141,6 +157,10 @@ extern char *yytext; // 'foo:bar . <' is shifted (in a trait reference occurring in a // bounds list), parsing as foo:(bar) rather than (foo:bar). %precedence IDENT + // Put the weak keywords that can be used as idents here as well +%precedence CATCH +%precedence DEFAULT +%precedence UNION // A couple fake-precedence symbols to use in rules associated with + // and < in trailing type contexts. These come up when you have a type @@ -161,13 +181,13 @@ extern char *yytext; %precedence FOR // Binops & unops, and their precedences +%precedence '?' %precedence BOX -%precedence BOXPLACE %nonassoc DOTDOT // RETURN needs to be lower-precedence than tokens that start // prefix_exprs -%precedence RETURN +%precedence RETURN YIELD %right '=' SHLEQ SHREQ MINUSEQ ANDEQ OREQ PLUSEQ STAREQ SLASHEQ CARETEQ PERCENTEQ %right LARROW @@ -321,6 +341,8 @@ view_path | path_no_types_allowed MOD_SEP '{' idents_or_self ',' '}' { $$ = mk_node("ViewPathList", 2, $1, $4); } | MOD_SEP '{' idents_or_self ',' '}' { $$ = mk_node("ViewPathList", 1, $3); } | path_no_types_allowed MOD_SEP '*' { $$ = mk_node("ViewPathGlob", 1, $1); } +| MOD_SEP '*' { $$ = mk_atom("ViewPathGlob"); } +| '*' { $$ = mk_atom("ViewPathGlob"); } | '{' '}' { $$ = mk_atom("ViewPathListEmpty"); } | '{' idents_or_self '}' { $$ = mk_node("ViewPathList", 1, $2); } | '{' idents_or_self ',' '}' { $$ = mk_node("ViewPathList", 1, $2); } @@ -334,6 +356,7 @@ block_item | item_foreign_mod { $$ = mk_node("ItemForeignMod", 1, $1); } | item_struct | item_enum +| item_union | item_trait | item_impl ; @@ -387,6 +410,7 @@ struct_decl_field struct_tuple_fields : struct_tuple_field { $$ = mk_node("StructFields", 1, $1); } | struct_tuple_fields ',' struct_tuple_field { $$ = ext_node($1, 1, $3); } +| %empty { $$ = mk_none(); } ; struct_tuple_field @@ -417,6 +441,11 @@ enum_args | %empty { $$ = mk_none(); } ; +// unions +item_union +: UNION ident generic_params maybe_where_clause '{' struct_decl_fields '}' { $$ = mk_node("ItemUnion", 0); } +| UNION ident generic_params maybe_where_clause '{' struct_decl_fields ',' '}' { $$ = mk_node("ItemUnion", 0); } + item_mod : MOD ident ';' { $$ = mk_node("ItemMod", 1, $2); } | MOD ident '{' maybe_mod_items '}' { $$ = mk_node("ItemMod", 2, $2, $4); } @@ -475,7 +504,7 @@ visibility idents_or_self : ident_or_self { $$ = mk_node("IdentsOrSelf", 1, $1); } -| ident_or_self AS ident { $$ = mk_node("IdentsOrSelf", 2, $1, $3); } +| idents_or_self AS ident { $$ = mk_node("IdentsOrSelf", 2, $1, $3); } | idents_or_self ',' ident_or_self { $$ = ext_node($1, 1, $3); } ; @@ -515,6 +544,7 @@ trait_item : trait_const | trait_type | trait_method +| maybe_outer_attrs item_macro { $$ = mk_node("TraitMacroItem", 2, $1, $2); } ; trait_const @@ -547,36 +577,48 @@ trait_method ; type_method -: attrs_and_vis maybe_unsafe FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause ';' +: maybe_outer_attrs maybe_unsafe FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause ';' { $$ = mk_node("TypeMethod", 6, $1, $2, $4, $5, $6, $7); } -| attrs_and_vis maybe_unsafe EXTERN maybe_abi FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause ';' +| maybe_outer_attrs CONST maybe_unsafe FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause ';' +{ + $$ = mk_node("TypeMethod", 6, $1, $3, $5, $6, $7, $8); +} +| maybe_outer_attrs maybe_unsafe EXTERN maybe_abi FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause ';' { $$ = mk_node("TypeMethod", 7, $1, $2, $4, $6, $7, $8, $9); } ; method -: attrs_and_vis maybe_unsafe FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause inner_attrs_and_block +: maybe_outer_attrs maybe_unsafe FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause inner_attrs_and_block { $$ = mk_node("Method", 7, $1, $2, $4, $5, $6, $7, $8); } -| attrs_and_vis maybe_unsafe EXTERN maybe_abi FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause inner_attrs_and_block +| maybe_outer_attrs CONST maybe_unsafe FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause inner_attrs_and_block +{ + $$ = mk_node("Method", 7, $1, $3, $5, $6, $7, $8, $9); +} +| maybe_outer_attrs maybe_unsafe EXTERN maybe_abi FN ident generic_params fn_decl_with_self_allow_anon_params maybe_where_clause inner_attrs_and_block { $$ = mk_node("Method", 8, $1, $2, $4, $6, $7, $8, $9, $10); } ; impl_method -: attrs_and_vis maybe_unsafe FN ident generic_params fn_decl_with_self maybe_where_clause inner_attrs_and_block +: attrs_and_vis maybe_default maybe_unsafe FN ident generic_params fn_decl_with_self maybe_where_clause inner_attrs_and_block { - $$ = mk_node("Method", 7, $1, $2, $4, $5, $6, $7, $8); + $$ = mk_node("Method", 8, $1, $2, $3, $5, $6, $7, $8, $9); } -| attrs_and_vis maybe_unsafe EXTERN maybe_abi FN ident generic_params fn_decl_with_self maybe_where_clause inner_attrs_and_block +| attrs_and_vis maybe_default CONST maybe_unsafe FN ident generic_params fn_decl_with_self maybe_where_clause inner_attrs_and_block { $$ = mk_node("Method", 8, $1, $2, $4, $6, $7, $8, $9, $10); } +| attrs_and_vis maybe_default maybe_unsafe EXTERN maybe_abi FN ident generic_params fn_decl_with_self maybe_where_clause inner_attrs_and_block +{ + $$ = mk_node("Method", 9, $1, $2, $3, $5, $7, $8, $9, $10, $11); +} ; // There are two forms of impl: @@ -638,12 +680,17 @@ impl_item | impl_type ; +maybe_default +: DEFAULT { $$ = mk_atom("Default"); } +| %empty { $$ = mk_none(); } +; + impl_const -: attrs_and_vis item_const { $$ = mk_node("ImplConst", 1, $1, $2); } +: attrs_and_vis maybe_default item_const { $$ = mk_node("ImplConst", 3, $1, $2, $3); } ; impl_type -: attrs_and_vis TYPE ident generic_params '=' ty_sum ';' { $$ = mk_node("ImplType", 4, $1, $3, $4, $6); } +: attrs_and_vis maybe_default TYPE ident generic_params '=' ty_sum ';' { $$ = mk_node("ImplType", 5, $1, $2, $4, $5, $7); } ; item_fn @@ -651,6 +698,10 @@ item_fn { $$ = mk_node("ItemFn", 5, $2, $3, $4, $5, $6); } +| CONST FN ident generic_params fn_decl maybe_where_clause inner_attrs_and_block +{ + $$ = mk_node("ItemFn", 5, $3, $4, $5, $6, $7); +} ; item_unsafe_fn @@ -658,6 +709,10 @@ item_unsafe_fn { $$ = mk_node("ItemUnsafeFn", 5, $3, $4, $5, $6, $7); } +| CONST UNSAFE FN ident generic_params fn_decl maybe_where_clause inner_attrs_and_block +{ + $$ = mk_node("ItemUnsafeFn", 5, $4, $5, $6, $7, $8); +} | UNSAFE EXTERN maybe_abi FN ident generic_params fn_decl maybe_where_clause inner_attrs_and_block { $$ = mk_node("ItemUnsafeFn", 6, $3, $5, $6, $7, $8, $9); @@ -723,12 +778,6 @@ inferrable_param : pat maybe_ty_ascription { $$ = mk_node("InferrableParam", 2, $1, $2); } ; -maybe_unboxed_closure_kind -: %empty -| ':' -| '&' maybe_mut ':' -; - maybe_comma_params : ',' { $$ = mk_none(); } | ',' params { $$ = $2; } @@ -784,7 +833,8 @@ ret_ty ; generic_params -: '<' lifetimes '>' { $$ = mk_node("Generics", 2, $2, mk_none()); } +: '<' '>' { $$ = mk_node("Generics", 2, mk_none(), mk_none()); } +| '<' lifetimes '>' { $$ = mk_node("Generics", 2, $2, mk_none()); } | '<' lifetimes ',' '>' { $$ = mk_node("Generics", 2, $2, mk_none()); } | '<' lifetimes SHR { push_back('>'); $$ = mk_node("Generics", 2, $2, mk_none()); } | '<' lifetimes ',' SHR { push_back('>'); $$ = mk_node("Generics", 2, $2, mk_none()); } @@ -837,6 +887,8 @@ path_no_types_allowed | MOD_SEP ident { $$ = mk_node("ViewPath", 1, $2); } | SELF { $$ = mk_node("ViewPath", 1, mk_atom("Self")); } | MOD_SEP SELF { $$ = mk_node("ViewPath", 1, mk_atom("Self")); } +| SUPER { $$ = mk_node("ViewPath", 1, mk_atom("Super")); } +| MOD_SEP SUPER { $$ = mk_node("ViewPath", 1, mk_atom("Super")); } | path_no_types_allowed MOD_SEP ident { $$ = ext_node($1, 1, $3); } ; @@ -882,7 +934,7 @@ generic_args ; generic_values -: maybe_lifetimes maybe_ty_sums_and_or_bindings { $$ = mk_node("GenericValues", 2, $1, $2); } +: maybe_ty_sums_and_or_bindings { $$ = mk_node("GenericValues", 1, $1); } ; maybe_ty_sums_and_or_bindings @@ -910,12 +962,11 @@ pat | ANDAND pat { $$ = mk_node("PatRegion", 1, mk_node("PatRegion", 1, $2)); } | '(' ')' { $$ = mk_atom("PatUnit"); } | '(' pat_tup ')' { $$ = mk_node("PatTup", 1, $2); } -| '(' pat_tup ',' ')' { $$ = mk_node("PatTup", 1, $2); } | '[' pat_vec ']' { $$ = mk_node("PatVec", 1, $2); } | lit_or_path | lit_or_path DOTDOTDOT lit_or_path { $$ = mk_node("PatRange", 2, $1, $3); } | path_expr '{' pat_struct '}' { $$ = mk_node("PatStruct", 2, $1, $3); } -| path_expr '(' DOTDOT ')' { $$ = mk_node("PatEnum", 1, $1); } +| path_expr '(' ')' { $$ = mk_node("PatEnum", 2, $1, mk_none()); } | path_expr '(' pat_tup ')' { $$ = mk_node("PatEnum", 2, $1, $3); } | path_expr '!' maybe_ident delimited_token_trees { $$ = mk_node("PatMac", 3, $1, $3, $4); } | binding_mode ident { $$ = mk_node("PatIdent", 2, $1, $2); } @@ -953,6 +1004,7 @@ pat_field | BOX binding_mode ident { $$ = mk_node("PatField", 3, mk_atom("box"), $2, $3); } | ident ':' pat { $$ = mk_node("PatField", 2, $1, $3); } | binding_mode ident ':' pat { $$ = mk_node("PatField", 3, $1, $2, $4); } +| LIT_INTEGER ':' pat { $$ = mk_node("PatField", 2, mk_atom(yytext), $3); } ; pat_fields @@ -965,11 +1017,26 @@ pat_struct | pat_fields ',' { $$ = mk_node("PatStruct", 2, $1, mk_atom("false")); } | pat_fields ',' DOTDOT { $$ = mk_node("PatStruct", 2, $1, mk_atom("true")); } | DOTDOT { $$ = mk_node("PatStruct", 1, mk_atom("true")); } +| %empty { $$ = mk_node("PatStruct", 1, mk_none()); } ; pat_tup -: pat { $$ = mk_node("pat_tup", 1, $1); } -| pat_tup ',' pat { $$ = ext_node($1, 1, $3); } +: pat_tup_elts { $$ = mk_node("PatTup", 2, $1, mk_none()); } +| pat_tup_elts ',' { $$ = mk_node("PatTup", 2, $1, mk_none()); } +| pat_tup_elts DOTDOT { $$ = mk_node("PatTup", 2, $1, mk_none()); } +| pat_tup_elts ',' DOTDOT { $$ = mk_node("PatTup", 2, $1, mk_none()); } +| pat_tup_elts DOTDOT ',' pat_tup_elts { $$ = mk_node("PatTup", 2, $1, $4); } +| pat_tup_elts DOTDOT ',' pat_tup_elts ',' { $$ = mk_node("PatTup", 2, $1, $4); } +| pat_tup_elts ',' DOTDOT ',' pat_tup_elts { $$ = mk_node("PatTup", 2, $1, $5); } +| pat_tup_elts ',' DOTDOT ',' pat_tup_elts ',' { $$ = mk_node("PatTup", 2, $1, $5); } +| DOTDOT ',' pat_tup_elts { $$ = mk_node("PatTup", 2, mk_none(), $3); } +| DOTDOT ',' pat_tup_elts ',' { $$ = mk_node("PatTup", 2, mk_none(), $3); } +| DOTDOT { $$ = mk_node("PatTup", 2, mk_none(), mk_none()); } +; + +pat_tup_elts +: pat { $$ = mk_node("PatTupElts", 1, $1); } +| pat_tup_elts ',' pat { $$ = ext_node($1, 1, $3); } ; pat_vec @@ -1007,24 +1074,25 @@ ty ; ty_prim -: %prec IDENT path_generic_args_without_colons { $$ = mk_node("TyPath", 2, mk_node("global", 1, mk_atom("false")), $1); } -| %prec IDENT MOD_SEP path_generic_args_without_colons { $$ = mk_node("TyPath", 2, mk_node("global", 1, mk_atom("true")), $2); } -| %prec IDENT SELF MOD_SEP path_generic_args_without_colons { $$ = mk_node("TyPath", 2, mk_node("self", 1, mk_atom("true")), $3); } -| BOX ty { $$ = mk_node("TyBox", 1, $2); } -| '*' maybe_mut_or_const ty { $$ = mk_node("TyPtr", 2, $2, $3); } -| '&' ty { $$ = mk_node("TyRptr", 2, mk_atom("MutImmutable"), $2); } -| '&' MUT ty { $$ = mk_node("TyRptr", 2, mk_atom("MutMutable"), $3); } -| ANDAND ty { $$ = mk_node("TyRptr", 1, mk_node("TyRptr", 2, mk_atom("MutImmutable"), $2)); } -| ANDAND MUT ty { $$ = mk_node("TyRptr", 1, mk_node("TyRptr", 2, mk_atom("MutMutable"), $3)); } -| '&' lifetime maybe_mut ty { $$ = mk_node("TyRptr", 3, $2, $3, $4); } -| ANDAND lifetime maybe_mut ty { $$ = mk_node("TyRptr", 1, mk_node("TyRptr", 3, $2, $3, $4)); } -| '[' ty ']' { $$ = mk_node("TyVec", 1, $2); } -| '[' ty ',' DOTDOT expr ']' { $$ = mk_node("TyFixedLengthVec", 2, $2, $5); } -| '[' ty ';' expr ']' { $$ = mk_node("TyFixedLengthVec", 2, $2, $4); } -| TYPEOF '(' expr ')' { $$ = mk_node("TyTypeof", 1, $3); } -| UNDERSCORE { $$ = mk_atom("TyInfer"); } +: %prec IDENT path_generic_args_without_colons { $$ = mk_node("TyPath", 2, mk_node("global", 1, mk_atom("false")), $1); } +| %prec IDENT MOD_SEP path_generic_args_without_colons { $$ = mk_node("TyPath", 2, mk_node("global", 1, mk_atom("true")), $2); } +| %prec IDENT SELF MOD_SEP path_generic_args_without_colons { $$ = mk_node("TyPath", 2, mk_node("self", 1, mk_atom("true")), $3); } +| %prec IDENT path_generic_args_without_colons '!' maybe_ident delimited_token_trees { $$ = mk_node("TyMacro", 3, $1, $3, $4); } +| %prec IDENT MOD_SEP path_generic_args_without_colons '!' maybe_ident delimited_token_trees { $$ = mk_node("TyMacro", 3, $2, $4, $5); } +| BOX ty { $$ = mk_node("TyBox", 1, $2); } +| '*' maybe_mut_or_const ty { $$ = mk_node("TyPtr", 2, $2, $3); } +| '&' ty { $$ = mk_node("TyRptr", 2, mk_atom("MutImmutable"), $2); } +| '&' MUT ty { $$ = mk_node("TyRptr", 2, mk_atom("MutMutable"), $3); } +| ANDAND ty { $$ = mk_node("TyRptr", 1, mk_node("TyRptr", 2, mk_atom("MutImmutable"), $2)); } +| ANDAND MUT ty { $$ = mk_node("TyRptr", 1, mk_node("TyRptr", 2, mk_atom("MutMutable"), $3)); } +| '&' lifetime maybe_mut ty { $$ = mk_node("TyRptr", 3, $2, $3, $4); } +| ANDAND lifetime maybe_mut ty { $$ = mk_node("TyRptr", 1, mk_node("TyRptr", 3, $2, $3, $4)); } +| '[' ty ']' { $$ = mk_node("TyVec", 1, $2); } +| '[' ty ',' DOTDOT expr ']' { $$ = mk_node("TyFixedLengthVec", 2, $2, $5); } +| '[' ty ';' expr ']' { $$ = mk_node("TyFixedLengthVec", 2, $2, $4); } +| TYPEOF '(' expr ')' { $$ = mk_node("TyTypeof", 1, $3); } +| UNDERSCORE { $$ = mk_atom("TyInfer"); } | ty_bare_fn -| ty_proc | for_in_type ; @@ -1046,17 +1114,12 @@ ty_closure | OROR maybe_bounds ret_ty { $$ = mk_node("TyClosure", 2, $2, $3); } ; -ty_proc -: PROC generic_params fn_params maybe_bounds ret_ty { $$ = mk_node("TyProc", 4, $2, $3, $4, $5); } -; - for_in_type : FOR '<' maybe_lifetimes '>' for_in_type_suffix { $$ = mk_node("ForInType", 2, $3, $5); } ; for_in_type_suffix -: ty_proc -| ty_bare_fn +: ty_bare_fn | trait_ref | ty_closure ; @@ -1100,13 +1163,23 @@ ty_sums ; ty_sum -: ty { $$ = mk_node("TySum", 1, $1); } -| ty '+' ty_param_bounds { $$ = mk_node("TySum", 2, $1, $3); } +: ty_sum_elt { $$ = mk_node("TySum", 1, $1); } +| ty_sum '+' ty_sum_elt { $$ = ext_node($1, 1, $3); } +; + +ty_sum_elt +: ty +| lifetime ; ty_prim_sum -: ty_prim { $$ = mk_node("TySum", 1, $1); } -| ty_prim '+' ty_param_bounds { $$ = mk_node("TySum", 2, $1, $3); } +: ty_prim_sum_elt { $$ = mk_node("TySum", 1, $1); } +| ty_prim_sum '+' ty_prim_sum_elt { $$ = ext_node($1, 1, $3); } +; + +ty_prim_sum_elt +: ty_prim +| lifetime ; maybe_ty_param_bounds @@ -1127,6 +1200,7 @@ boundseq polybound : FOR '<' maybe_lifetimes '>' bound { $$ = mk_node("PolyBound", 2, $3, $5); } | bound +| '?' FOR '<' maybe_lifetimes '>' bound { $$ = mk_node("PolyBound", 2, $4, $6); } | '?' bound { $$ = $2; } ; @@ -1244,11 +1318,6 @@ maybe_stmts // block, nonblock-prefix, and nonblock-nonprefix. // // In non-stmts contexts, expr can relax this trichotomy. -// -// There is also one other expr subtype: nonparen_expr disallows exprs -// surrounded by parens (including tuple expressions), this is -// necessary for BOX (place) expressions, so a parens expr following -// the BOX is always parsed as the place. stmts : stmt { $$ = mk_node("stmts", 1, $1); } @@ -1256,14 +1325,15 @@ stmts ; stmt -: let +: maybe_outer_attrs let { $$ = $2; } | stmt_item | PUB stmt_item { $$ = $2; } | outer_attrs stmt_item { $$ = $2; } | outer_attrs PUB stmt_item { $$ = $3; } | full_block_expr -| block -| nonblock_expr ';' +| maybe_outer_attrs block { $$ = $2; } +| nonblock_expr ';' +| outer_attrs nonblock_expr ';' { $$ = $2; } | ';' { $$ = mk_none(); } ; @@ -1296,7 +1366,9 @@ path_expr // expressions. path_generic_args_with_colons : ident { $$ = mk_node("components", 1, $1); } +| SUPER { $$ = mk_atom("Super"); } | path_generic_args_with_colons MOD_SEP ident { $$ = ext_node($1, 1, $3); } +| path_generic_args_with_colons MOD_SEP SUPER { $$ = ext_node($1, 1, mk_atom("Super")); } | path_generic_args_with_colons MOD_SEP generic_args { $$ = ext_node($1, 1, $3); } ; @@ -1313,6 +1385,7 @@ nonblock_expr | SELF { $$ = mk_node("ExprPath", 1, mk_node("ident", 1, mk_atom("self"))); } | macro_expr { $$ = mk_node("ExprMac", 1, $1); } | path_expr '{' struct_expr_fields '}' { $$ = mk_node("ExprStruct", 2, $1, $3); } +| nonblock_expr '?' { $$ = mk_node("ExprTry", 1, $1); } | nonblock_expr '.' path_generic_args_with_colons { $$ = mk_node("ExprField", 2, $1, $3); } | nonblock_expr '.' LIT_INTEGER { $$ = mk_node("ExprTupleIndex", 1, $1); } | nonblock_expr '[' maybe_expr ']' { $$ = mk_node("ExprIndex", 2, $1, $3); } @@ -1325,6 +1398,8 @@ nonblock_expr | RETURN expr { $$ = mk_node("ExprRet", 1, $2); } | BREAK { $$ = mk_node("ExprBreak", 0); } | BREAK lifetime { $$ = mk_node("ExprBreak", 1, $2); } +| YIELD { $$ = mk_node("ExprYield", 0); } +| YIELD expr { $$ = mk_node("ExprYield", 1, $2); } | nonblock_expr LARROW expr { $$ = mk_node("ExprInPlace", 2, $1, $3); } | nonblock_expr '=' expr { $$ = mk_node("ExprAssign", 2, $1, $3); } | nonblock_expr SHLEQ expr { $$ = mk_node("ExprAssignShl", 2, $1, $3); } @@ -1360,8 +1435,8 @@ nonblock_expr | DOTDOT expr { $$ = mk_node("ExprRange", 2, mk_none(), $2); } | DOTDOT { $$ = mk_node("ExprRange", 2, mk_none(), mk_none()); } | nonblock_expr AS ty { $$ = mk_node("ExprCast", 2, $1, $3); } -| BOX nonparen_expr { $$ = mk_node("ExprBox", 1, $2); } -| %prec BOXPLACE BOX '(' maybe_expr ')' nonblock_expr { $$ = mk_node("ExprBox", 2, $3, $5); } +| nonblock_expr ':' ty { $$ = mk_node("ExprTypeAscr", 2, $1, $3); } +| BOX expr { $$ = mk_node("ExprBox", 1, $2); } | expr_qualified_path | nonblock_prefix_expr ; @@ -1373,6 +1448,7 @@ expr | SELF { $$ = mk_node("ExprPath", 1, mk_node("ident", 1, mk_atom("self"))); } | macro_expr { $$ = mk_node("ExprMac", 1, $1); } | path_expr '{' struct_expr_fields '}' { $$ = mk_node("ExprStruct", 2, $1, $3); } +| expr '?' { $$ = mk_node("ExprTry", 1, $1); } | expr '.' path_generic_args_with_colons { $$ = mk_node("ExprField", 2, $1, $3); } | expr '.' LIT_INTEGER { $$ = mk_node("ExprTupleIndex", 1, $1); } | expr '[' maybe_expr ']' { $$ = mk_node("ExprIndex", 2, $1, $3); } @@ -1385,6 +1461,8 @@ expr | RETURN expr { $$ = mk_node("ExprRet", 1, $2); } | BREAK { $$ = mk_node("ExprBreak", 0); } | BREAK ident { $$ = mk_node("ExprBreak", 1, $2); } +| YIELD { $$ = mk_node("ExprYield", 0); } +| YIELD expr { $$ = mk_node("ExprYield", 1, $2); } | expr LARROW expr { $$ = mk_node("ExprInPlace", 2, $1, $3); } | expr '=' expr { $$ = mk_node("ExprAssign", 2, $1, $3); } | expr SHLEQ expr { $$ = mk_node("ExprAssignShl", 2, $1, $3); } @@ -1420,69 +1498,8 @@ expr | DOTDOT expr { $$ = mk_node("ExprRange", 2, mk_none(), $2); } | DOTDOT { $$ = mk_node("ExprRange", 2, mk_none(), mk_none()); } | expr AS ty { $$ = mk_node("ExprCast", 2, $1, $3); } -| BOX nonparen_expr { $$ = mk_node("ExprBox", 1, $2); } -| %prec BOXPLACE BOX '(' maybe_expr ')' expr { $$ = mk_node("ExprBox", 2, $3, $5); } -| expr_qualified_path -| block_expr -| block -| nonblock_prefix_expr -; - -nonparen_expr -: lit { $$ = mk_node("ExprLit", 1, $1); } -| %prec IDENT - path_expr { $$ = mk_node("ExprPath", 1, $1); } -| SELF { $$ = mk_node("ExprPath", 1, mk_node("ident", 1, mk_atom("self"))); } -| macro_expr { $$ = mk_node("ExprMac", 1, $1); } -| path_expr '{' struct_expr_fields '}' { $$ = mk_node("ExprStruct", 2, $1, $3); } -| nonparen_expr '.' path_generic_args_with_colons { $$ = mk_node("ExprField", 2, $1, $3); } -| nonparen_expr '.' LIT_INTEGER { $$ = mk_node("ExprTupleIndex", 1, $1); } -| nonparen_expr '[' maybe_expr ']' { $$ = mk_node("ExprIndex", 2, $1, $3); } -| nonparen_expr '(' maybe_exprs ')' { $$ = mk_node("ExprCall", 2, $1, $3); } -| '[' vec_expr ']' { $$ = mk_node("ExprVec", 1, $2); } -| CONTINUE { $$ = mk_node("ExprAgain", 0); } -| CONTINUE ident { $$ = mk_node("ExprAgain", 1, $2); } -| RETURN { $$ = mk_node("ExprRet", 0); } -| RETURN expr { $$ = mk_node("ExprRet", 1, $2); } -| BREAK { $$ = mk_node("ExprBreak", 0); } -| BREAK ident { $$ = mk_node("ExprBreak", 1, $2); } -| nonparen_expr LARROW nonparen_expr { $$ = mk_node("ExprInPlace", 2, $1, $3); } -| nonparen_expr '=' nonparen_expr { $$ = mk_node("ExprAssign", 2, $1, $3); } -| nonparen_expr SHLEQ nonparen_expr { $$ = mk_node("ExprAssignShl", 2, $1, $3); } -| nonparen_expr SHREQ nonparen_expr { $$ = mk_node("ExprAssignShr", 2, $1, $3); } -| nonparen_expr MINUSEQ nonparen_expr { $$ = mk_node("ExprAssignSub", 2, $1, $3); } -| nonparen_expr ANDEQ nonparen_expr { $$ = mk_node("ExprAssignBitAnd", 2, $1, $3); } -| nonparen_expr OREQ nonparen_expr { $$ = mk_node("ExprAssignBitOr", 2, $1, $3); } -| nonparen_expr PLUSEQ nonparen_expr { $$ = mk_node("ExprAssignAdd", 2, $1, $3); } -| nonparen_expr STAREQ nonparen_expr { $$ = mk_node("ExprAssignMul", 2, $1, $3); } -| nonparen_expr SLASHEQ nonparen_expr { $$ = mk_node("ExprAssignDiv", 2, $1, $3); } -| nonparen_expr CARETEQ nonparen_expr { $$ = mk_node("ExprAssignBitXor", 2, $1, $3); } -| nonparen_expr PERCENTEQ nonparen_expr { $$ = mk_node("ExprAssignRem", 2, $1, $3); } -| nonparen_expr OROR nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiOr"), $1, $3); } -| nonparen_expr ANDAND nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiAnd"), $1, $3); } -| nonparen_expr EQEQ nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiEq"), $1, $3); } -| nonparen_expr NE nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiNe"), $1, $3); } -| nonparen_expr '<' nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiLt"), $1, $3); } -| nonparen_expr '>' nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiGt"), $1, $3); } -| nonparen_expr LE nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiLe"), $1, $3); } -| nonparen_expr GE nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiGe"), $1, $3); } -| nonparen_expr '|' nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitOr"), $1, $3); } -| nonparen_expr '^' nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitXor"), $1, $3); } -| nonparen_expr '&' nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiBitAnd"), $1, $3); } -| nonparen_expr SHL nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiShl"), $1, $3); } -| nonparen_expr SHR nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiShr"), $1, $3); } -| nonparen_expr '+' nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiAdd"), $1, $3); } -| nonparen_expr '-' nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiSub"), $1, $3); } -| nonparen_expr '*' nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiMul"), $1, $3); } -| nonparen_expr '/' nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiDiv"), $1, $3); } -| nonparen_expr '%' nonparen_expr { $$ = mk_node("ExprBinary", 3, mk_atom("BiRem"), $1, $3); } -| nonparen_expr DOTDOT { $$ = mk_node("ExprRange", 2, $1, mk_none()); } -| nonparen_expr DOTDOT nonparen_expr { $$ = mk_node("ExprRange", 2, $1, $3); } -| DOTDOT nonparen_expr { $$ = mk_node("ExprRange", 2, mk_none(), $2); } -| DOTDOT { $$ = mk_node("ExprRange", 2, mk_none(), mk_none()); } -| nonparen_expr AS ty { $$ = mk_node("ExprCast", 2, $1, $3); } -| BOX nonparen_expr { $$ = mk_node("ExprBox", 1, $2); } -| %prec BOXPLACE BOX '(' maybe_expr ')' expr { $$ = mk_node("ExprBox", 1, $3, $5); } +| expr ':' ty { $$ = mk_node("ExprTypeAscr", 2, $1, $3); } +| BOX expr { $$ = mk_node("ExprBox", 1, $2); } | expr_qualified_path | block_expr | block @@ -1495,6 +1512,7 @@ expr_nostruct path_expr { $$ = mk_node("ExprPath", 1, $1); } | SELF { $$ = mk_node("ExprPath", 1, mk_node("ident", 1, mk_atom("self"))); } | macro_expr { $$ = mk_node("ExprMac", 1, $1); } +| expr_nostruct '?' { $$ = mk_node("ExprTry", 1, $1); } | expr_nostruct '.' path_generic_args_with_colons { $$ = mk_node("ExprField", 2, $1, $3); } | expr_nostruct '.' LIT_INTEGER { $$ = mk_node("ExprTupleIndex", 1, $1); } | expr_nostruct '[' maybe_expr ']' { $$ = mk_node("ExprIndex", 2, $1, $3); } @@ -1507,6 +1525,8 @@ expr_nostruct | RETURN expr { $$ = mk_node("ExprRet", 1, $2); } | BREAK { $$ = mk_node("ExprBreak", 0); } | BREAK ident { $$ = mk_node("ExprBreak", 1, $2); } +| YIELD { $$ = mk_node("ExprYield", 0); } +| YIELD expr { $$ = mk_node("ExprYield", 1, $2); } | expr_nostruct LARROW expr_nostruct { $$ = mk_node("ExprInPlace", 2, $1, $3); } | expr_nostruct '=' expr_nostruct { $$ = mk_node("ExprAssign", 2, $1, $3); } | expr_nostruct SHLEQ expr_nostruct { $$ = mk_node("ExprAssignShl", 2, $1, $3); } @@ -1542,8 +1562,8 @@ expr_nostruct | DOTDOT expr_nostruct { $$ = mk_node("ExprRange", 2, mk_none(), $2); } | DOTDOT { $$ = mk_node("ExprRange", 2, mk_none(), mk_none()); } | expr_nostruct AS ty { $$ = mk_node("ExprCast", 2, $1, $3); } -| BOX nonparen_expr { $$ = mk_node("ExprBox", 1, $2); } -| %prec BOXPLACE BOX '(' maybe_expr ')' expr_nostruct { $$ = mk_node("ExprBox", 1, $3, $5); } +| expr_nostruct ':' ty { $$ = mk_node("ExprTypeAscr", 2, $1, $3); } +| BOX expr { $$ = mk_node("ExprBox", 1, $2); } | expr_qualified_path | block_expr | block @@ -1558,7 +1578,6 @@ nonblock_prefix_expr_nostruct | ANDAND maybe_mut expr_nostruct { $$ = mk_node("ExprAddrOf", 1, mk_node("ExprAddrOf", 2, $2, $3)); } | lambda_expr_nostruct | MOVE lambda_expr_nostruct { $$ = $2; } -| proc_expr_nostruct ; nonblock_prefix_expr @@ -1569,7 +1588,6 @@ nonblock_prefix_expr | ANDAND maybe_mut expr { $$ = mk_node("ExprAddrOf", 1, mk_node("ExprAddrOf", 2, $2, $3)); } | lambda_expr | MOVE lambda_expr { $$ = $2; } -| proc_expr ; expr_qualified_path @@ -1606,43 +1624,42 @@ maybe_as_trait_ref lambda_expr : %prec LAMBDA - OROR ret_ty expr { $$ = mk_node("ExprFnBlock", 3, mk_none(), $2, $3); } + OROR ret_ty expr { $$ = mk_node("ExprFnBlock", 3, mk_none(), $2, $3); } | %prec LAMBDA - '|' maybe_unboxed_closure_kind '|' ret_ty expr { $$ = mk_node("ExprFnBlock", 3, mk_none(), $4, $5); } + '|' '|' ret_ty expr { $$ = mk_node("ExprFnBlock", 3, mk_none(), $3, $4); } | %prec LAMBDA - '|' inferrable_params '|' ret_ty expr { $$ = mk_node("ExprFnBlock", 3, $2, $4, $5); } + '|' inferrable_params '|' ret_ty expr { $$ = mk_node("ExprFnBlock", 3, $2, $4, $5); } | %prec LAMBDA - '|' '&' maybe_mut ':' inferrable_params '|' ret_ty expr { $$ = mk_node("ExprFnBlock", 3, $5, $7, $8); } + '|' inferrable_params OROR lambda_expr_no_first_bar { $$ = mk_node("ExprFnBlock", 3, $2, mk_none(), $4); } +; + +lambda_expr_no_first_bar +: %prec LAMBDA + '|' ret_ty expr { $$ = mk_node("ExprFnBlock", 3, mk_none(), $2, $3); } | %prec LAMBDA - '|' ':' inferrable_params '|' ret_ty expr { $$ = mk_node("ExprFnBlock", 3, $3, $5, $6); } + inferrable_params '|' ret_ty expr { $$ = mk_node("ExprFnBlock", 3, $1, $3, $4); } +| %prec LAMBDA + inferrable_params OROR lambda_expr_no_first_bar { $$ = mk_node("ExprFnBlock", 3, $1, mk_none(), $3); } ; lambda_expr_nostruct : %prec LAMBDA - OROR expr_nostruct { $$ = mk_node("ExprFnBlock", 2, mk_none(), $2); } + OROR expr_nostruct { $$ = mk_node("ExprFnBlock", 2, mk_none(), $2); } | %prec LAMBDA - '|' maybe_unboxed_closure_kind '|' expr_nostruct { $$ = mk_node("ExprFnBlock", 2, mk_none(), $4); } + '|' '|' ret_ty expr_nostruct { $$ = mk_node("ExprFnBlock", 3, mk_none(), $3, $4); } | %prec LAMBDA - '|' inferrable_params '|' expr_nostruct { $$ = mk_node("ExprFnBlock", 2, $2, $4); } + '|' inferrable_params '|' expr_nostruct { $$ = mk_node("ExprFnBlock", 2, $2, $4); } | %prec LAMBDA - '|' '&' maybe_mut ':' inferrable_params '|' expr_nostruct { $$ = mk_node("ExprFnBlock", 2, $5, $7); } -| %prec LAMBDA - '|' ':' inferrable_params '|' expr_nostruct { $$ = mk_node("ExprFnBlock", 2, $3, $5); } - + '|' inferrable_params OROR lambda_expr_nostruct_no_first_bar { $$ = mk_node("ExprFnBlock", 3, $2, mk_none(), $4); } ; -proc_expr +lambda_expr_nostruct_no_first_bar : %prec LAMBDA - PROC '(' ')' expr { $$ = mk_node("ExprProc", 2, mk_none(), $4); } + '|' ret_ty expr_nostruct { $$ = mk_node("ExprFnBlock", 3, mk_none(), $2, $3); } | %prec LAMBDA - PROC '(' inferrable_params ')' expr { $$ = mk_node("ExprProc", 2, $3, $5); } -; - -proc_expr_nostruct -: %prec LAMBDA - PROC '(' ')' expr_nostruct { $$ = mk_node("ExprProc", 2, mk_none(), $4); } + inferrable_params '|' ret_ty expr_nostruct { $$ = mk_node("ExprFnBlock", 3, $1, $3, $4); } | %prec LAMBDA - PROC '(' inferrable_params ')' expr_nostruct { $$ = mk_node("ExprProc", 2, $3, $5); } + inferrable_params OROR lambda_expr_nostruct_no_first_bar { $$ = mk_node("ExprFnBlock", 3, $1, mk_none(), $3); } ; vec_expr @@ -1654,6 +1671,7 @@ struct_expr_fields : field_inits | field_inits ',' | maybe_field_inits default_field_init { $$ = ext_node($1, 1, $2); } +| %empty { $$ = mk_none(); } ; maybe_field_inits @@ -1668,7 +1686,9 @@ field_inits ; field_init -: ident ':' expr { $$ = mk_node("FieldInit", 2, $1, $3); } +: ident { $$ = mk_node("FieldInit", 1, $1); } +| ident ':' expr { $$ = mk_node("FieldInit", 2, $1, $3); } +| LIT_INTEGER ':' expr { $$ = mk_node("FieldInit", 2, mk_atom(yytext), $3); } ; default_field_init @@ -1689,10 +1709,18 @@ block_expr full_block_expr : block_expr -| full_block_expr '.' path_generic_args_with_colons %prec IDENT { $$ = mk_node("ExprField", 2, $1, $3); } -| full_block_expr '.' path_generic_args_with_colons '[' maybe_expr ']' { $$ = mk_node("ExprIndex", 3, $1, $3, $5); } -| full_block_expr '.' path_generic_args_with_colons '(' maybe_exprs ')' { $$ = mk_node("ExprCall", 3, $1, $3, $5); } -| full_block_expr '.' LIT_INTEGER { $$ = mk_node("ExprTupleIndex", 1, $1); } +| block_expr_dot +; + +block_expr_dot +: block_expr '.' path_generic_args_with_colons %prec IDENT { $$ = mk_node("ExprField", 2, $1, $3); } +| block_expr_dot '.' path_generic_args_with_colons %prec IDENT { $$ = mk_node("ExprField", 2, $1, $3); } +| block_expr '.' path_generic_args_with_colons '[' maybe_expr ']' { $$ = mk_node("ExprIndex", 3, $1, $3, $5); } +| block_expr_dot '.' path_generic_args_with_colons '[' maybe_expr ']' { $$ = mk_node("ExprIndex", 3, $1, $3, $5); } +| block_expr '.' path_generic_args_with_colons '(' maybe_exprs ')' { $$ = mk_node("ExprCall", 3, $1, $3, $5); } +| block_expr_dot '.' path_generic_args_with_colons '(' maybe_exprs ')' { $$ = mk_node("ExprCall", 3, $1, $3, $5); } +| block_expr '.' LIT_INTEGER { $$ = mk_node("ExprTupleIndex", 1, $1); } +| block_expr_dot '.' LIT_INTEGER { $$ = mk_node("ExprTupleIndex", 1, $1); } ; expr_match @@ -1714,12 +1742,13 @@ match_clause ; nonblock_match_clause -: maybe_outer_attrs pats_or maybe_guard FAT_ARROW nonblock_expr { $$ = mk_node("Arm", 4, $1, $2, $3, $5); } -| maybe_outer_attrs pats_or maybe_guard FAT_ARROW full_block_expr { $$ = mk_node("Arm", 4, $1, $2, $3, $5); } +: maybe_outer_attrs pats_or maybe_guard FAT_ARROW nonblock_expr { $$ = mk_node("ArmNonblock", 4, $1, $2, $3, $5); } +| maybe_outer_attrs pats_or maybe_guard FAT_ARROW block_expr_dot { $$ = mk_node("ArmNonblock", 4, $1, $2, $3, $5); } ; block_match_clause -: maybe_outer_attrs pats_or maybe_guard FAT_ARROW block { $$ = mk_node("Arm", 4, $1, $2, $3, $5); } +: maybe_outer_attrs pats_or maybe_guard FAT_ARROW block { $$ = mk_node("ArmBlock", 4, $1, $2, $3, $5); } +| maybe_outer_attrs pats_or maybe_guard FAT_ARROW block_expr { $$ = mk_node("ArmBlock", 4, $1, $2, $3, $5); } ; maybe_guard @@ -1796,6 +1825,10 @@ maybe_ident ident : IDENT { $$ = mk_node("ident", 1, mk_atom(yytext)); } +// Weak keywords that can be used as identifiers +| CATCH { $$ = mk_node("ident", 1, mk_atom(yytext)); } +| DEFAULT { $$ = mk_node("ident", 1, mk_atom(yytext)); } +| UNION { $$ = mk_node("ident", 1, mk_atom(yytext)); } ; unpaired_token @@ -1836,13 +1869,20 @@ unpaired_token | LIFETIME { $$ = mk_atom(yytext); } | SELF { $$ = mk_atom(yytext); } | STATIC { $$ = mk_atom(yytext); } +| ABSTRACT { $$ = mk_atom(yytext); } +| ALIGNOF { $$ = mk_atom(yytext); } | AS { $$ = mk_atom(yytext); } +| BECOME { $$ = mk_atom(yytext); } | BREAK { $$ = mk_atom(yytext); } +| CATCH { $$ = mk_atom(yytext); } | CRATE { $$ = mk_atom(yytext); } +| DEFAULT { $$ = mk_atom(yytext); } +| DO { $$ = mk_atom(yytext); } | ELSE { $$ = mk_atom(yytext); } | ENUM { $$ = mk_atom(yytext); } | EXTERN { $$ = mk_atom(yytext); } | FALSE { $$ = mk_atom(yytext); } +| FINAL { $$ = mk_atom(yytext); } | FN { $$ = mk_atom(yytext); } | FOR { $$ = mk_atom(yytext); } | IF { $$ = mk_atom(yytext); } @@ -1850,21 +1890,31 @@ unpaired_token | IN { $$ = mk_atom(yytext); } | LET { $$ = mk_atom(yytext); } | LOOP { $$ = mk_atom(yytext); } +| MACRO { $$ = mk_atom(yytext); } | MATCH { $$ = mk_atom(yytext); } | MOD { $$ = mk_atom(yytext); } | MOVE { $$ = mk_atom(yytext); } | MUT { $$ = mk_atom(yytext); } +| OFFSETOF { $$ = mk_atom(yytext); } +| OVERRIDE { $$ = mk_atom(yytext); } | PRIV { $$ = mk_atom(yytext); } | PUB { $$ = mk_atom(yytext); } +| PURE { $$ = mk_atom(yytext); } | REF { $$ = mk_atom(yytext); } | RETURN { $$ = mk_atom(yytext); } | STRUCT { $$ = mk_atom(yytext); } +| SIZEOF { $$ = mk_atom(yytext); } +| SUPER { $$ = mk_atom(yytext); } | TRUE { $$ = mk_atom(yytext); } | TRAIT { $$ = mk_atom(yytext); } | TYPE { $$ = mk_atom(yytext); } +| UNION { $$ = mk_atom(yytext); } | UNSAFE { $$ = mk_atom(yytext); } +| UNSIZED { $$ = mk_atom(yytext); } | USE { $$ = mk_atom(yytext); } +| VIRTUAL { $$ = mk_atom(yytext); } | WHILE { $$ = mk_atom(yytext); } +| YIELD { $$ = mk_atom(yytext); } | CONTINUE { $$ = mk_atom(yytext); } | PROC { $$ = mk_atom(yytext); } | BOX { $$ = mk_atom(yytext); } @@ -1942,4 +1992,4 @@ brackets_delimited_token_trees $2, mk_node("TTTok", 1, mk_atom("]"))); } -; \ No newline at end of file +; diff --git a/src/grammar/tokens.h b/src/grammar/tokens.h index 081bd050259..15ea738ed00 100644 --- a/src/grammar/tokens.h +++ b/src/grammar/tokens.h @@ -30,6 +30,7 @@ enum Token { DOTDOT, DOTDOTDOT, MOD_SEP, + LARROW, RARROW, FAT_ARROW, LIT_BYTE, @@ -47,13 +48,20 @@ enum Token { // keywords SELF, STATIC, + ABSTRACT, + ALIGNOF, AS, + BECOME, BREAK, + CATCH, CRATE, + DEFAULT, + DO, ELSE, ENUM, EXTERN, FALSE, + FINAL, FN, FOR, IF, @@ -61,21 +69,31 @@ enum Token { IN, LET, LOOP, + MACRO, MATCH, MOD, MOVE, MUT, + OFFSETOF, + OVERRIDE, PRIV, PUB, + PURE, REF, RETURN, + SIZEOF, STRUCT, + SUPER, + UNION, TRUE, TRAIT, TYPE, UNSAFE, + UNSIZED, USE, + VIRTUAL, WHILE, + YIELD, CONTINUE, PROC, BOX, From 53a648522b0263aa13752b78c9e27464d6caf579 Mon Sep 17 00:00:00 2001 From: k0pernicus Date: Thu, 5 Oct 2017 22:34:49 +0200 Subject: [PATCH 35/42] New rebase for the issue #45022 Add pretty printer files into test execution time-stamping Move find_rust_src_path() as a method for Config Move find_rust_src_path() as a method for Config Call find_rust_src_path() from Config Move find_rust_src_path() from common.rs to header.rs Add pretty printer files as relevant files to get up_to_date information Remove dead code Add two pretty printer files to keep a close watch on Move find_rust_src_path() as a method for Config Move find_rust_src_path() as a method for Config Call find_rust_src_path() from Config Move find_rust_src_path() from common.rs to header.rs Remove dead code Add two pretty printer files to keep a close watch on --- src/tools/compiletest/src/header.rs | 13 ++++++++++ src/tools/compiletest/src/main.rs | 27 +++++++++++++++------ src/tools/compiletest/src/runtest.rs | 36 +++++++++++----------------- 3 files changed, 47 insertions(+), 29 deletions(-) diff --git a/src/tools/compiletest/src/header.rs b/src/tools/compiletest/src/header.rs index bb9bf57d55e..19195838791 100644 --- a/src/tools/compiletest/src/header.rs +++ b/src/tools/compiletest/src/header.rs @@ -567,6 +567,19 @@ impl Config { None } } + + pub fn find_rust_src_root(&self) -> Option { + let mut path = self.src_base.clone(); + let path_postfix = Path::new("src/etc/lldb_batchmode.py"); + + while path.pop() { + if path.join(&path_postfix).is_file() { + return Some(path); + } + } + + None + } } pub fn lldb_version_to_int(version_string: &str) -> isize { diff --git a/src/tools/compiletest/src/main.rs b/src/tools/compiletest/src/main.rs index 26c447d01d3..306497da9e3 100644 --- a/src/tools/compiletest/src/main.rs +++ b/src/tools/compiletest/src/main.rs @@ -489,15 +489,28 @@ fn stamp(config: &Config, testpaths: &TestPaths) -> PathBuf { } fn up_to_date(config: &Config, testpaths: &TestPaths, props: &EarlyProps) -> bool { + let rust_src_dir = config.find_rust_src_root().expect( + "Could not find Rust source root", + ); let stamp = mtime(&stamp(config, testpaths)); - let mut inputs = vec![ - mtime(&testpaths.file), - mtime(&config.rustc_path), - ]; + let mut inputs = vec![mtime(&testpaths.file), mtime(&config.rustc_path)]; for aux in props.aux.iter() { - inputs.push(mtime(&testpaths.file.parent().unwrap() - .join("auxiliary") - .join(aux))); + inputs.push(mtime( + &testpaths.file.parent().unwrap().join("auxiliary").join( + aux, + ), + )); + } + // Relevant pretty printer files + let pretty_printer_files = [ + "src/etc/debugger_pretty_printers_common.py", + "src/etc/gdb_load_rust_pretty_printers.py", + "src/etc/gdb_rust_pretty_printing.py", + "src/etc/lldb_batchmode.py", + "src/etc/lldb_rust_formatters.py", + ]; + for pretty_printer_file in &pretty_printer_files { + inputs.push(mtime(&rust_src_dir.join(pretty_printer_file))); } for lib in config.run_lib_path.read_dir().unwrap() { let lib = lib.unwrap(); diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 10ef326d9db..870e08cc6e5 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -571,9 +571,10 @@ actual:\n\ } } - _=> { - let rust_src_root = self.find_rust_src_root() - .expect("Could not find Rust source root"); + _ => { + let rust_src_root = self.config.find_rust_src_root().expect( + "Could not find Rust source root", + ); let rust_pp_module_rel_path = Path::new("./src/etc"); let rust_pp_module_abs_path = rust_src_root.join(rust_pp_module_rel_path) .to_str() @@ -664,19 +665,6 @@ actual:\n\ self.check_debugger_output(&debugger_run_result, &check_lines); } - fn find_rust_src_root(&self) -> Option { - let mut path = self.config.src_base.clone(); - let path_postfix = Path::new("src/etc/lldb_batchmode.py"); - - while path.pop() { - if path.join(&path_postfix).is_file() { - return Some(path); - } - } - - None - } - fn run_debuginfo_lldb_test(&self) { assert!(self.revision.is_none(), "revisions not relevant here"); @@ -735,7 +723,9 @@ actual:\n\ script_str.push_str("version\n"); // Switch LLDB into "Rust mode" - let rust_src_root = self.find_rust_src_root().expect("Could not find Rust source root"); + let rust_src_root = self.config.find_rust_src_root().expect( + "Could not find Rust source root", + ); let rust_pp_module_rel_path = Path::new("./src/etc/lldb_rust_formatters.py"); let rust_pp_module_abs_path = rust_src_root.join(rust_pp_module_rel_path) .to_str() @@ -1717,11 +1707,13 @@ actual:\n\ if self.props.check_test_line_numbers_match { self.check_rustdoc_test_option(proc_res); } else { - let root = self.find_rust_src_root().unwrap(); - let res = self.cmd2procres(Command::new(&self.config.docck_python) - .arg(root.join("src/etc/htmldocck.py")) - .arg(out_dir) - .arg(&self.testpaths.file)); + let root = self.config.find_rust_src_root().unwrap(); + let res = self.cmd2procres( + Command::new(&self.config.docck_python) + .arg(root.join("src/etc/htmldocck.py")) + .arg(out_dir) + .arg(&self.testpaths.file), + ); if !res.status.success() { self.fatal_proc_rec("htmldocck failed!", &res); } From 4a9df0ec6256d0318b9679c8da62cff3f84d1fe4 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Mon, 9 Oct 2017 15:38:51 +0200 Subject: [PATCH 36/42] incr.comp.: Move macro-export test case to src/test/incremental. --- .../macro_export.rs} | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) rename src/test/{compile-fail/incr_comp_with_macro_export.rs => incremental/macro_export.rs} (90%) diff --git a/src/test/compile-fail/incr_comp_with_macro_export.rs b/src/test/incremental/macro_export.rs similarity index 90% rename from src/test/compile-fail/incr_comp_with_macro_export.rs rename to src/test/incremental/macro_export.rs index eafef172303..914632e96ba 100644 --- a/src/test/compile-fail/incr_comp_with_macro_export.rs +++ b/src/test/incremental/macro_export.rs @@ -8,10 +8,9 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// compile-flags: -Zincremental=tmp/cfail-tests/incr_comp_with_macro_export +// revisions: cfail1 cfail2 cfail3 // must-compile-successfully - // This test case makes sure that we can compile with incremental compilation // enabled when there are macros exported from this crate. (See #37756) From c3ff62863d9745f690fea65ef12fb205222d01b4 Mon Sep 17 00:00:00 2001 From: johnthagen Date: Mon, 9 Oct 2017 10:02:50 -0400 Subject: [PATCH 37/42] Clarify RAM usage during build --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 95d543b8bb3..779acb9fab4 100644 --- a/README.md +++ b/README.md @@ -193,7 +193,7 @@ Snapshot binaries are currently built and tested on several platforms: You may find that other platforms work, but these are our officially supported build environments that are most likely to work. -Rust currently needs between 600MiB and 1.5GiB to build, depending on platform. +Rust currently needs between 600MiB and 1.5GiB of RAM to build, depending on platform. If it hits swap, it will take a very long time to build. There is more advice about hacking on Rust in [CONTRIBUTING.md]. From 3e4d9df02bf8a801fb6f4903697ec523590210a9 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 9 Oct 2017 20:02:17 +0300 Subject: [PATCH 38/42] Fix a bug in diagnostics for `x as usize < y` Improve diagnostics for `x as usize << y` --- src/libsyntax/parse/parser.rs | 19 ++++++++++++++++--- src/test/ui/issue-22644.rs | 2 ++ src/test/ui/issue-22644.stderr | 15 ++++++++++++--- src/test/ui/issue-44406.rs | 19 +++++++++++++++++++ src/test/ui/issue-44406.stderr | 26 ++++++++++++++++++++++++++ 5 files changed, 75 insertions(+), 6 deletions(-) create mode 100644 src/test/ui/issue-44406.rs create mode 100644 src/test/ui/issue-44406.stderr diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 978e06c75dd..ff020445715 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -2890,17 +2890,30 @@ impl<'a> Parser<'a> { match self.parse_path(PathStyle::Expr) { Ok(path) => { + let (op_noun, op_verb) = match self.token { + token::Lt => ("comparison", "comparing"), + token::BinOp(token::Shl) => ("shift", "shifting"), + _ => { + // We can end up here even without `<` being the next token, for + // example because `parse_ty_no_plus` returns `Err` on keywords, + // but `parse_path` returns `Ok` on them due to error recovery. + // Return original error and parser state. + mem::replace(self, parser_snapshot_after_type); + return Err(type_err); + } + }; + // Successfully parsed the type path leaving a `<` yet to parse. type_err.cancel(); // Report non-fatal diagnostics, keep `x as usize` as an expression // in AST and continue parsing. let msg = format!("`<` is interpreted as a start of generic \ - arguments for `{}`, not a comparison", path); + arguments for `{}`, not a {}", path, op_noun); let mut err = self.sess.span_diagnostic.struct_span_err(self.span, &msg); err.span_label(self.look_ahead_span(1).to(parser_snapshot_after_type.span), "interpreted as generic arguments"); - err.span_label(self.span, "not interpreted as comparison"); + err.span_label(self.span, format!("not interpreted as {}", op_noun)); let expr = mk_expr(self, P(Ty { span: path.span, @@ -2911,7 +2924,7 @@ impl<'a> Parser<'a> { let expr_str = self.sess.codemap().span_to_snippet(expr.span) .unwrap_or(pprust::expr_to_string(&expr)); err.span_suggestion(expr.span, - "try comparing the casted value", + &format!("try {} the casted value", op_verb), format!("({})", expr_str)); err.emit(); diff --git a/src/test/ui/issue-22644.rs b/src/test/ui/issue-22644.rs index b482d0595f7..c8e0cd1763f 100644 --- a/src/test/ui/issue-22644.rs +++ b/src/test/ui/issue-22644.rs @@ -35,5 +35,7 @@ fn main() { < 5); + println!("{}", a as usize << long_name); + println!("{}", a: &mut 4); } diff --git a/src/test/ui/issue-22644.stderr b/src/test/ui/issue-22644.stderr index 54c325b24a3..f4967c4803b 100644 --- a/src/test/ui/issue-22644.stderr +++ b/src/test/ui/issue-22644.stderr @@ -76,9 +76,18 @@ help: try comparing the casted value 33 | ... -error: expected type, found `4` - --> $DIR/issue-22644.rs:38:28 +error: `<` is interpreted as a start of generic arguments for `usize`, not a shift + --> $DIR/issue-22644.rs:38:31 | -38 | println!("{}", a: &mut 4); +38 | println!("{}", a as usize << long_name); + | ---------- ^^ --------- interpreted as generic arguments + | | | + | | not interpreted as shift + | help: try shifting the casted value: `(a as usize)` + +error: expected type, found `4` + --> $DIR/issue-22644.rs:40:28 + | +40 | println!("{}", a: &mut 4); | ^ expecting a type here because of type ascription diff --git a/src/test/ui/issue-44406.rs b/src/test/ui/issue-44406.rs new file mode 100644 index 00000000000..abf572118fc --- /dev/null +++ b/src/test/ui/issue-44406.rs @@ -0,0 +1,19 @@ +// Copyright 2017 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +macro_rules! foo { + ($rest: tt) => { + bar(baz: $rest) + } +} + +fn main() { + foo!(true); +} diff --git a/src/test/ui/issue-44406.stderr b/src/test/ui/issue-44406.stderr new file mode 100644 index 00000000000..e07face24ba --- /dev/null +++ b/src/test/ui/issue-44406.stderr @@ -0,0 +1,26 @@ +error: expected identifier, found keyword `true` + --> $DIR/issue-44406.rs:18:10 + | +18 | foo!(true); + | ^^^^ + +error: expected type, found keyword `true` + --> $DIR/issue-44406.rs:18:10 + | +13 | bar(baz: $rest) + | - help: did you mean to use `;` here? +... +18 | foo!(true); + | ^^^^ expecting a type here because of type ascription + +error: expected one of `!`, `&&`, `&`, `(`, `*`, `.`, `;`, `<`, `?`, `[`, `_`, `extern`, `fn`, `for`, `impl`, `unsafe`, `}`, an operator, or lifetime, found `true` + --> $DIR/issue-44406.rs:18:10 + | +13 | bar(baz: $rest) + | - expected one of 19 possible tokens here +... +18 | foo!(true); + | ^^^^ unexpected token + +error: aborting due to 3 previous errors + From 679457ad2a0f33aed6b206107afedcccf5124374 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malo=20Jaffr=C3=A9?= Date: Mon, 9 Oct 2017 20:09:08 +0200 Subject: [PATCH 39/42] Refactor to use `debug_struct` in several Debug impls Fixes #44771. --- src/librustc_data_structures/graph/mod.rs | 15 ++------------ src/libstd/sync/mpsc/mod.rs | 24 +++-------------------- src/libstd/sync/mpsc/select.rs | 18 ++--------------- src/libstd/sync/mutex.rs | 13 +++++++++--- src/libstd/sync/rwlock.rs | 13 +++++++++--- src/libstd/sys_common/remutex.rs | 13 +++++++++--- src/libsyntax_pos/lib.rs | 7 +++++-- 7 files changed, 42 insertions(+), 61 deletions(-) diff --git a/src/librustc_data_structures/graph/mod.rs b/src/librustc_data_structures/graph/mod.rs index 474622f3669..56d5f5ffa3f 100644 --- a/src/librustc_data_structures/graph/mod.rs +++ b/src/librustc_data_structures/graph/mod.rs @@ -31,7 +31,7 @@ //! be indexed by the direction (see the type `Direction`). use bitvec::BitVector; -use std::fmt::{Formatter, Error, Debug}; +use std::fmt::Debug; use std::usize; use snapshot_vec::{SnapshotVec, SnapshotVecDelegate}; @@ -48,6 +48,7 @@ pub struct Node { pub data: N, } +#[derive(Debug)] pub struct Edge { next_edge: [EdgeIndex; 2], // see module comment source: NodeIndex, @@ -69,18 +70,6 @@ impl SnapshotVecDelegate for Edge { fn reverse(_: &mut Vec>, _: ()) {} } -impl Debug for Edge { - fn fmt(&self, f: &mut Formatter) -> Result<(), Error> { - write!(f, - "Edge {{ next_edge: [{:?}, {:?}], source: {:?}, target: {:?}, data: {:?} }}", - self.next_edge[0], - self.next_edge[1], - self.source, - self.target, - self.data) - } -} - #[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)] pub struct NodeIndex(pub usize); diff --git a/src/libstd/sync/mpsc/mod.rs b/src/libstd/sync/mpsc/mod.rs index dcd4c8dfdf5..ce1a07b31b2 100644 --- a/src/libstd/sync/mpsc/mod.rs +++ b/src/libstd/sync/mpsc/mod.rs @@ -919,7 +919,7 @@ impl Drop for Sender { #[stable(feature = "mpsc_debug", since = "1.8.0")] impl fmt::Debug for Sender { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Sender {{ .. }}") + f.debug_struct("Sender").finish() } } @@ -1049,7 +1049,7 @@ impl Drop for SyncSender { #[stable(feature = "mpsc_debug", since = "1.8.0")] impl fmt::Debug for SyncSender { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "SyncSender {{ .. }}") + f.debug_struct("SyncSender").finish() } } @@ -1551,7 +1551,7 @@ impl Drop for Receiver { #[stable(feature = "mpsc_debug", since = "1.8.0")] impl fmt::Debug for Receiver { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Receiver {{ .. }}") + f.debug_struct("Receiver").finish() } } @@ -3009,22 +3009,4 @@ mod sync_tests { repro() } } - - #[test] - fn fmt_debug_sender() { - let (tx, _) = channel::(); - assert_eq!(format!("{:?}", tx), "Sender { .. }"); - } - - #[test] - fn fmt_debug_recv() { - let (_, rx) = channel::(); - assert_eq!(format!("{:?}", rx), "Receiver { .. }"); - } - - #[test] - fn fmt_debug_sync_sender() { - let (tx, _) = sync_channel::(1); - assert_eq!(format!("{:?}", tx), "SyncSender { .. }"); - } } diff --git a/src/libstd/sync/mpsc/select.rs b/src/libstd/sync/mpsc/select.rs index e49f4cff024..a9f3cea243f 100644 --- a/src/libstd/sync/mpsc/select.rs +++ b/src/libstd/sync/mpsc/select.rs @@ -354,13 +354,13 @@ impl Iterator for Packets { impl fmt::Debug for Select { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Select {{ .. }}") + f.debug_struct("Select").finish() } } impl<'rx, T:Send+'rx> fmt::Debug for Handle<'rx, T> { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Handle {{ .. }}") + f.debug_struct("Handle").finish() } } @@ -774,18 +774,4 @@ mod tests { } } } - - #[test] - fn fmt_debug_select() { - let sel = Select::new(); - assert_eq!(format!("{:?}", sel), "Select { .. }"); - } - - #[test] - fn fmt_debug_handle() { - let (_, rx) = channel::(); - let sel = Select::new(); - let handle = sel.handle(&rx); - assert_eq!(format!("{:?}", handle), "Handle { .. }"); - } } diff --git a/src/libstd/sync/mutex.rs b/src/libstd/sync/mutex.rs index 62d8de18f4b..a0349fe9d8b 100644 --- a/src/libstd/sync/mutex.rs +++ b/src/libstd/sync/mutex.rs @@ -384,11 +384,18 @@ impl Default for Mutex { impl fmt::Debug for Mutex { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.try_lock() { - Ok(guard) => write!(f, "Mutex {{ data: {:?} }}", &*guard), + Ok(guard) => f.debug_struct("Mutex").field("data", &&*guard).finish(), Err(TryLockError::Poisoned(err)) => { - write!(f, "Mutex {{ data: Poisoned({:?}) }}", &**err.get_ref()) + f.debug_struct("Mutex").field("data", &&**err.get_ref()).finish() }, - Err(TryLockError::WouldBlock) => write!(f, "Mutex {{ }}") + Err(TryLockError::WouldBlock) => { + struct LockedPlaceholder; + impl fmt::Debug for LockedPlaceholder { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("") } + } + + f.debug_struct("Mutex").field("data", &LockedPlaceholder).finish() + } } } } diff --git a/src/libstd/sync/rwlock.rs b/src/libstd/sync/rwlock.rs index 4757faabfb8..5c49d6b5845 100644 --- a/src/libstd/sync/rwlock.rs +++ b/src/libstd/sync/rwlock.rs @@ -428,11 +428,18 @@ unsafe impl<#[may_dangle] T: ?Sized> Drop for RwLock { impl fmt::Debug for RwLock { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.try_read() { - Ok(guard) => write!(f, "RwLock {{ data: {:?} }}", &*guard), + Ok(guard) => f.debug_struct("RwLock").field("data", &&*guard).finish(), Err(TryLockError::Poisoned(err)) => { - write!(f, "RwLock {{ data: Poisoned({:?}) }}", &**err.get_ref()) + f.debug_struct("RwLock").field("data", &&**err.get_ref()).finish() }, - Err(TryLockError::WouldBlock) => write!(f, "RwLock {{ }}") + Err(TryLockError::WouldBlock) => { + struct LockedPlaceholder; + impl fmt::Debug for LockedPlaceholder { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("") } + } + + f.debug_struct("RwLock").field("data", &LockedPlaceholder).finish() + } } } } diff --git a/src/libstd/sys_common/remutex.rs b/src/libstd/sys_common/remutex.rs index 4d0407ccf6c..ce43ec6d9ab 100644 --- a/src/libstd/sys_common/remutex.rs +++ b/src/libstd/sys_common/remutex.rs @@ -116,11 +116,18 @@ impl Drop for ReentrantMutex { impl fmt::Debug for ReentrantMutex { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.try_lock() { - Ok(guard) => write!(f, "ReentrantMutex {{ data: {:?} }}", &*guard), + Ok(guard) => f.debug_struct("ReentrantMutex").field("data", &*guard).finish(), Err(TryLockError::Poisoned(err)) => { - write!(f, "ReentrantMutex {{ data: Poisoned({:?}) }}", &**err.get_ref()) + f.debug_struct("ReentrantMutex").field("data", &**err.get_ref()).finish() }, - Err(TryLockError::WouldBlock) => write!(f, "ReentrantMutex {{ }}") + Err(TryLockError::WouldBlock) => { + struct LockedPlaceholder; + impl fmt::Debug for LockedPlaceholder { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.write_str("") } + } + + f.debug_struct("ReentrantMutex").field("data", &LockedPlaceholder).finish() + } } } } diff --git a/src/libsyntax_pos/lib.rs b/src/libsyntax_pos/lib.rs index 582f2798181..a06873aac0e 100644 --- a/src/libsyntax_pos/lib.rs +++ b/src/libsyntax_pos/lib.rs @@ -338,8 +338,11 @@ impl serialize::UseSpecializedDecodable for Span { } fn default_span_debug(span: Span, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "Span {{ lo: {:?}, hi: {:?}, ctxt: {:?} }}", - span.lo(), span.hi(), span.ctxt()) + f.debug_struct("Span") + .field("lo", &span.lo()) + .field("hi", &span.hi()) + .field("ctxt", &span.ctxt()) + .finish() } impl fmt::Debug for Span { From 06b9168d3362dc60a2e87d475319686332634319 Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Tue, 10 Oct 2017 10:05:29 +0200 Subject: [PATCH 40/42] Rename test Linux target to avoid conflict with built-in target It seems like the file wasn't actually used, since there is a built-in target with the same name. See https://github.com/rust-lang/rust/pull/45108#issuecomment-335173165 for more details. --- src/test/run-make/target-specs/Makefile | 2 +- ...linux-gnu.json => my-x86_64-unknown-linux-gnu-platform.json} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/test/run-make/target-specs/{x86_64-unknown-linux-gnu.json => my-x86_64-unknown-linux-gnu-platform.json} (100%) diff --git a/src/test/run-make/target-specs/Makefile b/src/test/run-make/target-specs/Makefile index 6b58ad7b6df..5ea96daa3ef 100644 --- a/src/test/run-make/target-specs/Makefile +++ b/src/test/run-make/target-specs/Makefile @@ -5,5 +5,5 @@ all: $(RUSTC) foo.rs --target=my-invalid-platform.json 2>&1 | grep -q "Error loading target specification" $(RUSTC) foo.rs --target=my-incomplete-platform.json 2>&1 | grep 'Field llvm-target' RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=my-awesome-platform --crate-type=lib --emit=asm - RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=x86_64-unknown-linux-gnu --crate-type=lib --emit=asm + RUST_TARGET_PATH=. $(RUSTC) foo.rs --target=my-x86_64-unknown-linux-gnu-platform --crate-type=lib --emit=asm $(RUSTC) -Z unstable-options --target=my-awesome-platform.json --print target-spec-json > $(TMPDIR)/test-platform.json && $(RUSTC) -Z unstable-options --target=$(TMPDIR)/test-platform.json --print target-spec-json | diff -q $(TMPDIR)/test-platform.json - diff --git a/src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json b/src/test/run-make/target-specs/my-x86_64-unknown-linux-gnu-platform.json similarity index 100% rename from src/test/run-make/target-specs/x86_64-unknown-linux-gnu.json rename to src/test/run-make/target-specs/my-x86_64-unknown-linux-gnu-platform.json From 8628d51c3b4c9a45e9066019f0e0853da7643794 Mon Sep 17 00:00:00 2001 From: Aidan Hobson Sayers Date: Tue, 10 Oct 2017 13:11:28 +0100 Subject: [PATCH 41/42] Band-aid fix to stop race conditions in llvm errors This is a big hammer, but should be effective at completely removing a few issues, including inconsistent error messages and segfaults when LLVM workers race to report results LLVM_THREAD_LOCAL has been present in LLVM since 8 months before 3.7 (the earliest supported LLVM version that Rust can use) Maybe fixes #43402 (third time lucky?) --- src/rustllvm/RustWrapper.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index bc616f64881..20ea8d70302 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -57,7 +57,7 @@ static AtomicOrdering fromRust(LLVMAtomicOrdering Ordering) { llvm_unreachable("Invalid LLVMAtomicOrdering value!"); } -static char *LastError; +static LLVM_THREAD_LOCAL char *LastError; extern "C" LLVMMemoryBufferRef LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) { From d5d449421398fe4005f3b3ded551a6274e3d856e Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 10 Oct 2017 18:59:40 -0700 Subject: [PATCH 42/42] ci: Fix installing the Android SDK Apparently the https urls are broken due to some certificate validation whatnots, and so far the least intrusive solution I've found is to just disable that. --- src/ci/docker/scripts/android-sdk.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ci/docker/scripts/android-sdk.sh b/src/ci/docker/scripts/android-sdk.sh index d343aae9dfb..3aa2b9d58d5 100644 --- a/src/ci/docker/scripts/android-sdk.sh +++ b/src/ci/docker/scripts/android-sdk.sh @@ -31,7 +31,7 @@ download_sysimage() { # Keep printing yes to accept the licenses while true; do echo yes; sleep 10; done | \ /android/sdk/tools/android update sdk -a --no-ui \ - --filter "$filter" + --filter "$filter" --no-https } create_avd() {