Skip to content

Commit 8e4f315

Browse files
author
Robin Kruppe
committed
Remove rustc_llvm dependency from librustc
Consequently, session creation can no longer initialize LLVM. The few places that use the compiler without going through rustc_driver/CompilerCalls thus need to be careful to manually initialize LLVM (via rustc_trans!) immediately after session creation. This means librustc is not rebuilt when LLVM changes.
1 parent 1a24a59 commit 8e4f315

File tree

10 files changed

+59
-57
lines changed

10 files changed

+59
-57
lines changed

src/Cargo.lock

Lines changed: 0 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/librustc/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ rustc_bitflags = { path = "../librustc_bitflags" }
1919
rustc_const_math = { path = "../librustc_const_math" }
2020
rustc_data_structures = { path = "../librustc_data_structures" }
2121
rustc_errors = { path = "../librustc_errors" }
22-
rustc_llvm = { path = "../librustc_llvm" }
2322
serialize = { path = "../libserialize" }
2423
syntax = { path = "../libsyntax" }
2524
syntax_pos = { path = "../libsyntax_pos" }

src/librustc/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ extern crate getopts;
5555
extern crate graphviz;
5656
extern crate libc;
5757
extern crate owning_ref;
58-
extern crate rustc_llvm as llvm;
5958
extern crate rustc_back;
6059
extern crate rustc_data_structures;
6160
extern crate serialize;

src/librustc/session/mod.rs

Lines changed: 0 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,16 @@ use syntax_pos::{Span, MultiSpan, FileMap};
3737
use rustc_back::{LinkerFlavor, PanicStrategy};
3838
use rustc_back::target::Target;
3939
use rustc_data_structures::flock;
40-
use llvm;
4140

4241
use std::path::{Path, PathBuf};
4342
use std::cell::{self, Cell, RefCell};
4443
use std::collections::HashMap;
4544
use std::env;
46-
use std::ffi::CString;
4745
use std::io::Write;
4846
use std::rc::Rc;
4947
use std::fmt;
5048
use std::time::Duration;
5149
use std::sync::Arc;
52-
use libc::c_int;
5350

5451
mod code_stats;
5552
pub mod config;
@@ -713,8 +710,6 @@ pub fn build_session_(sopts: config::Options,
713710
out_of_fuel: Cell::new(false),
714711
};
715712

716-
init_llvm(&sess);
717-
718713
sess
719714
}
720715

@@ -743,55 +738,6 @@ pub enum IncrCompSession {
743738
}
744739
}
745740

746-
fn init_llvm(sess: &Session) {
747-
unsafe {
748-
// Before we touch LLVM, make sure that multithreading is enabled.
749-
use std::sync::Once;
750-
static INIT: Once = Once::new();
751-
static mut POISONED: bool = false;
752-
INIT.call_once(|| {
753-
if llvm::LLVMStartMultithreaded() != 1 {
754-
// use an extra bool to make sure that all future usage of LLVM
755-
// cannot proceed despite the Once not running more than once.
756-
POISONED = true;
757-
}
758-
759-
configure_llvm(sess);
760-
});
761-
762-
if POISONED {
763-
bug!("couldn't enable multi-threaded LLVM");
764-
}
765-
}
766-
}
767-
768-
unsafe fn configure_llvm(sess: &Session) {
769-
let mut llvm_c_strs = Vec::new();
770-
let mut llvm_args = Vec::new();
771-
772-
{
773-
let mut add = |arg: &str| {
774-
let s = CString::new(arg).unwrap();
775-
llvm_args.push(s.as_ptr());
776-
llvm_c_strs.push(s);
777-
};
778-
add("rustc"); // fake program name
779-
if sess.time_llvm_passes() { add("-time-passes"); }
780-
if sess.print_llvm_passes() { add("-debug-pass=Structure"); }
781-
782-
for arg in &sess.opts.cg.llvm_args {
783-
add(&(*arg));
784-
}
785-
}
786-
787-
llvm::LLVMInitializePasses();
788-
789-
llvm::initialize_available_targets();
790-
791-
llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int,
792-
llvm_args.as_ptr());
793-
}
794-
795741
pub fn early_error(output: config::ErrorOutputType, msg: &str) -> ! {
796742
let emitter: Box<Emitter> = match output {
797743
config::ErrorOutputType::HumanReadable(color_config) => {

src/librustc_driver/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ pub fn run_compiler<'a>(args: &[String],
211211
let mut sess = session::build_session_with_codemap(
212212
sopts, &dep_graph, input_file_path, descriptions, cstore.clone(), codemap, emitter_dest,
213213
);
214+
rustc_trans::init(&sess);
214215
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
215216

216217
let mut cfg = config::build_configuration(&sess, cfg);
@@ -415,6 +416,7 @@ impl<'a> CompilerCalls<'a> for RustcDefaultCalls {
415416
None,
416417
descriptions.clone(),
417418
cstore.clone());
419+
rustc_trans::init(&sess);
418420
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
419421
let mut cfg = config::build_configuration(&sess, cfg.clone());
420422
target_features::add_configuration(&mut cfg, &sess);

src/librustc_driver/test.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ fn test_env<F>(source_string: &str,
112112
diagnostic_handler,
113113
Rc::new(CodeMap::new(FilePathMapping::empty())),
114114
cstore.clone());
115+
rustc_trans::init(&sess);
115116
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
116117
let input = config::Input::Str {
117118
name: driver::anon_src(),

src/librustc_trans/lib.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,3 +178,55 @@ pub struct CrateTranslation {
178178
}
179179

180180
__build_diagnostic_array! { librustc_trans, DIAGNOSTICS }
181+
182+
use rustc::session::Session;
183+
pub fn init(sess: &Session) {
184+
unsafe {
185+
// Before we touch LLVM, make sure that multithreading is enabled.
186+
use std::sync::Once;
187+
static INIT: Once = Once::new();
188+
static mut POISONED: bool = false;
189+
INIT.call_once(|| {
190+
if llvm::LLVMStartMultithreaded() != 1 {
191+
// use an extra bool to make sure that all future usage of LLVM
192+
// cannot proceed despite the Once not running more than once.
193+
POISONED = true;
194+
}
195+
196+
configure_llvm(sess);
197+
});
198+
199+
if POISONED {
200+
bug!("couldn't enable multi-threaded LLVM");
201+
}
202+
}
203+
}
204+
205+
use std::ffi::CString;
206+
use libc::c_int;
207+
unsafe fn configure_llvm(sess: &Session) {
208+
let mut llvm_c_strs = Vec::new();
209+
let mut llvm_args = Vec::new();
210+
211+
{
212+
let mut add = |arg: &str| {
213+
let s = CString::new(arg).unwrap();
214+
llvm_args.push(s.as_ptr());
215+
llvm_c_strs.push(s);
216+
};
217+
add("rustc"); // fake program name
218+
if sess.time_llvm_passes() { add("-time-passes"); }
219+
if sess.print_llvm_passes() { add("-debug-pass=Structure"); }
220+
221+
for arg in &sess.opts.cg.llvm_args {
222+
add(&(*arg));
223+
}
224+
}
225+
226+
llvm::LLVMInitializePasses();
227+
228+
llvm::initialize_available_targets();
229+
230+
llvm::LLVMRustSetLLVMOptions(llvm_args.len() as c_int,
231+
llvm_args.as_ptr());
232+
}

src/librustdoc/core.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ pub fn run_core(search_paths: SearchPaths,
143143
let mut sess = session::build_session_(
144144
sessopts, &dep_graph, cpath, diagnostic_handler, codemap, cstore.clone()
145145
);
146+
rustc_trans::init(&sess);
146147
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
147148

148149
let mut cfg = config::build_configuration(&sess, config::parse_cfgspecs(cfgs));

src/librustdoc/test.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ pub fn run(input: &str,
8686
let mut sess = session::build_session_(
8787
sessopts, &dep_graph, Some(input_path.clone()), handler, codemap.clone(), cstore.clone(),
8888
);
89+
rustc_trans::init(&sess);
8990
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
9091
sess.parse_sess.config =
9192
config::build_configuration(&sess, config::parse_cfgspecs(cfgs.clone()));
@@ -234,6 +235,7 @@ fn runtest(test: &str, cratename: &str, cfgs: Vec<String>, libs: SearchPaths,
234235
let mut sess = session::build_session_(
235236
sessopts, &dep_graph, None, diagnostic_handler, codemap, cstore.clone(),
236237
);
238+
rustc_trans::init(&sess);
237239
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
238240

239241
let outdir = Mutex::new(TempDir::new("rustdoctest").ok().expect("rustdoc needs a tempdir"));

src/test/run-make/issue-19371/foo.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ fn basic_sess(sysroot: PathBuf) -> (Session, Rc<CStore>) {
6161
let dep_graph = DepGraph::new(opts.build_dep_graph());
6262
let cstore = Rc::new(CStore::new(&dep_graph, Box::new(rustc_trans::LlvmMetadataLoader)));
6363
let sess = build_session(opts, &dep_graph, None, descriptions, cstore.clone());
64+
rustc_trans::init(&sess);
6465
rustc_lint::register_builtins(&mut sess.lint_store.borrow_mut(), Some(&sess));
6566
(sess, cstore)
6667
}

0 commit comments

Comments
 (0)