-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Mostly fix metadata_only backend and extract some code out of rustc_codegen_llvm #51590
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
Conversation
r? @cramertj (rust_highfive has picked a reviewer for you, use r? to override) |
src/librustc_driver/lib.rs
Outdated
**This is suitable for dev purposes only**", | ||
backend_name, sysroot.display()); | ||
early_warn(ErrorOutputType::default(), &warn); | ||
return rustc_codegen_utils::codegen_backend::MetadataOnlyCodegenBackend::new; |
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 couldn't find a reliable way to pass -Zcodegen-backend=metadata-only
to stage1+, but not the bootstrap compiler.
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.
Isn't it RUSTFLAGS_STAGE_NOT_0
?
@@ -0,0 +1,112 @@ | |||
use rustc::session::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.
Moved to rustc_codegen_utils
, because MetadataOnlyCodegenBackend
needs to pass them to target_features_whitelist
to compile core
.
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 don't think this is a good direction - LLVM shouldn't be treated that special. Is there a way to make core
not contain a usage core::arch
if the target features are missing?
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.
@eddyb what do you mean here with "if the target features are missing"? Because of run-time feature detection, core::arch
always need to be available.
I don't think this is a good direction - LLVM shouldn't be treated that special
Once we add cranelift as a backend we'll need to map Rust's feature names to backend names (once for LLVM, once for Cranelift), and all backends won't support all targets. So I think that at least the white-lists are going to need to exist on a per backend basis.
let buf: OwningRef<Vec<u8>, [u8]> = OwningRef::new(buf).into(); | ||
return Ok(rustc_erase_owner!(buf.map_owner_box())); | ||
} | ||
} |
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.
It couldn't load all metadata produced by rustc_codegen_llvm
anyway, because it didn't support dylibs.
@@ -81,96 +76,27 @@ pub trait CodegenBackend { | |||
) -> Result<(), CompileIncomplete>; | |||
} | |||
|
|||
pub struct DummyCodegenBackend; |
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.
It isn't used anywere
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.
Not even in librustc_driver/test.rs
?
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.
No
src/librustc_codegen_llvm/lib.rs
Outdated
@@ -79,6 +79,7 @@ use rustc::ty::{self, TyCtxt}; | |||
use rustc::util::nodemap::{FxHashSet, FxHashMap}; | |||
use rustc_mir::monomorphize; | |||
use rustc_codegen_utils::codegen_backend::CodegenBackend; | |||
use rustc_codegen_utils::time_graph; |
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.
Moved to rustc_codegen_utils
, because it is useful for other future backends too.
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
54a7f98
to
d77bf58
Compare
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
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.
Rustbuild changes look acceptable; could you add a comment to config.toml.example about disabling LLVM via the codegen-backends array?
src/bootstrap/compile.rs
Outdated
@@ -640,7 +642,9 @@ impl Step for CodegenBackend { | |||
.arg(builder.src.join("src/librustc_codegen_llvm/Cargo.toml")); | |||
rustc_cargo_env(builder, &mut cargo); | |||
|
|||
features += &build_codegen_backend(&builder, &mut cargo, &compiler, target, backend); | |||
if !backend.is_empty() { |
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 is probably not the check you wanted -- we shouldn't be creating CodegenBackend
with an empty string. I think we can probably just remove this if.
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.
What exactly do you mean?
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.
backend
here isn't an array, but a Interned<String>
-- this check should be removed.
src/librustc_codegen_llvm/base.rs
Outdated
@@ -715,7 +714,7 @@ pub fn codegen_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, | |||
rx: mpsc::Receiver<Box<Any + Send>>) | |||
-> OngoingCodegen { | |||
|
|||
check_for_rustc_errors_attr(tcx); | |||
::rustc_codegen_utils::check_for_rustc_errors_attr(tcx); |
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.
What's the advantage to not importing this?
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.
Nothing
r? @eddyb |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Why is it failing? Edit: hopefully fixed it. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Still not fixed :( |
Fixed :) |
219d2b2
to
fb804ad
Compare
Squashed the commits to fix the test |
@@ -225,7 +161,7 @@ impl CodegenBackend for MetadataOnlyCodegenBackend { | |||
collector::MonoItemCollectionMode::Eager | |||
).0.iter() | |||
); | |||
::rustc::middle::dependency_format::calculate(tcx); | |||
//::rustc::middle::dependency_format::calculate(tcx); |
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.
commented out code?
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.
Crashes atm.
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.
Added a FIXME
config.toml.example
Outdated
# make this an empty array (but that probably won't get too far in the | ||
# bootstrap) | ||
# make this an empty array (that will disable LLVM, but bootstrap will fail at | ||
# the time the final rustc binary is built for stage 1) |
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.
Is this the right stage? I always get confused about it.
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 don't think this needs to be that explicit, keeping the original "but that probably won't get too far in the bootstrap" and just adding "which will disable LLVM" before it seems enough.
cc @alexcrichton on the rustbuild/LLVM changes |
src/librustc_codegen_llvm/common.rs
Outdated
@@ -448,3 +448,101 @@ pub fn ty_fn_sig<'a, 'tcx>(cx: &CodegenCx<'a, 'tcx>, | |||
_ => bug!("unexpected type {:?} to ty_fn_sig", ty) | |||
} | |||
} | |||
|
|||
pub fn size_and_align_of_dst<'a, 'tcx>(bx: &Builder<'a, 'tcx>, t: Ty<'tcx>, info: ValueRef) |
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.
Why move this? I'd rather see base
and common
go away just as much as glue
, so moving something here doesn't seem that useful. IMO this should be a method on PlaceRef
, that's just size_and_align_of
.
let header = Header::new("rust.metadata.bin".to_string(), metadata.len() as u64); | ||
builder.append(&header, Cursor::new(metadata)).unwrap(); | ||
let mut file = File::create(&output_name).unwrap(); | ||
file.write_all(metadata).unwrap(); |
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 all library types are effectively the same as --emit=metadata
?
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.
For the metadata-only backend yes, except for dylibs, because these must have compressed metadata.
@@ -2110,7 +2110,6 @@ dependencies = [ | |||
name = "rustc_codegen_utils" | |||
version = "0.0.0" | |||
dependencies = [ | |||
"ar 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", |
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.
Does something else depend on this crate?
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.
No
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 was asking because there's a "checksum" line that would also be removed if this was the last use of ar
.
I just checked and rustc_driver
also depends on ar
.
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.
what??? how did tidy pass then? i removed ar as whitelisted dep
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 unused dep
|
||
use rustc_data_structures::owning_ref::OwningRef; | ||
use rustc_data_structures::sync::Lrc; | ||
use ar::{Archive, Builder, Header}; | ||
use flate2::Compression; | ||
use flate2::write::DeflateEncoder; |
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.
What is flate2
used for?
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.
Compressing the metadata, when rustc_metadata expects it.
In general I dislike |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
1148253
to
ff12beb
Compare
Rebased |
This comment has been minimized.
This comment has been minimized.
@bors: r+ |
📌 Commit 23c0b3b has been approved by |
Mostly fix metadata_only backend and extract some code out of rustc_codegen_llvm Removes dependency on the `ar` crate and removes the `llvm.enabled` config option in favour of setting `rust.codegen-backends` to `[]`.
☀️ Test successful - status-appveyor, status-travis |
Removes dependency on the
ar
crate and removes thellvm.enabled
config option in favour of settingrust.codegen-backends
to[]
.