-
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
Custom MIR: Many more improvements #105356
Conversation
Some changes occurred in compiler/rustc_codegen_cranelift cc @bjorn3 Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred in src/tools/clippy cc @rust-lang/clippy This PR changes MIR cc @oli-obk, @RalfJung, @JakobDegen, @davidtwco, @celinval, @vakaras Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
Oh, did not mean to reping everyone. Sorry about that |
This comment has been minimized.
This comment has been minimized.
5c2b44f
to
e17bc54
Compare
This comment has been minimized.
This comment has been minimized.
e17bc54
to
9706162
Compare
This comment has been minimized.
This comment has been minimized.
9706162
to
b998485
Compare
This comment has been minimized.
This comment has been minimized.
b998485
to
c3d532e
Compare
@bors r+ |
📌 Commit c3d532e8f2b3036f6b09cc5cab653c952d90822f has been approved by It is now in the queue for this repository. |
@oli-obk probably shouldn't merge this until the parent is merged |
@bors r- oh right, there was a reason I didn't r+ this earlier ^^ I thought it was jsut CI |
☔ The latest upstream changes (presumably #105425) made this pull request unmergeable. Please resolve the merge conflicts. |
c3d532e
to
eaa31d3
Compare
//! extern crate core; | ||
//! use core::intrinsics::mir::*; | ||
//! | ||
//! #[custom_mir(dialect = "built")] |
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 a dialect? Perhaps I'm just supposed to know this, but it's not documented anywhere here and somehow I've escaped learning about this concept.
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.
Docs. I've added a link and brief explanation
//! #### Rvalues | ||
//! | ||
//! - Operands implicitly convert to `Use` rvalues. | ||
//! - `&`, `&mut`, `addr_of!`, and `addr_of_mut!` all work to create their associated rvalue. |
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 addr_of!
instead of &raw
? IMO this is going too far in trying to imitate the way people write surface Rust, and &raw
makes more sense here.
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.
&raw
works just as well. `addr_of! literally just expands to that, the only difference is that you don't need to turn on a feature to use the latter
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. addr_of!
just seems like a very high-level construct to adopt as custom MIR syntax. And personally I like the symmetry of &, &raw, &mut.
//! #### Terminators | ||
//! | ||
//! - [`Goto`] and [`Return`] have associated functions. | ||
//! - `match some_int_operand` becomes a `SwitchInt`. Each arm should be `literal => basic_block` |
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.
The choice to use Rust match syntax makes RET
and Return()
even more odd. I think in this case it might just be better to at least call it SwitchInt
, because otherwise it seems to easy to forget that this match
only works on integers.
Jake asked me for comments in general, and I have some comments that are not on lines changed in this PR:
At this stage, reading this in the docs, it's entirely unclear to me whether
|
I don't have a better idea either. I suppose
The
|
Thanks for the improvements 👍 The limitations of the syntax make a bit more sense knowing a bit about the implementation 😉 though I wonder about the wisdom of using |
I would love to write a proc macro for this instead, but then it wouldn't be available in std and that seems like it defeats most of the point |
b5bbec1
to
b580f29
Compare
@bors r+ |
☀️ Test successful - checks-actions |
Finished benchmarking commit (ec56537): comparison URL. Overall result: ❌ regressions - no action needed@rustbot label: -perf-regression Instruction countThis is a highly reliable metric that was used to determine the overall result at the top of this comment.
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.
CyclesThis benchmark run did not return any relevant results for this metric. |
Custom MIR: Many more improvements Commits are each atomic changes, best reviewed one at a time, with the exception that the last commit includes all the documentation. ### First commit Unsafetyck was not correctly disabled before for `dialect = "built"` custom MIR. This is fixed and a regression test is added. ### Second commit Implements `Discriminant`, `SetDiscriminant`, and `SwitchInt`. ### Third commit Implements indexing, field, and variant projections. ### Fourth commit Documents the previous commits and everything else. There is some amount of weirdness here due to having to beat Rust syntax into cooperating with MIR concepts, but it hopefully should not be too much. All of it is documented. r? `@oli-obk`
Commits are each atomic changes, best reviewed one at a time, with the exception that the last commit includes all the documentation.
First commit
Unsafetyck was not correctly disabled before for
dialect = "built"
custom MIR. This is fixed and a regression test is added.Second commit
Implements
Discriminant
,SetDiscriminant
, andSwitchInt
.Third commit
Implements indexing, field, and variant projections.
Fourth commit
Documents the previous commits and everything else.
There is some amount of weirdness here due to having to beat Rust syntax into cooperating with MIR concepts, but it hopefully should not be too much. All of it is documented.
r? @oli-obk