-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 rustc_target usable outside of rustc #103693
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
Which parts of I'm going to nominate this for @rust-lang/compiler to gather feedback. |
Things I need overall are |
IIRC there are a few parts of this that would be useful for |
Intellij-rust would also be interested in using such crate so there are more reasons to do that. |
I've heard something about this idea before, from @eddyb maybe? |
What's the way you plan to use this crate? Download the rustc-src component and build it from there? |
No, I want to use auto published versions in crates.io, similar to how |
OK, so from our end we don't need to have any stability across releases? Just publish breaking version bumps when they happen? |
Thanks for pinging me, though I'm not sure how useful I can be for this specific usecase. One of the old thoughts (circa 2017 IIRC?) about the whole ABI (incl. type layout) abstraction system in Naming-wise, I prefer putting "type layout" under the larger umbrella of "ABI", i.e. I've been wanting to rename In terms of making the Rust type -> layout computation reusable (which I would put in However if you want to be 1:1 compatible with So it would be useful to know the limitations you expect - you mention type size, and you could approximate that, but if you want to be exact, testing-oriented features like |
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
I moved
I had the same thing in my mind and tried to implement it. There is now a function for unions, a function for structs and enums, one for never type, and a function for univariants which is used for closures and similars and inside implementation of structs. I think it covers most of the interesting parts, and the rest is some type-dependent boilerplate which trying to reuse them will cause more trouble than good, until a shared representation of types between rustc and rust-analyzer.
I want to be compatible with the latest stable rustc with a reasonable delay, and I think by frequently bumping the |
Probably not, we're not 100% compatible in other ways already. |
So the big risks I can see here are:
|
As an example of what I meant by 2, @wesleywiser brought up the idea in the triage meeting of a CI check to make sure the crate compiles on stable. |
We discussed this in T-compiler triage, see discussion here Overall we think things can move forward here. There may be a number of creaky spots that we'll have to deal with (e.g. adding CI checks as mentioned above, and also the auto-publish scripts haven't actually been running for a while). But these issues need not block this PR. |
☀️ Test successful - checks-actions |
Finished benchmarking commit (b3bc6bf): comparison URL. Overall result: no relevant changes - no action needed@rustbot label: -perf-regression Instruction countThis benchmark run did not return any relevant results for this metric. Max RSS (memory usage)ResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
CyclesResultsThis is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.
|
|
||
#[derive(PartialEq, Eq, Hash, Clone)] | ||
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] | ||
pub struct LayoutS<V: Idx> { |
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.
If you removed the other Layout
, can you please rename this back?
The S
suffix is a historical accidental that has been recently re-perpetuated, and I've told some people about it but sadly without more communication it won't be systemically fixed.
(i.e. it's always a mistake to do, the correct thing looks more like LayoutData
, etc. - or in this case, since the weird-new-style interning is gone again, just Layout
).
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.
cc @oli-obk who seems to have been cleaning up some of that noise
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.
Layout
is still there, in rustc_target
, just nested layouts are not interned.
} | ||
|
||
#[derive(PartialEq, Eq, Hash, Clone, Debug)] | ||
#[cfg_attr(feature = "nightly", derive(HashStable_Generic))] |
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.
These features should've been named dep-of-rustc
or something, HashStable_Generic
is internal and not available "on nightly".
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.
Hmm, maybe nightly isn't the best name, but since the auto publish script will publish dependencies as well, it will work in a nightly compiler and doesn't need to be in rustc necessarily.
impl Target { | ||
pub fn parse_data_layout<'a>(&'a self) -> Result<TargetDataLayout, TargetDataLayoutErrors<'a>> { |
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 like that this is in the "spec" section, the syntax is not dictated by rustc target specs, it's a LLVM thing.
So maybe we need TargetDataLayout::parse_from_llvm_datalayout_string
and then this method can keep the extra checks?
#![cfg_attr( | ||
feature = "nightly", | ||
feature( | ||
allow_internal_unstable, | ||
extend_one, | ||
min_specialization, | ||
new_uninit, | ||
step_trait, | ||
stmt_expr_attributes, | ||
test | ||
) | ||
)] |
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.
Oh, I see... So you want both a "nightly" feature and a "dep-of-rustc" feature (or however that's spelled) and then the latter should imply the former.
rustc_index::newtype_index! { | ||
pub struct VariantIdx { | ||
derive [HashStable_Generic] | ||
} | ||
} | ||
|
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 keep this here? Does RA want to substitute its own?
(Long-term it might make sense to have Layout
take, as a generic parameter, some type that implements a trait with one associated parameter per type we want to customize etc. - instead of just adding more and more parameters - if the need arises, anyway)
Speaking of which, such a generic parameter would've allowed you to keep interning for variants, for rustc (which IIRC @nnethercote added intentionally), but use e.g. Box<Layout<...>>
in other cases.
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 keep this here? Does RA want to substitute its own?
It needed to make changes rustc_macros, and r-a had an index system itself, so I choosed to do this.
Long-term it might make sense to have Layout take, as a generic parameter, some type that implements a trait with one associated parameter per type
Similar to chalk's interner. It make sense, but currently there is only one such argument. If we want to bring interning of nested layouts back (which doesn't showed itself in perf, maybe it only affects memory usage?) I can do that.
Extract llvm datalayout parsing out of spec module fix rust-lang#103693 (comment)
Extract llvm datalayout parsing out of spec module fix rust-lang#103693 (comment)
Extract llvm datalayout parsing out of spec module fix rust-lang#103693 (comment)
Make rustc_target usable outside of rustc I'm working on showing type size in rust-analyzer (rust-lang/rust-analyzer#13490) and I currently copied rustc code inside rust-analyzer, which works, but is bad. With this change, I would become able to use `rustc_target` and `rustc_index` directly in r-a, reducing the amount of copy needed. This PR contains some feature flag to put nightly features behind them to make crates buildable on the stable compiler + makes layout related types generic over index type + removes interning of nested layouts.
#117812 bisects to this |
I'm working on showing type size in rust-analyzer (rust-lang/rust-analyzer#13490) and I currently copied rustc code inside rust-analyzer, which works, but is bad. With this change, I would become able to use
rustc_target
andrustc_index
directly in r-a, reducing the amount of copy needed.This PR contains some feature flag to put nightly features behind them to make crates buildable on the stable compiler + makes layout related types generic over index type + removes interning of nested layouts.