-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Allow runtime switching between trans backends #45684
Conversation
cc @alexcrichton @rust-lang/compiler I'm not sure a flag is the right thing to use here. |
Most of the driver is the same for each backend. We could pass different compiler callbacks to rustc_driver for each backend. |
This seems to add |
@bjorn3 We use "custom drivers" to refer to different binaries using |
type OngoingCrateTranslation; | ||
type TranslatedCrate; |
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.
Now with less object unsafe associated types 🎊
What's the status of this PR @bjorn3 @alexcrichton @eddyb? I'm having a tough time telling :) |
I'm not sure what we should do here. Nominating for discussion in the next compiler meeting. |
src/librustc_trans/lib.rs
Outdated
@@ -157,10 +157,6 @@ impl LlvmTransCrate { | |||
} | |||
|
|||
impl rustc_trans_utils::trans_crate::TransCrate for LlvmTransCrate { | |||
type MetadataLoader = metadata::LlvmMetadataLoader; | |||
type OngoingCrateTranslation = back::write::OngoingCrateTranslation; | |||
type TranslatedCrate = CrateTranslation; |
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.
Now with less object unsafe associated types 🎊
Edit: now completely object safe
@bjorn3 Out of curiosity, do you have some specific motivation/need behind this PR, or is it intended as a general refactoring towards supporting multiple backends? |
Mainly refactoring, but when this is merged I want to try to add basic cranelift support. |
I'd suggest more coordination between you, @sunfishcode and me, and the compiler team in general. Just to avoid stepping on eachother's toes, as we are all interested in this goal :). |
eae208e
to
fd38507
Compare
@@ -1,87 +0,0 @@ | |||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
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.
Removed as it requires the now removed after_llvm
callback.
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.
So, eddyb kicked this to me, but I actually don't know that I'm the right person to do a detailed review here. I mean I could, but I think that @eddyb and perhaps @michaelwoerister have stronger opinions about how this should be internally architected. @bjorn3 can you and @eddyb sync up at some point and talk it over?
src/librustc_driver/driver.rs
Outdated
|
||
sess.abort_if_errors(); | ||
} | ||
// FIXME: Check if the compilation options are supported for the selected backend. |
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.
This seems like an important thing to get right before we land, no? Although I guess it's only a warning, not an error, but I wouldn't want to silently be accepting bad things.
☔ The latest upstream changes (presumably #45944) made this pull request unmergeable. Please resolve the merge conflicts. |
831a965
to
b3a986a
Compare
@@ -226,7 +226,7 @@ impl TransCrate for MetadataOnlyTransCrate { | |||
}; | |||
} | |||
fn provide_extern(&self, providers: &mut Providers) { | |||
self.provide_local(providers) | |||
self.provide(providers) |
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.
You shouldn't need to do anything here, this is redundant.
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.
You mean i should remove this line?
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.
Fixed ICE |
@bors r+ |
📌 Commit a4854e8 has been approved by |
Allow runtime switching between trans backends The driver callback after_llvm has been removed as it doesnt work with multiple backends. r? @eddyb
💔 Test failed - status-travis |
fb976fb
to
a30232f
Compare
@bors r+ |
📌 Commit a30232f has been approved by |
⌛ Testing commit a30232f with merge 3153d4a27cf582356da0bb5a2190c7bebd150372... |
💔 Test failed - status-travis |
@bors retry |
Allow runtime switching between trans backends The driver callback after_llvm has been removed as it doesnt work with multiple backends. r? @eddyb
☀️ Test successful - status-appveyor, status-travis |
Tested on commit rust-lang/rust@9368a1e. 💔 rls on windows: test-pass → build-fail (cc @nrc). 💔 rls on linux: test-pass → build-fail (cc @nrc).
rustc: Load the `rustc_trans` crate at runtime Building on the work of #45684 this commit updates the compiler to unconditionally load the `rustc_trans` crate at runtime instead of linking to it at compile time. The end goal of this work is to implement #46819 where rustc will have multiple backends available to it to load. This commit starts off by removing the `extern crate rustc_trans` from the driver. This involved moving some miscellaneous functionality into the `TransCrate` trait and also required an implementation of how to locate and load the trans backend. This ended up being a little tricky because the sysroot isn't always the right location (for example `--sysroot` arguments) so some extra code was added as well to probe a directory relative to the current dll (the rustc_driver dll). Rustbuild has been updated accordingly as well to have a separate compilation invocation for the `rustc_trans` crate and assembly it accordingly into the sysroot. Finally, the distribution logic for the `rustc` package was also updated to slurp up the trans backends folder. A number of assorted fallout changes were included here as well to ensure tests pass and such, and they should all be commented inline.
The driver callback after_llvm has been removed as it doesnt work with multiple backends.
r? @eddyb