forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathinterner.rs
232 lines (203 loc) · 7.29 KB
/
interner.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
#![feature(associated_type_defaults)]
use std::cmp::Ord;
use std::fmt::{Debug, Formatter};
use std::hash::Hash;
use std::ops::ControlFlow;
pub trait Interner: Sized {
type DefId: Copy + Debug + Hash + Ord;
type AdtDef: Copy + Debug + Hash + Ord;
type GenericArgs: Copy
+ DebugWithInfcx<Self>
+ Hash
+ Ord
+ IntoIterator<Item = Self::GenericArg>;
type GenericArg: Copy + DebugWithInfcx<Self> + Hash + Ord;
type Term: Copy + Debug + Hash + Ord;
type Binder<T: TypeVisitable<Self>>: BoundVars<Self> + TypeSuperVisitable<Self>;
type BoundVars: IntoIterator<Item = Self::BoundVar>;
type BoundVar;
type CanonicalVars: Copy + Debug + Hash + Eq + IntoIterator<Item = CanonicalVarInfo<Self>>;
type Ty: Copy
+ DebugWithInfcx<Self>
+ Hash
+ Ord
+ Into<Self::GenericArg>
+ IntoKind<Kind = TyKind<Self>>
+ TypeSuperVisitable<Self>
+ Flags
+ Ty<Self>;
type Tys: Copy + Debug + Hash + Ord + IntoIterator<Item = Self::Ty>;
type AliasTy: Copy + DebugWithInfcx<Self> + Hash + Ord;
type ParamTy: Copy + Debug + Hash + Ord;
type BoundTy: Copy + Debug + Hash + Ord;
type PlaceholderTy: Copy + Debug + Hash + Ord + PlaceholderLike;
type ErrorGuaranteed: Copy + Debug + Hash + Ord;
type BoundExistentialPredicates: Copy + DebugWithInfcx<Self> + Hash + Ord;
type PolyFnSig: Copy + DebugWithInfcx<Self> + Hash + Ord;
type AllocId: Copy + Debug + Hash + Ord;
type Const: Copy
+ DebugWithInfcx<Self>
+ Hash
+ Ord
+ Into<Self::GenericArg>
+ IntoKind<Kind = ConstKind<Self>>
+ ConstTy<Self>
+ TypeSuperVisitable<Self>
+ Flags
+ Const<Self>;
type AliasConst: Copy + DebugWithInfcx<Self> + Hash + Ord;
type PlaceholderConst: Copy + Debug + Hash + Ord + PlaceholderLike;
type ParamConst: Copy + Debug + Hash + Ord;
type BoundConst: Copy + Debug + Hash + Ord;
type ValueConst: Copy + Debug + Hash + Ord;
type ExprConst: Copy + DebugWithInfcx<Self> + Hash + Ord;
type Region: Copy
+ DebugWithInfcx<Self>
+ Hash
+ Ord
+ Into<Self::GenericArg>
+ IntoKind<Kind = RegionKind<Self>>
+ Flags
+ Region<Self>;
type EarlyParamRegion: Copy + Debug + Hash + Ord;
type LateParamRegion: Copy + Debug + Hash + Ord;
type BoundRegion: Copy + Debug + Hash + Ord;
type InferRegion: Copy + DebugWithInfcx<Self> + Hash + Ord;
type PlaceholderRegion: Copy + Debug + Hash + Ord + PlaceholderLike;
type Predicate: Copy + Debug + Hash + Eq + TypeSuperVisitable<Self> + Flags;
type TraitPredicate: Copy + Debug + Hash + Eq;
type RegionOutlivesPredicate: Copy + Debug + Hash + Eq;
type TypeOutlivesPredicate: Copy + Debug + Hash + Eq;
type ProjectionPredicate: Copy + Debug + Hash + Eq;
type NormalizesTo: Copy + Debug + Hash + Eq;
type SubtypePredicate: Copy + Debug + Hash + Eq;
type CoercePredicate: Copy + Debug + Hash + Eq;
type ClosureKind: Copy + Debug + Hash + Eq;
// Required method
fn mk_canonical_var_infos(self, infos: &[CanonicalVarInfo<Self>]) -> Self::CanonicalVars;
}
pub trait DebugWithInfcx<I: Interner>: Debug {
// Required method
fn fmt<Infcx: InferCtxtLike<Interner = I>>(
this: WithInfcx<'_, Infcx, &Self>,
f: &mut Formatter<'_>,
) -> std::fmt::Result;
}
pub trait TypeVisitable<I: Interner>: Debug + Clone {
// Required method
fn visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result;
}
pub trait BoundVars<I: Interner> {
// Required methods
fn bound_vars(&self) -> I::BoundVars;
fn has_no_bound_vars(&self) -> bool;
}
pub trait TypeSuperVisitable<I: Interner>: TypeVisitable<I> {
// Required method
fn super_visit_with<V: TypeVisitor<I>>(&self, visitor: &mut V) -> V::Result;
}
pub struct CanonicalVarInfo<I: Interner> {
pub kind: CanonicalVarKind<I>,
}
pub struct CanonicalVarKind<I>(std::marker::PhantomData<I>);
pub struct TyKind<I>(std::marker::PhantomData<I>);
pub trait IntoKind {
type Kind;
// Required method
fn kind(self) -> Self::Kind;
}
pub trait Flags {
// Required methods
fn flags(&self) -> TypeFlags;
fn outer_exclusive_binder(&self) -> DebruijnIndex;
}
pub struct TypeFlags;
pub trait Ty<I: Interner<Ty = Self>> {
// Required method
fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar) -> Self;
}
pub trait PlaceholderLike {
// Required methods
fn universe(self) -> UniverseIndex;
fn var(self) -> BoundVar;
fn with_updated_universe(self, ui: UniverseIndex) -> Self;
fn new(ui: UniverseIndex, var: BoundVar) -> Self;
}
pub struct UniverseIndex;
pub struct BoundVar;
pub struct ConstKind<I>(std::marker::PhantomData<I>);
pub trait Const<I: Interner<Const = Self>> {
// Required method
fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar, ty: I::Ty) -> Self;
}
pub trait ConstTy<I: Interner> {
// Required method
fn ty(self) -> I::Ty;
}
pub struct DebruijnIndex;
pub struct RegionKind<I>(std::marker::PhantomData<I>);
pub trait Region<I: Interner<Region = Self>> {
// Required method
fn new_anon_bound(interner: I, debruijn: DebruijnIndex, var: BoundVar) -> Self;
}
pub trait TypeVisitor<I: Interner>: Sized {
type Result: VisitorResult = ();
// Provided methods
fn visit_binder<T: TypeVisitable<I>>(&mut self, t: &I::Binder<T>) -> Self::Result {
unimplemented!()
}
fn visit_ty(&mut self, t: I::Ty) -> Self::Result {
unimplemented!()
}
fn visit_region(&mut self, _r: I::Region) -> Self::Result {
unimplemented!()
}
fn visit_const(&mut self, c: I::Const) -> Self::Result {
unimplemented!()
}
fn visit_predicate(&mut self, p: I::Predicate) -> Self::Result {
unimplemented!()
}
}
pub trait VisitorResult {
type Residual;
// Required methods
fn output() -> Self;
fn from_residual(residual: Self::Residual) -> Self;
fn from_branch(b: ControlFlow<Self::Residual>) -> Self;
fn branch(self) -> ControlFlow<Self::Residual>;
}
impl VisitorResult for () {
type Residual = ();
fn output() -> Self {}
fn from_residual(_: Self::Residual) -> Self {}
fn from_branch(_: ControlFlow<Self::Residual>) -> Self {}
fn branch(self) -> ControlFlow<Self::Residual> {
ControlFlow::Continue(())
}
}
pub struct WithInfcx<'a, Infcx: InferCtxtLike, T> {
pub data: T,
pub infcx: &'a Infcx,
}
pub trait InferCtxtLike {
type Interner: Interner;
// Required methods
fn interner(&self) -> Self::Interner;
fn universe_of_ty(&self, ty: TyVid) -> Option<UniverseIndex>;
fn root_ty_var(&self, vid: TyVid) -> TyVid;
fn probe_ty_var(&self, vid: TyVid) -> Option<<Self::Interner as Interner>::Ty>;
fn universe_of_lt(
&self,
lt: <Self::Interner as Interner>::InferRegion,
) -> Option<UniverseIndex>;
fn opportunistic_resolve_lt_var(
&self,
vid: <Self::Interner as Interner>::InferRegion,
) -> Option<<Self::Interner as Interner>::Region>;
fn universe_of_ct(&self, ct: ConstVid) -> Option<UniverseIndex>;
fn root_ct_var(&self, vid: ConstVid) -> ConstVid;
fn probe_ct_var(&self, vid: ConstVid) -> Option<<Self::Interner as Interner>::Const>;
}
pub struct TyVid;
pub struct ConstVid;