From af466f8542173002361eb134e66102908c7cd024 Mon Sep 17 00:00:00 2001 From: Florian Diebold Date: Sun, 14 Mar 2021 17:25:29 +0100 Subject: 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. --- crates/hir_ty/src/infer.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) (limited to 'crates/hir_ty/src/infer.rs') 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 { pub actual: Ty, } +#[derive(Clone, PartialEq, Eq, Debug)] +struct InternedStandardTypes { + unknown: Ty, +} + +impl Default for InternedStandardTypes { + fn default() -> Self { + InternedStandardTypes { unknown: TyKind::Unknown.intern(&Interner) } + } +} + /// The result of type inference: A mapping from expressions and patterns to types. #[derive(Clone, PartialEq, Eq, Debug, Default)] pub struct InferenceResult { @@ -126,6 +137,8 @@ pub struct InferenceResult { pub type_of_expr: ArenaMap, pub type_of_pat: ArenaMap, pub(super) type_mismatches: ArenaMap, + /// Interned Unknown to return references to. + standard_types: InternedStandardTypes, } impl InferenceResult { @@ -170,7 +183,7 @@ impl Index for InferenceResult { type Output = Ty; fn index(&self, expr: ExprId) -> &Ty { - self.type_of_expr.get(expr).unwrap_or(&Ty(TyKind::Unknown)) + self.type_of_expr.get(expr).unwrap_or(&self.standard_types.unknown) } } @@ -178,7 +191,7 @@ impl Index for InferenceResult { type Output = Ty; fn index(&self, pat: PatId) -> &Ty { - self.type_of_pat.get(pat).unwrap_or(&Ty(TyKind::Unknown)) + self.type_of_pat.get(pat).unwrap_or(&self.standard_types.unknown) } } @@ -723,14 +736,19 @@ impl Expectation { /// This expresses no expectation on the type. fn none() -> Self { - Expectation { ty: TyKind::Unknown.intern(&Interner), rvalue_hint: false } + Expectation { + // FIXME + ty: TyKind::Unknown.intern(&Interner), + rvalue_hint: false, + } } - fn coercion_target(&self) -> &Ty { + fn coercion_target(&self) -> Ty { if self.rvalue_hint { - &Ty(TyKind::Unknown) + // FIXME + TyKind::Unknown.intern(&Interner) } else { - &self.ty + self.ty.clone() } } } -- cgit v1.2.3