aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty/src/infer.rs
diff options
context:
space:
mode:
authorFlorian Diebold <[email protected]>2021-03-14 16:25:29 +0000
committerFlorian Diebold <[email protected]>2021-03-14 16:31:08 +0000
commitaf466f8542173002361eb134e66102908c7cd024 (patch)
tree75a970fa98bf1f67ae390ae5b6a71d09fd963641 /crates/hir_ty/src/infer.rs
parent195414783402d6973f4e673e84be9b7bc19cbfa6 (diff)
Make Ty wrap TyKind in an Arc
... like it will be in Chalk. We still keep `interned_mut` and `into_inner` methods that will probably not exist with Chalk. This worsens performance slightly (5ginstr inference on RA), but doesn't include other simplifications we can do yet.
Diffstat (limited to 'crates/hir_ty/src/infer.rs')
-rw-r--r--crates/hir_ty/src/infer.rs30
1 files changed, 24 insertions, 6 deletions
diff --git a/crates/hir_ty/src/infer.rs b/crates/hir_ty/src/infer.rs
index fbfedb4e6..6dfe53902 100644
--- a/crates/hir_ty/src/infer.rs
+++ b/crates/hir_ty/src/infer.rs
@@ -108,6 +108,17 @@ pub struct TypeMismatch {
108 pub actual: Ty, 108 pub actual: Ty,
109} 109}
110 110
111#[derive(Clone, PartialEq, Eq, Debug)]
112struct InternedStandardTypes {
113 unknown: Ty,
114}
115
116impl Default for InternedStandardTypes {
117 fn default() -> Self {
118 InternedStandardTypes { unknown: TyKind::Unknown.intern(&Interner) }
119 }
120}
121
111/// The result of type inference: A mapping from expressions and patterns to types. 122/// The result of type inference: A mapping from expressions and patterns to types.
112#[derive(Clone, PartialEq, Eq, Debug, Default)] 123#[derive(Clone, PartialEq, Eq, Debug, Default)]
113pub struct InferenceResult { 124pub struct InferenceResult {
@@ -126,6 +137,8 @@ pub struct InferenceResult {
126 pub type_of_expr: ArenaMap<ExprId, Ty>, 137 pub type_of_expr: ArenaMap<ExprId, Ty>,
127 pub type_of_pat: ArenaMap<PatId, Ty>, 138 pub type_of_pat: ArenaMap<PatId, Ty>,
128 pub(super) type_mismatches: ArenaMap<ExprId, TypeMismatch>, 139 pub(super) type_mismatches: ArenaMap<ExprId, TypeMismatch>,
140 /// Interned Unknown to return references to.
141 standard_types: InternedStandardTypes,
129} 142}
130 143
131impl InferenceResult { 144impl InferenceResult {
@@ -170,7 +183,7 @@ impl Index<ExprId> for InferenceResult {
170 type Output = Ty; 183 type Output = Ty;
171 184
172 fn index(&self, expr: ExprId) -> &Ty { 185 fn index(&self, expr: ExprId) -> &Ty {
173 self.type_of_expr.get(expr).unwrap_or(&Ty(TyKind::Unknown)) 186 self.type_of_expr.get(expr).unwrap_or(&self.standard_types.unknown)
174 } 187 }
175} 188}
176 189
@@ -178,7 +191,7 @@ impl Index<PatId> for InferenceResult {
178 type Output = Ty; 191 type Output = Ty;
179 192
180 fn index(&self, pat: PatId) -> &Ty { 193 fn index(&self, pat: PatId) -> &Ty {
181 self.type_of_pat.get(pat).unwrap_or(&Ty(TyKind::Unknown)) 194 self.type_of_pat.get(pat).unwrap_or(&self.standard_types.unknown)
182 } 195 }
183} 196}
184 197
@@ -723,14 +736,19 @@ impl Expectation {
723 736
724 /// This expresses no expectation on the type. 737 /// This expresses no expectation on the type.
725 fn none() -> Self { 738 fn none() -> Self {
726 Expectation { ty: TyKind::Unknown.intern(&Interner), rvalue_hint: false } 739 Expectation {
740 // FIXME
741 ty: TyKind::Unknown.intern(&Interner),
742 rvalue_hint: false,
743 }
727 } 744 }
728 745
729 fn coercion_target(&self) -> &Ty { 746 fn coercion_target(&self) -> Ty {
730 if self.rvalue_hint { 747 if self.rvalue_hint {
731 &Ty(TyKind::Unknown) 748 // FIXME
749 TyKind::Unknown.intern(&Interner)
732 } else { 750 } else {
733 &self.ty 751 self.ty.clone()
734 } 752 }
735 } 753 }
736} 754}