Skip to content

Consider structurally impossible Sized predicates in MIR - #156609

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
qaijuang:mir-opt-impossible-sized-predicates
Jul 13, 2026
Merged

Consider structurally impossible Sized predicates in MIR#156609
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
qaijuang:mir-opt-impossible-sized-predicates

Conversation

@qaijuang

@qaijuangqaijuang commented May 15, 2026

Copy link
Copy Markdown
Contributor

Fixes#156051

ImpossiblePredicates filters predicates mentioning local generics before invoking the trait solver, which avoids normalization and solver work in generic contexts, thereby skipping predicates such as dyn Trait<T>: Sized, even though they are impossible for every substitution.

This PR adds a narrow structural fast path for positive Sized predicates whose self type is known-unsized without normalization, letting the pass clear unreachable bodies before later MIR opts can evaluate SizedTypeProperties constants such as size_of::<Self>().

@rustbotrustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels May 15, 2026
@qaijuang
qaijuang marked this pull request as ready for review May 15, 2026 16:04
@rustbot

Copy link
Copy Markdown
Collaborator

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

@rustbotrustbot 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 May 15, 2026
@rustbot

Copy link
Copy Markdown
Collaborator

r? @TaKO8Ki

rustbot has assigned @TaKO8Ki.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler, mir, mir-opt
  • compiler, mir, mir-opt expanded to 73 candidates
  • Random selection from 17 candidates

@qaijuang

Copy link
Copy Markdown
ContributorAuthor

cc @matthiaskrgr

Comment threadtests/ui/const_prop/issue-102553.rs Outdated
@rust-bors

This comment has been minimized.

@qaijuang
qaijuangforce-pushed the mir-opt-impossible-sized-predicates branch from 5672c89 to eeacc59CompareJune 13, 2026 01:01
@rustbot

Copy link
Copy Markdown
Collaborator

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.

@rust-log-analyzer

This comment has been minimized.

@qaijuang
qaijuangforce-pushed the mir-opt-impossible-sized-predicates branch from eeacc59 to f86ad47CompareJune 13, 2026 01:36
@qaijuang

Copy link
Copy Markdown
ContributorAuthor

Hi @TaKO8Ki are there any blockers on this PR that i should know?

@qaijuang

Copy link
Copy Markdown
ContributorAuthor

Safe to @rustbot reroll

@rustbotrustbot assigned petrochenkov and unassigned TaKO8KiJul 13, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

@rustbot reroll

@rustbotrustbot assigned oli-obk and unassigned petrochenkovJul 13, 2026
@TaKO8Ki

Copy link
Copy Markdown
Member

Sorry for the delay, I completely overlooked this PR and your ping because I got a lot of notifications.

@bors r+ rollup

r? TaKO8Ki

@rust-bors

rust-borsBot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

📌 Commit f86ad47 has been approved by TaKO8Ki

It is now in the queue for this repository.

@rust-borsrust-borsBot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jul 13, 2026
@rust-borsrust-borsBot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 13, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 13, 2026
…predicates, r=TaKO8Ki
Consider structurally impossible Sized predicates in MIR
Fixesrust-lang#156051
`ImpossiblePredicates` filters predicates mentioning local generics before invoking the trait solver, which avoids normalization and solver work in generic contexts, thereby skipping predicates such as `dyn Trait<T>: Sized`, even though they are impossible for every substitution.
This PR adds a narrow structural fast path for positive `Sized` predicates whose self type is known-unsized without normalization, letting the pass clear unreachable bodies before later MIR opts can evaluate `SizedTypeProperties` constants such as `size_of::<Self>()`.
rust-borsBot pushed a commit that referenced this pull request Jul 13, 2026
…uwer
Rollup of 13 pull requests
Successful merges:
- #159039 (resolve: fix effective visibilities for items in ambiguous glob sets)
- #157706 (Deny `todo!()` in tidy)
- #156712 (Pointer authentication config and user facing options)
- #158535 (Support `#[track_caller]` on EII declarations)
- #158632 (First steps of late-bound turbofishing (place FnDef behind a dummy binder))
- #159002 (Small refactorings in `need_type_info` module)
- #159202 (Bump rustc-demangle to 0.1.28)
- #159216 (Avoid using probe self_ty for delegation arguments)
- #159222 (semicolon_in_expressions_from_macros: Lint on non-local macros too)
- #156609 (Consider structurally impossible Sized predicates in MIR)
- #158854 (Add `#[rustc_test_entrypoint_marker]`)
- #158998 (Some minor ast validation and visiting cleanups)
- #159123 (doc: clarify attr parser APIs)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 13, 2026
…predicates, r=TaKO8Ki
Consider structurally impossible Sized predicates in MIR
Fixesrust-lang#156051
`ImpossiblePredicates` filters predicates mentioning local generics before invoking the trait solver, which avoids normalization and solver work in generic contexts, thereby skipping predicates such as `dyn Trait<T>: Sized`, even though they are impossible for every substitution.
This PR adds a narrow structural fast path for positive `Sized` predicates whose self type is known-unsized without normalization, letting the pass clear unreachable bodies before later MIR opts can evaluate `SizedTypeProperties` constants such as `size_of::<Self>()`.
rust-borsBot pushed a commit that referenced this pull request Jul 13, 2026
…uwer
Rollup of 14 pull requests
Successful merges:
- #159039 (resolve: fix effective visibilities for items in ambiguous glob sets)
- #157706 (Deny `todo!()` in tidy)
- #158535 (Support `#[track_caller]` on EII declarations)
- #158632 (First steps of late-bound turbofishing (place FnDef behind a dummy binder))
- #158846 (Fix unused variable warnings for diverging expressions)
- #159002 (Small refactorings in `need_type_info` module)
- #159202 (Bump rustc-demangle to 0.1.28)
- #159216 (Avoid using probe self_ty for delegation arguments)
- #159222 (semicolon_in_expressions_from_macros: Lint on non-local macros too)
- #156609 (Consider structurally impossible Sized predicates in MIR)
- #157993 (Expose more info about ADTs and functions in rustc_public)
- #158854 (Add `#[rustc_test_entrypoint_marker]`)
- #158998 (Some minor ast validation and visiting cleanups)
- #159123 (doc: clarify attr parser APIs)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 13, 2026
…predicates, r=TaKO8Ki
Consider structurally impossible Sized predicates in MIR
Fixesrust-lang#156051
`ImpossiblePredicates` filters predicates mentioning local generics before invoking the trait solver, which avoids normalization and solver work in generic contexts, thereby skipping predicates such as `dyn Trait<T>: Sized`, even though they are impossible for every substitution.
This PR adds a narrow structural fast path for positive `Sized` predicates whose self type is known-unsized without normalization, letting the pass clear unreachable bodies before later MIR opts can evaluate `SizedTypeProperties` constants such as `size_of::<Self>()`.
rust-borsBot pushed a commit that referenced this pull request Jul 13, 2026
…uwer
Rollup of 15 pull requests
Successful merges:
- #159039 (resolve: fix effective visibilities for items in ambiguous glob sets)
- #157706 (Deny `todo!()` in tidy)
- #156047 (Fix trait method resolution on an adjusted never type)
- #158535 (Support `#[track_caller]` on EII declarations)
- #158632 (First steps of late-bound turbofishing (place FnDef behind a dummy binder))
- #158846 (Fix unused variable warnings for diverging expressions)
- #159002 (Small refactorings in `need_type_info` module)
- #159202 (Bump rustc-demangle to 0.1.28)
- #159216 (Avoid using probe self_ty for delegation arguments)
- #156609 (Consider structurally impossible Sized predicates in MIR)
- #157993 (Expose more info about ADTs and functions in rustc_public)
- #158804 (Clarify `as_uninit_mut` may point to uninitialized memory)
- #158854 (Add `#[rustc_test_entrypoint_marker]`)
- #158998 (Some minor ast validation and visiting cleanups)
- #159123 (doc: clarify attr parser APIs)
rust-borsBot pushed a commit that referenced this pull request Jul 13, 2026
…uwer
Rollup of 13 pull requests
Successful merges:
- #157706 (Deny `todo!()` in tidy)
- #158535 (Support `#[track_caller]` on EII declarations)
- #158632 (First steps of late-bound turbofishing (place FnDef behind a dummy binder))
- #158846 (Fix unused variable warnings for diverging expressions)
- #159002 (Small refactorings in `need_type_info` module)
- #159202 (Bump rustc-demangle to 0.1.28)
- #159216 (Avoid using probe self_ty for delegation arguments)
- #156609 (Consider structurally impossible Sized predicates in MIR)
- #157993 (Expose more info about ADTs and functions in rustc_public)
- #158804 (Clarify `as_uninit_mut` may point to uninitialized memory)
- #158854 (Add `#[rustc_test_entrypoint_marker]`)
- #158998 (Some minor ast validation and visiting cleanups)
- #159123 (doc: clarify attr parser APIs)
@rust-bors
rust-borsBot merged commit 3198c7a into rust-lang:mainJul 13, 2026
13 checks passed
@rustbotrustbot added this to the 1.99.0 milestone Jul 13, 2026
rust-timer added a commit that referenced this pull request Jul 13, 2026
Rollup merge of #156609 - qaijuang:mir-opt-impossible-sized-predicates, r=TaKO8Ki
Consider structurally impossible Sized predicates in MIR
Fixes#156051
`ImpossiblePredicates` filters predicates mentioning local generics before invoking the trait solver, which avoids normalization and solver work in generic contexts, thereby skipping predicates such as `dyn Trait<T>: Sized`, even though they are impossible for every substitution.
This PR adds a narrow structural fast path for positive `Sized` predicates whose self type is known-unsized without normalization, letting the pass clear unreachable bodies before later MIR opts can evaluate `SizedTypeProperties` constants such as `size_of::<Self>()`.
@qaijuang
qaijuang deleted the mir-opt-impossible-sized-predicates branch July 13, 2026 23:40
github-actionsBot pushed a commit to rust-lang/stdarch that referenced this pull request Jul 16, 2026
…uwer
Rollup of 13 pull requests
Successful merges:
- rust-lang/rust#157706 (Deny `todo!()` in tidy)
- rust-lang/rust#158535 (Support `#[track_caller]` on EII declarations)
- rust-lang/rust#158632 (First steps of late-bound turbofishing (place FnDef behind a dummy binder))
- rust-lang/rust#158846 (Fix unused variable warnings for diverging expressions)
- rust-lang/rust#159002 (Small refactorings in `need_type_info` module)
- rust-lang/rust#159202 (Bump rustc-demangle to 0.1.28)
- rust-lang/rust#159216 (Avoid using probe self_ty for delegation arguments)
- rust-lang/rust#156609 (Consider structurally impossible Sized predicates in MIR)
- rust-lang/rust#157993 (Expose more info about ADTs and functions in rustc_public)
- rust-lang/rust#158804 (Clarify `as_uninit_mut` may point to uninitialized memory)
- rust-lang/rust#158854 (Add `#[rustc_test_entrypoint_marker]`)
- rust-lang/rust#158998 (Some minor ast validation and visiting cleanups)
- rust-lang/rust#159123 (doc: clarify attr parser APIs)
@Kobzol

