Generics -> GenericParams

This commit is contained in:
Florian Diebold 2019-01-19 18:58:04 +01:00
parent 9e4b5ecec4
commit 969f588025
7 changed files with 41 additions and 41 deletions

View File

@ -12,7 +12,7 @@
expr::BodySyntaxMapping,
ty::InferenceResult,
adt::VariantData,
generics::Generics,
generics::GenericParams,
code_model_impl::def_id_to_ast,
};
@ -203,8 +203,8 @@ pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::StructDe
def_id_to_ast(db, self.def_id)
}
pub fn generics(&self, db: &impl HirDatabase) -> Arc<Generics> {
db.generics(self.def_id)
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
db.generic_params(self.def_id)
}
}
@ -234,8 +234,8 @@ pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::EnumDef>
def_id_to_ast(db, self.def_id)
}
pub fn generics(&self, db: &impl HirDatabase) -> Arc<Generics> {
db.generics(self.def_id)
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
db.generic_params(self.def_id)
}
}
@ -349,8 +349,8 @@ pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> {
db.infer(self.def_id)
}
pub fn generics(&self, db: &impl HirDatabase) -> Arc<Generics> {
db.generics(self.def_id)
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
db.generic_params(self.def_id)
}
}
@ -398,8 +398,8 @@ pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TraitDef
def_id_to_ast(db, self.def_id)
}
pub fn generics(&self, db: &impl HirDatabase) -> Arc<Generics> {
db.generics(self.def_id)
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
db.generic_params(self.def_id)
}
}
@ -417,7 +417,7 @@ pub fn source(&self, db: &impl HirDatabase) -> (HirFileId, TreeArc<ast::TypeDef>
def_id_to_ast(db, self.def_id)
}
pub fn generics(&self, db: &impl HirDatabase) -> Arc<Generics> {
db.generics(self.def_id)
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
db.generic_params(self.def_id)
}
}

View File

