From d7638b65bea1c340d7f5b74f28342eba9a1e12b5 Mon Sep 17 00:00:00 2001 From: Eric Huss Date: Sun, 14 Jan 2018 13:09:31 -0800 Subject: [PATCH 1/4] Update cargo on beta. --- src/tools/cargo | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/cargo b/src/tools/cargo index a88fbace48ac4..64326d735a0c8 160000 --- a/src/tools/cargo +++ b/src/tools/cargo @@ -1 +1 @@ -Subproject commit a88fbace48ac42ab21e1d8609012480d0aeab982 +Subproject commit 64326d735a0c883ad6aa0a2c49fe12b5b61307e1 From a32a9e4544314f7cb1b7947ba851fdfc416248f5 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 16 Jan 2018 15:49:58 -0800 Subject: [PATCH 2/4] rustc: Spawn `cmd /c` for `.bat` scripts This fixes an accidental regression #46335 where the behavior of `Path::ends_with` is different from `str::ends_with` (paths operate over components, strs operate over chars). --- src/librustc_trans/back/link.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/librustc_trans/back/link.rs b/src/librustc_trans/back/link.rs index 42538c5a3ad96..896acad6754e9 100644 --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -69,13 +69,14 @@ pub fn get_linker(sess: &Session) -> (PathBuf, Command, Vec<(OsString, OsString) // was tagged as #42791) and some more info can be found on #44443 for // emscripten itself. let cmd = |linker: &Path| { - if cfg!(windows) && linker.ends_with(".bat") { - let mut cmd = Command::new("cmd"); - cmd.arg("/c").arg(linker); - cmd - } else { - Command::new(linker) + if let Some(linker) = linker.to_str() { + if cfg!(windows) && linker.ends_with(".bat") { + let mut cmd = Command::new("cmd"); + cmd.arg("/c").arg(linker); + return cmd + } } + Command::new(linker) }; if let Some(ref linker) = sess.opts.cg.linker { From 334ef6246d85f1861e50a6963711b4aa21ef5e13 Mon Sep 17 00:00:00 2001 From: Simonas Kazlauskas Date: Thu, 4 Jan 2018 22:19:23 +0200 Subject: [PATCH 3/4] Use name-discarding LLVM context This is only applicable when neither of --emit=llvm-ir or --emit=llvm-bc are not requested. In case either of these outputs are wanted, but the benefits of such context are desired as well, -Zfewer_names option provides the same functionality regardless of the outputs requested. --- src/librustc/session/config.rs | 6 ++++++ src/librustc/session/mod.rs | 9 ++++++++- src/librustc_llvm/ffi.rs | 2 +- src/librustc_trans/back/lto.rs | 2 +- src/librustc_trans/back/write.rs | 2 ++ src/librustc_trans/context.rs | 2 +- src/rustllvm/RustWrapper.cpp | 8 +++++++- src/rustllvm/rustllvm.h | 2 +- 8 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index a86f079f3bc5f..9b578f4942389 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1082,6 +1082,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "gather borrowck statistics"), no_landing_pads: bool = (false, parse_bool, [TRACKED], "omit landing pads for unwinding"), + fewer_names: bool = (false, parse_bool, [TRACKED], + "reduce memory use by retaining fewer names within compilation artifacts (LLVM-IR)"), debug_llvm: bool = (false, parse_bool, [UNTRACKED], "enable debug output from LLVM"), meta_stats: bool = (false, parse_bool, [UNTRACKED], @@ -2813,6 +2815,10 @@ mod tests { opts.debugging_opts.no_landing_pads = true; assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash()); + opts = reference.clone(); + opts.debugging_opts.fewer_names = true; + assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash()); + opts = reference.clone(); opts.debugging_opts.no_trans = true; assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash()); diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 54bcc64d0685d..9e09a5d8fbe5e 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -18,7 +18,7 @@ use lint; use middle::allocator::AllocatorKind; use middle::dependency_format; use session::search_paths::PathKind; -use session::config::{BorrowckMode, DebugInfoLevel}; +use session::config::{BorrowckMode, DebugInfoLevel, OutputType}; use ty::tls; use util::nodemap::{FxHashMap, FxHashSet}; use util::common::{duration_to_secs_str, ErrorReported}; @@ -504,6 +504,13 @@ impl Session { pub fn linker_flavor(&self) -> LinkerFlavor { self.opts.debugging_opts.linker_flavor.unwrap_or(self.target.target.linker_flavor) } + + pub fn fewer_names(&self) -> bool { + let more_names = self.opts.output_types.contains_key(&OutputType::LlvmAssembly) || + self.opts.output_types.contains_key(&OutputType::Bitcode); + self.opts.debugging_opts.fewer_names || !more_names + } + pub fn no_landing_pads(&self) -> bool { self.opts.debugging_opts.no_landing_pads || self.panic_strategy() == PanicStrategy::Abort } diff --git a/src/librustc_llvm/ffi.rs b/src/librustc_llvm/ffi.rs index 7d65349446516..274a0d7cca8f0 100644 --- a/src/librustc_llvm/ffi.rs +++ b/src/librustc_llvm/ffi.rs @@ -514,7 +514,7 @@ pub enum ModuleBuffer {} #[link(name = "rustllvm", kind = "static")] extern "C" { // Create and destroy contexts. - pub fn LLVMContextCreate() -> ContextRef; + pub fn LLVMRustContextCreate(shouldDiscardNames: bool) -> ContextRef; pub fn LLVMContextDispose(C: ContextRef); pub fn LLVMGetMDKindIDInContext(C: ContextRef, Name: *const c_char, SLen: c_uint) -> c_uint; diff --git a/src/librustc_trans/back/lto.rs b/src/librustc_trans/back/lto.rs index 298716840926a..60b24a578c6b0 100644 --- a/src/librustc_trans/back/lto.rs +++ b/src/librustc_trans/back/lto.rs @@ -607,7 +607,7 @@ impl ThinModule { // into that context. One day, however, we may do this for upstream // crates but for locally translated modules we may be able to reuse // that LLVM Context and Module. - let llcx = llvm::LLVMContextCreate(); + let llcx = llvm::LLVMRustContextCreate(cgcx.fewer_names); let llmod = llvm::LLVMRustParseBitcodeForThinLTO( llcx, self.data().as_ptr(), diff --git a/src/librustc_trans/back/write.rs b/src/librustc_trans/back/write.rs index d8e95cd2cf2e0..4d1bcd9bf467d 100644 --- a/src/librustc_trans/back/write.rs +++ b/src/librustc_trans/back/write.rs @@ -323,6 +323,7 @@ pub struct CodegenContext { pub thinlto: bool, pub no_landing_pads: bool, pub save_temps: bool, + pub fewer_names: bool, pub exported_symbols: Arc, pub opts: Arc, pub crate_types: Vec, @@ -1407,6 +1408,7 @@ fn start_executing_work(tcx: TyCtxt, unsafe { llvm::LLVMRustThinLTOAvailable() }, no_landing_pads: sess.no_landing_pads(), + fewer_names: sess.fewer_names(), save_temps: sess.opts.cg.save_temps, opts: Arc::new(sess.opts.clone()), time_passes: sess.time_passes(), diff --git a/src/librustc_trans/context.rs b/src/librustc_trans/context.rs index e13ad43c92d5e..3014963a97ff4 100644 --- a/src/librustc_trans/context.rs +++ b/src/librustc_trans/context.rs @@ -197,7 +197,7 @@ pub fn is_pie_binary(sess: &Session) -> bool { } pub unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextRef, ModuleRef) { - let llcx = llvm::LLVMContextCreate(); + let llcx = llvm::LLVMRustContextCreate(sess.fewer_names()); let mod_name = CString::new(mod_name).unwrap(); let llmod = llvm::LLVMModuleCreateWithNameInContext(mod_name.as_ptr(), llcx); diff --git a/src/rustllvm/RustWrapper.cpp b/src/rustllvm/RustWrapper.cpp index 6f51ea67cb1d1..1ebbd73e6feb8 100644 --- a/src/rustllvm/RustWrapper.cpp +++ b/src/rustllvm/RustWrapper.cpp @@ -76,11 +76,17 @@ extern "C" char *LLVMRustGetLastError(void) { return Ret; } -void LLVMRustSetLastError(const char *Err) { +extern "C" void LLVMRustSetLastError(const char *Err) { free((void *)LastError); LastError = strdup(Err); } +extern "C" LLVMContextRef LLVMRustContextCreate(bool shouldDiscardNames) { + auto ctx = new LLVMContext(); + ctx->setDiscardValueNames(shouldDiscardNames); + return wrap(ctx); +} + extern "C" void LLVMRustSetNormalizedTarget(LLVMModuleRef M, const char *Triple) { unwrap(M)->setTargetTriple(Triple::normalize(Triple)); diff --git a/src/rustllvm/rustllvm.h b/src/rustllvm/rustllvm.h index 8c2f855c226ba..714173f86020d 100644 --- a/src/rustllvm/rustllvm.h +++ b/src/rustllvm/rustllvm.h @@ -71,7 +71,7 @@ #include "llvm/IR/IRPrintingPasses.h" #include "llvm/Linker/Linker.h" -void LLVMRustSetLastError(const char *); +extern "C" void LLVMRustSetLastError(const char *); enum class LLVMRustResult { Success, Failure }; From cbfb9858951da7aee22d82178405306fca9decb1 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Thu, 18 Jan 2018 07:14:12 -0800 Subject: [PATCH 4/4] [beta] Attempt to fix prerelease version calculation We got #47396 merged but it looks like rcs failed to deploy the beta because when it tried to calculate the beta version its cwd was different. Let's try to fix this bug and fix auto-deploy by explicitly setting the `current_dir` for git commands. --- src/bootstrap/lib.rs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 8813b5dc50087..a10868b84d264 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -787,6 +787,7 @@ impl Build { .arg("ls-remote") .arg("origin") .arg("beta") + .current_dir(&self.src) ); let beta = beta.trim().split_whitespace().next().unwrap(); let master = output( @@ -794,6 +795,7 @@ impl Build { .arg("ls-remote") .arg("origin") .arg("master") + .current_dir(&self.src) ); let master = master.trim().split_whitespace().next().unwrap(); @@ -802,7 +804,8 @@ impl Build { Command::new("git") .arg("merge-base") .arg(beta) - .arg(master), + .arg(master) + .current_dir(&self.src), ); let base = base.trim(); @@ -813,7 +816,8 @@ impl Build { .arg("rev-list") .arg("--count") .arg("--merges") - .arg(format!("{}...HEAD", base)), + .arg(format!("{}...HEAD", base)) + .current_dir(&self.src), ); let n = count.trim().parse().unwrap(); self.prerelease_version.set(Some(n));