Skip to content
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

Merged
merged 5 commits into from
May 16, 2017
Merged

Conversation

hanna-kruppe
Copy link
Contributor

@hanna-kruppe hanna-kruppe commented Apr 26, 2017

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

@rust-highfive
Copy link
Collaborator

r? @arielb1

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

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.

@alexcrichton alexcrichton added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 27, 2017
@shepmaster shepmaster added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 28, 2017
@hanna-kruppe hanna-kruppe force-pushed the llvm-sys branch 4 times, most recently from b09da8c to c328b3e Compare April 30, 2017 23:48
@bors
Copy link
Contributor

bors commented May 1, 2017

☔ The latest upstream changes (presumably #41560) made this pull request unmergeable. Please resolve the merge conflicts.

@hanna-kruppe hanna-kruppe changed the title WIP towards only rustc_trans depend on rustc_llvm Make only rustc_trans depend on rustc_llvm May 2, 2017
@hanna-kruppe
Copy link
Contributor Author

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.

@hanna-kruppe hanna-kruppe force-pushed the llvm-sys branch 2 times, most recently from 36c2a96 to 4d765c8 Compare May 4, 2017 14:26
@hanna-kruppe
Copy link
Contributor Author

Fixed the travis failure, I missed one place in rustdoc (as I had feared when I did this refactoring 😅 ).

@Mark-Simulacrum
Copy link
Member

Looks like there are a few more test failures:

[00:53:00] failures:
[00:53:00]     [run-make] run-make/issue-19371
[00:53:00]     [run-make] run-make/sysroot-crates-are-unstable

@Mark-Simulacrum Mark-Simulacrum added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels May 7, 2017
@hanna-kruppe
Copy link
Contributor Author

hanna-kruppe commented May 7, 2017

Fixed run-make/issue-19371, thanks for pointing that out!

The other failure is expected due to #27812. Fixing it involves either adding #![cfg_attr(rustbuild, unstable(...))] to the crates.io packages pulled in (boo) or @eddyb implementing -Z force-unstable=rustc_private. Either way, this PR can be reviewed independently of that.

Copy link
Contributor

@arielb1 arielb1 left a 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

@@ -565,4 +552,9 @@ impl CrateStore for cstore::CStore {
drop(visible_parent_map);
self.visible_parent_map.borrow()
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: extra newline

@@ -180,3 +180,55 @@ pub struct CrateTranslation {
}

__build_diagnostic_array! { librustc_trans, DIAGNOSTICS }

use rustc::session::Session;
pub fn init(sess: &Session) {
Copy link
Contributor

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)?

use libc::{c_int, c_char};
use std::ffi::CString;

pub fn init(sess: &Session) {
Copy link
Contributor

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)?

Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@bors
Copy link
Contributor

bors commented May 8, 2017

☔ The latest upstream changes (presumably #41818) made this pull request unmergeable. Please resolve the merge conflicts.

@@ -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;
Copy link
Member

@eddyb eddyb May 10, 2017

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.

@@ -652,12 +657,10 @@ impl RustcDefaultCalls {
}
}
PrintRequest::TargetCPUs => {
let tm = create_target_machine(sess);
unsafe { llvm::LLVMRustPrintTargetCPUs(tm); }
rustc_trans::print_target_cpus(sess);
Copy link
Member

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?

Copy link
Contributor Author

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 😄

println!("LLVM version: {}.{}",
llvm::LLVMRustVersionMajor(), llvm::LLVMRustVersionMinor());
}
rustc_trans::print_llvm_version();
Copy link
Member

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.

Copy link
Contributor Author

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));
Copy link
Member

@eddyb eddyb May 10, 2017

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

@bors
Copy link
Contributor

bors commented May 15, 2017

💔 Test failed - status-travis

@Mark-Simulacrum
Copy link
Member

Legitimate failure, presumably: [01:22:46] thread '[run-make] run-make/llvm-pass' panicked at 'explicit panic', src/tools/compiletest/src/runtest.rs:2472.

@hanna-kruppe
Copy link
Contributor Author

Oops! I thought I'd tested run-make. Maybe it was on Windows, where that test is disabled? Anyway, fixed.

@hanna-kruppe
Copy link
Contributor Author

(Well, hopefully fixed, I can't test right now due to being on Windows.)

@eddyb
Copy link
Member

eddyb commented May 15, 2017

@bors r+

@bors
Copy link
Contributor

bors commented May 15, 2017

📌 Commit 04a16ff has been approved by eddyb

frewsxcv added a commit to frewsxcv/rust that referenced this pull request May 15, 2017
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
frewsxcv added a commit to frewsxcv/rust that referenced this pull request May 15, 2017
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
@bors
Copy link
Contributor

bors commented May 15, 2017

⌛ Testing commit 04a16ff with merge ceef6c9...

@bors
Copy link
Contributor

bors commented May 15, 2017

💔 Test failed - status-appveyor

@alexcrichton
Copy link
Member

@bors
Copy link
Contributor

bors commented May 15, 2017

⌛ Testing commit 04a16ff with merge ed1bd1a...

@bors
Copy link
Contributor

bors commented May 15, 2017

💔 Test failed - status-appveyor

@Mark-Simulacrum
Copy link
Member

@bors retry

@bors
Copy link
Contributor

bors commented May 15, 2017

⌛ Testing commit 04a16ff with merge 8ec9946...

@bors
Copy link
Contributor

bors commented May 15, 2017

💔 Test failed - status-appveyor

@alexcrichton
Copy link
Member

@bors
Copy link
Contributor

bors commented May 16, 2017

⌛ Testing commit 04a16ff with merge fa78d5b...

bors added a commit that referenced this pull request May 16, 2017
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
@bors
Copy link
Contributor

bors commented May 16, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: eddyb
Pushing fa78d5b to master...

@bors bors merged commit 04a16ff into rust-lang:master May 16, 2017
nnethercote added a commit to nnethercote/rust that referenced this pull request Nov 30, 2023
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants