Repository navigation
Fix invalid instantiation of fake intrinsic bodies - #165769
rust-bors[bot] merged 2 commits into
Conversation
|
Some changes occurred to MIR optimizations cc @rust-lang/wg-mir-opt |
|
r? @jieyouxu rustbot has assigned @jieyouxu. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
cc @RalfJung |
This comment has been minimized.
This comment has been minimized.
ab84fb6 to
8714e50
Compare
| sess.time("MIR_borrow_checking", || { | ||
| tcx.par_hir_body_owners(|def_id| { | ||
| if tcx.is_intrinsic_that_must_be_overridden(def_id) { | ||
| return; |
There was a problem hiding this comment.
| return; | |
| return; // there is no MIR here to check |
| @@ -334,7 +334,10 @@ fn mir_keys(tcx: TyCtxt<'_>, (): ()) -> FxIndexSet<LocalDefId> { | |||
|
|
|||
| // Remove the fake bodies for `global_asm!`, since they're not useful | |||
There was a problem hiding this comment.
The comment needs to be updated
There was a problem hiding this comment.
Where does this nice error come from? I expected this to ICE.
There was a problem hiding this comment.
Checking upstream crates' mir goes through is_mir_available as MIR isn't encoded unless the function is inline or generic
There was a problem hiding this comment.
Sure -- but why does that not ICE? Hitting this error is always a bug, isn't it?
There was a problem hiding this comment.
iirc there are some tests for weird combinations of cli flags that can cause this. But yea, ideally this would be an ICE
There was a problem hiding this comment.
This error can happen without a bug in rustc when a dependency is only available in rmeta form while doing codegen I believe. Or at least it can if dependency_formats is called after codegen (which we did in the past IIRC and have to do again to fix -Zno-link/-Zlink-only)
There was a problem hiding this comment.
That's still a bug in cargo if it ever happens, isn't it?
|
Reminder, once the PR becomes ready for a review, use |
8714e50 to
1e52c52
Compare
|
@rustbot ready |
1e52c52 to
b474d01
Compare
This comment has been minimized.
This comment has been minimized.
| // Remove the fake bodies for `global_asm!` and intrinsics without fallback bodies, | ||
| // since they're not useful to be emitted (`--emit=mir`) or encoded (in metadata). |
There was a problem hiding this comment.
I am confused... we don't even generate fake bodies any more, why do they have to be removed?
There was a problem hiding this comment.
the issue is that set is all hir_body_owners, and at the HIR level we still treat intrinsics as if they have a body (and as you probably noticed, or at least left a comment in the code), this is very hard to avoid without being an ICE hazard.
so we have to limit the list of DefIds that have a body to those that actually have one at the MIR level. This is pretty robust, if you screw it up you hit the new span_bug
There was a problem hiding this comment.
If I understood correctly, that means the comment is quite confusing? (I did not write that comment.)
I posted suggestions for an improved comment, but I am not sure it is accurate.
There was a problem hiding this comment.
Oh I meant the comment you wrote in #135031
There was a problem hiding this comment.
Oh I see. I wonder what happens with that infinite loop... having a MIR body be an infinite loop is still better than UB, arguably.
b474d01 to
a371ccb
Compare
|
The problematic code in MIR-build still exists, right? rust/compiler/rustc_mir_build/src/builder/mod.rs Lines 1052 to 1057 in 07e526d What do we need this for? |
This comment has been minimized.
This comment has been minimized.
a371ccb to
7d1f0a9
Compare
|
cc @rust-lang/clippy |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
| if self.tcx.intrinsic(self.def_id).is_some_and(|i| i.must_be_overridden) | ||
| || self.tcx.is_sdylib_interface_build() | ||
| { | ||
| if self.tcx.is_sdylib_interface_build() { |
There was a problem hiding this comment.
This still looks suspicious, but orthogonal...
@bjorn3 @Bryanskiy why is it necessary and okay to just mark these is_sdylib_interface_build functions as unreachable, silently introducing UB if we accidentally invoke them anyway? That's a huge footgun.
There was a problem hiding this comment.
I don't recall the specifics, but already when sdylibs were originally introduced I had my concerns about the design of them (see the various comments I left). And I'm not aware of any work that has happened on them since the initial PR beyond fixing a couple of bugs. As such I wouldn't be surprised if this is another way it is unsound (beyond nothing checking that the sdylib interface files actually match the dylib that is linked against and the lack of crate disambiguators causing conflicts for two sdylibs with the same crate name but distinct -Cmetadata)
There was a problem hiding this comment.
Okay, thanks for the context -- I left a note in the tracking issue.
|
LGTM for the intrinsics, thanks! |
There was a problem hiding this comment.
Can clippy not deal with bodyless intrinsics, or what is going on here?
There was a problem hiding this comment.
Well, previously it was generating MIR for everything. I could probably make it stop doing that, but it also isn't very important for clippy, as that is expected to be run on non-internal code
There was a problem hiding this comment.
I thought we are running clippy on the compiler as well... so probably one day also on the standard library.
But I suppose that's a problem we can solve when it actually arises.
Rollup of 11 pull requests Successful merges: - #165769 (Fix invalid instantiation of fake intrinsic bodies) - #166374 (Undo accidental duplication checking for attributes on macro calls) - #166386 (Replace manual `AttributeParser` construction by `parse_limited_all`) - #162565 (Add `c_buffer_length` lint helper) - #166096 (llvm-wrapper: Pass more arguments to PreCodeGenCallback) - #166395 (std: fix positioned read/write on VxWorks) - #166404 (Change `ChildExt::kill_process_group` to be `&self`) - #166405 (Check for errors before encoding metadata) - #166412 (std: Fix locking test on GNU/Hurd) - #166413 (std: Fix symlink chmod test on GNU/Hurd) - #166421 (core: Stabilize `float_bits_const`)
Rollup merge of #165769 - oli-obk:lmao-unreachable-body-in-any-intrinsic, r=RalfJung Fix invalid instantiation of fake intrinsic bodies fixes #164984 In #122037 I created those fake bodies because we wanted to avoid all the checks I added here, and the intrinsics are always overridden anyway. Well, so we thought. If you're creative you can get at them, and it's possible there are cases that could be exposed on stable. Seems generally nicer to make it more robust
|
Note This PR was benchmarked as part of triage of its containing rollup: triage URL. Finished benchmarking commit (0de6426): comparison URL. Overall result: ❌✅ regressions and improvements - please read:Our benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesResults (secondary 12.8%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Binary sizeThis perf run didn't have relevant results for this metric. Artifact size: 406.38 MiB -> 405.72 MiB (-0.16%) |
|
@rustbot label: +perf-regression-triaged Somewhat expected small regressions due to extra query cache hits for the new checks |
Rollup of 11 pull requests Successful merges: - rust-lang/rust#165769 (Fix invalid instantiation of fake intrinsic bodies) - rust-lang/rust#166374 (Undo accidental duplication checking for attributes on macro calls) - rust-lang/rust#166386 (Replace manual `AttributeParser` construction by `parse_limited_all`) - rust-lang/rust#162565 (Add `c_buffer_length` lint helper) - rust-lang/rust#166096 (llvm-wrapper: Pass more arguments to PreCodeGenCallback) - rust-lang/rust#166395 (std: fix positioned read/write on VxWorks) - rust-lang/rust#166404 (Change `ChildExt::kill_process_group` to be `&self`) - rust-lang/rust#166405 (Check for errors before encoding metadata) - rust-lang/rust#166412 (std: Fix locking test on GNU/Hurd) - rust-lang/rust#166413 (std: Fix symlink chmod test on GNU/Hurd) - rust-lang/rust#166421 (core: Stabilize `float_bits_const`)
This is necessary due to a rearrangement of the `has_ffi_unwind_calls` by rust-lang/rust#165769 . This query now early-exits in panic=abort configurations, which changes the failing query stack (and thus the printed error message) in some tests.
View all comments
fixes #164984
In #122037 I created those fake bodies because we wanted to avoid all the checks I added here, and the intrinsics are always overridden anyway. Well, so we thought. If you're creative you can get at them, and it's possible there are cases that could be exposed on stable. Seems generally nicer to make it more robust