aboutsummaryrefslogtreecommitdiff
path: root/crates/hir_ty
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2021-04-05 20:34:50 +0100
committerGitHub <[email protected]>2021-04-05 20:34:50 +0100
commit8c96a7d81e29061537d78b5670a3474cb136422d (patch)
treed33a50deed6fb0ee85804ba9b0430e25115283e2 /crates/hir_ty
parent72781085bba92756d11f9fcc3d879b60108d230f (diff)
parentd587ca2991406bd348768b2912c3cb66c869e7e8 (diff)
Merge #8353
8353: Replace hir_ty::Lifetime with chalk equivalent r=flodiebold a=Veykril Our `Lifetime` isn't really used yet so this is a rather simple change Co-authored-by: Lukas Wirth <[email protected]>
Diffstat (limited to 'crates/hir_ty')
-rw-r--r--crates/hir_ty/src/db.rs8
-rw-r--r--crates/hir_ty/src/display.rs39
-rw-r--r--crates/hir_ty/src/lib.rs14
-rw-r--r--crates/hir_ty/src/types.rs7
4 files changed, 50 insertions, 18 deletions
diff --git a/crates/hir_ty/src/db.rs b/crates/hir_ty/src/db.rs
index 4300680d9..07510ae02 100644
--- a/crates/hir_ty/src/db.rs
+++ b/crates/hir_ty/src/db.rs
@@ -5,7 +5,7 @@ use std::sync::Arc;
5use base_db::{impl_intern_key, salsa, CrateId, Upcast}; 5use base_db::{impl_intern_key, salsa, CrateId, Upcast};
6use hir_def::{ 6use hir_def::{
7 db::DefDatabase, expr::ExprId, ConstParamId, DefWithBodyId, FunctionId, GenericDefId, ImplId, 7 db::DefDatabase, expr::ExprId, ConstParamId, DefWithBodyId, FunctionId, GenericDefId, ImplId,
8 LocalFieldId, TypeParamId, VariantId, 8 LifetimeParamId, LocalFieldId, TypeParamId, VariantId,
9}; 9};
10use la_arena::ArenaMap; 10use la_arena::ArenaMap;
11 11
@@ -86,6 +86,8 @@ pub trait HirDatabase: DefDatabase + Upcast<dyn DefDatabase> {
86 #[salsa::interned] 86 #[salsa::interned]
87 fn intern_type_param_id(&self, param_id: TypeParamId) -> InternedTypeParamId; 87 fn intern_type_param_id(&self, param_id: TypeParamId) -> InternedTypeParamId;
88 #[salsa::interned] 88 #[salsa::interned]
89 fn intern_lifetime_param_id(&self, param_id: LifetimeParamId) -> InternedLifetimeParamId;
90 #[salsa::interned]
89 fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId; 91 fn intern_impl_trait_id(&self, id: ImplTraitId) -> InternedOpaqueTyId;
90 #[salsa::interned] 92 #[salsa::interned]
91 fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId; 93 fn intern_closure(&self, id: (DefWithBodyId, ExprId)) -> InternedClosureId;
@@ -156,6 +158,10 @@ pub struct InternedTypeParamId(salsa::InternId);
156impl_intern_key!(InternedTypeParamId); 158impl_intern_key!(InternedTypeParamId);
157 159
158#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] 160#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
161pub struct InternedLifetimeParamId(salsa::InternId);
162impl_intern_key!(InternedLifetimeParamId);
163
164#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
159pub struct InternedOpaqueTyId(salsa::InternId); 165pub struct InternedOpaqueTyId(salsa::InternId);
160impl_intern_key!(InternedOpaqueTyId); 166impl_intern_key!(InternedOpaqueTyId);
161 167
diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs
index f31e6b108..01c7ef91f 100644
--- a/crates/hir_ty/src/display.rs
+++ b/crates/hir_ty/src/display.rs
@@ -1,8 +1,10 @@
1//! FIXME: write short doc here 1//! FIXME: write short doc here
2 2
3use std::{array, fmt}; 3use std::{
4 array,
5 fmt::{self, Debug},
6};
4 7
5use chalk_ir::Mutability;
6use hir_def::{ 8use hir_def::{
7 db::DefDatabase, 9 db::DefDatabase,
8 find_path, 10 find_path,
@@ -16,9 +18,10 @@ use hir_def::{
16use hir_expand::name::Name; 18use hir_expand::name::Name;
17 19
18use crate::{ 20use crate::{
19 db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx, primitive, 21 db::HirDatabase, from_assoc_type_id, from_foreign_def_id, from_placeholder_idx,
20 to_assoc_type_id, traits::chalk::from_chalk, utils::generics, AdtId, AliasEq, AliasTy, 22 lt_from_placeholder_idx, primitive, to_assoc_type_id, traits::chalk::from_chalk,
21 CallableDefId, CallableSig, DomainGoal, GenericArg, ImplTraitId, Interner, Lifetime, OpaqueTy, 23 utils::generics, AdtId, AliasEq, AliasTy, CallableDefId, CallableSig, DomainGoal, GenericArg,
24 ImplTraitId, Interner, Lifetime, LifetimeData, LifetimeOutlives, Mutability, OpaqueTy,
22 ProjectionTy, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, WhereClause, 25 ProjectionTy, QuantifiedWhereClause, Scalar, TraitRef, Ty, TyExt, TyKind, WhereClause,
23}; 26};
24 27
@@ -827,15 +830,35 @@ impl HirDisplay for WhereClause {
827 } 830 }
828} 831}
829 832
833impl HirDisplay for LifetimeOutlives {
834 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
835 self.a.hir_fmt(f)?;
836 write!(f, ": ")?;
837 self.b.hir_fmt(f)
838 }
839}
840
830impl HirDisplay for Lifetime { 841impl HirDisplay for Lifetime {
831 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> { 842 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
843 self.interned().hir_fmt(f)
844 }
845}
846
847impl HirDisplay for LifetimeData {
848 fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
832 match self { 849 match self {
833 Lifetime::Parameter(id) => { 850 LifetimeData::BoundVar(idx) => write!(f, "?{}.{}", idx.debruijn.depth(), idx.index),
851 LifetimeData::InferenceVar(_) => write!(f, "_"),
852 LifetimeData::Placeholder(idx) => {
853 let id = lt_from_placeholder_idx(f.db, *idx);
834 let generics = generics(f.db.upcast(), id.parent); 854 let generics = generics(f.db.upcast(), id.parent);
835 let param_data = &generics.params.lifetimes[id.local_id]; 855 let param_data = &generics.params.lifetimes[id.local_id];
836 write!(f, "{}", &param_data.name) 856 write!(f, "{}", param_data.name)
837 } 857 }
838 Lifetime::Static => write!(f, "'static"), 858 LifetimeData::Static => write!(f, "'static"),
859 LifetimeData::Empty(_) => Ok(()),
860 LifetimeData::Erased => Ok(()),
861 LifetimeData::Phantom(_, _) => Ok(()),
839 } 862 }
840 } 863 }
841} 864}
diff --git a/crates/hir_ty/src/lib.rs b/crates/hir_ty/src/lib.rs
index daf379ef8..a3addc8e9 100644
--- a/crates/hir_ty/src/lib.rs
+++ b/crates/hir_ty/src/lib.rs
@@ -35,8 +35,8 @@ use smallvec::SmallVec;
35 35
36use base_db::salsa; 36use base_db::salsa;
37use hir_def::{ 37use hir_def::{
38 expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId, GenericDefId, HasModule, Lookup, 38 expr::ExprId, type_ref::Rawness, AssocContainerId, FunctionId, GenericDefId, HasModule,
39 TraitId, TypeAliasId, TypeParamId, 39 LifetimeParamId, Lookup, TraitId, TypeAliasId, TypeParamId,
40}; 40};
41 41
42use crate::{db::HirDatabase, display::HirDisplay, utils::generics}; 42use crate::{db::HirDatabase, display::HirDisplay, utils::generics};
@@ -70,6 +70,10 @@ pub type VariableKind = chalk_ir::VariableKind<Interner>;
70pub type VariableKinds = chalk_ir::VariableKinds<Interner>; 70pub type VariableKinds = chalk_ir::VariableKinds<Interner>;
71pub type CanonicalVarKinds = chalk_ir::CanonicalVarKinds<Interner>; 71pub type CanonicalVarKinds = chalk_ir::CanonicalVarKinds<Interner>;
72 72
73pub type Lifetime = chalk_ir::Lifetime<Interner>;
74pub type LifetimeData = chalk_ir::LifetimeData<Interner>;
75pub type LifetimeOutlives = chalk_ir::LifetimeOutlives<Interner>;
76
73pub type ChalkTraitId = chalk_ir::TraitId<Interner>; 77pub type ChalkTraitId = chalk_ir::TraitId<Interner>;
74 78
75impl ProjectionTy { 79impl ProjectionTy {
@@ -546,6 +550,12 @@ pub fn to_placeholder_idx(db: &dyn HirDatabase, id: TypeParamId) -> PlaceholderI
546 } 550 }
547} 551}
548 552
553pub fn lt_from_placeholder_idx(db: &dyn HirDatabase, idx: PlaceholderIndex) -> LifetimeParamId {
554 assert_eq!(idx.ui, chalk_ir::UniverseIndex::ROOT);
555 let interned_id = salsa::InternKey::from_intern_id(salsa::InternId::from(idx.idx));
556 db.lookup_intern_lifetime_param_id(interned_id)
557}
558
549pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId { 559pub fn to_chalk_trait_id(id: TraitId) -> ChalkTraitId {
550 chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id)) 560 chalk_ir::TraitId(salsa::InternKey::as_intern_id(&id))
551} 561}
diff --git a/crates/hir_ty/src/types.rs b/crates/hir_ty/src/types.rs
index 46c705a76..dc64e6e2b 100644
--- a/crates/hir_ty/src/types.rs
+++ b/crates/hir_ty/src/types.rs
@@ -7,7 +7,6 @@ use chalk_ir::{
7 cast::{CastTo, Caster}, 7 cast::{CastTo, Caster},
8 BoundVar, Mutability, Scalar, TyVariableKind, 8 BoundVar, Mutability, Scalar, TyVariableKind,
9}; 9};
10use hir_def::LifetimeParamId;
11use smallvec::SmallVec; 10use smallvec::SmallVec;
12 11
13use crate::{ 12use crate::{
@@ -16,12 +15,6 @@ use crate::{
16}; 15};
17 16
18#[derive(Clone, PartialEq, Eq, Debug, Hash)] 17#[derive(Clone, PartialEq, Eq, Debug, Hash)]
19pub enum Lifetime {
20 Parameter(LifetimeParamId),
21 Static,
22}
23
24#[derive(Clone, PartialEq, Eq, Debug, Hash)]
25pub struct OpaqueTy { 18pub struct OpaqueTy {
26 pub opaque_ty_id: OpaqueTyId, 19 pub opaque_ty_id: OpaqueTyId,
27 pub substitution: Substitution, 20 pub substitution: Substitution,