rustc_type_ir/
flags.rs

1bitflags::bitflags! {
2    /// Flags that we track on types. These flags are propagated upwards
3    /// through the type during type construction, so that we can quickly check
4    /// whether the type has various kinds of types in it without recursing
5    /// over the type itself.
6    #[derive(Debug, PartialEq, Eq, Clone, Copy)]
7    pub struct TypeFlags: u32 {
8        // Does this have parameters? Used to determine whether instantiation is
9        // required.
10        /// Does this have `Param`?
11        const HAS_TY_PARAM                = 1 << 0;
12        /// Does this have `ReEarlyParam`?
13        const HAS_RE_PARAM                = 1 << 1;
14        /// Does this have `ConstKind::Param`?
15        const HAS_CT_PARAM                = 1 << 2;
16
17        const HAS_PARAM                   = TypeFlags::HAS_TY_PARAM.bits()
18                                          | TypeFlags::HAS_RE_PARAM.bits()
19                                          | TypeFlags::HAS_CT_PARAM.bits();
20
21        /// Does this have `Infer`?
22        const HAS_TY_INFER                = 1 << 3;
23        /// Does this have `ReVar`?
24        const HAS_RE_INFER                = 1 << 4;
25        /// Does this have `ConstKind::Infer`?
26        const HAS_CT_INFER                = 1 << 5;
27
28        /// Does this have inference variables? Used to determine whether
29        /// inference is required.
30        const HAS_INFER                   = TypeFlags::HAS_TY_INFER.bits()
31                                          | TypeFlags::HAS_RE_INFER.bits()
32                                          | TypeFlags::HAS_CT_INFER.bits();
33
34        /// Does this have `Placeholder`?
35        const HAS_TY_PLACEHOLDER          = 1 << 6;
36        /// Does this have `RePlaceholder`?
37        const HAS_RE_PLACEHOLDER          = 1 << 7;
38        /// Does this have `ConstKind::Placeholder`?
39        const HAS_CT_PLACEHOLDER          = 1 << 8;
40
41        /// Does this have placeholders?
42        const HAS_PLACEHOLDER             = TypeFlags::HAS_TY_PLACEHOLDER.bits()
43                                          | TypeFlags::HAS_RE_PLACEHOLDER.bits()
44                                          | TypeFlags::HAS_CT_PLACEHOLDER.bits();
45
46        /// `true` if there are "names" of regions and so forth
47        /// that are local to a particular fn/inferctxt
48        const HAS_FREE_LOCAL_REGIONS      = 1 << 9;
49
50        /// `true` if there are "names" of types and regions and so forth
51        /// that are local to a particular fn
52        const HAS_FREE_LOCAL_NAMES        = TypeFlags::HAS_TY_PARAM.bits()
53                                          | TypeFlags::HAS_CT_PARAM.bits()
54                                          | TypeFlags::HAS_TY_INFER.bits()
55                                          | TypeFlags::HAS_CT_INFER.bits()
56                                          | TypeFlags::HAS_TY_PLACEHOLDER.bits()
57                                          | TypeFlags::HAS_CT_PLACEHOLDER.bits()
58                                          // We consider 'freshened' types and constants
59                                          // to depend on a particular fn.
60                                          // The freshening process throws away information,
61                                          // which can make things unsuitable for use in a global
62                                          // cache. Note that there is no 'fresh lifetime' flag -
63                                          // freshening replaces all lifetimes with `ReErased`,
64                                          // which is different from how types/const are freshened.
65                                          | TypeFlags::HAS_TY_FRESH.bits()
66                                          | TypeFlags::HAS_CT_FRESH.bits()
67                                          | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits()
68                                          | TypeFlags::HAS_RE_ERASED.bits();
69
70        /// Does this have `Projection`?
71        const HAS_TY_PROJECTION           = 1 << 10;
72        /// Does this have `Weak`?
73        const HAS_TY_WEAK                 = 1 << 11;
74        /// Does this have `Opaque`?
75        const HAS_TY_OPAQUE               = 1 << 12;
76        /// Does this have `Inherent`?
77        const HAS_TY_INHERENT             = 1 << 13;
78        /// Does this have `ConstKind::Unevaluated`?
79        const HAS_CT_PROJECTION           = 1 << 14;
80
81        /// Does this have `Alias` or `ConstKind::Unevaluated`?
82        ///
83        /// Rephrased, could this term be normalized further?
84        const HAS_ALIAS                   = TypeFlags::HAS_TY_PROJECTION.bits()
85                                          | TypeFlags::HAS_TY_WEAK.bits()
86                                          | TypeFlags::HAS_TY_OPAQUE.bits()
87                                          | TypeFlags::HAS_TY_INHERENT.bits()
88                                          | TypeFlags::HAS_CT_PROJECTION.bits();
89
90        /// Is an error type/lifetime/const reachable?
91        const HAS_ERROR                   = 1 << 15;
92
93        /// Does this have any region that "appears free" in the type?
94        /// Basically anything but `ReBound` and `ReErased`.
95        const HAS_FREE_REGIONS            = 1 << 16;
96
97        /// Does this have any `ReBound` regions?
98        const HAS_RE_BOUND                = 1 << 17;
99        /// Does this have any `Bound` types?
100        const HAS_TY_BOUND                = 1 << 18;
101        /// Does this have any `ConstKind::Bound` consts?
102        const HAS_CT_BOUND                = 1 << 19;
103        /// Does this have any bound variables?
104        /// Used to check if a global bound is safe to evaluate.
105        const HAS_BOUND_VARS              = TypeFlags::HAS_RE_BOUND.bits()
106                                          | TypeFlags::HAS_TY_BOUND.bits()
107                                          | TypeFlags::HAS_CT_BOUND.bits();
108
109        /// Does this have any `ReErased` regions?
110        const HAS_RE_ERASED               = 1 << 20;
111
112        /// Does this value have parameters/placeholders/inference variables which could be
113        /// replaced later, in a way that would change the results of `impl` specialization?
114        const STILL_FURTHER_SPECIALIZABLE = TypeFlags::HAS_TY_PARAM.bits()
115                                          | TypeFlags::HAS_TY_PLACEHOLDER.bits()
116                                          | TypeFlags::HAS_TY_INFER.bits()
117                                          | TypeFlags::HAS_CT_PARAM.bits()
118                                          | TypeFlags::HAS_CT_PLACEHOLDER.bits()
119                                          | TypeFlags::HAS_CT_INFER.bits();
120
121        /// Does this value have `InferTy::FreshTy/FreshIntTy/FreshFloatTy`?
122        const HAS_TY_FRESH                = 1 << 21;
123
124        /// Does this value have `InferConst::Fresh`?
125        const HAS_CT_FRESH                = 1 << 22;
126
127        /// Does this have any binders with bound vars (e.g. that need to be anonymized)?
128        const HAS_BINDER_VARS             = 1 << 23;
129    }
130}