@ -14,7 +14,7 @@
ty::{InferenceResult, Ty, method_resolution::CrateImplBlocks},
adt::{StructData, EnumData, EnumVariantData},
impl_block::ModuleImplBlocks,
generics::Generics,
generics::GenericParams,
};
#[salsa::query_group]
@ -102,8 +102,8 @@ fn impls_in_module(
#[salsa::invoke(crate::expr::body_syntax_mapping)]
fn body_syntax_mapping(&self, def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping>;
#[salsa::invoke(crate::generics::Generics::generics_query)]
fn generics(&self, def_id: DefId) -> Arc<Generics>;
#[salsa::invoke(crate::generics::GenericParams::generic_params_query)]
fn generic_params(&self, def_id: DefId) -> Arc<GenericParams>;
#[salsa::invoke(crate::FnSignature::fn_signature_query)]
fn fn_signature(&self, def_id: DefId) -> Arc<FnSignature>;

View File

@ -18,14 +18,14 @@ pub struct GenericParam {
/// Data about the generic parameters of a function, struct, impl, etc.
#[derive(Clone, PartialEq, Eq, Debug, Default)]
pub struct Generics {
pub struct GenericParams {
pub(crate) params: Vec<GenericParam>,
}
impl Generics {
pub(crate) fn generics_query(db: &impl HirDatabase, def_id: DefId) -> Arc<Generics> {
impl GenericParams {
pub(crate) fn generic_params_query(db: &impl HirDatabase, def_id: DefId) -> Arc<GenericParams> {
let (_file_id, node) = def_id.source(db);
let mut generics = Generics::default();
let mut generics = GenericParams::default();
if let Some(type_param_list) = node.children().find_map(TypeParamList::cast) {
for (idx, type_param) in type_param_list.type_params().enumerate() {
let name = type_param

View File

@ -243,7 +243,7 @@ impl db::HirDatabase {
fn body_hir() for db::BodyHirQuery;
fn body_syntax_mapping() for db::BodySyntaxMappingQuery;
fn fn_signature() for db::FnSignatureQuery;
fn generics() for db::GenericsQuery;
fn generic_params() for db::GenericParamsQuery;
}
}
}

View File

@ -37,7 +37,7 @@
type_ref::{TypeRef, Mutability},
name::KnownName,
expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat},
generics::Generics,
generics::GenericParams,
path::GenericArg,
};
@ -283,7 +283,7 @@ pub(crate) fn from_hir(
// resolver architecture
module: &Module,
impl_block: Option<&ImplBlock>,
generics: &Generics,
generics: &GenericParams,
type_ref: &TypeRef,
) -> Self {
match type_ref {
@ -335,7 +335,7 @@ pub(crate) fn from_hir_opt(
db: &impl HirDatabase,
module: &Module,
impl_block: Option<&ImplBlock>,
generics: &Generics,
generics: &GenericParams,
type_ref: Option<&TypeRef>,
) -> Self {
type_ref.map_or(Ty::Unknown, |t| {
@ -347,7 +347,7 @@ pub(crate) fn from_hir_path(
db: &impl HirDatabase,
module: &Module,
impl_block: Option<&ImplBlock>,
generics: &Generics,
generics: &GenericParams,
path: &Path,
) -> Self {
if let Some(name) = path.as_ident() {
@ -357,7 +357,7 @@ pub(crate) fn from_hir_path(
return Ty::Float(float_ty);
} else if name.as_known_name() == Some(KnownName::SelfType) {
// TODO pass the impl block's generics?
let generics = &Generics::default();
let generics = &GenericParams::default();
return Ty::from_hir_opt(
db,
module,
@ -397,7 +397,7 @@ fn substs_from_path(
// the scope of the segment...
module: &Module,
impl_block: Option<&ImplBlock>,
outer_generics: &Generics,
outer_generics: &GenericParams,
path: &Path,
resolved: DefId,
) -> Substs {
@ -408,10 +408,10 @@ fn substs_from_path(
.last()
.expect("path should have at least one segment");
let (def_generics, segment) = match def {
Def::Struct(s) => (s.generics(db), last),
Def::Enum(e) => (e.generics(db), last),
Def::Function(f) => (f.generics(db), last),
Def::Trait(t) => (t.generics(db), last),
Def::Struct(s) => (s.generic_params(db), last),
Def::Enum(e) => (e.generic_params(db), last),
Def::Function(f) => (f.generic_params(db), last),
Def::Trait(t) => (t.generic_params(db), last),
Def::EnumVariant(ev) => {
// the generic args for an enum variant may be either specified
// on the segment referring to the enum, or on the segment
@ -426,7 +426,7 @@ fn substs_from_path(
// Option::None::<T>
last
};
(ev.parent_enum(db).generics(db), segment)
(ev.parent_enum(db).generic_params(db), segment)
}
_ => return Substs::empty(),
};
@ -607,7 +607,7 @@ fn type_for_fn(db: &impl HirDatabase, f: Function) -> Ty {
let signature = f.signature(db);
let module = f.module(db);
let impl_block = f.impl_block(db);
let generics = f.generics(db);
let generics = f.generic_params(db);
let input = signature
.params()
.iter()
@ -624,7 +624,7 @@ fn type_for_fn(db: &impl HirDatabase, f: Function) -> Ty {
Ty::FnPtr(Arc::new(sig))
}
fn make_substs(generics: &Generics) -> Substs {
fn make_substs(generics: &GenericParams) -> Substs {
Substs(
generics
.params
@ -636,7 +636,7 @@ fn make_substs(generics: &Generics) -> Substs {
}
fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Ty {
let generics = s.generics(db);
let generics = s.generic_params(db);
Ty::Adt {
def_id: s.def_id(),
name: s.name(db).unwrap_or_else(Name::missing),
@ -645,7 +645,7 @@ fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Ty {
}
pub(crate) fn type_for_enum(db: &impl HirDatabase, s: Enum) -> Ty {
let generics = s.generics(db);
let generics = s.generic_params(db);
Ty::Adt {
def_id: s.def_id(),
name: s.name(db).unwrap_or_else(Name::missing),
@ -684,8 +684,8 @@ pub(super) fn type_for_def(db: &impl HirDatabase, def_id: DefId) -> Ty {
pub(super) fn type_for_field(db: &impl HirDatabase, def_id: DefId, field: Name) -> Option<Ty> {
let def = def_id.resolve(db);
let (variant_data, generics) = match def {
Def::Struct(s) => (s.variant_data(db), s.generics(db)),
Def::EnumVariant(ev) => (ev.variant_data(db), ev.parent_enum(db).generics(db)),
Def::Struct(s) => (s.variant_data(db), s.generic_params(db)),
Def::EnumVariant(ev) => (ev.variant_data(db), ev.parent_enum(db).generic_params(db)),
// TODO: unions
_ => panic!(
"trying to get type for field in non-struct/variant {:?}",
@ -880,7 +880,7 @@ fn write_pat_ty(&mut self, pat: PatId, ty: Ty) {
fn make_ty(&mut self, type_ref: &TypeRef) -> Ty {
// TODO provide generics of function
let generics = Generics::default();
let generics = GenericParams::default();
let ty = Ty::from_hir(
self.db,
&self.module,
@ -1075,7 +1075,7 @@ fn resolve_variant(&mut self, path: Option<&Path>) -> (Ty, Option<DefId>) {
};
// TODO remove the duplication between here and `Ty::from_path`?
// TODO provide generics of function
let generics = Generics::default();
let generics = GenericParams::default();
let substs = Ty::substs_from_path(
self.db,
&self.module,

View File

@ -11,7 +11,7 @@
use crate::{
HirDatabase, DefId, module_tree::ModuleId, Module, Crate, Name, Function,
impl_block::{ImplId, ImplBlock, ImplItem},
generics::Generics
generics::GenericParams
};
use super::Ty;
@ -69,7 +69,7 @@ fn collect_recursive(&mut self, db: &impl HirDatabase, module: Module) {
// ignore for now
} else {
// TODO provide generics of impl
let generics = Generics::default();
let generics = GenericParams::default();
let target_ty = Ty::from_hir(
db,
&module,

View File

@ -129,7 +129,7 @@ impl hir::db::HirDatabase {
fn body_hir() for hir::db::BodyHirQuery;
fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery;
fn fn_signature() for hir::db::FnSignatureQuery;
fn generics() for hir::db::GenericsQuery;
fn generic_params() for hir::db::GenericParamsQuery;
}
}
}