1use super::ty::{TyEntry, TyTag};
15use super::ty_prim::TyMutability;
16
17pub const IMPL_FLAG_TRAIT: u8 = 1 << 0;
19pub const IMPL_FLAG_NEGATIVE: u8 = 1 << 1;
21pub const IMPL_FLAG_UNSAFE: u8 = 1 << 2;
23pub const IMPL_FLAG_RESERVATION: u8 = 1 << 3;
25pub const IMPL_FLAG_CONST: u8 = 1 << 4;
27
28#[repr(u8)]
34#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
35pub enum SimplifiedSelfKind {
36 Adt = 0,
37 Bool = 1,
38 Char = 2,
39 Int = 3,
40 Uint = 4,
41 Float = 5,
42 Str = 6,
43 Slice = 7,
44 Array = 8,
45 Tuple = 9,
46 RefShared = 10,
47 RefMut = 11,
48 PtrConst = 12,
49 PtrMut = 13,
50 FnPtr = 14,
51 Dynamic = 15,
52 Never = 16,
53 Param = 17,
54 Unit = 18,
55 Other = 19,
56}
57
58impl SimplifiedSelfKind {
59 #[inline]
60 pub const fn from_u8(v: u8) -> Self {
61 match v {
62 0 => Self::Adt,
63 1 => Self::Bool,
64 2 => Self::Char,
65 3 => Self::Int,
66 4 => Self::Uint,
67 5 => Self::Float,
68 6 => Self::Str,
69 7 => Self::Slice,
70 8 => Self::Array,
71 9 => Self::Tuple,
72 10 => Self::RefShared,
73 11 => Self::RefMut,
74 12 => Self::PtrConst,
75 13 => Self::PtrMut,
76 14 => Self::FnPtr,
77 15 => Self::Dynamic,
78 16 => Self::Never,
79 17 => Self::Param,
80 18 => Self::Unit,
81 _ => Self::Other,
82 }
83 }
84
85 #[inline]
86 pub const fn from_ty_entry(entry: TyEntry) -> Self {
87 match TyTag::from_u8(entry.tag) {
88 TyTag::Adt => Self::Adt,
89 TyTag::Bool => Self::Bool,
90 TyTag::Char => Self::Char,
91 TyTag::Int => Self::Int,
92 TyTag::Uint => Self::Uint,
93 TyTag::Float => Self::Float,
94 TyTag::Str => Self::Str,
95 TyTag::Slice => Self::Slice,
96 TyTag::Array => Self::Array,
97 TyTag::Tuple => Self::Tuple,
98 TyTag::Ref => match TyMutability::from_u8(entry.flags) {
99 TyMutability::Shared => Self::RefShared,
100 TyMutability::Mut => Self::RefMut,
101 },
102 TyTag::Ptr => match TyMutability::from_u8(entry.flags) {
103 TyMutability::Shared => Self::PtrConst,
104 TyMutability::Mut => Self::PtrMut,
105 },
106 TyTag::FnPtr => Self::FnPtr,
107 TyTag::Dyn => Self::Dynamic,
108 TyTag::Never => Self::Never,
109 TyTag::Param => Self::Param,
110 TyTag::Unit => Self::Unit,
111 TyTag::FnDef | TyTag::Assoc | TyTag::ImplTrait | TyTag::Unknown => Self::Other,
112 }
113 }
114}
115
116#[repr(C)]
120#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
121pub struct ImplEntry {
122 pub def_index: u32,
124 pub self_ty: u32,
126 pub trait_def: u32,
128 pub trait_args_start: u32,
130 pub assoc_tys_start: u32,
132 pub assoc_defs_start: u32,
134 pub trait_args_len: u16,
136 pub assoc_tys_len: u16,
138 pub assoc_defs_len: u16,
140 pub flags: u8,
142 pub simplified_self: u8,
144}
145
146impl ImplEntry {
147 #[inline]
148 pub const fn to_le(self) -> Self {
149 Self {
150 def_index: self.def_index.to_le(),
151 self_ty: self.self_ty.to_le(),
152 trait_def: self.trait_def.to_le(),
153 trait_args_start: self.trait_args_start.to_le(),
154 assoc_tys_start: self.assoc_tys_start.to_le(),
155 assoc_defs_start: self.assoc_defs_start.to_le(),
156 trait_args_len: self.trait_args_len.to_le(),
157 assoc_tys_len: self.assoc_tys_len.to_le(),
158 assoc_defs_len: self.assoc_defs_len.to_le(),
159 flags: self.flags,
160 simplified_self: self.simplified_self,
161 }
162 }
163
164 #[inline]
165 pub const fn from_le(self) -> Self {
166 Self {
167 def_index: u32::from_le(self.def_index),
168 self_ty: u32::from_le(self.self_ty),
169 trait_def: u32::from_le(self.trait_def),
170 trait_args_start: u32::from_le(self.trait_args_start),
171 assoc_tys_start: u32::from_le(self.assoc_tys_start),
172 assoc_defs_start: u32::from_le(self.assoc_defs_start),
173 trait_args_len: u16::from_le(self.trait_args_len),
174 assoc_tys_len: u16::from_le(self.assoc_tys_len),
175 assoc_defs_len: u16::from_le(self.assoc_defs_len),
176 flags: self.flags,
177 simplified_self: self.simplified_self,
178 }
179 }
180
181 #[inline]
182 pub const fn simplified_self_kind(&self) -> SimplifiedSelfKind {
183 SimplifiedSelfKind::from_u8(self.simplified_self)
184 }
185
186 #[inline]
187 pub const fn is_trait(&self) -> bool {
188 (self.flags & IMPL_FLAG_TRAIT) != 0
189 }
190}
191
192#[repr(C)]
196#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
197pub struct AssocTyEntry {
198 pub impl_index: u32,
200 pub def_index: u32,
202 pub name_offset: u32,
204 pub ty: u32,
206}
207
208impl AssocTyEntry {
209 #[inline]
210 pub const fn to_le(self) -> Self {
211 Self { impl_index: self.impl_index.to_le(), def_index: self.def_index.to_le(), name_offset: self.name_offset.to_le(), ty: self.ty.to_le() }
212 }
213
214 #[inline]
215 pub const fn from_le(self) -> Self {
216 Self { impl_index: u32::from_le(self.impl_index), def_index: u32::from_le(self.def_index), name_offset: u32::from_le(self.name_offset), ty: u32::from_le(self.ty) }
217 }
218}