2018-11-24 14:12:15 +01:00
|
|
|
use super::BackendTypes;
|
2019-02-09 23:31:47 +09:00
|
|
|
use crate::mir::place::PlaceRef;
|
Introduce `ConstAllocation`.
Currently some `Allocation`s are interned, some are not, and it's very
hard to tell at a use point which is which.
This commit introduces `ConstAllocation` for the known-interned ones,
which makes the division much clearer. `ConstAllocation::inner()` is
used to get the underlying `Allocation`.
In some places it's natural to use an `Allocation`, in some it's natural
to use a `ConstAllocation`, and in some places there's no clear choice.
I've tried to make things look as nice as possible, while generally
favouring `ConstAllocation`, which is the type that embodies more
information. This does require quite a few calls to `inner()`.
The commit also tweaks how `PartialOrd` works for `Interned`. The
previous code was too clever by half, building on `T: Ord` to make the
code shorter. That caused problems with deriving `PartialOrd` and `Ord`
for `ConstAllocation`, so I changed it to build on `T: PartialOrd`,
which is slightly more verbose but much more standard and avoided the
problems.
2022-03-02 07:15:04 +11:00
|
|
|
use rustc_middle::mir::interpret::{ConstAllocation, Scalar};
|
2020-03-31 18:16:47 +02:00
|
|
|
use rustc_middle::ty::layout::TyAndLayout;
|
|
|
|
|
use rustc_target::abi::{self, Size};
|
2018-08-28 17:03:46 +02:00
|
|
|
|
2018-11-24 14:12:15 +01:00
|
|
|
pub trait ConstMethods<'tcx>: BackendTypes {
|
2018-08-28 17:03:46 +02:00
|
|
|
// Constant constructors
|
2018-09-06 11:57:42 -07:00
|
|
|
fn const_null(&self, t: Self::Type) -> Self::Value;
|
|
|
|
|
fn const_undef(&self, t: Self::Type) -> Self::Value;
|
|
|
|
|
fn const_int(&self, t: Self::Type, i: i64) -> Self::Value;
|
|
|
|
|
fn const_uint(&self, t: Self::Type, i: u64) -> Self::Value;
|
|
|
|
|
fn const_uint_big(&self, t: Self::Type, u: u128) -> Self::Value;
|
|
|
|
|
fn const_bool(&self, val: bool) -> Self::Value;
|
2021-11-10 20:14:23 -08:00
|
|
|
fn const_i16(&self, i: i16) -> Self::Value;
|
2018-09-06 11:57:42 -07:00
|
|
|
fn const_i32(&self, i: i32) -> Self::Value;
|
|
|
|
|
fn const_u32(&self, i: u32) -> Self::Value;
|
|
|
|
|
fn const_u64(&self, i: u64) -> Self::Value;
|
|
|
|
|
fn const_usize(&self, i: u64) -> Self::Value;
|
|
|
|
|
fn const_u8(&self, i: u8) -> Self::Value;
|
2019-07-07 19:08:40 +02:00
|
|
|
fn const_real(&self, t: Self::Type, val: f64) -> Self::Value;
|
2018-09-24 17:35:39 +02:00
|
|
|
|
2022-06-28 17:34:24 +00:00
|
|
|
fn const_str(&self, s: &str) -> (Self::Value, Self::Value);
|
2018-09-13 14:58:19 +02:00
|
|
|
fn const_struct(&self, elts: &[Self::Value], packed: bool) -> Self::Value;
|
2018-08-28 17:03:46 +02:00
|
|
|
|
2019-08-27 11:51:53 +02:00
|
|
|
fn const_to_opt_uint(&self, v: Self::Value) -> Option<u64>;
|
2018-08-30 15:41:59 +02:00
|
|
|
fn const_to_opt_u128(&self, v: Self::Value, sign_ext: bool) -> Option<u128>;
|
|
|
|
|
|
Introduce `ConstAllocation`.
Currently some `Allocation`s are interned, some are not, and it's very
hard to tell at a use point which is which.
This commit introduces `ConstAllocation` for the known-interned ones,
which makes the division much clearer. `ConstAllocation::inner()` is
used to get the underlying `Allocation`.
In some places it's natural to use an `Allocation`, in some it's natural
to use a `ConstAllocation`, and in some places there's no clear choice.
I've tried to make things look as nice as possible, while generally
favouring `ConstAllocation`, which is the type that embodies more
information. This does require quite a few calls to `inner()`.
The commit also tweaks how `PartialOrd` works for `Interned`. The
previous code was too clever by half, building on `T: Ord` to make the
code shorter. That caused problems with deriving `PartialOrd` and `Ord`
for `ConstAllocation`, so I changed it to build on `T: PartialOrd`,
which is slightly more verbose but much more standard and avoided the
problems.
2022-03-02 07:15:04 +11:00
|
|
|
fn const_data_from_alloc(&self, alloc: ConstAllocation<'tcx>) -> Self::Value;
|
2021-06-20 17:43:25 +08:00
|
|
|
|
2021-08-29 11:06:55 +02:00
|
|
|
fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, llty: Self::Type) -> Self::Value;
|
2018-09-20 15:47:22 +02:00
|
|
|
fn from_const_alloc(
|
|
|
|
|
&self,
|
2020-03-31 18:16:47 +02:00
|
|
|
layout: TyAndLayout<'tcx>,
|
Introduce `ConstAllocation`.
Currently some `Allocation`s are interned, some are not, and it's very
hard to tell at a use point which is which.
This commit introduces `ConstAllocation` for the known-interned ones,
which makes the division much clearer. `ConstAllocation::inner()` is
used to get the underlying `Allocation`.
In some places it's natural to use an `Allocation`, in some it's natural
to use a `ConstAllocation`, and in some places there's no clear choice.
I've tried to make things look as nice as possible, while generally
favouring `ConstAllocation`, which is the type that embodies more
information. This does require quite a few calls to `inner()`.
The commit also tweaks how `PartialOrd` works for `Interned`. The
previous code was too clever by half, building on `T: Ord` to make the
code shorter. That caused problems with deriving `PartialOrd` and `Ord`
for `ConstAllocation`, so I changed it to build on `T: PartialOrd`,
which is slightly more verbose but much more standard and avoided the
problems.
2022-03-02 07:15:04 +11:00
|
|
|
alloc: ConstAllocation<'tcx>,
|
2020-03-31 18:16:47 +02:00
|
|
|
offset: Size,
|
2018-09-20 15:47:22 +02:00
|
|
|
) -> PlaceRef<'tcx, Self::Value>;
|
2018-11-24 17:23:22 +01:00
|
|
|
|
|
|
|
|
fn const_ptrcast(&self, val: Self::Value, ty: Self::Type) -> Self::Value;
|
2018-08-28 17:03:46 +02:00
|
|
|
}
|