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

Add a scheme for moving away from extern "rust-intrinsic" entirely #120675

Merged
merged 6 commits into from
Mar 5, 2024

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Feb 5, 2024

All rust-intrinsics can become free functions now, either with a fallback body, or with a dummy body and an attribute, requiring backends to actually implement the intrinsic.

This PR demonstrates the dummy-body scheme with the vtable_size intrinsic.

cc #63585

follow-up to #120500

MCP at rust-lang/compiler-team#720

@rustbot
Copy link
Collaborator

rustbot commented Feb 5, 2024

r? @pnkfelix

(rustbot has picked a reviewer for you, use r? to override)

@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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. labels Feb 5, 2024
@rustbot
Copy link
Collaborator

rustbot commented Feb 5, 2024

The Miri subtree was changed

cc @rust-lang/miri

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred in compiler/rustc_codegen_cranelift

cc @bjorn3

Some changes occurred in src/librustdoc/clean/types.rs

cc @camelid

Some changes occurred in compiler/rustc_codegen_gcc

cc @antoyo, @GuillaumeGomez

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

Some changes occurred to the CTFE / Miri engine

cc @rust-lang/miri

Comment on lines 1012 to 1025
if tcx.has_attr(def_id, sym::rustc_intrinsic_must_be_overridden) {
// These are implemented by backends directly and have no meaningful body.
return false;
}
Copy link
Contributor Author

@oli-obk oli-obk Feb 5, 2024

Choose a reason for hiding this comment

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

This is what causes linker errors (prevents shipping bodies of such functions) if the backend accidentally tries to actually use the body.

if let Some(attr) = tcx.get_attr(did, sym::rustc_intrinsic_must_be_overridden) {
span_bug!(
attr.span,
"this intrinsic must be overridden by the codegen backend, it has no meaningful body",
)
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sanity check preventing actually ending up with MIR for these functions. Can't actually get hit due to the mono collector bailout

@rust-log-analyzer

This comment has been minimized.

@oli-obk oli-obk added the S-blocked Status: Blocked on something else such as an RFC or other implementation work. label Feb 5, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@@ -24,6 +24,13 @@ fn foo() -> u32 {
}
```

## Intrinsics lowered to MIR instructions

Various intrinsics have native MIR operations that they correspond to. Instead of requiring
Copy link
Member

Choose a reason for hiding this comment

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

The other two sections (Intrinsics {with, without} fallback logic) show how each respective kind of intrinsic is declared. Can you give a hint here as to how an Intrinsic lowered-to-MIR-instructions is declared?

DefKind::Fn => {} // entirely within check_item_body
DefKind::Fn => {
if let Some(name) = tcx.intrinsic(def_id) {
intrinsic::check_intrinsic_type(
Copy link
Member

Choose a reason for hiding this comment

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

out of curiosity, do you know if we are testing the check_intrinsic_type logic anywhere in our unit tests? (E.g. via a #![no_core] test that adds its own intrinsics?)

Copy link
Member

Choose a reason for hiding this comment

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

okay I see b9d8f00 so there is at least some testing

@pnkfelix
Copy link
Member

pnkfelix commented Feb 5, 2024

@oli-obk I think @RalfJung is right; go make an MCP and link this to it. Hopefully it shouldn't be too hard to put together.

@pnkfelix
Copy link
Member

pnkfelix commented Feb 5, 2024

@rustbot label: +S-waiting-on-author -S-waiting-on-review

@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 Feb 5, 2024
@pnkfelix
Copy link
Member

pnkfelix commented Feb 5, 2024

Hmm. I need to read the descriptions more carefully, I missed the bit saying that only the last two commits were new. (And I didn't check PR #120500, so I missed the detall that those earlier commits are being landed independently.)

@RalfJung
Copy link
Member

RalfJung commented Feb 5, 2024

For some intrinsics having a fallback body makes no sense, as there is either no reasonable default or it's something absolutely compiler internal (e.g. size_of). In that case, one can add another #[rustc_intrinsic_must_be_overridden] to the function. This causes the function body to not get monomorphized and sent to the backend. The implementation has various assertions that prevent screwing this up. So if a backend forgets to implement, at best they get an assertion explaining what's going on, at worst they get a linker error.

Since the interpreter doesn't go through monomorphization, let's make sure it also has such an assertion. :)

@bors
Copy link
Contributor

bors commented Mar 4, 2024

📌 Commit c04f0ca has been approved by pnkfelix

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 4, 2024
@bors
Copy link
Contributor

bors commented Mar 5, 2024

⌛ Testing commit c04f0ca with merge 2eeff46...

@coolreader18
Copy link
Contributor

Maybe I'm missing something here, but is there a reason not to just allow #[rustc_intrinsic_must_be_overridden] functions to have no body at all? Free functions having bodies is a semantic requirement, not a syntactic one, so I'd think that would parse fine.

@bors
Copy link
Contributor

bors commented Mar 5, 2024

☀️ Test successful - checks-actions
Approved by: pnkfelix
Pushing 2eeff46 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Mar 5, 2024
@bors bors merged commit 2eeff46 into rust-lang:master Mar 5, 2024
12 checks passed
@rustbot rustbot added this to the 1.78.0 milestone Mar 5, 2024
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (2eeff46): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
0.6% [0.2%, 1.0%] 93
Regressions ❌
(secondary)
0.8% [0.2%, 2.4%] 28
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.6% [0.2%, 1.0%] 93

Max RSS (memory usage)

Results

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

mean range count
Regressions ❌
(primary)
3.9% [0.8%, 16.7%] 7
Regressions ❌
(secondary)
7.9% [6.2%, 11.2%] 3
Improvements ✅
(primary)
-2.7% [-3.9%, -1.0%] 9
Improvements ✅
(secondary)
-2.7% [-4.2%, -1.5%] 31
All ❌✅ (primary) 0.2% [-3.9%, 16.7%] 16

Cycles

Results

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

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
3.1% [3.0%, 3.2%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) - - 0

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 644.33s -> 644.326s (-0.00%)
Artifact size: 174.98 MiB -> 174.98 MiB (0.00%)

@oli-obk oli-obk deleted the intrinsics3.0 branch March 5, 2024 04:21
@Mark-Simulacrum Mark-Simulacrum added the perf-regression-triaged The performance regression has been triaged. label Mar 5, 2024
@Mark-Simulacrum
Copy link
Member

Regression is being addressed in #122010.

flip1995 pushed a commit to flip1995/rust that referenced this pull request Mar 7, 2024
Add a scheme for moving away from `extern "rust-intrinsic"` entirely

All `rust-intrinsic`s can become free functions now, either with a fallback body, or with a dummy body and an attribute, requiring backends to actually implement the intrinsic.

This PR demonstrates the dummy-body scheme with the `vtable_size` intrinsic.

cc rust-lang#63585

follow-up to rust-lang#120500

MCP at rust-lang/compiler-team#720
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2024
Avoid invoking the `intrinsic` query for DefKinds other than `Fn` or `AssocFn`

fixes the perf regression from rust-lang#120675 by only invoking (and thus inserting into the dep graph) the `intrinsic` query if the `DefKind` matches items that can actually be intrinsics
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 8, 2024
Avoid invoking the `intrinsic` query for DefKinds other than `Fn` or `AssocFn`

fixes the perf regression from rust-lang#120675 by only invoking (and thus inserting into the dep graph) the `intrinsic` query if the `DefKind` matches items that can actually be intrinsics
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 9, 2024
Avoid invoking the `intrinsic` query for DefKinds other than `Fn` or `AssocFn`

fixes the perf regression from rust-lang#120675 by only invoking (and thus inserting into the dep graph) the `intrinsic` query if the `DefKind` matches items that can actually be intrinsics
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Mar 9, 2024
Avoid invoking the `intrinsic` query for DefKinds other than `Fn` or `AssocFn`

fixes the perf regression from rust-lang/rust#120675 by only invoking (and thus inserting into the dep graph) the `intrinsic` query if the `DefKind` matches items that can actually be intrinsics
celinval pushed a commit to model-checking/kani that referenced this pull request Mar 12, 2024
Relevant upstream changes:

rust-lang/rust#120675: An intrinsic `Symbol` is
now wrapped in a `IntrinsicDef` struct, so the relevant part of the code
needed to be updated.
rust-lang/rust#121464: The second argument of
the `create_wrapper_file` function changed from a vector to a string.
rust-lang/rust#121662: `NullOp::DebugAssertions`
was renamed to `NullOp::UbCheck` and it now has data (currently unused
by Kani)
rust-lang/rust#121728: Introduces `F16` and
`F128`, so needed to add stubs for them
rust-lang/rust#121969: `parse_sess` was renamed
to `psess`, so updated the relevant code.
rust-lang/rust#122059: The
`is_val_statically_known` intrinsic is now used in some `core::fmt`
code, so had to handle it in (codegen'ed to false).
rust-lang/rust#122233: This added a new
`retag_box_to_raw` intrinsic. This is an operation that is primarily
relevant for stacked borrows. For Kani, we just return the pointer.

Resolves #3057
lnicola pushed a commit to lnicola/rust-analyzer that referenced this pull request Apr 7, 2024
Avoid invoking the `intrinsic` query for DefKinds other than `Fn` or `AssocFn`

fixes the perf regression from rust-lang/rust#120675 by only invoking (and thus inserting into the dep graph) the `intrinsic` query if the `DefKind` matches items that can actually be intrinsics
RalfJung pushed a commit to RalfJung/rust-analyzer that referenced this pull request Apr 27, 2024
Avoid invoking the `intrinsic` query for DefKinds other than `Fn` or `AssocFn`

fixes the perf regression from rust-lang/rust#120675 by only invoking (and thus inserting into the dep graph) the `intrinsic` query if the `DefKind` matches items that can actually be intrinsics
matthiaskrgr pushed a commit to matthiaskrgr/rust that referenced this pull request Jun 15, 2024
rust-lang#120675 introduced a new mechanism to declare intrinsics
which will potentially replace the rust-intrinsic ABI.

The new mechanism introduces a placeholder body and mark the intrinsic
with #[rustc_intrinsic_must_be_overridden].
In practice, this means that backends should not generate code for the
placeholder, and shim the intrinsic.
The new annotation is an internal compiler implementation,
and it doesn't need to be exposed to StableMIR users.

In this PR, intrinsics marked with `rustc_intrinsic_must_be_overridden`
are handled the same way as intrinsics that do not have a body.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 15, 2024
…li-obk

Unify intrinsics body handling in StableMIR

rust-lang#120675 introduced a new mechanism to declare intrinsics which will potentially replace the rust-intrinsic ABI.

The new mechanism introduces a placeholder body and mark the intrinsic with `#[rustc_intrinsic_must_be_overridden]`.
In practice, this means that a backend should not generate code for the placeholder, and shim the intrinsic.
The new annotation is an internal compiler implementation, and it doesn't need to be exposed to StableMIR users.

In this PR, we unify the interface for intrinsics marked with `rustc_intrinsic_must_be_overridden` and intrinsics that do not have a body.

Fixes rust-lang/project-stable-mir#79

r? `@oli-obk`

cc: `@momvart`
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 15, 2024
…li-obk

Unify intrinsics body handling in StableMIR

rust-lang#120675 introduced a new mechanism to declare intrinsics which will potentially replace the rust-intrinsic ABI.

The new mechanism introduces a placeholder body and mark the intrinsic with `#[rustc_intrinsic_must_be_overridden]`.
In practice, this means that a backend should not generate code for the placeholder, and shim the intrinsic.
The new annotation is an internal compiler implementation, and it doesn't need to be exposed to StableMIR users.

In this PR, we unify the interface for intrinsics marked with `rustc_intrinsic_must_be_overridden` and intrinsics that do not have a body.

Fixes rust-lang/project-stable-mir#79

r? ``@oli-obk``

cc: ``@momvart``
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jun 15, 2024
Rollup merge of rust-lang#126361 - celinval:issue-0079-intrinsic, r=oli-obk

Unify intrinsics body handling in StableMIR

rust-lang#120675 introduced a new mechanism to declare intrinsics which will potentially replace the rust-intrinsic ABI.

The new mechanism introduces a placeholder body and mark the intrinsic with `#[rustc_intrinsic_must_be_overridden]`.
In practice, this means that a backend should not generate code for the placeholder, and shim the intrinsic.
The new annotation is an internal compiler implementation, and it doesn't need to be exposed to StableMIR users.

In this PR, we unify the interface for intrinsics marked with `rustc_intrinsic_must_be_overridden` and intrinsics that do not have a body.

Fixes rust-lang/project-stable-mir#79

r? ``@oli-obk``

cc: ``@momvart``
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Jun 17, 2024
Unify intrinsics body handling in StableMIR

rust-lang/rust#120675 introduced a new mechanism to declare intrinsics which will potentially replace the rust-intrinsic ABI.

The new mechanism introduces a placeholder body and mark the intrinsic with `#[rustc_intrinsic_must_be_overridden]`.
In practice, this means that a backend should not generate code for the placeholder, and shim the intrinsic.
The new annotation is an internal compiler implementation, and it doesn't need to be exposed to StableMIR users.

In this PR, we unify the interface for intrinsics marked with `rustc_intrinsic_must_be_overridden` and intrinsics that do not have a body.

Fixes rust-lang/project-stable-mir#79

r? ``@oli-obk``

cc: ``@momvart``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. perf-regression Performance regression. perf-regression-triaged The performance regression has been triaged. 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.