-
Notifications
You must be signed in to change notification settings - Fork 13k
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
turn rustc_box into an intrinsic #135046
turn rustc_box into an intrinsic #135046
Conversation
library/alloc/src/boxed.rs
Outdated
@@ -233,6 +233,26 @@ pub struct Box< | |||
#[unstable(feature = "allocator_api", issue = "32838")] A: Allocator = Global, | |||
>(Unique<T>, A); | |||
|
|||
/// Magic intrinsic to synthesize a `box <expr>` expression. |
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 a circular and unhelpful definition, because #[rustc_box]
is what is left of the box <expr>
syntax (and now this intrinsic will be, instead) — box <expr>
itself isn't part of the language any more. Wouldn’t it be better to say something like
Constructs a
Box<T>
value <...specify properties it has thatBox::new
doesn't...>
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.
That's what the next line already does, doesn't 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'm saying that the phrase “a box <expr>
expression” doesn't formally mean anything any more, and should therefore be replaced with something else.
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 could probably call it a thir::ExprKind::Box
, or ShallowInitBox
+ Move
in MIR, perhaps?
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 think it is quite clear what "a box expression" means. It's the thing being generated by this intrinsic.
The doc comment now reads:
/// Constructs a `Box<T>` by calling the `exchange_malloc` lang item and moving the argument into
/// the newly allocated memory.
///
/// This is the surface syntax for `box <expr>` expressions.
This comment has been minimized.
This comment has been minimized.
0a79683
to
2ba6a5f
Compare
This comment has been minimized.
This comment has been minimized.
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.
Anyways, I think other than the fact that this is presumably now the only "THIR" intrinsic, this does clean up the code well
side-note: It would be nice to have some way to make intrinsics more self-documenting about where what stage they're handled in the compiler, since some are lowered in MIR, some are handled by codegen backends, and one now seems to be intercepted THIR 😸.
r=me after blessing |
2ba6a5f
to
b101c5d
Compare
I don't disagree but I don't think this should be in the library docs. That seems more like something that should be somewhere in the compiler docs. Also, it seems hard to keep up-to-date... |
b101c5d
to
c00a7e6
Compare
This comment has been minimized.
This comment has been minimized.
c00a7e6
to
893885b
Compare
Some changes occurred in src/tools/clippy cc @rust-lang/clippy |
This comment has been minimized.
This comment has been minimized.
893885b
to
ac9cb90
Compare
@bors r=compiler-errors |
Experiment: Remove #[rustc_box] usage in the vec![] macro [Discussion](https://rust-lang.zulipchat.com/#narrow/channel/131828-t-compiler/topic/.23.5Brustc_box.5D.20attribute) around rust-lang#135046 suggested that this annotation may not be needed anymore. Note that the comment claims compile-time improvements, not run-time improvements, so I thought I'd do a perf run. The PR that had removed all other uses and added this comment is rust-lang#108476. r? `@ghost`
…kingjubilee Rollup of 6 pull requests Successful merges: - rust-lang#135046 (turn rustc_box into an intrinsic) - rust-lang#135061 (crashes: add latest batch of tests) - rust-lang#135070 (std: sync to dep versions of backtrace) - rust-lang#135088 (Force code generation in assembly generation smoke-tests) - rust-lang#135091 (Bump backtrace to 0.3.75) - rust-lang#135094 (bootstrap: If dir_is_empty fails, show the non-existent directory path) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#135046 - RalfJung:rustc_box_intrinsic, r=compiler-errors turn rustc_box into an intrinsic I am not entirely sure why this was made a special magic attribute, but an intrinsic seems like a more natural way to add magic expressions to the language.
This likely had negative results for max RSS for I assume that the |
I didn't expect this to change anything TBH, this is just a small change in how the intrinsic is represented but the generated MIR should be exactly the same... but fair point, apparently even that can have perf impact somehow. Is it worth investigating the RSS regression? I don't know how I'd even start doing that. |
Ah, the max RSS regression was discussed here, on a different PR, I thought that this PR is related to that other one, but probably not. Given that the regression was only in https://github.com/rust-lang/rustc-perf/blob/master/collector/compile-benchmarks/deep-vector/src/main.rs, which doesn't seem super realistic, and the regression wasn't that big (like the 80% figure that we saw in the other PR), I'd say that we should only investigate if someone finds a problem with this change in real code. |
…mpiler-errors turn rustc_box into an intrinsic I am not entirely sure why this was made a special magic attribute, but an intrinsic seems like a more natural way to add magic expressions to the language.
I am not entirely sure why this was made a special magic attribute, but an intrinsic seems like a more natural way to add magic expressions to the language.