Skip to content

Stop backends from needing to support nullary intrinsics #142839

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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Jun 21, 2025

And then remove our infrastructure special casing them. Further improvements can now be done to them by avoiding the intermediate ConstValue step, but let's leave that to follow up work

r? @RalfJung

@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 Jun 21, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 21, 2025

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_codegen_ssa

cc @WaffleLapkin

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 21, 2025

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 21, 2025
@bors
Copy link
Collaborator

bors commented Jun 21, 2025

⌛ Trying commit a44843e with merge a5e9784...

bors added a commit that referenced this pull request Jun 21, 2025
Stop backends from needing to support nullary intrinsics

And then remove our infrastructure special casing them. Further improvements can now be done to them by avoiding the intermediate ConstValue step, but let's leave that to follow up work

r? `@ghost` wanna see perf first
@rust-log-analyzer

This comment has been minimized.


match intrinsic_name {
sym::type_name => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I see this is a code-move & fixup to work in here, but is it worth sorting these arms into the rest of the match? though I guess the other arms are also not sorted simply... it was mostly that needs_drop is between type_id & type_name that caught my eye hehe

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yea, could do that, good point. didn't want to do it in the first commit to kinda make the diff line up

@bors
Copy link
Collaborator

bors commented Jun 21, 2025

☀️ Try build successful - checks-actions
Build commit: a5e9784 (a5e97845d0268f3cbfc1f7da350c0e9127ab0b99)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (a5e9784): comparison URL.

Overall result: ❌✅ regressions and improvements - please read the text below

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

Next Steps: If you can justify the regressions found in this try perf run, please do so in sufficient writing along with @rustbot label: +perf-regression-triaged. If not, please fix the regressions and do another perf run. If its results are neutral or positive, the label will be automatically removed.

@bors rollup=never
@rustbot label: -S-waiting-on-perf +perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
3.2% [2.8%, 3.5%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.3% [-0.3%, -0.3%] 1
Improvements ✅
(secondary)
-0.3% [-0.3%, -0.2%] 2
All ❌✅ (primary) 2.0% [-0.3%, 3.5%] 3

Max RSS (memory usage)

Results (primary 3.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.7% [2.0%, 5.5%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.7% [2.0%, 5.5%] 2

Cycles

Results (primary 2.7%, secondary -6.5%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.7% [2.7%, 2.8%] 2
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-6.5% [-6.5%, -6.5%] 1
All ❌✅ (primary) 2.7% [2.7%, 2.8%] 2

Binary size

Results (primary 0.4%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.5% [0.0%, 1.1%] 9
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.1%, -0.0%] 2
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.4% [-0.1%, 1.1%] 11

Bootstrap: 691.091s -> 687.91s (-0.46%)
Artifact size: 371.86 MiB -> 371.89 MiB (0.01%)

@rustbot rustbot added perf-regression Performance regression. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Jun 22, 2025
@oli-obk oli-obk force-pushed the denullarification branch from a44843e to 1dd711a Compare June 23, 2025 08:35
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the denullarification branch from 1dd711a to 93129de Compare June 23, 2025 08:46
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the denullarification branch from 93129de to 5952269 Compare June 24, 2025 08:52
@rustbot
Copy link
Collaborator

rustbot commented Jun 24, 2025

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

@oli-obk oli-obk force-pushed the denullarification branch from 5952269 to 2082fe8 Compare June 24, 2025 08:55
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the denullarification branch from 2082fe8 to cdb3a21 Compare June 24, 2025 12:22
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the denullarification branch from cdb3a21 to 7c1059f Compare June 24, 2025 12:59
@rust-log-analyzer

This comment has been minimized.

@RalfJung
Copy link
Member

RalfJung commented Jun 26, 2025

In my view, the goal of this PR is to establish a new invariant -- nullary intrinsics must be invoked in const blocks only, codegen should never see them. So before this PR there wasn't any invariant to worry about.

I like the plan, it's a lightweight version of "nullary intrinsics are consts, really" without having to figure out how to shove that into a mir::Const::Unevaluated. I guess the alternative would be to say that the DefId in an UnevaluatedConst can be a nullary intrinsic, and then we can handle them in lower_intrinsics (translating intrinsic calls into const values)... but that sounds like it might require some "interesting" hackery.

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 26, 2025

We already have nullary intrinsics that can't be a constant:

  • cold_path,
  • breakpoint

Tho technically abort and unreachable also qualify, but these could easily be special cased on the return type. I guess we could make a list of intrinsics that are nullary but do not need to be constants and check against that.

@RalfJung
Copy link
Member

Ah... well I guess then we don't actually have a new invariant here, and we'd have to rely on comments to ensure this will be consistent. I am quite confident this won't be enough, but OTOH if a nullary intrinsic creeps back in we can always fix that again later.

@oli-obk oli-obk force-pushed the denullarification branch from b2442f2 to 856b771 Compare June 26, 2025 16:19
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the denullarification branch from 856b771 to f98b42e Compare June 27, 2025 07:27
@oli-obk oli-obk force-pushed the denullarification branch from f98b42e to 11a98df Compare June 27, 2025 07:28
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the denullarification branch from 11a98df to c57d350 Compare June 27, 2025 08:01
@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk force-pushed the denullarification branch from c57d350 to c6d611b Compare June 27, 2025 08:23
@oli-obk oli-obk force-pushed the denullarification branch from c6d611b to b144fa6 Compare June 27, 2025 08:26
@RalfJung
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jun 27, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jun 27, 2025

Reminder, once the PR becomes ready for a review, use @rustbot ready.

@rust-log-analyzer

This comment has been minimized.

@rustbot
Copy link
Collaborator

rustbot commented Jun 27, 2025

The Miri subtree was changed

cc @rust-lang/miri

@oli-obk
Copy link
Contributor Author

oli-obk commented Jun 27, 2025

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 27, 2025
@RalfJung
Copy link
Member

The core parts LGTM, but I have no idea how to review the stable MIR test changes.
Cc @celinval

@bors
Copy link
Collaborator

bors commented Jun 27, 2025

☔ The latest upstream changes (presumably #143091) made this pull request unmergeable. Please resolve the merge conflicts.

@celinval
Copy link
Contributor

The core parts LGTM, but I have no idea how to review the stable MIR test changes. Cc @celinval

The test changes make sense to me. Thanks for checking!

@RalfJung
Copy link
Member

Thanks! r=RalfJung,celinval after a rebase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
perf-regression Performance regression. 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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants