-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make only rustc_trans depend on rustc_llvm #41565
Conversation
r? @arielb1 (rust_highfive has picked a reviewer for you, use r? to override) |
Thanks for the PR! We’ll periodically check in on it to make sure that @arielb1 or someone else from the team reviews it soon. |
b09da8c
to
c328b3e
Compare
☔ The latest upstream changes (presumably #41560) made this pull request unmergeable. Please resolve the merge conflicts. |
This is now ready for review, though it still can't merge because of #27812. I updated the PR description to summarize what this PR does and doesn't do. |
36c2a96
to
4d765c8
Compare
Fixed the travis failure, I missed one place in rustdoc (as I had feared when I did this refactoring 😅 ). |
Looks like there are a few more test failures:
|
Fixed The other failure is expected due to #27812. Fixing it involves either adding |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nits are minor. fix these if you want.
r+ modulo owning_ref
working
src/librustc_metadata/cstore_impl.rs
Outdated
@@ -565,4 +552,9 @@ impl CrateStore for cstore::CStore { | |||
drop(visible_parent_map); | |||
self.visible_parent_map.borrow() | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: extra newline
src/librustc_trans/lib.rs
Outdated
@@ -180,3 +180,55 @@ pub struct CrateTranslation { | |||
} | |||
|
|||
__build_diagnostic_array! { librustc_trans, DIAGNOSTICS } | |||
|
|||
use rustc::session::Session; | |||
pub fn init(sess: &Session) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this return a token so that you can't call the 10 or so public trans functions without calling init
(AFAICT half of these - provide
, find_crate_name
, filename_for_input
, default_output_for_target
, invalid_output_for_target
- don't need LLVM, but a few others do)?
src/librustc_trans/llvm_util.rs
Outdated
use libc::{c_int, c_char}; | ||
use std::ffi::CString; | ||
|
||
pub fn init(sess: &Session) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you make this return a token so that you can't call the 10 or so public trans functions without calling init (AFAICT half of these - provide
, find_crate_name
, filename_for_input
, default_output_for_target
, invalid_output_for_target
- don't need LLVM, but a few others do)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't they just call init
themselves? The Once
would prevent misuse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a bit torn on this. Threading a token everywhere is a lot of infrastructure for the benefit IMHO. Initializing when calling into trans solves that, but needs care when exposing new functions from trans. Requiring the driver to call init obviously places a burden on the driver, but it's a relatively simple one (a single call, and can be the same for all backends) that needs to be observed in fewer places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've decided to punt on this for the time being. I hope we'll get something like a Backend
trait object, which would solve this issue without having to audit every public API of trans.
☔ The latest upstream changes (presumably #41818) made this pull request unmergeable. Please resolve the merge conflicts. |
src/librustc/middle/cstore.rs
Outdated
@@ -268,6 +286,9 @@ pub trait CrateStore { | |||
reachable: &NodeSet) | |||
-> EncodedMetadata; | |||
fn metadata_encoding_version(&self) -> &[u8]; | |||
|
|||
// access to the metadata loader | |||
fn metadata_loader(&self) -> &MetadataLoader; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you move this next to crate_data_as_rc_any
(at the top of the trait)? They're both special.
src/librustc_driver/lib.rs
Outdated
@@ -652,12 +657,10 @@ impl RustcDefaultCalls { | |||
} | |||
} | |||
PrintRequest::TargetCPUs => { | |||
let tm = create_target_machine(sess); | |||
unsafe { llvm::LLVMRustPrintTargetCPUs(tm); } | |||
rustc_trans::print_target_cpus(sess); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be a single entry-point that takes a PrintRequest
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I just didn't realize how when I wrote this code. One advantage of leaving a PR to rot for a week: You get a fresh perspective 😄
src/librustc_driver/lib.rs
Outdated
println!("LLVM version: {}.{}", | ||
llvm::LLVMRustVersionMajor(), llvm::LLVMRustVersionMinor()); | ||
} | ||
rustc_trans::print_llvm_version(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this be print_version
? Other backends would print other information.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will do.
@@ -103,13 +104,14 @@ fn test_env<F>(source_string: &str, | |||
|
|||
let dep_graph = DepGraph::new(false); | |||
let _ignore = dep_graph.in_ignore(); | |||
let cstore = Rc::new(CStore::new(&dep_graph)); | |||
let cstore = Rc::new(CStore::new(&dep_graph, box rustc_trans::LlvmMetadataLoader)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can this not use a dummy CStore
? cc @nikomatsakis
💔 Test failed - status-travis |
Legitimate failure, presumably: |
Oops! I thought I'd tested run-make. Maybe it was on Windows, where that test is disabled? Anyway, fixed. |
(Well, hopefully fixed, I can't test right now due to being on Windows.) |
@bors r+ |
📌 Commit 04a16ff has been approved by |
Make only rustc_trans depend on rustc_llvm With these changes, only rustc_trans depends directly on rustc_llvm (and no crate gained a new dependency on trans). This means changing LLVM doesn't rebuild librustc or rustc_metadata, only rustc_trans, rustc_driver and the rustc executable Also, rustc_driver technically doesn't know about LLVM any more (of course, it still handles a ton of options that conceptually refer to LLVM, but it delegates their implementation to trans). What I *didn't* implement was merging most or all of rustc_llvm into rustc_trans. I ran into a nasty bug, which was probably just a silly typo somewhere but I probably won't have the time to figure it out in the next week or two. I opened rust-lang#41699 for that step. Fixes rust-lang#41473
Make only rustc_trans depend on rustc_llvm With these changes, only rustc_trans depends directly on rustc_llvm (and no crate gained a new dependency on trans). This means changing LLVM doesn't rebuild librustc or rustc_metadata, only rustc_trans, rustc_driver and the rustc executable Also, rustc_driver technically doesn't know about LLVM any more (of course, it still handles a ton of options that conceptually refer to LLVM, but it delegates their implementation to trans). What I *didn't* implement was merging most or all of rustc_llvm into rustc_trans. I ran into a nasty bug, which was probably just a silly typo somewhere but I probably won't have the time to figure it out in the next week or two. I opened rust-lang#41699 for that step. Fixes rust-lang#41473
⌛ Testing commit 04a16ff with merge ceef6c9... |
💔 Test failed - status-appveyor |
@bors: retry
|
⌛ Testing commit 04a16ff with merge ed1bd1a... |
💔 Test failed - status-appveyor |
@bors retry
|
⌛ Testing commit 04a16ff with merge 8ec9946... |
💔 Test failed - status-appveyor |
@bors: retry
|
Make only rustc_trans depend on rustc_llvm With these changes, only rustc_trans depends directly on rustc_llvm (and no crate gained a new dependency on trans). This means changing LLVM doesn't rebuild librustc or rustc_metadata, only rustc_trans, rustc_driver and the rustc executable Also, rustc_driver technically doesn't know about LLVM any more (of course, it still handles a ton of options that conceptually refer to LLVM, but it delegates their implementation to trans). What I *didn't* implement was merging most or all of rustc_llvm into rustc_trans. I ran into a nasty bug, which was probably just a silly typo somewhere but I probably won't have the time to figure it out in the next week or two. I opened #41699 for that step. Fixes #41473
☀️ Test successful - status-appveyor, status-travis |
They're not used in `rustc_session`, and `rustc_metadata` is a more obvious location. `MetadataLoader` was originally put into `rustc_session` in rust-lang#41565 to avoid a dependency on LLVM, but things have changed a lot since then and that's no longer relevant, e.g. `rustc_codegen_llvm` depends on `rustc_metadata`.
With these changes, only rustc_trans depends directly on rustc_llvm (and no crate gained a new dependency on trans). This means changing LLVM doesn't rebuild librustc or rustc_metadata, only rustc_trans, rustc_driver and the rustc executable
Also, rustc_driver technically doesn't know about LLVM any more (of course, it still handles a ton of options that conceptually refer to LLVM, but it delegates their implementation to trans).
What I didn't implement was merging most or all of rustc_llvm into rustc_trans. I ran into a nasty bug, which was probably just a silly typo somewhere but I probably won't have the time to figure it out in the next week or two. I opened #41699 for that step.
Fixes #41473