Skip to content

Refactor is_opsem_inhabited#159625

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
camsteffen:opsem-inhabited-refactor
Jul 22, 2026
Merged

Refactor is_opsem_inhabited#159625
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
camsteffen:opsem-inhabited-refactor

Conversation

@camsteffen

@camsteffen camsteffen commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

View all comments

Refactor of #156977

Introduce a struct to generally simplify the recursion.

r? WaffleLapkin
cc @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. labels Jul 20, 2026
@rustbot

rustbot commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

WaffleLapkin is not on the review rotation at the moment.
They may take a while to respond.

@RalfJung RalfJung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Okay yeah that is less confusing than my closure nest. :)

@rustbot author

View changes since this review

@@ -251,107 +248,125 @@ fn inhabited_predicate_type<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> InhabitedP

/// Recurse over a type to determine whether it is inhabited on the opsem level.
/// See `is_opsem_inhabited` above for the spec of what we compute.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This comment does not really make sense on a type IMO. It should probably go on the ty method, with another brief comment here explaining the point of this type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Tweaked the comment. I think the method is self documenting enough after renaming it?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The type doesn't compute anything though.

I'd suggest renaming to OpsemInhabitedCtx and then having the docs be something like

/// Context for computing whether a type is inhabited on the opsem level.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed

}

#[derive(Default)]
struct OpsemInhabitedInQuery {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What's this type for? Needs a doc comment either here or at the in_query field.

Or you can avoid this type entirely by making stop_at_ref a field of OpsemInhabited (which will also simplify some code a bit) and then just having seen: Option<FxHashSet> in OpsemInhabited.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added comments. I wanted the structure to be explicit about in-query vs. not-in-query modalities. OTOH I think the fact that only ty::Adt triggers the query is an implementation detail that could be tweaked. For example ty::Tuple could also trigger the query.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤷 I still think this would be simpler with stop_at_ref in the main ctx type and without a second type, and I don't see what this has to do with tuples triggering or not triggering the query, but I don't care strong enough to block the PR over it.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah I guess I over-engineered it. I flattened it.

Comment thread compiler/rustc_middle/src/ty/inhabitedness/mod.rs Outdated
Comment thread compiler/rustc_middle/src/ty/inhabitedness/mod.rs Outdated
Comment thread compiler/rustc_middle/src/ty/inhabitedness/mod.rs Outdated
Comment thread compiler/rustc_middle/src/ty/inhabitedness/mod.rs Outdated
@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 Jul 21, 2026
@rustbot

rustbot commented Jul 21, 2026

Copy link
Copy Markdown
Collaborator

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

@RalfJung

Copy link
Copy Markdown
Member

r? me

@rustbot rustbot assigned RalfJung and unassigned WaffleLapkin Jul 21, 2026
@camsteffen
camsteffen force-pushed the opsem-inhabited-refactor branch from 1d6f449 to 5d6890f Compare July 21, 2026 13:44
Comment thread compiler/rustc_middle/src/ty/inhabitedness/mod.rs
Comment thread compiler/rustc_middle/src/ty/inhabitedness/mod.rs Outdated
Comment thread compiler/rustc_middle/src/ty/inhabitedness/mod.rs Outdated
Comment thread compiler/rustc_middle/src/ty/inhabitedness/mod.rs
@camsteffen
camsteffen force-pushed the opsem-inhabited-refactor branch from 5d6890f to d9d430a Compare July 21, 2026 15:54
@camsteffen

Copy link
Copy Markdown
Contributor Author

@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 Jul 21, 2026
Comment on lines +366 to +369
let seen = self.seen.as_mut().unwrap();
// Remove the type again so that we allow it to appear on other branches.
if new_adt {
seen.remove(&adt_def.did());

@RalfJung RalfJung Jul 21, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
let seen = self.seen.as_mut().unwrap();
// Remove the type again so that we allow it to appear on other branches.
if new_adt {
seen.remove(&adt_def.did());
// Remove the type again so that we allow it to appear on other branches.
if new_adt {
self.seen.as_mut().unwrap().remove(&adt_def.did());

Or if you want a let-binding, move it inside the if, since it is only needed there.

View changes since the review

@RalfJung RalfJung left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks. :)
r=me with last nit resolved.

View changes since this review

@camsteffen
camsteffen force-pushed the opsem-inhabited-refactor branch from d9d430a to 7f2417b Compare July 21, 2026 17:31
@RalfJung

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 7f2417b has been approved by RalfJung

It is now in the queue for this repository.

@rust-bors rust-bors Bot 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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 21, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 21, 2026
…r, r=RalfJung

Refactor is_opsem_inhabited

Refactor of rust-lang#156977

Introduce a struct to generally simplify the recursion.

r? WaffleLapkin
cc @RalfJung
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 21, 2026
…r, r=RalfJung

Refactor is_opsem_inhabited

Refactor of rust-lang#156977

Introduce a struct to generally simplify the recursion.

r? WaffleLapkin
cc @RalfJung
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jul 21, 2026
…r, r=RalfJung

Refactor is_opsem_inhabited

Refactor of rust-lang#156977

Introduce a struct to generally simplify the recursion.

r? WaffleLapkin
cc @RalfJung
rust-bors Bot pushed a commit that referenced this pull request Jul 21, 2026
Rollup of 12 pull requests

Successful merges:

 - #159582 (Sync from portable simd 2026 07 20)
 - #158890 (Fix splat v0 mangling)
 - #159411 ([rustdoc] Correctly handle output options with --show-coverage)
 - #159647 (Remove `early_exit` closures)
 - #159656 (define a `Simd` type in `minicore`)
 - #156474 (Add paths for linked associated items)
 - #159211 (Fix debuginfo argument when invoking LLBC linker)
 - #159527 (Bring runtime symbols statics on par with foreign functions)
 - #159625 (Refactor is_opsem_inhabited)
 - #159652 (Remove `cfg(not(no_global_oom_handling))` from the `Drop` impl of `UniqueArcUninit`)
 - #159657 (Remove the blanket `#![cfg_attr(test, allow(unused))]` from bootstrap )
 - #159663 (Add layout cycle hang regression test)
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 22, 2026
…r, r=RalfJung

Refactor is_opsem_inhabited

Refactor of rust-lang#156977

Introduce a struct to generally simplify the recursion.

r? WaffleLapkin
cc @RalfJung
rust-bors Bot pushed a commit that referenced this pull request Jul 22, 2026
Rollup of 13 pull requests

Successful merges:

 - #159582 (Sync from portable simd 2026 07 20)
 - #158890 (Fix splat v0 mangling)
 - #159614 (debuginfo generation for unsafe binders)
 - #159647 (Remove `early_exit` closures)
 - #159656 (define a `Simd` type in `minicore`)
 - #156474 (Add paths for linked associated items)
 - #159211 (Fix debuginfo argument when invoking LLBC linker)
 - #159527 (Bring runtime symbols statics on par with foreign functions)
 - #159625 (Refactor is_opsem_inhabited)
 - #159629 (Add more splat rust-call regression tests)
 - #159652 (Remove `cfg(not(no_global_oom_handling))` from the `Drop` impl of `UniqueArcUninit`)
 - #159657 (Remove the blanket `#![cfg_attr(test, allow(unused))]` from bootstrap )
 - #159663 (Add layout cycle hang regression test)
rust-bors Bot pushed a commit that referenced this pull request Jul 22, 2026
Rollup of 13 pull requests

Successful merges:

 - #159582 (Sync from portable simd 2026 07 20)
 - #158890 (Fix splat v0 mangling)
 - #159614 (debuginfo generation for unsafe binders)
 - #159647 (Remove `early_exit` closures)
 - #159656 (define a `Simd` type in `minicore`)
 - #156474 (Add paths for linked associated items)
 - #159211 (Fix debuginfo argument when invoking LLBC linker)
 - #159527 (Bring runtime symbols statics on par with foreign functions)
 - #159625 (Refactor is_opsem_inhabited)
 - #159629 (Add more splat rust-call regression tests)
 - #159652 (Remove `cfg(not(no_global_oom_handling))` from the `Drop` impl of `UniqueArcUninit`)
 - #159657 (Remove the blanket `#![cfg_attr(test, allow(unused))]` from bootstrap )
 - #159663 (Add layout cycle hang regression test)
@rust-bors
rust-bors Bot merged commit ca0d2f7 into rust-lang:main Jul 22, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 22, 2026
rust-timer added a commit that referenced this pull request Jul 22, 2026
Rollup merge of #159625 - camsteffen:opsem-inhabited-refactor, r=RalfJung

Refactor is_opsem_inhabited

Refactor of #156977

Introduce a struct to generally simplify the recursion.

r? WaffleLapkin
cc @RalfJung
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants