-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththir.rs
More file actions
51 lines (42 loc) · 1.07 KB
/
Copy paththir.rs
File metadata and controls
51 lines (42 loc) · 1.07 KB
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
use crate::prelude::*;
use hir::*;
pub struct Thir<'hir> {
pub hir: &'hir Hir,
pub identifier_tys: BTreeMap<IdentifierBindingId, TypeId>,
pub expression_tys: IndexedVec<ExpressionId, TypeId>,
}
impl Deref for Thir<'_> {
type Target = Hir;
fn deref(&self) -> &Self::Target {
self.hir
}
}
impl<'hir> Thir<'hir> {
pub fn new(
hir: &'hir Hir,
identifiers_tys: BTreeMap<IdentifierBindingId, TypeId>,
expressions_tys: IndexedVec<ExpressionId, TypeId>,
) -> Self {
Self {
hir,
identifier_tys: identifiers_tys,
expression_tys: expressions_tys,
}
}
pub fn type_of(&self, id: impl ThirIndex) -> TypeId {
id.type_of(self)
}
}
pub trait ThirIndex: Copy {
fn type_of(self, thir: &Thir<'_>) -> TypeId;
}
impl ThirIndex for IdentifierBindingId {
fn type_of(self, thir: &Thir<'_>) -> TypeId {
thir.identifier_tys[&self]
}
}
impl ThirIndex for ExpressionId {
fn type_of(self, thir: &Thir<'_>) -> TypeId {
thir.expression_tys[self]
}
}