rust/compiler
bors 32e7a4b92b Auto merge of #144405 - lcnr:hir-typeck-uniquify, r=BoxyUwU
uniquify root goals during HIR typeck

We need to rely on region identity to deal with hangs such as https://github.com/rust-lang/trait-system-refactor-initiative/issues/210 and to keep the current behavior of `fn try_merge_responses`.

This is a problem as borrowck starts by replacing each *occurrence* of a region with a unique inference variable. This frequently splits a single region during HIR typeck into multiple distinct regions. As we assume goals to always succeed during borrowck, relying on two occurances of a region being identical during HIR typeck causes ICE. See the now fixed examples in https://github.com/rust-lang/trait-system-refactor-initiative/issues/27 and rust-lang/rust#139409.

We've previously tried to avoid this issue by always *uniquifying* regions when canonicalizing goals. This prevents caching subtrees during canonicalization which resulted in hangs for very large types. People rely on such types in practice, which caused us to revert our attempt to reinstate `#[type_length_limit]` in https://github.com/rust-lang/rust/pull/127670. The complete list of changes here:
- rust-lang/rust#107981
- rust-lang/rust#110180
- rust-lang/rust#114117
- rust-lang/rust#130821

After more consideration, all occurrences of such large types need to happen outside of typeck/borrowck. We know this as we already walk over all types in the MIR body when replacing their regions with nll vars.

This PR therefore enables us to rely on region identity inside of the trait solver by exclusively **uniquifying root goals during HIR typeck**. These are the only goals we assume to hold during borrowck. This is insufficient as type inference variables may "hide" regions we later uniquify. Because of this, we now stash proven goals which depend on inference variables in HIR typeck and reprove them after writeback. This closes https://github.com/rust-lang/trait-system-refactor-initiative/issues/127.

This was originally part of rust-lang/rust#144258 but I've moved it into a separate PR. While I believe we need to rely on region identity to fix the performance issues in some way, I don't know whether rust-lang/rust#144258 is the best approach to actually do so. Regardless of how we deal with the hangs however, this change is necessary and desirable regardless.

r? `@compiler-errors` or `@BoxyUwU`
2025-07-31 00:32:55 +00:00
..
rustc rename stable_mir to rustc_public, and rustc_smir to rustc_public_bridge 2025-07-14 09:25:54 +00:00
rustc_abi Reuse sign_extend helper 2025-07-29 14:17:48 +00:00
rustc_arena Introduce Arena::try_alloc_from_iter. 2025-04-19 01:13:18 +00:00
rustc_ast Don't lint against named labels in naked_asm! 2025-07-26 00:42:21 +01:00
rustc_ast_ir Use -Wunused_crate_dependencies for compiler crates. 2025-03-20 08:59:43 +11:00
rustc_ast_lowering Auto merge of #144557 - cjgillot:lower-more-span, r=compiler-errors 2025-07-29 17:39:48 +00:00
rustc_ast_passes use let chains in ast, borrowck, codegen, const_eval 2025-07-28 06:08:48 +05:00
rustc_ast_pretty use let chains in ast, borrowck, codegen, const_eval 2025-07-28 06:08:48 +05:00
rustc_attr_data_structures coverage: Rename CoverageStatus to CoverageAttrKind 2025-07-29 19:55:54 +10:00
rustc_attr_parsing coverage: Rename CoverageStatus to CoverageAttrKind 2025-07-29 19:55:54 +10:00
rustc_baked_icu_data
rustc_borrowck Rollup merge of #144666 - compiler-errors:correct-late, r=lqd 2025-07-30 17:59:40 +10:00
rustc_builtin_macros expand: Micro-optimize prelude injection 2025-07-28 17:35:09 +03:00
rustc_codegen_cranelift Update codegen_{cranelift,gcc} and opt-dist to use build.compiletest-allow-stage0 2025-07-30 19:55:07 +08:00
rustc_codegen_gcc Update codegen_{cranelift,gcc} and opt-dist to use build.compiletest-allow-stage0 2025-07-30 19:55:07 +08:00
rustc_codegen_llvm Rollup merge of #144407 - godzie44:godzie44/fix_dwarf_inconsistency, r=wesleywiser 2025-07-29 20:19:49 +10:00
rustc_codegen_ssa clean up codegen fn attrs 2025-07-30 16:39:16 +02:00
rustc_const_eval Rename trait_of_item -> trait_of_assoc 2025-07-28 09:53:50 -05:00
rustc_data_structures Allow pretty printing paths with -Zself-profile-events=args 2025-07-25 22:24:21 +02:00
rustc_driver Remove recursion_limit increases. 2025-04-02 16:25:27 +11:00
rustc_driver_impl Rollup merge of #143719 - xizheyin:142812-1, r=jieyouxu 2025-07-18 04:27:51 +02:00
rustc_error_codes Update uitest stderrs 2025-07-23 13:33:23 +02:00
rustc_error_messages Remove unused feature gates 2025-06-28 23:36:46 +00:00
rustc_errors feat: Right align line numbers 2025-07-28 16:32:11 -06:00
rustc_expand Rollup merge of #143607 - JonathanBrouwer:proc_macro_attrs, r=jdonszelmann,traviscross 2025-07-28 01:16:38 +02:00
rustc_feature Mitigate #[align] name resolution ambiguity regression with a rename 2025-07-19 01:42:30 +08:00
rustc_fluent_macro Remove all unused feature gates from the compiler 2025-06-08 14:50:42 +00:00
rustc_fs_util Retry if creating temp fails with access denied 2025-04-25 11:28:36 +00:00
rustc_graphviz
rustc_hashes
rustc_hir Rollup merge of #144578 - FractalFir:m68k_fix, r=compiler-errors 2025-07-29 16:16:45 +10:00
rustc_hir_analysis Rename impl_of_method -> impl_of_assoc 2025-07-28 09:54:53 -05:00
rustc_hir_pretty parse const trait Trait 2025-07-17 18:06:26 +08:00
rustc_hir_typeck Auto merge of #144405 - lcnr:hir-typeck-uniquify, r=BoxyUwU 2025-07-31 00:32:55 +00:00
rustc_incremental Auto merge of #139758 - Zoxc:thread-local-graph, r=oli-obk 2025-05-07 12:39:54 +00:00
rustc_index use div_ceil instead of manual logic 2025-07-05 10:55:42 +02:00
rustc_index_macros In rustc_mir_tranform, iterate over index newtypes instead of ints 2025-04-12 11:53:07 +00:00
rustc_infer handle region dependent goals due to infer vars 2025-07-30 14:01:37 +02:00
rustc_interface Stop compilation if macro expansion failed 2025-07-25 23:46:28 +02:00
rustc_lexer test(lexer): Add frontmatter unit test 2025-07-10 10:25:29 -05:00
rustc_lint Create two methods to fix find_oldest_ancestor_in_same_ctxt 2025-07-29 14:54:47 +08:00
rustc_lint_defs Rollup merge of #144014 - dianne:edition-guide-links, r=estebank 2025-07-24 15:08:21 +02:00
rustc_llvm cc dependencies: clarify comment 2025-07-29 09:22:24 +02:00
rustc_log Add documentation for init_logger_with_additional_layer 2025-06-12 12:11:15 +02:00
rustc_macros Implement AST visitors using a derive macro. 2025-07-22 01:52:34 +00:00
rustc_metadata Support multiple crate versions in --extern-html-root-url 2025-07-28 13:34:03 +01:00
rustc_middle Auto merge of #116316 - cjgillot:incr-privacy, r=petrochenkov 2025-07-30 21:29:47 +00:00
rustc_mir_build fix: Reject upvar scrutinees for loop_match 2025-07-28 22:24:58 +09:00
rustc_mir_dataflow use let chains in hir, lint, mir 2025-07-28 06:10:14 +05:00
rustc_mir_transform Rollup merge of #144566 - scottmcm:align-of-slice, r=oli-obk 2025-07-29 23:50:35 +10:00
rustc_monomorphize Rename impl_of_method -> impl_of_assoc 2025-07-28 09:54:53 -05:00
rustc_next_trait_solver Auto merge of #144405 - lcnr:hir-typeck-uniquify, r=BoxyUwU 2025-07-31 00:32:55 +00:00
rustc_parse Rollup merge of #144589 - compiler-errors:postfix-yield-after-cast, r=petrochenkov 2025-07-29 23:50:37 +10:00
rustc_parse_format update to literal-escaper-0.0.5 2025-07-08 10:16:44 +00:00
rustc_passes Rename impl_of_method -> impl_of_assoc 2025-07-28 09:54:53 -05:00
rustc_pattern_analysis Rollup merge of #144171 - Nadrieril:exhaustive-witnesses, r=davidtwco 2025-07-26 01:15:04 -05:00
rustc_privacy use let chains in mir, resolve, target 2025-07-28 06:10:36 +05:00
rustc_proc_macro update to literal-escaper-0.0.5 2025-07-08 10:16:44 +00:00
rustc_public remove movability from RigidTy::Coroutine and AggregateKind::Coroutine 2025-07-24 18:26:08 +08:00
rustc_public_bridge Remove useless lifetime parameter. 2025-07-23 23:54:37 +00:00
rustc_query_impl Remove unused allow attrs 2025-07-07 12:58:16 +00:00
rustc_query_system Auto merge of #144469 - Kivooeo:chains-cleanup, r=SparrowLii 2025-07-28 05:25:23 +00:00
rustc_resolve Rollup merge of #144605 - LorrensP-2158466:cache-extern-prelude, r=petrochenkov 2025-07-29 18:55:20 -04:00
rustc_sanitizers Rename impl_of_method -> impl_of_assoc 2025-07-28 09:54:53 -05:00
rustc_serialize use div_ceil instead of manual logic 2025-07-05 10:55:42 +02:00
rustc_session Auto merge of #144562 - matthiaskrgr:rollup-mlvn7qo, r=matthiaskrgr 2025-07-28 08:50:59 +00:00
rustc_span Create two methods to fix find_oldest_ancestor_in_same_ctxt 2025-07-29 14:54:47 +08:00
rustc_symbol_mangling use codegen_instance_attrs where an instance is (easily) available 2025-07-16 23:24:32 +02:00
rustc_target Rollup merge of #144640 - FractalFir:m68k_arch, r=Urgau 2025-07-29 18:55:22 -04:00
rustc_thread_pool Correct comments. 2025-06-28 17:58:21 +08:00
rustc_trait_selection Auto merge of #144405 - lcnr:hir-typeck-uniquify, r=BoxyUwU 2025-07-31 00:32:55 +00:00
rustc_traits Consider param-env for fast path 2025-07-20 17:45:01 +00:00
rustc_transmute compiler: Parse p- specs in datalayout string, allow definition of custom default data address space 2025-07-07 09:04:53 +02:00
rustc_ty_utils Rename trait_of_item -> trait_of_assoc 2025-07-28 09:53:50 -05:00
rustc_type_ir Auto merge of #144405 - lcnr:hir-typeck-uniquify, r=BoxyUwU 2025-07-31 00:32:55 +00:00
rustc_type_ir_macros Split TypeFolder and FallibleTypeFolder 2025-04-15 18:30:35 +00:00