-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Conversation
r? @pnkfelix (rustbot has picked a reviewer for you, use r? to override) |
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 Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt Some changes occurred to the CTFE / Miri engine cc @rust-lang/miri |
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; | ||
} |
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 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", | ||
) | ||
} |
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.
Sanity check preventing actually ending up with MIR for these functions. Can't actually get hit due to the mono collector bailout
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
d587e44
to
95d7abf
Compare
This comment has been minimized.
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 |
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 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( |
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.
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?)
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.
okay I see b9d8f00 so there is at least some testing
@rustbot label: +S-waiting-on-author -S-waiting-on-review |
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.) |
Since the interpreter doesn't go through monomorphization, let's make sure it also has such an assertion. :) |
Maybe I'm missing something here, but is there a reason not to just allow |
☀️ Test successful - checks-actions |
Finished benchmarking commit (2eeff46): comparison URL. Overall result: ❌ regressions - ACTION NEEDEDNext Steps: If you can justify the regressions found in this perf run, please indicate this with @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.
CyclesResultsThis 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.
Binary sizeThis benchmark run did not return any relevant results for this metric. Bootstrap: 644.33s -> 644.326s (-0.00%) |
Regression is being addressed in #122010. |
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
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
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
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
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
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
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
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
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.
…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`
…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``
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``
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``
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 #63585
follow-up to #120500
MCP at rust-lang/compiler-team#720