Use GenericDefId more

This commit is contained in:
Aleksey Kladov 2019-11-25 15:39:12 +03:00
parent 9f7fcc6ecd
commit c2a16632d0
5 changed files with 20 additions and 33 deletions

View File

@ -24,7 +24,7 @@
RawItemsWithSourceMapQuery, StaticDataQuery, StructDataQuery, TraitDataQuery,
TypeAliasDataQuery,
},
LocalStructFieldId, VariantId,
GenericDefId, LocalStructFieldId, VariantId,
};
pub use hir_expand::db::{
AstDatabase, AstDatabaseStorage, AstIdMapQuery, MacroArgQuery, MacroDefQuery, MacroExpandQuery,
@ -54,7 +54,7 @@ fn generic_predicates_for_param(
) -> Arc<[GenericPredicate]>;
#[salsa::invoke(crate::ty::generic_predicates_query)]
fn generic_predicates(&self, def: GenericDef) -> Arc<[GenericPredicate]>;
fn generic_predicates(&self, def: GenericDefId) -> Arc<[GenericPredicate]>;
#[salsa::invoke(crate::ty::generic_defaults_query)]
fn generic_defaults(&self, def: GenericDef) -> Substs;

View File

@ -9,9 +9,8 @@
};
use crate::{
ty::{CallableDef, TypableDef},
Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function, GenericDef,
ModuleDef, Static, StructField, TypeAlias, VariantDef,
ty::TypableDef, Adt, AssocItem, AttrDef, Const, Crate, DefWithBody, EnumVariant, Function,
GenericDef, ModuleDef, Static, StructField, TypeAlias, VariantDef,
};
impl From<ra_db::CrateId> for Crate {
@ -214,18 +213,6 @@ fn from(id: Adt) -> Self {
}
}
impl From<CallableDef> for GenericDefId {
fn from(def: CallableDef) -> Self {
match def {
CallableDef::Function(it) => it.id.into(),
CallableDef::Struct(it) => it.id.into(),
CallableDef::EnumVariant(it) => {
EnumVariantId { parent: it.parent.id, local_id: it.id }.into()
}
}
}
}
impl From<VariantDef> for VariantId {
fn from(def: VariantDef) -> Self {
match def {

View File

@ -17,7 +17,7 @@
use std::sync::Arc;
use std::{fmt, iter, mem};
use hir_def::{generics::GenericParams, AdtId};
use hir_def::{generics::GenericParams, AdtId, GenericDefId};
use ra_db::{impl_intern_key, salsa};
use crate::{
@ -176,7 +176,7 @@ pub fn krate(self, db: &impl HirDatabase) -> Option<Crate> {
}
}
pub fn as_generic_def(self) -> Option<crate::GenericDef> {
pub fn as_generic_def(self) -> Option<GenericDefId> {
match self {
TypeCtor::Bool
| TypeCtor::Char
@ -193,7 +193,7 @@ pub fn as_generic_def(self) -> Option<crate::GenericDef> {
| TypeCtor::Closure { .. } => None,
TypeCtor::Adt(adt) => Some(adt.into()),
TypeCtor::FnDef(callable) => Some(callable.into()),
TypeCtor::AssociatedType(type_alias) => Some(type_alias.into()),
TypeCtor::AssociatedType(type_alias) => Some(type_alias.id.into()),
}
}
}

View File

@ -14,7 +14,7 @@
path::{GenericArg, PathSegment},
resolver::{HasResolver, Resolver, TypeNs},
type_ref::{TypeBound, TypeRef},
AdtId, GenericDefId, LocalStructFieldId, VariantId,
AdtId, EnumVariantId, GenericDefId, LocalStructFieldId, VariantId,
};
use ra_arena::map::ArenaMap;
@ -605,9 +605,9 @@ pub(crate) fn lower(db: &impl HirDatabase, resolver: &Resolver) -> Arc<TraitEnvi
/// Resolve the where clause(s) of an item with generics.
pub(crate) fn generic_predicates_query(
db: &impl HirDatabase,
def: GenericDef,
def: GenericDefId,
) -> Arc<[GenericPredicate]> {
let resolver = GenericDefId::from(def).resolver(db);
let resolver = def.resolver(db);
resolver
.where_predicates_in_scope()
.flat_map(|pred| GenericPredicate::from_where_predicate(db, &resolver, pred))
@ -819,12 +819,12 @@ pub fn krate(self, db: &impl HirDatabase) -> Option<crate::Crate> {
}
}
impl From<CallableDef> for GenericDef {
fn from(def: CallableDef) -> GenericDef {
impl From<CallableDef> for GenericDefId {
fn from(def: CallableDef) -> GenericDefId {
match def {
CallableDef::Function(f) => f.into(),
CallableDef::Struct(s) => s.into(),
CallableDef::EnumVariant(e) => e.into(),
CallableDef::Function(f) => f.id.into(),
CallableDef::Struct(s) => s.id.into(),
CallableDef::EnumVariant(e) => EnumVariantId::from(e).into(),
}
}
}

View File

@ -9,7 +9,7 @@
};
use chalk_rust_ir::{AssociatedTyDatum, AssociatedTyValue, ImplDatum, StructDatum, TraitDatum};
use hir_def::lang_item::LangItemTarget;
use hir_def::{lang_item::LangItemTarget, GenericDefId};
use hir_expand::name;
use ra_db::salsa::{InternId, InternKey};
@ -19,7 +19,7 @@
db::HirDatabase,
ty::display::HirDisplay,
ty::{ApplicationTy, GenericPredicate, ProjectionTy, Substs, TraitRef, Ty, TypeCtor, TypeWalk},
Crate, GenericDef, ImplBlock, Trait, TypeAlias,
Crate, ImplBlock, Trait, TypeAlias,
};
/// This represents a trait whose name we could not resolve.
@ -402,7 +402,7 @@ fn make_binders<T>(value: T, num_vars: usize) -> chalk_ir::Binders<T> {
fn convert_where_clauses(
db: &impl HirDatabase,
def: GenericDef,
def: GenericDefId,
substs: &Substs,
) -> Vec<chalk_ir::QuantifiedWhereClause<ChalkIr>> {
let generic_predicates = db.generic_predicates(def);
@ -561,7 +561,7 @@ pub(crate) fn trait_datum_query(
marker: false,
fundamental: false,
};
let where_clauses = convert_where_clauses(db, trait_.into(), &bound_vars);
let where_clauses = convert_where_clauses(db, trait_.id.into(), &bound_vars);
let associated_ty_ids = trait_
.items(db)
.into_iter()
@ -643,7 +643,7 @@ fn impl_block_datum(
} else {
chalk_rust_ir::ImplType::External
};
let where_clauses = convert_where_clauses(db, impl_block.into(), &bound_vars);
let where_clauses = convert_where_clauses(db, impl_block.id.into(), &bound_vars);
let negative = impl_block.is_negative(db);
debug!(
"impl {:?}: {}{} where {:?}",