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
..
2023-07-03 13:40:20 +01:00
2023-04-25 00:08:35 +02:00
2023-04-25 00:08:35 +02:00
2023-06-18 18:44:14 +08:00
2023-07-10 20:09:26 +00:00
2023-06-23 19:39:57 +02:00
2023-07-18 21:53:34 -04:00
2023-07-18 21:53:34 -04:00
2023-01-11 21:30:32 +00:00
2023-07-18 21:53:34 -04:00
2023-07-18 21:53:34 -04:00
2023-07-12 12:11:09 +00:00
2023-07-24 18:04:35 +02:00
2023-06-02 19:22:25 +00:00
2023-06-22 23:31:06 +00:00
2023-04-13 22:08:07 -05:00
2023-04-28 20:28:56 -05:00
2023-07-10 20:09:26 +00:00
2023-01-30 20:12:19 +00:00
2023-01-30 20:12:19 +00:00
2023-07-14 07:12:38 +08:00
2023-07-10 20:09:26 +00:00
2023-07-14 07:12:35 +08:00
2023-01-12 22:25:30 +00:00
2023-01-30 21:51:33 +00:00
2023-01-15 22:17:54 +13:00
2023-06-24 21:45:17 +08:00
2023-07-18 18:58:18 +08:00
2023-05-12 00:10:52 +00:00
2023-02-21 05:21:07 +00:00
2023-07-22 19:57:35 +02:00
2023-07-20 11:04:31 -07:00
2023-07-10 20:09:28 +00:00
2023-05-24 19:35:59 -03:00
2023-07-18 21:53:34 -04:00
2023-05-30 13:03:40 +02:00
2023-04-03 09:24:11 +02:00
2023-01-30 20:12:19 +00:00
2023-06-29 23:31:25 +08:00
2023-01-30 20:12:21 +00:00
2023-04-28 14:42:03 +02:00
2023-07-18 21:53:34 -04:00
2023-06-01 14:45:18 +00:00
2023-07-25 14:30:58 +02:00
2023-04-15 16:11:42 -07:00
2023-05-12 00:10:52 +00:00
2023-07-18 21:53:34 -04:00
2023-01-18 04:07:39 +00:00
2023-01-16 11:09:53 +01:00
2023-05-05 01:22:17 -05:00
2023-02-22 08:40:47 -07:00
2023-01-30 20:12:19 +00:00
2023-04-12 22:50:10 +00:00
2023-04-27 01:34:03 +00:00
2023-07-16 15:02:08 -07:00
2023-04-27 01:34:03 +00:00
2023-06-29 23:31:25 +08:00
2023-05-12 00:10:52 +00:00
2023-07-10 20:09:26 +00:00
2023-05-21 14:16:41 +02:00
2023-07-22 19:57:35 +02:00
2023-06-15 12:01:38 +02:00
2023-07-05 19:52:28 -04:00
2023-07-21 22:35:57 -07:00
2023-05-26 13:15:15 -04:00
2023-06-10 00:06:34 +08:00
2023-06-19 16:22:21 +01:00
2023-06-08 12:33:17 +00:00
2023-07-16 15:36:19 +02:00
2023-02-28 14:58:14 -08:00
2023-05-21 14:16:41 +02:00
2023-06-26 08:56:32 +00:00
2023-02-23 19:05:13 +09:00
2023-05-11 21:41:07 +01:00
2023-06-22 16:50:31 +00:00
2023-05-05 13:02:43 -07:00
2023-07-10 19:01:30 +00:00
2023-07-19 16:37:09 +00:00
2023-05-08 17:58:01 -03:00
2023-07-03 09:12:15 +02:00
2023-06-12 20:24:48 +08:00
2023-01-30 20:12:19 +00:00
2023-01-30 20:12:21 +00:00
2023-01-30 20:12:21 +00:00
2023-07-10 20:09:26 +00:00
2023-07-07 13:13:18 +00:00
2023-07-21 22:35:57 -07:00
2023-04-03 15:59:21 +00:00
2023-07-10 20:09:26 +00:00
2023-07-10 20:09:26 +00:00
2023-07-14 01:59:08 +00:00
2023-02-09 10:26:49 +00:00
2023-07-20 03:18:41 +00:00
2023-06-05 21:20:51 +00:00
2023-07-25 01:34:03 +08:00
2023-01-30 20:12:19 +00:00
2023-02-13 18:41:18 +00:00
2023-07-16 15:36:19 +02:00
2023-07-18 21:53:34 -04:00
2023-07-19 16:24:58 +00:00
2023-02-09 12:29:43 +09:00
2023-05-03 20:09:10 +03:00
2023-04-12 22:50:10 +00:00
2023-04-13 22:08:07 -05:00
2023-06-12 20:24:48 +08:00
2023-05-16 18:50:26 +02:00
2023-04-25 15:25:19 +00:00
2023-07-18 21:53:34 -04:00
2023-06-27 23:31:06 +00:00
2023-01-30 20:12:19 +00:00
2023-05-13 21:34:05 +00:00
2023-03-12 13:19:46 +00:00
2023-03-07 21:26:19 +01:00
2023-07-22 19:57:37 +02:00
2023-06-08 16:30:05 +00:00
2023-06-10 14:46:11 -04:00
2023-07-10 20:09:26 +00:00
2023-07-05 19:52:28 -04:00
2023-07-05 19:52:28 -04:00
2023-07-21 22:35:57 -07:00
2023-07-14 07:12:35 +08:00
2023-05-31 16:51:25 +00:00
2023-07-10 20:09:26 +00:00
2023-04-12 22:50:10 +00:00
2023-03-22 11:37:57 +01:00
2023-07-10 20:09:26 +00:00
2023-04-18 07:14:01 -05:00
2023-07-10 20:09:26 +00:00
2023-06-17 16:10:57 +00:00
2023-07-22 19:57:35 +02:00
2023-06-10 00:06:34 +08:00
2023-01-13 20:50:34 +00:00
2023-07-19 23:48:43 +00:00
2023-03-22 21:12:40 -07:00
2023-07-10 20:09:28 +00:00
2023-07-10 20:09:26 +00:00
2023-04-12 22:50:10 +00:00
2023-05-05 18:54:06 +01:00
2023-06-27 23:31:06 +00:00
2023-07-14 13:27:35 +01:00
2023-04-03 09:24:11 +02:00
2023-03-22 21:12:40 -07:00
2023-05-03 20:09:10 +03:00
2023-06-27 23:31:06 +00:00
2023-07-10 20:09:26 +00:00
2023-06-21 11:43:14 +03:00
2023-06-27 23:31:06 +00:00
2023-05-21 14:16:41 +02:00
2023-01-12 22:25:30 +00:00
2023-06-15 12:01:38 +02:00
2023-04-29 13:01:46 +01:00
2023-07-11 02:40:59 +00:00
2023-07-22 15:22:12 +00:00
2023-07-01 02:28:15 -04:00
2023-01-11 14:09:14 -08:00
2023-06-12 20:24:48 +08:00
2023-05-21 13:37:32 +02:00
2023-07-11 17:52:43 +08:00
2023-07-14 16:53:36 +01:00
2023-05-27 00:18:28 +02:00
2023-06-29 16:24:07 +03:00
2023-01-11 21:30:10 +00:00
2023-02-02 05:49:07 +00:00
2023-06-27 23:31:06 +00:00
2023-06-22 16:50:31 +00:00
2023-07-21 22:35:57 -07:00
2023-07-21 22:35:57 -07:00
2023-07-10 20:09:26 +00:00
2023-04-12 22:50:10 +00:00
2023-07-21 11:04:16 +02:00
2023-07-20 03:18:41 +00:00
2023-06-26 08:56:32 +00:00
2023-07-23 10:09:43 +00:00
2023-07-19 14:47:06 +00:00
2023-04-03 09:24:11 +02:00
2023-06-29 13:42:58 +03:00
2023-04-12 22:50:10 +00:00
2023-03-30 22:56:52 +02:00
2023-07-05 11:04:28 -05:00
2023-05-23 03:23:52 +00:00
2023-04-12 22:50:10 +00:00
2023-07-20 17:19:32 +02:00
2023-02-14 03:46:43 +00:00
2023-07-21 22:35:57 -07:00
2023-07-10 20:09:26 +00:00
2023-06-28 17:51:01 +00:00
2023-06-28 03:47:02 +00:00
2023-04-19 19:13:45 +00:00
2023-06-01 14:45:18 +00:00
2023-04-04 15:34:40 +00:00
2023-04-13 22:10:26 -05:00
2023-06-20 19:46:01 -04:00
2023-05-08 03:36:30 +00:00
2023-06-22 16:50:31 +00:00
2023-05-29 12:07:41 -03:00
2023-07-22 19:57:35 +02:00
2023-06-01 18:21:42 +00:00
2023-03-29 18:04:44 -04:00
2023-04-30 00:06:26 +08:00
2023-07-01 07:07:50 +00:00
2023-07-14 13:27:35 +01:00
2023-04-26 22:34:30 -04:00
2023-04-26 21:02:56 +02:00
2023-04-07 08:33:56 +01:00
2023-05-26 12:16:30 -05:00
2023-06-15 12:01:38 +02:00
2023-07-24 17:47:08 +02:00
2023-07-18 09:07:32 +00:00
2023-07-21 22:35:57 -07:00
2023-06-27 16:12:07 +02:00
2023-05-21 14:16:41 +02:00
2023-06-12 20:24:48 +08:00
2023-06-27 23:31:06 +00:00
2023-06-12 20:24:48 +08:00
2023-06-27 23:31:06 +00:00
2023-07-16 12:38:43 +02:00
2023-07-18 21:53:34 -04:00
2023-07-21 22:35:57 -07:00
2023-07-04 05:00:46 -04:00
2023-07-22 19:57:35 +02:00
2023-06-27 23:31:06 +00:00
2023-05-26 16:01:29 +01:00
2023-05-18 09:29:48 +08:00
2023-06-30 00:34:14 +00:00
2023-06-27 17:10:14 +00:00
2023-06-15 12:01:38 +02:00
2023-07-20 11:04:31 -07:00
2023-04-12 22:50:10 +00:00
2023-07-15 11:59:38 -04:00
2023-06-20 08:42:37 +00:00
2023-06-13 07:02:28 +02:00
2023-04-29 13:01:46 +01:00
2023-07-10 20:09:26 +00:00
2023-04-02 19:42:30 -04:00
2023-04-02 19:42:30 -04:00
2023-05-12 00:10:52 +00:00
2023-07-11 01:19:11 +02:00
2023-03-01 13:26:59 +01:00
2023-06-22 16:50:31 +00:00
2023-06-28 18:08:21 +00:00
2023-06-12 20:24:48 +08:00
2023-05-09 20:35:39 -04:00
2023-05-09 20:35:39 -04:00
2023-01-15 19:46:20 +00:00
2023-01-15 19:46:20 +00:00
2023-05-27 16:35:16 +02:00
2023-02-18 02:42:43 +00:00
2023-07-10 20:09:26 +00:00
2023-03-12 13:19:46 +00:00
2023-03-12 13:19:46 +00:00
2023-02-23 10:27:06 -07:00
2023-02-23 10:27:06 -07:00
2023-05-21 13:37:32 +02:00
2023-01-30 20:12:19 +00:00
2023-01-30 20:12:19 +00:00
2023-05-09 20:35:39 -04:00
2023-06-12 20:24:48 +08:00
2023-01-16 20:24:01 +13:00
2023-03-08 00:00:18 +00:00
2023-03-08 00:00:18 +00:00
2023-02-22 08:40:47 -07:00
2023-04-13 22:10:26 -05:00
2023-01-27 05:28:52 -08:00
2023-01-27 05:28:52 -08:00
2023-01-27 05:28:52 -08:00
2023-01-27 05:28:52 -08:00
2023-01-27 05:28:52 -08:00
2023-01-27 05:28:52 -08:00
2023-05-21 14:16:41 +02:00
2023-05-21 14:16:41 +02:00
2023-05-10 19:36:02 +02:00
2023-04-08 21:32:55 +00:00
2023-04-08 21:32:55 +00:00
2023-04-13 22:08:07 -05:00
2023-04-13 22:08:07 -05:00
2023-04-13 22:10:26 -05:00
2023-04-13 22:08:07 -05:00
2023-04-13 22:08:07 -05:00
2023-04-13 22:08:07 -05:00
2023-04-13 22:08:07 -05:00
2023-02-13 18:41:18 +00:00
2023-04-17 22:40:31 -05:00
2023-04-17 22:40:31 -05:00
2023-04-17 22:40:31 -05:00
2023-04-13 22:08:07 -05:00
2023-01-30 20:12:19 +00:00
2023-01-30 20:12:19 +00:00
2023-04-12 22:50:10 +00:00
2023-01-30 20:12:21 +00:00
2023-04-25 00:08:33 +02:00
2023-03-08 00:00:18 +00:00
2023-03-08 00:00:18 +00:00
2023-05-04 15:39:21 +02:00
2023-05-03 20:09:10 +03:00
2023-01-30 20:12:19 +00:00
2023-01-30 21:51:33 +00:00
2023-06-12 20:24:48 +08:00
2023-02-23 10:27:06 -07:00
2023-02-23 10:27:06 -07:00
2023-03-26 17:30:29 +00:00
2023-02-04 20:13:16 -08:00
2023-02-04 20:13:16 -08:00
2023-02-04 20:13:16 -08:00
2023-06-08 16:17:30 +00:00
2023-07-10 20:09:26 +00:00
2023-02-28 15:59:47 +01:00
2023-06-19 20:22:35 -07:00