Copy link
Copy Markdown
Member

@rust-timer build 25028da

For #159246.

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (25028da): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. It's automatically marked not fit for rolling up. Overriding is possible but disadvised: it risks changing compiler perf.

@bors rollup=never rustc-perf
@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.

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-1.8%[-2.5%, -0.5%]14
All ❌✅ (primary)--0

Max RSS (memory usage)

Results (primary 2.4%, secondary -20.0%)

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

meanrangecount
Regressions ❌
(primary)
2.4%[2.4%, 2.4%]1
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-20.0%[-23.3%, -11.7%]13
All ❌✅ (primary)2.4%[2.4%, 2.4%]1

Cycles

Results (secondary -14.1%)

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

meanrangecount
Regressions ❌
(primary)
--0
Regressions ❌
(secondary)
--0
Improvements ✅
(primary)
--0
Improvements ✅
(secondary)
-14.1%[-20.0%, -7.0%]13
All ❌✅ (primary)--0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 488.117s -> 486.539s (-0.32%)
Artifact size: 389.87 MiB -> 389.83 MiB (-0.01%)

Kobzol pushed a commit to Kobzol/rustc_codegen_cranelift that referenced this pull request Jul 23, 2026
…uwer
Rollup of 13 pull requests
Successful merges:
- rust-lang/rust#157706 (Deny `todo!()` in tidy)
- rust-lang/rust#158535 (Support `#[track_caller]` on EII declarations)
- rust-lang/rust#158632 (First steps of late-bound turbofishing (place FnDef behind a dummy binder))
- rust-lang/rust#158846 (Fix unused variable warnings for diverging expressions)
- rust-lang/rust#159002 (Small refactorings in `need_type_info` module)
- rust-lang/rust#159202 (Bump rustc-demangle to 0.1.28)
- rust-lang/rust#159216 (Avoid using probe self_ty for delegation arguments)
- rust-lang/rust#156609 (Consider structurally impossible Sized predicates in MIR)
- rust-lang/rust#157993 (Expose more info about ADTs and functions in rustc_public)
- rust-lang/rust#158804 (Clarify `as_uninit_mut` may point to uninitialized memory)
- rust-lang/rust#158854 (Add `#[rustc_test_entrypoint_marker]`)
- rust-lang/rust#158998 (Some minor ast validation and visiting cleanups)
- rust-lang/rust#159123 (doc: clarify attr parser APIs)
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Aug 17, 2026
…uwer
Rollup of 13 pull requests
Successful merges:
- rust-lang/rust#157706 (Deny `todo!()` in tidy)
- rust-lang/rust#158535 (Support `#[track_caller]` on EII declarations)
- rust-lang/rust#158632 (First steps of late-bound turbofishing (place FnDef behind a dummy binder))
- rust-lang/rust#158846 (Fix unused variable warnings for diverging expressions)
- rust-lang/rust#159002 (Small refactorings in `need_type_info` module)
- rust-lang/rust#159202 (Bump rustc-demangle to 0.1.28)
- rust-lang/rust#159216 (Avoid using probe self_ty for delegation arguments)
- rust-lang/rust#156609 (Consider structurally impossible Sized predicates in MIR)
- rust-lang/rust#157993 (Expose more info about ADTs and functions in rustc_public)
- rust-lang/rust#158804 (Clarify `as_uninit_mut` may point to uninitialized memory)
- rust-lang/rust#158854 (Add `#[rustc_test_entrypoint_marker]`)
- rust-lang/rust#158998 (Some minor ast validation and visiting cleanups)
- rust-lang/rust#159123 (doc: clarify attr parser APIs)
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-borsStatus: Waiting on bors to run and complete tests. Bors will change the label on completion.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: wasm: unsized type for size_of

8 participants

@qaijuang@rustbot@rust-log-analyzer@petrochenkov@TaKO8Ki@Kobzol@rust-timer@oli-obk