1
Fork 0
rust/compiler/rustc_mir_transform/src
bors 003a902792 Auto merge of #125958 - BoxyUwU:remove_const_ty, r=lcnr
Remove the `ty` field from type system `Const`s

Fixes #125556
Fixes #122908

Part of the work on `adt_const_params`/`generic_const_param_types`/`min_generic_const_exprs`/generally making the compiler nicer. cc rust-lang/project-const-generics#44

Please review commit-by-commit otherwise I wasted a lot of time not just squashing this into a giant mess (and also it'll be SO much nicer because theres a lot of fluff changes mixed in with other more careful changes if looking via File Changes

---

Why do this?
- The `ty` field keeps causing ICEs and weird behaviour due to it either being treated as "part of the const" or it being forgotten about leading to ICEs.
- As we move forward with `adt_const_params` and a potential `min_generic_const_exprs` it's going to become more complex to actually lower the correct `Ty<'tcx>`
- It muddles the idea behind how we check `Const` arguments have the correct type. By having the `ty` field it may seem like we ought to be relating it when we relate two types, or that its generally important information about the `Const`.
- Brings the compiler more in line with `a-mir-formality` as that also tracks the type of type system `Const`s via `ConstArgHasType` bounds in the env instead of on the `Const` itself.
- A lot of stuff is a lot nicer when you dont have to pass around the type of a const lol. Everywhere we construct `Const` is now significantly nicer 😅

See #125671's description for some more information about the `ty` field

---

General summary of changes in this PR:

- Add `Ty` to `ConstKind::Value` as otherwise there is no way to implement `ConstArgHasType` to ensure that const arguments are correctly typed for the parameter when we stop creating anon consts for all const args. It's also just incredibly difficult/annoying to thread the correct `Ty` around to a bunch of ctfe functions otherwise.
-  Fully implement `ConstArgHasType` in both the old and new solver. Since it now has no reliance on the `ty` field it serves its originally intended purpose of being able to act as a double check that trait vs impls have correctly typed const parameters. It also will now be able to be responsible for checking types of const arguments to parameters under `min_generic_const_exprs`.
- Add `Ty` to `mir::Const::Ty`. I dont have a great understanding of why mir constants are setup like this to be honest. Regardless they need to be able to determine the type of the const and the easiest way to make this happen was to simply store the `Ty` along side the `ty::Const`. Maybe we can do better here in the future but I'd have to spend way more time looking at everywhere we use `mir::Const`.
- rustdoc has its own `Const` which also has a `ty` field. It was relatively easy to remove this.

---

r? `@lcnr` `@compiler-errors`
2024-06-06 03:41:23 +00:00
..
coroutine Remove extern crate rustc_middle from rustc_mir_transform. 2024-05-13 08:20:18 +10:00
coverage coverage: Remove hole-carving code from the main span refiner 2024-06-04 13:51:08 +10:00
inline Add simple async drop glue generation 2024-04-16 20:45:07 +03:00
shim Optimize async drop glue for some old types 2024-05-29 12:56:59 +03:00
abort_unwinding_calls.rs Remove extern crate rustc_middle from rustc_mir_transform. 2024-05-13 08:20:18 +10:00
add_call_guards.rs remove redundant imports 2023-12-10 10:56:22 +08:00
add_moves_for_packed_drops.rs remove redundant imports 2023-12-10 10:56:22 +08:00
add_retag.rs add_retag: ensure box-to-raw-ptr casts are preserved for Miri 2024-03-18 10:32:25 +01:00
add_subtyping_projections.rs remove redundant imports 2023-12-10 10:56:22 +08:00
check_alignment.rs Make builtin_deref just return a Ty 2024-05-09 22:55:00 -04:00
check_const_item_mutation.rs Rename TyCtxt::emit_spanned_lint as TyCtxt::emit_node_span_lint. 2024-01-23 08:09:05 +11:00
check_packed_ref.rs Remove extern crate rustc_middle from rustc_mir_transform. 2024-05-13 08:20:18 +10:00
cleanup_post_borrowck.rs Add a non-shallow fake borrow 2024-04-20 16:01:35 +02:00
const_debuginfo.rs Format all the let chains in compiler 2023-10-13 08:59:36 +00:00
copy_prop.rs Merge borrowed locals too. 2024-04-20 19:20:38 +00:00
coroutine.rs Opt-in diagnostics reporting to avoid doing extra work in the new solver 2024-06-03 09:27:52 -04:00
cost_checker.rs Make is_intrinsic query return the intrinsic name 2024-02-12 09:33:52 +00:00
cross_crate_inline.rs Remove all checks of IntrinsicDef::must_be_overridden except for the actual overrides in codegen 2024-03-19 09:19:58 +00:00
ctfe_limit.rs Fix clippy::needless_borrow in the compiler 2023-11-21 20:13:40 +01:00
dataflow_const_prop.rs Add Ty to mir::Const::Ty 2024-06-05 22:25:41 +01:00
dead_store_elimination.rs Remove extern crate rustc_middle from rustc_mir_transform. 2024-05-13 08:20:18 +10:00
deduce_param_attrs.rs consistency rename: language item -> lang item 2024-04-17 13:00:43 +02:00
deduplicate_blocks.rs Merge dead bb pruning and unreachable bb deduplication. 2024-01-07 15:12:10 +00:00
deref_separator.rs remove redundant imports 2023-12-10 10:56:22 +08:00
dest_prop.rs Revert "Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obk" 2024-05-31 00:22:40 +00:00
dump_mir.rs Show files produced by --emit foo in json artifact notifications 2024-04-19 08:31:41 -04:00
early_otherwise_branch.rs Don't change the otherwise of the switch 2024-04-08 19:20:07 +08:00
elaborate_box_derefs.rs Remove extern crate rustc_middle from rustc_mir_transform. 2024-05-13 08:20:18 +10:00
elaborate_drops.rs Reformat mir! macro invocations to use braces. 2024-06-03 13:24:44 +10:00
errors.rs Remove LintDiagnostic::msg 2024-05-23 04:08:35 +02:00
ffi_unwind_calls.rs Remove extern crate rustc_middle from rustc_mir_transform. 2024-05-13 08:20:18 +10:00
function_item_references.rs Rename Unsafe to Safety 2024-05-17 18:33:37 -03:00
gvn.rs Auto merge of #125958 - BoxyUwU:remove_const_ty, r=lcnr 2024-06-06 03:41:23 +00:00
inline.rs compiler: const_eval/transform/validate.rs -> mir_transform/validate.rs 2024-05-24 09:56:56 -07:00
instsimplify.rs Add Ty to mir::Const::Ty 2024-06-05 22:25:41 +01:00
jump_threading.rs interpret: get rid of 'mir lifetime everywhere 2024-05-27 08:25:57 +02:00
known_panics_lint.rs check index value <= 0xFFFF_FF00 2024-06-01 09:40:46 +08:00
large_enums.rs Simplify use crate::rustc_foo::bar occurrences. 2024-05-08 16:57:31 +10:00
lib.rs Revert "Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obk" 2024-05-31 00:22:40 +00:00
lint.rs compiler: Lower fn call arg spans down to MIR 2024-01-15 19:07:11 +01:00
lower_intrinsics.rs Add an intrinsic for ptr::metadata 2024-05-28 09:28:51 -07:00
lower_slice_len.rs consistency rename: language item -> lang item 2024-04-17 13:00:43 +02:00
match_branches.rs Auto merge of #124156 - DianQK:disable-match_branches, r=RalfJung 2024-04-20 08:47:07 +00:00
mentioned_items.rs Make builtin_deref just return a Ty 2024-05-09 22:55:00 -04:00
multiple_return_terminators.rs remove redundant imports 2023-12-10 10:56:22 +08:00
normalize_array_len.rs Add Ty to mir::Const::Ty 2024-06-05 22:25:41 +01:00
nrvo.rs Revert "Auto merge of #115105 - cjgillot:dest-prop-default, r=oli-obk" 2024-05-31 00:22:40 +00:00
pass_manager.rs Only split by-ref/by-move futures for async closures 2024-03-19 16:59:23 -04:00
prettify.rs remove redundant imports 2023-12-10 10:56:22 +08:00
promote_consts.rs Add an intrinsic for ptr::metadata 2024-05-28 09:28:51 -07:00
ref_prop.rs Remove extern crate rustc_middle from rustc_mir_transform. 2024-05-13 08:20:18 +10:00
remove_noop_landing_pads.rs Avoid debug logging entire MIR body 2024-02-15 15:54:28 +01:00
remove_place_mention.rs remove redundant imports 2023-12-10 10:56:22 +08:00
remove_storage_markers.rs Move condition enabling the pass to is_enabled 2024-01-23 20:58:44 +01:00
remove_uninit_drops.rs remove redundant imports 2023-12-10 10:56:22 +08:00
remove_unneeded_drops.rs Merge dead bb pruning and unreachable bb deduplication. 2024-01-07 15:12:10 +00:00
remove_zsts.rs Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs 2024-02-06 02:22:58 +00:00
required_consts.rs properly fill a promoted's required_consts 2024-04-23 23:02:54 +02:00
reveal_all.rs remove redundant imports 2023-12-10 10:56:22 +08:00
shim.rs Uplift TypeRelation and Relate 2024-06-01 12:50:58 -04:00
simplify.rs rustc_index: Add a ZERO constant to index types 2024-04-03 19:06:22 +03:00
simplify_branches.rs simplify_branches: add comment 2024-03-24 12:53:03 +01:00
simplify_comparison_integral.rs Remove extern crate rustc_middle from rustc_mir_transform. 2024-05-13 08:20:18 +10:00
sroa.rs Stop SRoA'ing DynMetadata in MIR 2024-05-25 00:44:47 -07:00
ssa.rs Remove extern crate rustc_middle from rustc_mir_transform. 2024-05-13 08:20:18 +10:00
unreachable_enum_branching.rs Remove extern crate rustc_middle from rustc_mir_transform. 2024-05-13 08:20:18 +10:00
unreachable_prop.rs Remove extern crate rustc_middle from rustc_mir_transform. 2024-05-13 08:20:18 +10:00
validate.rs Add some more specific checks to the MIR validator 2024-06-01 15:36:23 -07:00