Skip to content
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

Merged
merged 1 commit into from
Jan 4, 2025
Merged

Conversation

RalfJung
Copy link
Member

@RalfJung RalfJung commented Jan 2, 2025

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.

@rustbot
Copy link
Collaborator

rustbot commented Jan 2, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Jan 2, 2025
@@ -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.
Copy link
Contributor

@kpreid kpreid Jan 2, 2025

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 that Box::new doesn't...>

Copy link
Member Author

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?

Copy link
Contributor

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.

Copy link
Member

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?

Copy link
Member Author

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.

@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the rustc_box_intrinsic branch from 0a79683 to 2ba6a5f Compare January 2, 2025 23:17
@rust-log-analyzer

This comment has been minimized.

Copy link
Member

@compiler-errors compiler-errors left a 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 😸.

@compiler-errors
Copy link
Member

r=me after blessing

@RalfJung RalfJung force-pushed the rustc_box_intrinsic branch from 2ba6a5f to b101c5d Compare January 3, 2025 09:22
@RalfJung
Copy link
Member Author

RalfJung commented Jan 3, 2025

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 😸.

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...

@RalfJung RalfJung force-pushed the rustc_box_intrinsic branch from b101c5d to c00a7e6 Compare January 3, 2025 09:40
@rust-log-analyzer

This comment has been minimized.

@RalfJung RalfJung force-pushed the rustc_box_intrinsic branch from c00a7e6 to 893885b Compare January 3, 2025 10:06
@rustbot
Copy link
Collaborator

rustbot commented Jan 3, 2025

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member Author

RalfJung commented Jan 3, 2025

@bors r=compiler-errors

@bors
Copy link
Contributor

bors commented Jan 3, 2025

📌 Commit ac9cb90 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 3, 2025
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 3, 2025
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`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 4, 2025
…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
@bors bors merged commit 7cf3b96 into rust-lang:master Jan 4, 2025
6 checks passed
@rustbot rustbot added this to the 1.86.0 milestone Jan 4, 2025
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 4, 2025
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.
@RalfJung RalfJung deleted the rustc_box_intrinsic branch January 6, 2025 14:47
@Kobzol
Copy link
Contributor

Kobzol commented Jan 7, 2025

This likely had negative results for max RSS for deep-vector, with slightly positive icount results.

I assume that the deep-vector effect was expected, since I saw it being discussed somewhere, but it would be nice to run perf. for anything related to the box intrinsic, as it's quite performance sensitive.

@RalfJung
Copy link
Member Author

RalfJung commented Jan 7, 2025

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.

@Kobzol
Copy link
Contributor

Kobzol commented Jan 7, 2025

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.

flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 9, 2025
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants