rust/compiler
bors 4fc6b33474 Auto merge of #114011 - RalfJung:place-projection, r=oli-obk
interpret: Unify projections for MPlaceTy, PlaceTy, OpTy

For ~forever, we didn't really have proper shared code for handling projections into those three types. This is mostly because `PlaceTy` projections require `&mut self`: they might have to `force_allocate` to be able to represent a project part-way into a local.

This PR finally fixes that, by enhancing `Place::Local` with an `offset` so that such an optimized place can point into a part of a place without having requiring an in-memory representation. If we later write to that place, we will still do `force_allocate` -- for now we don't have an optimized path in `write_immediate` that would avoid allocation for partial overwrites of immediately stored locals. But in `write_immediate` we have `&mut self` so at least this no longer pollutes all our type signatures.

(Ironically, I seem to distantly remember that many years ago, `Place::Local` *did* have an `offset`, and I removed it to simplify things. I guess I didn't realize why it was so useful... I am also not sure if this was actually used to achieve place projection on `&self` back then.)

The `offset` had type `Option<Size>`, where `None` represent "no projection was applied". This is needed because locals *can* be unsized (when they are arguments) but `Place::Local` cannot store metadata: if the offset is `None`, this refers to the entire local, so we can use the metadata of the local itself (which must be indirect); if a projection gets applied, since the local is indirect, it will turn into a `Place::Ptr`. (Note that even for indirect locals we can have `Place::Local`: when the local appears in MIR, we always start with `Place::Local`, and only check `frame.locals` later. We could eagerly normalize to `Place::Ptr` but I don't think that would actually simplify things much.)

Having done all that, we can finally properly abstract projections: we have a new `Projectable` trait that has the basic methods required for projecting, and then all projection methods are implemented for anything that implements that trait. We can even implement it for `ImmTy`! (Not that we need that, but it seems neat.) The visitor can be greatly simplified; it doesn't need its own trait any more but it can use the `Projectable` trait. We also don't need the separate `Mut` visitor any more; that was required only to reflect that projections on `PlaceTy` needed `&mut self`.

It is possible that there are some more `&mut self` that can now become `&self`... I guess we'll notice that over time.

r? `@oli-obk`
2023-07-25 14:18:08 +00:00
..
rustc
rustc_abi interpret: refactor projection code to work on a common trait, and use that for visitors 2023-07-25 14:30:58 +02:00
rustc_apfloat
rustc_arena
rustc_ast more clippy::style fixes: 2023-07-23 23:39:04 +02:00
rustc_ast_lowering more clippy::style fixes: 2023-07-23 23:39:04 +02:00
rustc_ast_passes Lint against misplaced where-clauses on assoc tys in traits 2023-07-11 01:19:11 +02:00
rustc_ast_pretty more clippy::style fixes: 2023-07-23 23:39:04 +02:00
rustc_attr Add infrastructure #[rustc_confusables] attribute to allow targeted 2023-07-16 19:22:03 +08:00
rustc_baked_icu_data
rustc_borrowck Rename arg_iter to iter_instantiated 2023-07-17 21:04:12 +00:00
rustc_builtin_macros fix couple of clippy findings: 2023-07-23 10:50:14 +02:00
rustc_codegen_cranelift Merge commit '1eded3619d0e55d57521a259bf27a03906fdfad0' into sync_cg_clif-2023-07-22 2023-07-22 13:32:34 +00:00
rustc_codegen_gcc Auto merge of #113877 - JhonnyBillM:reuse-codegen-ssa-monomorphization-errors-in-gcc, r=davidtwco 2023-07-24 11:29:59 +00:00
rustc_codegen_llvm Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk" 2023-07-21 22:35:57 -07:00
rustc_codegen_ssa remove redundant clones 2023-07-23 09:48:07 +02:00
rustc_const_eval Auto merge of #114011 - RalfJung:place-projection, r=oli-obk 2023-07-25 14:18:08 +00:00
rustc_data_structures more clippy::style fixes: 2023-07-23 23:39:04 +02:00
rustc_driver Update rustix 2023-07-03 07:20:51 +00:00
rustc_driver_impl Rollup merge of #113780 - dtolnay:printkindpath, r=b-naber 2023-07-21 06:52:28 +02:00
rustc_error_codes error/E0691: include alignment in error message 2023-07-21 11:04:16 +02:00
rustc_error_messages On nightly, dump ICE backtraces to disk 2023-07-19 14:10:07 +00:00
rustc_errors Optimize format usage 2023-07-24 00:08:09 -04:00
rustc_expand Don't translate compiler-internal bug messages 2023-07-20 09:51:47 +00:00
rustc_feature Add infrastructure #[rustc_confusables] attribute to allow targeted 2023-07-16 19:22:03 +08:00
rustc_fluent_macro
rustc_fs_util
rustc_graphviz
rustc_hir more clippy::style fixes: 2023-07-23 23:39:04 +02:00
rustc_hir_analysis fix clippy::useless_format 2023-07-23 11:14:52 +02:00
rustc_hir_pretty hir: Add Become expression kind 2023-06-26 08:56:32 +00:00
rustc_hir_typeck fix some clippy::style findings 2023-07-23 23:36:56 +02:00
rustc_incremental Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_index Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_infer fix some clippy::style findings 2023-07-23 23:36:56 +02:00
rustc_interface Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk" 2023-07-21 22:35:57 -07:00
rustc_lexer Auto merge of #113476 - fee1-dead-contrib:c-str-lit, r=petrochenkov 2023-07-25 12:04:34 +00:00
rustc_lint lint/ctypes: only try normalize 2023-07-21 15:42:25 +01:00
rustc_lint_defs Fix removal span calculation of unused_qualifications suggestion 2023-07-18 09:52:08 +08:00
rustc_llvm Support .comment section like GCC/Clang (!llvm.ident) 2023-07-21 22:01:50 +02:00
rustc_log Downgrade tracing and syn 2023-07-02 21:02:31 +02:00
rustc_macros Re-format let-else per rustfmt update 2023-07-12 21:49:27 -04:00
rustc_metadata Auto merge of #113958 - lukas-code:doc-links, r=GuillaumeGomez,petrochenkov 2023-07-25 01:35:53 +00:00
rustc_middle Auto merge of #114011 - RalfJung:place-projection, r=oli-obk 2023-07-25 14:18:08 +00:00
rustc_mir_build Make it clearer that edition functions are >=, not == 2023-07-19 16:38:35 +00:00
rustc_mir_dataflow Turn copy into moves during DSE. 2023-07-19 09:59:12 +00:00
rustc_mir_transform Reuse MIR validator for inliner. 2023-07-21 13:58:33 +00:00
rustc_monomorphize more clippy::style fixes: 2023-07-23 23:39:04 +02:00
rustc_parse Auto merge of #113476 - fee1-dead-contrib:c-str-lit, r=petrochenkov 2023-07-25 12:04:34 +00:00
rustc_parse_format Fix unit tests 2023-07-19 16:37:09 +00:00
rustc_passes validate doc(masked) 2023-07-24 18:04:35 +02:00
rustc_plugin_impl
rustc_privacy refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
rustc_query_impl fix couple of clippy findings: 2023-07-23 10:50:14 +02:00
rustc_query_system Revert "Auto merge of #113166 - moulins:ref-niches-initial, r=oli-obk" 2023-07-21 22:35:57 -07:00
rustc_resolve Auto merge of #113980 - bvanjoi:fix-113953, r=petrochenkov 2023-07-25 05:25:11 +00:00
rustc_serialize Upgrade to indexmap 2.0.0 2023-07-03 13:51:54 -07:00
rustc_session Add missing documentation for Session::time 2023-07-24 16:50:25 +02:00
rustc_smir Dynamic for smir 2023-07-24 00:17:45 -04:00
rustc_span Make it clearer that edition functions are >=, not == 2023-07-19 16:38:35 +00:00
rustc_symbol_mangling more clippy::style fixes: 2023-07-23 23:39:04 +02:00
rustc_target Auto merge of #113411 - unikraft:unikraft, r=wesleywiser 2023-07-25 03:41:56 +00:00
rustc_trait_selection Auto merge of #114024 - matthiaskrgr:rollup-uhdbq64, r=matthiaskrgr 2023-07-24 17:13:24 +00:00
rustc_traits refactor(rustc_middle): Substs -> GenericArg 2023-07-14 13:27:35 +01:00
rustc_transmute Auto merge of #113677 - bryangarza:unevaluated-const-ice_issue-110892, r=davidtwco 2023-07-18 09:07:32 +00:00
rustc_ty_utils fix some clippy::style findings 2023-07-23 23:36:56 +02:00
rustc_type_ir add docs for AliasKind::Inherent 2023-07-22 15:38:41 -04:00