Skip to content

Reflection refactor ptrs - #162294

Open
yara-blue wants to merge 6 commits into
rust-lang:mainfrom
yara-blue:reflection-refactor-ptrs
Open

Reflection refactor ptrs#162294
yara-blue wants to merge 6 commits into
rust-lang:mainfrom
yara-blue:reflection-refactor-ptrs

Conversation

@yara-blue

Copy link
Copy Markdown
Contributor

Tracking issue #146922

Part of the Refactoring to many methods reflection subgoal. See that for the full context. In short for various reasons we are moving from an enum TypeKind where the variants hold the types information to one that just tells you the type kind. Separate methods on TypeId provide a way to get to the data that used to be in the variant.

Since function pointers have a lot of fields it felt better to keep the FnPtr struct we have now then add an intrinsic for each field.

r? @oli-obk

@rustbot

rustbot commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

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

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 machinery

cc @RalfJung, @oli-obk, @lcnr

Some changes occurred in compiler/rustc_attr_ir

cc @jdonszelmann, @JonathanBrouwer

@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 Sep 4, 2026
@rustbot

rustbot commented Sep 4, 2026

Copy link
Copy Markdown
Collaborator

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

FromFn, sym::from, from_fn, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None;

// Experimental lang item for `Reflection and comptime`(https://goals.rust-lang.org/2025h2/reflection-and-comptime.html)
FnPtr, sym::FnPtr, fn_ptr, Target::Struct, GenericRequirement::None;

@yara-blue yara-blue Sep 4, 2026

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.

Note: I think adding a lang item is required to return a struct from a generic, please correct me if I'm wrong here.

View changes since the review

let variant_index = if let ty::FnPtr(sig, fn_header) = ty.kind() {
let (variant, variant_place) = ecx.project_downcast_named(dest, sym::Some)?;
let field_place = ecx.project_field(&variant_place, FieldIdx::ZERO)?;
let sig = sig.skip_binder(); // FIXME: handle lifetime bounds

@yara-blue yara-blue Sep 4, 2026

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.

the FIXME was pre-existing, itis copied from the CTFE code that wrote the FnPtr field in TypeKind::FnPtr(FnPtr). Not resolving that as part of this refactor.

View changes since the review

@yara-blue
yara-blue force-pushed the reflection-refactor-ptrs branch 2 times, most recently from 52f2e49 to b9b9421 Compare September 4, 2026 13:21

@yara-blue yara-blue Sep 4, 2026

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.

I originally did a straightforward port of these tests but decided to "uncouple" (testing only one "thing" per test) them also. Happy rewrite as a straightforward port.

View changes since the review

@rust-log-analyzer

This comment has been minimized.

@yara-blue
yara-blue force-pushed the reflection-refactor-ptrs branch from b9b9421 to 06fa642 Compare September 4, 2026 17:28
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-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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants