Skip to content

Reflection: refactor Type and TypeKind - #166150

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
Tess4552:reflection-type-flattening
Nov 20, 2026
Merged

rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
Tess4552:reflection-type-flattening

Conversation

@Tess4552

Copy link
Copy Markdown
Contributor

Refactor by moving some things around.
Since we only had one field in Type, removed struct Type and renamed enum TypeKind to Type.

Flattened Type to be fieldless enum in the spirit of not computing things the user didn't ask for.

Added Never type as a variant of Type.

r? @oli-obk
cc @yara-blue

@rustbot

rustbot commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in compiler/rustc_attr_ir

cc @jdonszelmann, @JonathanBrouwer

The reflection data structures are tied exactly to the implementation
in the compiler. Make sure to also adjust rustc_const_eval/src/const_eval/type_info.rs

cc @oli-obk

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the intrinsics. Make sure the CTFE / Miri interpreter
gets adapted for the changes, if necessary.

cc @rust-lang/miri, @RalfJung, @oli-obk, @lcnr

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) 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. labels Nov 18, 2026
@Tess4552
Tess4552 force-pushed the reflection-type-flattening branch from e5e79b1 to d650051 Compare November 18, 2026 12:32
@rust-log-analyzer

This comment has been minimized.

@Tess4552
Tess4552 force-pushed the reflection-type-flattening branch from d650051 to c961662 Compare November 18, 2026 13:20

@yara-blue yara-blue 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.

minor typo in example.

View changes since this review

Comment thread library/core/src/mem/type_info.rs Resolved
Comment thread library/core/src/mem/type_info.rs Resolved
@yara-blue

yara-blue commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Might be better to rename the outer Type to TypeKind since it no longer contains any info about the type (as that now goes exclusively through queries on TypeId). What do you think?

@Tess4552

Copy link
Copy Markdown
Contributor Author

Agreed, think TypeKind is a better name.

@Tess4552
Tess4552 force-pushed the reflection-type-flattening branch from c961662 to 9abc52d Compare November 18, 2026 14:32
@rust-log-analyzer

This comment has been minimized.

@Tess4552
Tess4552 force-pushed the reflection-type-flattening branch from 9abc52d to 5c0a0de Compare November 18, 2026 14:57
@rust-bors

This comment has been minimized.

@Tess4552
Tess4552 force-pushed the reflection-type-flattening branch from 5c0a0de to 7ae1242 Compare November 18, 2026 15:59
@rustbot

This comment has been minimized.

Comment thread library/core/src/mem/type_info.rs Resolved

@oli-obk oli-obk left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@rust-bors

rust-bors Bot commented Nov 19, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 7ae1242 has been approved by oli-obk

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 Nov 19, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 19, 2026
…uwer

Rollup of 13 pull requests

Successful merges:

 - #157721 (compiletest: Add testing for lint machinery at runtime)
 - #165934 (Avoid using Terminator:None in simplify_cfg)
 - #166117 (Remove ebadf handling from stdio)
 - #165094 (reflection: doc attributes from adts, fields, and variants)
 - #165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected)
 - #165694 (view-types: make sure view types are !Sized)
 - #165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector)
 - #165971 (fix: non-deterministic temporary object paths in linker maps)
 - #166136 (Move ub_checks() inside the const_eval_select branch.)
 - #166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`)
 - #166176 (compiletest: Move all code out of the crate root)
 - #166185 (simd-test: Fix cfg syntax in the test macro)
 - #166194 (std: Unstably constify `std::process::abort`)

Failed merges:

 - #166150 (Reflection: refactor Type and TypeKind)
 - #166160 (refactor CTFE-specific intrinsics to different file)
rust-bors Bot pushed a commit that referenced this pull request Nov 19, 2026
…uwer

Rollup of 16 pull requests

Successful merges:

 - #166078 (rustc_type_ir: Optimize `sub_root_lookup_table` by using `SsoHashMap`, not `HashMap`)
 - #165934 (Avoid using Terminator:None in simplify_cfg)
 - #166050 (Use attribute parser for lang attributes in `LateResolutionVisitor`)
 - #166117 (Remove ebadf handling from stdio)
 - #166119 (Avoid an ICE on re-exports of private imports without a DefId)
 - #165094 (reflection: doc attributes from adts, fields, and variants)
 - #165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected)
 - #165694 (view-types: make sure view types are !Sized)
 - #165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector)
 - #165971 (fix: non-deterministic temporary object paths in linker maps)
 - #166064 (Add const generic transmute min support)
 - #166136 (Move ub_checks() inside the const_eval_select branch.)
 - #166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`)
 - #166176 (compiletest: Move all code out of the crate root)
 - #166185 (simd-test: Fix cfg syntax in the test macro)
 - #166194 (std: Unstably constify `std::process::abort`)

Failed merges:

 - #166150 (Reflection: refactor Type and TypeKind)
 - #166160 (refactor CTFE-specific intrinsics to different file)
rust-bors Bot pushed a commit that referenced this pull request Nov 20, 2026
Rollup of 21 pull requests

Successful merges:

 - #165707 (bootstrap: Make low priority the default)
 - #165716 (Refactor split_block in check_pointers to avoid Terminator: None)
 - #165934 (Avoid using Terminator:None in simplify_cfg)
 - #166050 (Use attribute parser for lang attributes in `LateResolutionVisitor`)
 - #166069 (bootstrap: fix keep-stage-std)
 - #166117 (Remove ebadf handling from stdio)
 - #166119 (Avoid an ICE on re-exports of private imports without a DefId)
 - #165094 (reflection: doc attributes from adts, fields, and variants)
 - #165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected)
 - #165694 (view-types: make sure view types are !Sized)
 - #165802 (Add CI workflow to publish backtrace after a push to main)
 - #165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector)
 - #165906 (fix ICE when a forced keyword follows a parameter pattern)
 - #166064 (Add const generic transmute min support)
 - #166136 (Move ub_checks() inside the const_eval_select branch.)
 - #166158 (bump some tools' `toml` dependency)
 - #166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`)
 - #166176 (compiletest: Move all code out of the crate root)
 - #166185 (simd-test: Fix cfg syntax in the test macro)
 - #166194 (std: Unstably constify `std::process::abort`)
 - #166210 (Avoid terminator: None in insert_direct_enum_check)

Failed merges:

 - #166150 (Reflection: refactor Type and TypeKind)
 - #166160 (refactor CTFE-specific intrinsics to different file)
rust-bors Bot pushed a commit that referenced this pull request Nov 20, 2026
Rollup of 20 pull requests

Successful merges:

 - #165716 (Refactor split_block in check_pointers to avoid Terminator: None)
 - #165934 (Avoid using Terminator:None in simplify_cfg)
 - #166050 (Use attribute parser for lang attributes in `LateResolutionVisitor`)
 - #166069 (bootstrap: fix keep-stage-std)
 - #166117 (Remove ebadf handling from stdio)
 - #166119 (Avoid an ICE on re-exports of private imports without a DefId)
 - #165094 (reflection: doc attributes from adts, fields, and variants)
 - #165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected)
 - #165694 (view-types: make sure view types are !Sized)
 - #165802 (Add CI workflow to publish backtrace after a push to main)
 - #165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector)
 - #165906 (fix ICE when a forced keyword follows a parameter pattern)
 - #166064 (Add const generic transmute min support)
 - #166136 (Move ub_checks() inside the const_eval_select branch.)
 - #166158 (bump some tools' `toml` dependency)
 - #166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`)
 - #166176 (compiletest: Move all code out of the crate root)
 - #166185 (simd-test: Fix cfg syntax in the test macro)
 - #166194 (std: Unstably constify `std::process::abort`)
 - #166210 (Avoid terminator: None in insert_direct_enum_check)

