Skip to content

reflection and comptime #406

Description

@nikomatsakis
Metadata
Contact @oli-obk
Team(s) compiler (@oli-obk), lang (@scottmcm), libs (@joshtriplett), types
Goal document 2026/reflection-and-comptime
Funding contact Funding team

Summary

Finish the implemented reflection scheme based on const fn that can only be called at compile time.
Validate it against existing reflection libraries by giving them a nightly feature that obsoletes having derives and makes the derives no-ops.
Obtain T-lang and T-libs buy-in for the scheme and write an RFC.
This proposal is solely for producing const eval values, not for putting types back into the type system.
That will be a follow-up once this proposal has a merged MVP.


This issue is intended for status updates only.

For general questions or comments, please contact a goal owner or post in the Zulip topic.

Activity

  1. added this to the 2025h2 milestone on Sep 16, 2025
  2. nikomatsakis commented on Sep 16, 2025

    @nikomatsakis
    ContributorAuthor

    This issue is intended for status updates only.

    For general questions or comments, please contact the owner(s) directly.

  3. locked and limited conversation to collaborators on Sep 16, 2025
  4. oli-obk commented on Oct 22, 2025

    @oli-obk
    Contributor

    I implemented an initial MVP supporting only tuples and primitives (tho those are just opaque things you can't interact with further), and getting offsets for the tuple fields as well as the size of the tuple: rust-lang/rust#146923

    There are two designs of how to expose this from a libs perspective, but after a sync meeting with scottmcm yesterday we came to the conclusion that neither is objectively better at this stage so we're just going to go with the nice end-user UX version for now. For details see the PR description.

    Once the MVP lands, I will mentor various interested contributors who will keep adding fields to the Type struct and variants the TypeKind enum.

    The next major step is restricting what information you can get from structs outside of the current module or crate. We want to honor visibility, so an initial step would be to just never show private fields, but we want to explore allowing private fields to be shown either just within the current module or via some opt-in marker trait

  5. nikomatsakis commented on Nov 12, 2025

    @nikomatsakis
    ContributorAuthor

    Another related PR:

    rust-lang/rust#148820

  6. oli-obk commented on Dec 15, 2025

    @oli-obk
    Contributor

    Updates

    Blockers

  7. oli-obk commented on Jan 14, 2026

    @oli-obk
    Contributor
  8. oli-obk commented on Feb 9, 2026

    @oli-obk
    Contributor

    There is ongoing work for Adts and function pointers, both of which will land as MVPs and will need some work to make them respect semver or generally become useful in practice

    Removing the 'static bound from try_as_dyn turned out to have many warts, so I'm limiting it to a much smaller subset and will have borrowck emit the 'static requirement if the other rules do not apply (instead of having an unconditional 'static requirement)

  9. oli-obk commented on Mar 19, 2026

    @oli-obk
    Contributor
  10. oli-obk commented on Apr 22, 2026

    @oli-obk
    Contributor

    No changes since last time.

    I'm writing a document for the lang team meeting on reflection next week

  11. 2 remaining items

  12. added this to the 2026 milestone on May 5, 2026
  13. tomassedovic commented on May 5, 2026

    @tomassedovic
    Contributor

    This is a continuing project goal, and the updates below this comment will be for the new period 2026

  14. added
    ex-2025h2Goals that were previously in 2025h2 (for reporting)
    and removed on May 11, 2026
  15. oli-obk commented on Jun 17, 2026

    @oli-obk
    Contributor

    We're changing the design away from one big enum with lots of structs inside to a more "many small functions giving you pieces" system. This has various reasons:

    • we stop computing the layout ahead of time for reflection, so you can use reflection to analyze the fields of a struct within an array length of a field of that struct. Arguably niche, but I expect there are more realistic layout cycle errors we would encounter in practical usage
    • it's so much simpler inside the compiler impl
    • the reflection libraries want their own representation anyway and they often just want a subset, so now they only pay for what they use

    @SpriteOvO has started this work in

    I landed an MVP of comptime fns in

    and started using it for the reflection methods in

    There's still lots to figure out around comptime and how it interacts with const traits, because in contrast to const Trait bounds, which are essentially sugar for Trait + rustc_comptime!(Trait) bounds, we do actually need something that adds bounds that can only be used at compile time (the rustc_comptime! macro doesn't actually exist).

  16. oli-obk commented on Jul 24, 2026

    @oli-obk
    Contributor

    has landed. You can now try_as_dyn on any T, even without a 'static bound. On the negative side, this now means we return None in more cases. See the documentation of try_as_dyn for details.

    moves over some more information from the big enum to individual methods. This made me realize we need the ability to fetch information directly for enum variants (name, non_exhaustive, ...). While we could just add a variant index to all the intrinsics, it would be nicer if we did the FRT thing and just had pattern types for individual variants, and were able to fetch information from them. Short term we'll just use the variant index and have a Variant data structure that wraps the index and the base type's typeid.

  17. oli-obk commented on Sep 9, 2026

    @oli-obk
    Contributor

    @yara-blue has made good progress on moving to the "many intrinsics" design (in contrast to the less flexible "one big enum" design):

    Once the transformation is complete, we'll add more methods until we have parity with at least bevy-reflect. Then we'll do an experiment to see if we can make the bevy-reflect derives be no-ops and instead have a single reflection based impl for bevy_reflect::Reflect

  18. oli-obk commented on Oct 9, 2026

    @oli-obk
    Contributor

    Yara continues cleaning up the API and the compiler impl

    She's also creating demos (e.g. a debug printer that uses Debug where it is there and reflection for debugging otherwise), and discovering what APIs are missing to enable some use cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions