rust/compiler
rust-bors[bot] f57eac1bf9
Auto merge of #146923 - oli-obk:comptime-reflect, r=BoxyUwU
Reflection MVP

I am opening this PR for discussion about the general design we should start out with, as there are various options (that are not too hard to transition between each other, so we should totally just pick one and go with it and reiterate later)

r? @scottmcm and @joshtriplett

project goal issue: https://github.com/rust-lang/rust-project-goals/issues/406
tracking issue: https://github.com/rust-lang/rust/issues/146922

The design currently implemented by this PR is

* `TypeId::info` (method, usually used as `id.info()` returns a `Type` struct
* the `Type` struct has fields that contain information about the type
* the most notable field is `kind`, which is a non-exhaustive enum over all possible type kinds and their specific information. So it has a `Tuple(Tuple)` variant, where the only field is a `Tuple` struct type that contains more information (The list of type ids that make up the tuple).
* To get nested type information (like the type of fields) you need to call `TypeId::info` again.
* There is only one language intrinsic to go from `TypeId` to `Type`, and it does all the work

An alternative design could be

* Lots of small methods (each backed by an intrinsic) on `TypeId` that return all the individual information pieces (size, align, number of fields, number of variants, ...)
* This is how C++ does it (see https://lemire.me/blog/2025/06/22/c26-will-include-compile-time-reflection-why-should-you-care/ and https://isocpp.org/files/papers/P2996R13.html#member-queries)
* Advantage: you only get the information you ask for, so it's probably cheaper if you get just one piece of information for lots of types (e.g. reimplementing size_of in terms of `TypeId::info` is likely expensive and wasteful)
* Disadvantage: lots of method calling (and `Option` return types, or "general" methods like `num_fields` returning 0 for primitives) instead of matching and field accesses
* a crates.io crate could implement `TypeId::info` in terms of this design

The backing implementation is modular enough that switching from one to the other is probably not an issue, and the alternative design could be easier for the CTFE engine's implementation, just not as nice to use for end users (without crates wrapping the logic)

One wart of this design that I'm fixing in separate branches is that `TypeId::info` will panic if used at runtime, while it should be uncallable
2026-01-10 15:00:14 +00:00
..
rustc Auto merge of #148925 - madsmtm:jemalloc-perf, r=Kobzol 2025-11-23 20:34:07 +00:00
rustc_abi Rollup merge of #149991 - Flakebi:gpu-kernel-cc, r=workingjubilee 2026-01-02 23:13:21 +01:00
rustc_arena Finish transition from semitransparent to semiopaque for rustc_macro_transparency 2026-01-08 19:14:45 +01:00
rustc_ast fix up diagnostics referring to the right items 2026-01-09 09:29:02 +01:00
rustc_ast_ir Implement &pin patterns and ref pin bindings 2025-11-10 09:57:08 +08:00
rustc_ast_lowering Rollup merge of #150822 - fix-149981, r=@Kivooeo 2026-01-09 23:28:16 +01:00
rustc_ast_passes Auto merge of #150640 - AprilNEA:mgca-merge-associated-const-equality, r=BoxyUwU 2026-01-06 01:36:53 +00:00
rustc_ast_pretty Create a rustc_ast representation for parsed attributes 2026-01-06 09:03:35 +01:00
rustc_attr_parsing Rollup merge of #150829 - fix_generic_param_target, r=JonathanBrouwer 2026-01-09 12:00:02 +01:00
rustc_baked_icu_data Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_borrowck Convert static lifetime to an nll var 2026-01-07 13:27:12 +00:00
rustc_builtin_macros trick with super imports that fixes nameres in anonymous modules 2026-01-09 09:29:02 +01:00
rustc_codegen_cranelift Finish transition from semitransparent to semiopaque for rustc_macro_transparency 2026-01-08 19:14:45 +01:00
rustc_codegen_gcc Finish transition from semitransparent to semiopaque for rustc_macro_transparency 2026-01-08 19:14:45 +01:00
rustc_codegen_llvm make sentence more simple 2026-01-09 22:49:32 +02:00
rustc_codegen_ssa fix up diagnostics referring to the right items 2026-01-09 09:29:02 +01:00
rustc_const_eval Add size information 2026-01-08 12:02:59 +00:00
rustc_data_structures Auto merge of #149273 - bjorn3:crate_locator_improvements, r=petrochenkov 2025-12-14 09:16:11 +00:00
rustc_driver Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_driver_impl Include rustc version in ICE messages 2025-12-24 10:21:07 +00:00
rustc_error_codes Port #[instruction_set] to attribute parser 2025-12-31 03:01:05 +01:00
rustc_error_messages Remove unused pop_span_label method 2025-11-21 14:16:12 +00:00
rustc_errors remove fixme & update stderr files 2025-12-16 13:23:48 +00:00
rustc_expand Auto merge of #150310 - JonathanBrouwer:cfg_trace2, r=jdonszelmann 2026-01-06 22:59:32 +00:00
rustc_feature Move feature(multiple_supertrait_upcastable) to the actual feature gates section (from the internal feature gates section) and give it a tracking issue. 2026-01-08 14:57:32 -06:00
rustc_fluent_macro move and rename proc_macro::tracked_{env::var,path::path} 2025-11-26 22:44:25 +01:00
rustc_fs_util Avoid using env::temp when linking a binary 2025-12-24 06:41:42 +00:00
rustc_graphviz change non-canonical clone impl to {*self}, fix some doc comments 2025-12-20 13:46:22 +00:00
rustc_hashes some cleanups in compiler 2025-10-12 08:08:30 +00:00
rustc_hir Auto merge of #146923 - oli-obk:comptime-reflect, r=BoxyUwU 2026-01-10 15:00:14 +00:00
rustc_hir_analysis Auto merge of #146923 - oli-obk:comptime-reflect, r=BoxyUwU 2026-01-10 15:00:14 +00:00
rustc_hir_id rustc_hir_id: Add a comment explaining why the crate exists 2025-08-20 15:04:00 -07:00
rustc_hir_pretty MGCA: literals support 2026-01-08 20:29:00 +05:00
rustc_hir_typeck Add span field for ConstArg 2026-01-07 08:44:32 +08:00
rustc_incremental Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_index layout: Store inverse memory index in FieldsShape::Arbitrary 2025-12-18 22:25:34 +01:00
rustc_index_macros Revert introduction of [workspace.dependencies]. 2025-09-02 19:12:54 +10:00
rustc_infer Remove Option from fold_infer_ty return type. 2025-12-23 07:46:12 +11:00
rustc_interface Add missing translator resources for interface parse_cfg and parse_check_cfg 2026-01-04 11:53:31 +08:00
rustc_lexer lexer/parser: ensure deps use the same unicode version 2025-12-27 11:20:42 +01:00
rustc_lint Add span field for ConstArg 2026-01-07 08:44:32 +08:00
rustc_lint_defs Update compiler/rustc_lint_defs/src/builtin.rs 2025-12-19 15:04:30 -08:00
rustc_llvm Rollup merge of #150511 - Sa4dUs:offload-inline, r=ZuseZ4 2025-12-31 14:30:48 +01:00
rustc_log Restrict sysroot crate imports to those defined in this repo. 2025-10-15 13:17:25 +01:00
rustc_macros Rollup merge of #149400 - Skgland:tracked_mod, r=Amanieu 2025-12-09 17:36:48 +01:00
rustc_metadata fix up diagnostics referring to the right items 2026-01-09 09:29:02 +01:00
rustc_middle Rollup merge of #150811 - defid-aliases, r=bjorn3 2026-01-08 22:21:21 +01:00
rustc_mir_build Rollup merge of #150670 - Zalathar:let-ty, r=Nadrieril 2026-01-06 16:19:41 +01:00
rustc_mir_dataflow Clarify MoveData::init_loc_map. 2026-01-02 09:29:26 +11:00
rustc_mir_transform Fix ICE in inline always warning emission. 2026-01-08 11:59:41 +00:00
rustc_monomorphize Rollup merge of #150569 - check_static_initializer_acyclic, r=workingjubilee 2026-01-08 16:25:30 +01:00
rustc_next_trait_solver Merge associated_const_equality feature gate into MGCA 2026-01-05 12:31:42 +08:00
rustc_parse Update literal-escaper version to 0.0.7 2026-01-08 14:10:33 +01:00
rustc_parse_format Update literal-escaper version to 0.0.7 2026-01-08 14:10:33 +01:00
rustc_passes trick with super imports that fixes nameres in anonymous modules 2026-01-09 09:29:02 +01:00
rustc_pattern_analysis Fix typo in pattern usefulness documentation 2026-01-03 22:46:09 +05:30
rustc_privacy Unify the configuration of the compiler docs 2025-11-05 11:25:27 +00:00
rustc_proc_macro Update literal-escaper version to 0.0.7 2026-01-08 14:10:33 +01:00
rustc_public Auto merge of #148766 - cjgillot:mir-const-runtime-checks, r=RalfJung,saethlin 2025-12-22 06:58:28 +00:00
rustc_public_bridge Overhaul filename handling for cross-compiler consistency 2025-12-12 07:33:09 +01:00
rustc_query_impl Lock shards while collecting active jobs. 2025-11-14 09:01:22 +08:00
rustc_query_system Make attr path symbols rather than idents 2025-12-22 16:26:14 +01:00
rustc_resolve Auto merge of #150502 - petrochenkov:overglob, r=yaahc 2026-01-10 05:03:09 +00:00
rustc_sanitizers Port #[cfi_encoding] to attribute parser 2025-12-21 22:11:33 +01:00
rustc_serialize Allow internal_features lint in doc tests 2025-11-05 11:25:29 +00:00
rustc_session Update test and verify that tgt_(un)register_lib have the right type 2026-01-04 06:58:31 -08:00
rustc_span Auto merge of #146923 - oli-obk:comptime-reflect, r=BoxyUwU 2026-01-10 15:00:14 +00:00
rustc_symbol_mangling refactor destructure_const 2025-12-28 16:12:27 +00:00
rustc_target Rollup merge of #150802 - fn_abi_cleanup, r=lqd 2026-01-08 22:21:19 +01:00
rustc_thread_pool change non-canonical clone impl to {*self}, fix some doc comments 2025-12-20 13:46:22 +00:00
rustc_trait_selection Add span field for ConstArg 2026-01-07 08:44:32 +08:00
rustc_traits add const_of_item query and use it in normalization 2025-11-08 13:50:47 -05:00
rustc_transmute Fix ICE when transmute Assume field is invalid 2026-01-06 04:38:51 +00:00
rustc_ty_utils Minor cleanups to fn_abi_new_uncached 2026-01-08 10:49:44 +00:00
rustc_type_ir Auto merge of #150640 - AprilNEA:mgca-merge-associated-const-equality, r=BoxyUwU 2026-01-06 01:36:53 +00:00
rustc_type_ir_macros Provide an extended framework for type visit, for use in rust-analyzer 2025-12-16 01:47:28 +02:00
rustc_windows_rc [win] Use find-msvc-tools instead of cc to find the linker and rc on Windows 2025-09-19 12:00:30 -07:00