Uh oh!
There was an error while loading. Please reload this page.
add --crate-type metadata - #37681
Conversation
alexcrichton
left a comment
There was a problem hiding this comment.
Looks great to me, thanks @nrc!
The only major thing I see is whether the format here is an rlib with a metadata file or just the metadata file itself (I'd sorta prefer the latter).
Can you also add a test with some native libraries? That is, despite whatever #[link] directives are found, they're all ignored when generating a metadata crate type.
Also, can you add tests which emit both an rlib and a metadata crate? Just to make sure nothing explodes too badly there.
There was a problem hiding this comment.
Having read through this file, everything looks good. I might expect though that libfoo.rmeta is not an archive but rather just the literal metadata file in the rlib normally itself. This'd avoid going through LLVM's archive support which may speed things up a bit, but probably won't have that much effect on perf.
I'm not sure if overall it'd be less code as well, just a thought!
There was a problem hiding this comment.
Presumably CrateTypeMetadata halts before the linking stage, right? So we should just skip it here?
There was a problem hiding this comment.
Hm so this is where I start to get a little uneasy, link_rlib has tons of logic for object files, native libraries, etc. Perhaps it'd be clearer and/or easier to just emit the metadata here to a dedicated file?
There was a problem hiding this comment.
We don't want bitcode for metadata, right? Just the metadata file?
There was a problem hiding this comment.
Whoa, I had no idea this existed!
alexcrichton
commented
Nov 10, 2016
cc @rust-lang/tools as well, a new crate type! @eddyb did you want to hold off on merging until the compiler team has a chance to talk about this as well? |
Yeah, For example, OTOH, the metadata file is part of an rlib like an object file, and you can get the latter through |
michaelwoerister
commented
Nov 10, 2016
Another question would be whether to include all MIR of the crate or none at all, maybe? Right now, this will omit MIR for those functions that would have been translated to machine code if this was an rlib, which does not make so much sense any more in the new setting. |
alexcrichton
commented
Nov 10, 2016
@eddyb yeah I'm not sure if this is most appropriate as an I'm not sure I follow the bits about MIR/miri personally, but so long as it serves the problem of "fast compilation which doesn't require linkers" seems plausible to me! @michaelwoerister I'd personally expect MIR to be omitted if we can, in the sense that I'm thinking metadata crates are purely used for static analysis and/or checking compiles. If MIR is needed for that it's included but if not then it's omitted. |
eddyb
commented
Nov 10, 2016
You need at least MIR for constants, now and |
michaelwoerister
commented
Nov 10, 2016
If we only include the minimal set of MIR needed for static analysis, we would be able to completely skip MIR optimization passes, translation item collection, and codegen unit partitioning. That might be a worthwhile goal for the future. |
alexcrichton
commented
Nov 10, 2016
Indeed! I'd imagine that we optimize metadata-generation to be as fast as possible and skip as much as possible in the compiler |
nrc
commented
Nov 10, 2016
I'd like to raise the question of stability here - to what extent can we change the contents of the output of a stable option like this? For obvious reasons I'd like to land this asap, but it sounds like there a things we could improve in the future around metadata, etc. On --emit vs --crate-type. I think this is a user-facing change if the user is using the compiler directly. I agree the two options are not at all orthogonal. I believe in the current model, --crate-type makes sense because we are changing the kind of crate emitted, but not really changing anything else. |
eddyb
commented
Nov 10, 2016
@nrc You probably want to enforce that no codegen happens in dependent crates, i.e. metadata crates can only be used to build more metadata crates, and only expand this in the future if we want to. |
nrc
commented
Nov 10, 2016
@eddyb is that not a Cargo issue, rather than a rustc one? We don't do any codegen for dep crates in any case do we? |
alexcrichton
commented
Nov 10, 2016
@nrc I feel like the stability here is the same as rlibs, which is to say that you're required to treat it as a black box from the outside and it's only guaranteed to work with one compiler. Put another way, there's zero stability but it hopefully doesn't have any bugs :) |
eddyb
commented
Nov 10, 2016
After the compiler meeting, I'm pretty much on board with this approach, even if it overlaps with both As long as it cannot be misused from dependent crates and there's no stabilization schedule, SGTM. |
nrc
commented
Nov 10, 2016
@eddyb it would be insta-stable (at least the option would be, sounds like the contents would be perma-unstable). |
Updated to use a raw metadata file, rather than a degenerate rlib. And added a test |
There was a problem hiding this comment.
Could this include the reason it failed to open as well? (e.g. the argument to map_err)
There was a problem hiding this comment.
I was basically following the errors from the rlib branch directly above here. Those follow the same pattern (ignoring the actual error), although in that case because the error gets converted into an Option in the meantime. So I could (c.f., rlibs) add the extra info here, but it would be inconsistent with the rlib version.
There was a problem hiding this comment.
Oh ok, I guess whatever is fine. We shouldn't ever throw away the error context, but it's not really that critical.
alexcrichton
commented
Nov 16, 2016
Looks good to me! r=me assuming compiler team's OK w/ this as well |
bors
commented
Nov 16, 2016
☔ The latest upstream changes (presumably #37545) made this pull request unmergeable. Please resolve the merge conflicts. |
msiglreith
commented
Nov 18, 2016
Just a quick question as I'm quite interested in this crate type: Will it contain all MIR as rlibs exclude some parts afaik (e.g https://github.com/rust-lang/rust/blob/master/src/librustc_metadata/encoder.rs#L826-L834)? |
nrc
commented
Nov 18, 2016
No, it contains exactly the same metadata that an rlib would contain. |
With the same semantics as -Zno-trans
nrc
commented
Nov 20, 2016
@bors: r= @alexcrichton |
bors
commented
Nov 20, 2016
📌 Commit d038ebc has been approved by `` |
nrc
commented
Nov 21, 2016
bors
commented
Nov 21, 2016
📌 Commit d038ebc has been approved by |
bors
commented
Nov 22, 2016
⌛ Testing commit d038ebc with merge 084ed2a... |
bors
commented
Nov 22, 2016
💔 Test failed - auto-win-gnu-32-opt-rustbuild |
sanxiyn
commented
Nov 22, 2016
Travis failed tidy. "/checkout/src/librustc_metadata/locator.rs:735: line longer than 100 chars". |
nrc
commented
Nov 22, 2016
bors
commented
Nov 22, 2016
📌 Commit af1b195 has been approved by |
bors
commented
Nov 23, 2016
add --crate-type metadata r? @alexcrichton
bors
commented
Nov 23, 2016
brson
commented
Nov 29, 2016
This looks like it is insta-stable. Why is it not feature gated? |
nrc
commented
Nov 29, 2016
|
cargo check ~~This is not finished - the big omission is no tests, and it needs some more testing too. It also requires rust-lang/rust#37681 However, this is my first non-trivial Cargo patch, so I'd like to get some early feedback. r? @alexcrichton and cc @rust-lang/tools since this adds a new Cargo sub-command (although we have previously discussed and approved the idea in a tools meeting).
r? @alexcrichton