1 use crate::ty
::{AdtDef, ClosureDef, Const, GeneratorDef, GenericArgs, Movability, Region}
;
3 use crate::{ty::Ty, Span}
;
5 #[derive(Clone, Debug)]
7 pub blocks
: Vec
<BasicBlock
>,
11 #[derive(Clone, Debug)]
12 pub struct BasicBlock
{
13 pub statements
: Vec
<Statement
>,
14 pub terminator
: Terminator
,
17 #[derive(Clone, Debug)]
24 targets
: Vec
<SwitchTarget
>,
40 target
: Option
<usize>,
53 operands
: Vec
<InlineAsmOperand
>,
56 destination
: Option
<usize>,
61 #[derive(Clone, Debug)]
62 pub struct InlineAsmOperand
{
63 pub in_value
: Option
<Operand
>,
64 pub out_place
: Option
<Place
>,
65 // This field has a raw debug representation of MIR's InlineAsmOperand.
66 // For now we care about place/operand + the rest in a debug format.
70 #[derive(Clone, Debug)]
71 pub enum UnwindAction
{
78 #[derive(Clone, Debug)]
79 pub enum AssertMessage
{
80 BoundsCheck { len: Operand, index: Operand }
,
81 Overflow(BinOp
, Operand
, Operand
),
83 DivisionByZero(Operand
),
84 RemainderByZero(Operand
),
85 ResumedAfterReturn(GeneratorKind
),
86 ResumedAfterPanic(GeneratorKind
),
87 MisalignedPointerDereference { required: Operand, found: Operand }
,
90 #[derive(Clone, Debug)]
116 #[derive(Clone, Debug)]
122 #[derive(Clone, Debug)]
123 pub enum GeneratorKind
{
124 Async(AsyncGeneratorKind
),
128 #[derive(Clone, Debug)]
129 pub enum AsyncGeneratorKind
{
135 pub(crate) type LocalDefId
= Opaque
;
136 /// The rustc coverage data structures are heavily tied to internal details of the
137 /// coverage implementation that are likely to change, and are unlikely to be
138 /// useful to third-party tools for the foreseeable future.
139 pub(crate) type Coverage
= Opaque
;
141 /// The FakeReadCause describes the type of pattern why a FakeRead statement exists.
142 #[derive(Clone, Debug)]
143 pub enum FakeReadCause
{
145 ForMatchedPlace(LocalDefId
),
151 /// Describes what kind of retag is to be performed
152 #[derive(Clone, Debug)]
160 #[derive(Clone, Debug)]
168 #[derive(Clone, Debug)]
169 pub struct CopyNonOverlapping
{
175 #[derive(Clone, Debug)]
176 pub enum NonDivergingIntrinsic
{
178 CopyNonOverlapping(CopyNonOverlapping
),
181 #[derive(Clone, Debug)]
183 Assign(Place
, Rvalue
),
184 FakeRead(FakeReadCause
, Place
),
185 SetDiscriminant { place: Place, variant_index: VariantIdx }
,
189 Retag(RetagKind
, Place
),
191 AscribeUserType { place: Place, projections: UserTypeProjection, variance: Variance }
,
193 Intrinsic(NonDivergingIntrinsic
),
198 #[derive(Clone, Debug)]
200 /// Creates a pointer with the indicated mutability to the place.
202 /// This is generated by pointer casts like `&v as *const _` or raw address of expressions like
203 /// `&raw v` or `addr_of!(v)`.
204 AddressOf(Mutability
, Place
),
206 /// Creates an aggregate value, like a tuple or struct.
208 /// This is needed because dataflow analysis needs to distinguish
209 /// `dest = Foo { x: ..., y: ... }` from `dest.x = ...; dest.y = ...;` in the case that `Foo`
210 /// has a destructor.
212 /// Disallowed after deaggregation for all aggregate kinds except `Array` and `Generator`. After
213 /// generator lowering, `Generator` aggregate kinds are disallowed too.
214 Aggregate(AggregateKind
, Vec
<Operand
>),
216 /// * `Offset` has the same semantics as `<*const T>::offset`, except that the second
217 /// parameter may be a `usize` as well.
218 /// * The comparison operations accept `bool`s, `char`s, signed or unsigned integers, floats,
219 /// raw pointers, or function pointers and return a `bool`. The types of the operands must be
220 /// matching, up to the usual caveat of the lifetimes in function pointers.
221 /// * Left and right shift operations accept signed or unsigned integers not necessarily of the
222 /// same type and return a value of the same type as their LHS. Like in Rust, the RHS is
223 /// truncated as needed.
224 /// * The `Bit*` operations accept signed integers, unsigned integers, or bools with matching
225 /// types and return a value of that type.
226 /// * The remaining operations accept signed integers, unsigned integers, or floats with
227 /// matching types and return a value of that type.
228 BinaryOp(BinOp
, Operand
, Operand
),
230 /// Performs essentially all of the casts that can be performed via `as`.
232 /// This allows for casts from/to a variety of types.
233 Cast(CastKind
, Operand
, Ty
),
235 /// Same as `BinaryOp`, but yields `(T, bool)` with a `bool` indicating an error condition.
237 /// For addition, subtraction, and multiplication on integers the error condition is set when
238 /// the infinite precision result would not be equal to the actual result.
239 CheckedBinaryOp(BinOp
, Operand
, Operand
),
241 /// A CopyForDeref is equivalent to a read from a place.
242 /// When such a read happens, it is guaranteed that the only use of the returned value is a
243 /// deref operation, immediately followed by one or more projections.
246 /// Computes the discriminant of the place, returning it as an integer.
247 /// Returns zero for types without discriminant.
249 /// The validity requirements for the underlying value are undecided for this rvalue, see
250 /// [#91095]. Note too that the value of the discriminant is not the same thing as the
253 /// [#91095]: https://github.com/rust-lang/rust/issues/91095
256 /// Yields the length of the place, as a `usize`.
258 /// If the type of the place is an array, this is the array length. For slices (`[T]`, not
259 /// `&[T]`) this accesses the place's metadata to determine the length. This rvalue is
260 /// ill-formed for places of other types.
263 /// Creates a reference to the place.
264 Ref(Region
, BorrowKind
, Place
),
266 /// Creates an array where each element is the value of the operand.
268 /// This is the cause of a bug in the case where the repetition count is zero because the value
269 /// is not dropped, see [#74836].
271 /// Corresponds to source code like `[x; 32]`.
273 /// [#74836]: https://github.com/rust-lang/rust/issues/74836
274 Repeat(Operand
, Const
),
276 /// Transmutes a `*mut u8` into shallow-initialized `Box<T>`.
278 /// This is different from a normal transmute because dataflow analysis will treat the box as
279 /// initialized but its content as uninitialized. Like other pointer casts, this in general
280 /// affects alias analysis.
281 ShallowInitBox(Operand
, Ty
),
283 /// Creates a pointer/reference to the given thread local.
285 /// The yielded type is a `*mut T` if the static is mutable, otherwise if the static is extern a
286 /// `*const T`, and if neither of those apply a `&T`.
288 /// **Note:** This is a runtime operation that actually executes code and is in this sense more
289 /// like a function call. Also, eliminating dead stores of this rvalue causes `fn main() {}` to
290 /// SIGILL for some reason that I (JakobDegen) never got a chance to look into.
292 /// **Needs clarification**: Are there weird additional semantics here related to the runtime
293 /// nature of this operation?
294 ThreadLocalRef(crate::CrateItem
),
296 /// Computes a value as described by the operation.
297 NullaryOp(NullOp
, Ty
),
299 /// Exactly like `BinaryOp`, but less operands.
301 /// Also does two's-complement arithmetic. Negation requires a signed integer or a float;
302 /// bitwise not requires a signed integer, unsigned integer, or bool. Both operation kinds
303 /// return a value with the same type as their operand.
304 UnaryOp(UnOp
, Operand
),
306 /// Yields the operand unchanged
310 #[derive(Clone, Debug)]
311 pub enum AggregateKind
{
314 Adt(AdtDef
, VariantIdx
, GenericArgs
, Option
<UserTypeAnnotationIndex
>, Option
<FieldIdx
>),
315 Closure(ClosureDef
, GenericArgs
),
316 Generator(GeneratorDef
, GenericArgs
, Movability
),
319 #[derive(Clone, Debug)]
326 #[derive(Clone, Debug)]
329 pub projection
: String
,
332 #[derive(Clone, Debug)]
333 pub struct UserTypeProjection
{
334 pub base
: UserTypeAnnotationIndex
,
335 pub projection
: String
,
338 pub type Local
= usize;
340 type FieldIdx
= usize;
342 /// The source-order index of a variant in a type.
343 pub type VariantIdx
= usize;
345 type UserTypeAnnotationIndex
= usize;
347 #[derive(Clone, Debug)]
348 pub struct Constant
{
350 pub user_ty
: Option
<UserTypeAnnotationIndex
>,
354 #[derive(Clone, Debug)]
355 pub struct SwitchTarget
{
360 #[derive(Clone, Debug)]
361 pub enum BorrowKind
{
362 /// Data must be immutable and is aliasable.
365 /// The immediately borrowed place must be immutable, but projections from
366 /// it don't need to be. This is used to prevent match guards from replacing
367 /// the scrutinee. For example, a fake borrow of `a.b` doesn't
368 /// conflict with a mutable borrow of `a.b.c`.
371 /// Data is mutable and not aliasable.
373 /// `true` if this borrow arose from method-call auto-ref
378 #[derive(Clone, Debug)]
379 pub enum MutBorrowKind
{
385 #[derive(Clone, Debug)]
386 pub enum Mutability
{
391 #[derive(Copy, Clone, Debug)]
397 #[derive(Clone, Debug)]
398 pub enum PointerCoercion
{
399 /// Go from a fn-item type to a fn-pointer type.
402 /// Go from a safe fn pointer to an unsafe fn pointer.
405 /// Go from a non-capturing closure to an fn pointer or an unsafe fn pointer.
406 /// It cannot convert a closure that requires unsafe.
407 ClosureFnPointer(Safety
),
409 /// Go from a mut raw pointer to a const raw pointer.
412 /// Go from `*const [T; N]` to `*const T`
415 /// Unsize a pointer/reference value, e.g., `&[T; n]` to
416 /// `&[T]`. Note that the source could be a thin or fat pointer.
417 /// This will do things like convert thin pointers to fat
418 /// pointers, or convert structs containing thin pointers to
419 /// structs containing fat pointers, or convert between fat
424 #[derive(Clone, Debug)]
426 PointerExposeAddress
,
427 PointerFromExposedAddress
,
428 PointerCoercion(PointerCoercion
),
439 #[derive(Clone, Debug)]
441 /// Returns the size of a value of that type.
443 /// Returns the minimum alignment of a type.
445 /// Returns the offset of a field.
446 OffsetOf(Vec
<FieldIdx
>),