2023-08-04 17:01:05 -03:00
|
|
|
use super::{mir::Mutability, mir::Safety, with, DefId};
|
2023-07-12 16:24:33 -03:00
|
|
|
use crate::rustc_internal::Opaque;
|
2023-04-24 01:04:44 +00:00
|
|
|
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
pub struct Ty(pub usize);
|
|
|
|
|
|
|
|
impl Ty {
|
|
|
|
pub fn kind(&self) -> TyKind {
|
|
|
|
with(|context| context.ty_kind(*self))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-28 12:31:59 +03:00
|
|
|
pub(crate) type Const = Opaque;
|
2023-08-04 17:23:26 -03:00
|
|
|
type Ident = Opaque;
|
2023-07-13 01:07:50 -04:00
|
|
|
pub(crate) type Region = Opaque;
|
2023-07-20 23:16:55 -03:00
|
|
|
type Span = Opaque;
|
2023-07-12 16:24:33 -03:00
|
|
|
|
2023-07-05 18:50:13 -03:00
|
|
|
#[derive(Clone, Debug)]
|
2023-04-24 01:04:44 +00:00
|
|
|
pub enum TyKind {
|
2023-06-28 11:31:28 -03:00
|
|
|
RigidTy(RigidTy),
|
2023-07-17 20:46:33 -04:00
|
|
|
Alias(AliasKind, AliasTy),
|
2023-07-21 14:18:32 -03:00
|
|
|
Param(ParamTy),
|
2023-07-21 14:52:45 -03:00
|
|
|
Bound(usize, BoundTy),
|
2023-06-28 11:31:28 -03:00
|
|
|
}
|
|
|
|
|
2023-07-05 18:50:13 -03:00
|
|
|
#[derive(Clone, Debug)]
|
2023-06-28 11:31:28 -03:00
|
|
|
pub enum RigidTy {
|
2023-04-24 01:04:44 +00:00
|
|
|
Bool,
|
2023-07-05 19:01:11 -03:00
|
|
|
Char,
|
2023-07-05 19:06:49 -03:00
|
|
|
Int(IntTy),
|
2023-07-05 19:26:52 -03:00
|
|
|
Uint(UintTy),
|
2023-07-05 19:30:24 -03:00
|
|
|
Float(FloatTy),
|
2023-07-18 12:11:49 -03:00
|
|
|
Adt(AdtDef, GenericArgs),
|
2023-07-18 11:18:40 -03:00
|
|
|
Foreign(ForeignDef),
|
2023-07-12 00:56:45 -04:00
|
|
|
Str,
|
|
|
|
Array(Ty, Const),
|
|
|
|
Slice(Ty),
|
2023-07-13 00:23:22 -04:00
|
|
|
RawPtr(Ty, Mutability),
|
2023-07-13 01:07:50 -04:00
|
|
|
Ref(Region, Ty, Mutability),
|
2023-07-18 12:16:38 -03:00
|
|
|
FnDef(FnDef, GenericArgs),
|
2023-07-20 23:16:55 -03:00
|
|
|
FnPtr(PolyFnSig),
|
2023-07-18 12:19:41 -03:00
|
|
|
Closure(ClosureDef, GenericArgs),
|
2023-07-18 13:38:16 -03:00
|
|
|
Generator(GeneratorDef, GenericArgs, Movability),
|
2023-07-23 23:53:08 -04:00
|
|
|
Dynamic(Vec<Binder<ExistentialPredicate>>, Region, DynKind),
|
2023-07-18 12:02:35 -03:00
|
|
|
Never,
|
2023-04-24 01:04:44 +00:00
|
|
|
Tuple(Vec<Ty>),
|
|
|
|
}
|
2023-07-05 19:06:49 -03:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
pub enum IntTy {
|
|
|
|
Isize,
|
|
|
|
I8,
|
|
|
|
I16,
|
|
|
|
I32,
|
|
|
|
I64,
|
|
|
|
I128,
|
|
|
|
}
|
2023-07-05 19:26:52 -03:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
pub enum UintTy {
|
|
|
|
Usize,
|
|
|
|
U8,
|
|
|
|
U16,
|
|
|
|
U32,
|
|
|
|
U64,
|
|
|
|
U128,
|
|
|
|
}
|
2023-07-05 19:30:24 -03:00
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
pub enum FloatTy {
|
|
|
|
F32,
|
|
|
|
F64,
|
|
|
|
}
|
2023-07-12 16:24:33 -03:00
|
|
|
|
2023-07-18 13:38:16 -03:00
|
|
|
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
|
|
|
pub enum Movability {
|
|
|
|
Static,
|
|
|
|
Movable,
|
|
|
|
}
|
|
|
|
|
2023-07-18 11:18:40 -03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct ForeignDef(pub(crate) DefId);
|
|
|
|
|
2023-07-18 12:16:38 -03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct FnDef(pub(crate) DefId);
|
|
|
|
|
2023-07-18 12:19:41 -03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct ClosureDef(pub(crate) DefId);
|
|
|
|
|
2023-07-18 13:38:16 -03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct GeneratorDef(pub(crate) DefId);
|
|
|
|
|
2023-07-20 23:16:55 -03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct ParamDef(pub(crate) DefId);
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct BrNamedDef(pub(crate) DefId);
|
|
|
|
|
2023-07-12 16:24:33 -03:00
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct AdtDef(pub(crate) DefId);
|
|
|
|
|
2023-07-17 20:46:33 -04:00
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct AliasDef(pub(crate) DefId);
|
|
|
|
|
2023-07-23 23:53:08 -04:00
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub struct TraitDef(pub(crate) DefId);
|
|
|
|
|
2023-08-05 22:08:30 -03:00
|
|
|
impl TraitDef {
|
|
|
|
pub fn trait_decl(&self) -> TraitDecl {
|
|
|
|
with(|cx| cx.trait_decl(self))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-12 16:24:33 -03:00
|
|
|
#[derive(Clone, Debug)]
|
2023-07-18 12:11:49 -03:00
|
|
|
pub struct GenericArgs(pub Vec<GenericArgKind>);
|
2023-07-12 16:24:33 -03:00
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum GenericArgKind {
|
|
|
|
Lifetime(Region),
|
|
|
|
Type(Ty),
|
|
|
|
Const(Const),
|
|
|
|
}
|
2023-07-20 23:16:55 -03:00
|
|
|
|
2023-07-23 23:53:08 -04:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum TermKind {
|
|
|
|
Type(Ty),
|
|
|
|
Const(Const),
|
|
|
|
}
|
|
|
|
|
2023-07-17 20:46:33 -04:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum AliasKind {
|
|
|
|
Projection,
|
|
|
|
Inherent,
|
|
|
|
Opaque,
|
|
|
|
Weak,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct AliasTy {
|
|
|
|
pub def_id: AliasDef,
|
|
|
|
pub args: GenericArgs,
|
|
|
|
}
|
|
|
|
|
2023-07-20 23:16:55 -03:00
|
|
|
pub type PolyFnSig = Binder<FnSig>;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct FnSig {
|
|
|
|
pub inputs_and_output: Vec<Ty>,
|
|
|
|
pub c_variadic: bool,
|
2023-08-04 17:01:05 -03:00
|
|
|
pub unsafety: Safety,
|
2023-07-20 23:16:55 -03:00
|
|
|
pub abi: Abi,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub enum Abi {
|
|
|
|
Rust,
|
|
|
|
C { unwind: bool },
|
|
|
|
Cdecl { unwind: bool },
|
|
|
|
Stdcall { unwind: bool },
|
|
|
|
Fastcall { unwind: bool },
|
|
|
|
Vectorcall { unwind: bool },
|
|
|
|
Thiscall { unwind: bool },
|
|
|
|
Aapcs { unwind: bool },
|
|
|
|
Win64 { unwind: bool },
|
|
|
|
SysV64 { unwind: bool },
|
|
|
|
PtxKernel,
|
|
|
|
Msp430Interrupt,
|
|
|
|
X86Interrupt,
|
|
|
|
AmdGpuKernel,
|
|
|
|
EfiApi,
|
|
|
|
AvrInterrupt,
|
|
|
|
AvrNonBlockingInterrupt,
|
|
|
|
CCmseNonSecureCall,
|
|
|
|
Wasm,
|
|
|
|
System { unwind: bool },
|
|
|
|
RustIntrinsic,
|
|
|
|
RustCall,
|
|
|
|
PlatformIntrinsic,
|
|
|
|
Unadjusted,
|
|
|
|
RustCold,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct Binder<T> {
|
|
|
|
pub value: T,
|
|
|
|
pub bound_vars: Vec<BoundVariableKind>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum BoundVariableKind {
|
|
|
|
Ty(BoundTyKind),
|
|
|
|
Region(BoundRegionKind),
|
|
|
|
Const,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub enum BoundTyKind {
|
|
|
|
Anon,
|
|
|
|
Param(ParamDef, String),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum BoundRegionKind {
|
|
|
|
BrAnon(Option<Span>),
|
|
|
|
BrNamed(BrNamedDef, String),
|
|
|
|
BrEnv,
|
|
|
|
}
|
2023-07-23 23:53:08 -04:00
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum DynKind {
|
|
|
|
Dyn,
|
|
|
|
DynStar,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub enum ExistentialPredicate {
|
|
|
|
Trait(ExistentialTraitRef),
|
|
|
|
Projection(ExistentialProjection),
|
|
|
|
AutoTrait(TraitDef),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct ExistentialTraitRef {
|
|
|
|
pub def_id: TraitDef,
|
|
|
|
pub generic_args: GenericArgs,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct ExistentialProjection {
|
|
|
|
pub def_id: TraitDef,
|
|
|
|
pub generic_args: GenericArgs,
|
|
|
|
pub term: TermKind,
|
|
|
|
}
|
2023-07-21 14:18:32 -03:00
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct ParamTy {
|
|
|
|
pub index: u32,
|
|
|
|
pub name: String,
|
|
|
|
}
|
2023-07-21 14:52:45 -03:00
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct BoundTy {
|
|
|
|
pub var: usize,
|
|
|
|
pub kind: BoundTyKind,
|
|
|
|
}
|
2023-08-02 15:12:38 +03:00
|
|
|
|
|
|
|
pub type Bytes = Vec<Option<u8>>;
|
|
|
|
pub type Size = usize;
|
|
|
|
pub type Prov = Opaque;
|
|
|
|
pub type Align = u64;
|
|
|
|
pub type InitMaskMaterialized = Vec<u64>;
|
|
|
|
|
|
|
|
/// Stores the provenance information of pointers stored in memory.
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct ProvenanceMap {
|
|
|
|
/// Provenance in this map applies from the given offset for an entire pointer-size worth of
|
|
|
|
/// bytes. Two entries in this map are always at least a pointer size apart.
|
|
|
|
pub ptrs: Vec<(Size, Prov)>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct Allocation {
|
|
|
|
pub bytes: Bytes,
|
|
|
|
pub provenance: ProvenanceMap,
|
|
|
|
pub align: Align,
|
|
|
|
pub mutability: Mutability,
|
|
|
|
}
|
2023-08-04 17:23:26 -03:00
|
|
|
|
|
|
|
pub enum TraitSpecializationKind {
|
|
|
|
None,
|
|
|
|
Marker,
|
|
|
|
AlwaysApplicable,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct TraitDecl {
|
|
|
|
pub def_id: TraitDef,
|
|
|
|
pub unsafety: Safety,
|
|
|
|
pub paren_sugar: bool,
|
|
|
|
pub has_auto_impl: bool,
|
|
|
|
pub is_marker: bool,
|
|
|
|
pub is_coinductive: bool,
|
|
|
|
pub skip_array_during_method_dispatch: bool,
|
|
|
|
pub specialization_kind: TraitSpecializationKind,
|
|
|
|
pub must_implement_one_of: Option<Vec<Ident>>,
|
|
|
|
pub implement_via_object: bool,
|
|
|
|
pub deny_explicit_impl: bool,
|
|
|
|
}
|