Failed merges:

 - #166150 (Reflection: refactor Type and TypeKind)
 - #166160 (refactor CTFE-specific intrinsics to different file)
@rust-bors rust-bors Bot 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-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Nov 20, 2026
@rust-bors

This comment has been minimized.

@Tess4552
Tess4552 force-pushed the reflection-type-flattening branch from 7ae1242 to dac20be Compare November 20, 2026 07:37
@rustbot

rustbot commented Nov 20, 2026

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.

@oli-obk

oli-obk commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Nov 20, 2026

Copy link
Copy Markdown
Contributor

📌 Commit dac20be has been tentatively approved by oli-obk

It will be put into the queue for this repository once PR CI succeeds.

@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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Nov 20, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 20, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #165814 (diag: Fix source location for macro diagnostic message)
 - #166091 (Abby: make the fields of `And/Or` private)
 - #166150 (Reflection: refactor Type and TypeKind)
 - #166213 (remove optionally_braced_mac_call)
 - #166233 (Allow `#[derive(StableHash)]` for enums with >256 variants)
 - #166237 (Add crash test for const param ty unchecked)
@rust-bors
rust-bors Bot merged commit ab8a3de into rust-lang:main Nov 20, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 20, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 20, 2026
Rollup merge of #166150 - Tess4552:reflection-type-flattening, r=oli-obk

Reflection: refactor Type and TypeKind

Refactor by moving some things around.
Since we only had one field in `Type`, removed `struct Type` and renamed  `enum TypeKind` to `Type`.

Flattened Type to be fieldless enum in the spirit of not computing things the user didn't ask for.

Added Never type as a variant of Type.

r? @oli-obk
cc @yara-blue
folkertdev pushed a commit to folkertdev/stdarch that referenced this pull request Nov 22, 2026
Rollup of 20 pull requests

Successful merges:

 - rust-lang/rust#165716 (Refactor split_block in check_pointers to avoid Terminator: None)
 - rust-lang/rust#165934 (Avoid using Terminator:None in simplify_cfg)
 - rust-lang/rust#166050 (Use attribute parser for lang attributes in `LateResolutionVisitor`)
 - rust-lang/rust#166069 (bootstrap: fix keep-stage-std)
 - rust-lang/rust#166117 (Remove ebadf handling from stdio)
 - rust-lang/rust#166119 (Avoid an ICE on re-exports of private imports without a DefId)
 - rust-lang/rust#165094 (reflection: doc attributes from adts, fields, and variants)
 - rust-lang/rust#165216 (Clearer diagnostics when `&FnOnce` was provided when `FnOnce` was expected)
 - rust-lang/rust#165694 (view-types: make sure view types are !Sized)
 - rust-lang/rust#165802 (Add CI workflow to publish backtrace after a push to main)
 - rust-lang/rust#165883 (Report a recursion limit error instead of delaying a bug in RPITIT collector)
 - rust-lang/rust#165906 (fix ICE when a forced keyword follows a parameter pattern)
 - rust-lang/rust#166064 (Add const generic transmute min support)
 - rust-lang/rust#166136 (Move ub_checks() inside the const_eval_select branch.)
 - rust-lang/rust#166158 (bump some tools' `toml` dependency)
 - rust-lang/rust#166166 (Don't recover if not allowed in `parse_seq_to_before_tokens`)
 - rust-lang/rust#166176 (compiletest: Move all code out of the crate root)
 - rust-lang/rust#166185 (simd-test: Fix cfg syntax in the test macro)
 - rust-lang/rust#166194 (std: Unstably constify `std::process::abort`)
 - rust-lang/rust#166210 (Avoid terminator: None in insert_direct_enum_check)

Failed merges:

 - rust-lang/rust#166150 (Reflection: refactor Type and TypeKind)
 - rust-lang/rust#166160 (refactor CTFE-specific intrinsics to different file)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants