From 8ebb8d29e18d7cb18bd2b57b004dcecd65a96232 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Mon, 24 May 2021 15:13:23 +0200 Subject: internal: intern `TypeBound`s Doesn't save much memory (~2 mb), but interning things is generally a good pattern to follow --- crates/hir_ty/src/display.rs | 7 +++++++ crates/hir_ty/src/lower.rs | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) (limited to 'crates/hir_ty') diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 7bbd1a1f7..637bbc634 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -13,6 +13,7 @@ use hir_def::{ db::DefDatabase, find_path, generics::TypeParamProvenance, + intern::{Internable, Interned}, item_scope::ItemInNs, path::{Path, PathKind}, type_ref::{TypeBound, TypeRef}, @@ -256,6 +257,12 @@ impl HirDisplay for &'_ T { } } +impl HirDisplay for Interned { + fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { + HirDisplay::hir_fmt(self.as_ref(), f) + } +} + impl HirDisplay for ProjectionTy { fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { if f.should_truncate() { diff --git a/crates/hir_ty/src/lower.rs b/crates/hir_ty/src/lower.rs index 8a375b973..1645ac533 100644 --- a/crates/hir_ty/src/lower.rs +++ b/crates/hir_ty/src/lower.rs @@ -10,6 +10,7 @@ use std::{iter, sync::Arc}; use base_db::CrateId; use chalk_ir::{cast::Cast, fold::Shift, interner::HasInterner, Mutability, Safety}; +use hir_def::intern::Interned; use hir_def::{ adt::StructKind, body::{Expander, LowerCtx}, @@ -843,7 +844,7 @@ impl<'a> TyLoweringContext<'a> { }) } - fn lower_impl_trait(&self, bounds: &[TypeBound]) -> ReturnTypeImplTrait { + fn lower_impl_trait(&self, bounds: &[Interned]) -> ReturnTypeImplTrait { cov_mark::hit!(lower_rpit); let self_ty = TyKind::BoundVar(BoundVar::new(DebruijnIndex::INNERMOST, 0)).intern(&Interner); -- cgit v1.2.3