Generics -> GenericParams
This commit is contained in:
parent
9e4b5ecec4
commit
969f588025
@ -12,7 +12,7 @@
|
|||||||
expr::BodySyntaxMapping,
|
expr::BodySyntaxMapping,
|
||||||
ty::InferenceResult,
|
ty::InferenceResult,
|
||||||
adt::VariantData,
|
adt::VariantData,
|
||||||
generics::Generics,
|
generics::GenericParams,
|
||||||
code_model_impl::def_id_to_ast,
|
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)
|
def_id_to_ast(db, self.def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generics(&self, db: &impl HirDatabase) -> Arc<Generics> {
|
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
|
||||||
db.generics(self.def_id)
|
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)
|
def_id_to_ast(db, self.def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generics(&self, db: &impl HirDatabase) -> Arc<Generics> {
|
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
|
||||||
db.generics(self.def_id)
|
db.generic_params(self.def_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,8 +349,8 @@ pub fn infer(&self, db: &impl HirDatabase) -> Arc<InferenceResult> {
|
|||||||
db.infer(self.def_id)
|
db.infer(self.def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generics(&self, db: &impl HirDatabase) -> Arc<Generics> {
|
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
|
||||||
db.generics(self.def_id)
|
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)
|
def_id_to_ast(db, self.def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generics(&self, db: &impl HirDatabase) -> Arc<Generics> {
|
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
|
||||||
db.generics(self.def_id)
|
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)
|
def_id_to_ast(db, self.def_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generics(&self, db: &impl HirDatabase) -> Arc<Generics> {
|
pub fn generic_params(&self, db: &impl HirDatabase) -> Arc<GenericParams> {
|
||||||
db.generics(self.def_id)
|
db.generic_params(self.def_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
ty::{InferenceResult, Ty, method_resolution::CrateImplBlocks},
|
ty::{InferenceResult, Ty, method_resolution::CrateImplBlocks},
|
||||||
adt::{StructData, EnumData, EnumVariantData},
|
adt::{StructData, EnumData, EnumVariantData},
|
||||||
impl_block::ModuleImplBlocks,
|
impl_block::ModuleImplBlocks,
|
||||||
generics::Generics,
|
generics::GenericParams,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[salsa::query_group]
|
#[salsa::query_group]
|
||||||
@ -102,8 +102,8 @@ fn impls_in_module(
|
|||||||
#[salsa::invoke(crate::expr::body_syntax_mapping)]
|
#[salsa::invoke(crate::expr::body_syntax_mapping)]
|
||||||
fn body_syntax_mapping(&self, def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping>;
|
fn body_syntax_mapping(&self, def_id: DefId) -> Arc<crate::expr::BodySyntaxMapping>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::generics::Generics::generics_query)]
|
#[salsa::invoke(crate::generics::GenericParams::generic_params_query)]
|
||||||
fn generics(&self, def_id: DefId) -> Arc<Generics>;
|
fn generic_params(&self, def_id: DefId) -> Arc<GenericParams>;
|
||||||
|
|
||||||
#[salsa::invoke(crate::FnSignature::fn_signature_query)]
|
#[salsa::invoke(crate::FnSignature::fn_signature_query)]
|
||||||
fn fn_signature(&self, def_id: DefId) -> Arc<FnSignature>;
|
fn fn_signature(&self, def_id: DefId) -> Arc<FnSignature>;
|
||||||
|
@ -18,14 +18,14 @@ pub struct GenericParam {
|
|||||||
|
|
||||||
/// Data about the generic parameters of a function, struct, impl, etc.
|
/// Data about the generic parameters of a function, struct, impl, etc.
|
||||||
#[derive(Clone, PartialEq, Eq, Debug, Default)]
|
#[derive(Clone, PartialEq, Eq, Debug, Default)]
|
||||||
pub struct Generics {
|
pub struct GenericParams {
|
||||||
pub(crate) params: Vec<GenericParam>,
|
pub(crate) params: Vec<GenericParam>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Generics {
|
impl GenericParams {
|
||||||
pub(crate) fn generics_query(db: &impl HirDatabase, def_id: DefId) -> Arc<Generics> {
|
pub(crate) fn generic_params_query(db: &impl HirDatabase, def_id: DefId) -> Arc<GenericParams> {
|
||||||
let (_file_id, node) = def_id.source(db);
|
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) {
|
if let Some(type_param_list) = node.children().find_map(TypeParamList::cast) {
|
||||||
for (idx, type_param) in type_param_list.type_params().enumerate() {
|
for (idx, type_param) in type_param_list.type_params().enumerate() {
|
||||||
let name = type_param
|
let name = type_param
|
||||||
|
@ -243,7 +243,7 @@ impl db::HirDatabase {
|
|||||||
fn body_hir() for db::BodyHirQuery;
|
fn body_hir() for db::BodyHirQuery;
|
||||||
fn body_syntax_mapping() for db::BodySyntaxMappingQuery;
|
fn body_syntax_mapping() for db::BodySyntaxMappingQuery;
|
||||||
fn fn_signature() for db::FnSignatureQuery;
|
fn fn_signature() for db::FnSignatureQuery;
|
||||||
fn generics() for db::GenericsQuery;
|
fn generic_params() for db::GenericParamsQuery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,7 +37,7 @@
|
|||||||
type_ref::{TypeRef, Mutability},
|
type_ref::{TypeRef, Mutability},
|
||||||
name::KnownName,
|
name::KnownName,
|
||||||
expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat},
|
expr::{Body, Expr, BindingAnnotation, Literal, ExprId, Pat, PatId, UnaryOp, BinaryOp, Statement, FieldPat},
|
||||||
generics::Generics,
|
generics::GenericParams,
|
||||||
path::GenericArg,
|
path::GenericArg,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -283,7 +283,7 @@ pub(crate) fn from_hir(
|
|||||||
// resolver architecture
|
// resolver architecture
|
||||||
module: &Module,
|
module: &Module,
|
||||||
impl_block: Option<&ImplBlock>,
|
impl_block: Option<&ImplBlock>,
|
||||||
generics: &Generics,
|
generics: &GenericParams,
|
||||||
type_ref: &TypeRef,
|
type_ref: &TypeRef,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
match type_ref {
|
match type_ref {
|
||||||
@ -335,7 +335,7 @@ pub(crate) fn from_hir_opt(
|
|||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
module: &Module,
|
module: &Module,
|
||||||
impl_block: Option<&ImplBlock>,
|
impl_block: Option<&ImplBlock>,
|
||||||
generics: &Generics,
|
generics: &GenericParams,
|
||||||
type_ref: Option<&TypeRef>,
|
type_ref: Option<&TypeRef>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
type_ref.map_or(Ty::Unknown, |t| {
|
type_ref.map_or(Ty::Unknown, |t| {
|
||||||
@ -347,7 +347,7 @@ pub(crate) fn from_hir_path(
|
|||||||
db: &impl HirDatabase,
|
db: &impl HirDatabase,
|
||||||
module: &Module,
|
module: &Module,
|
||||||
impl_block: Option<&ImplBlock>,
|
impl_block: Option<&ImplBlock>,
|
||||||
generics: &Generics,
|
generics: &GenericParams,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
if let Some(name) = path.as_ident() {
|
if let Some(name) = path.as_ident() {
|
||||||
@ -357,7 +357,7 @@ pub(crate) fn from_hir_path(
|
|||||||
return Ty::Float(float_ty);
|
return Ty::Float(float_ty);
|
||||||
} else if name.as_known_name() == Some(KnownName::SelfType) {
|
} else if name.as_known_name() == Some(KnownName::SelfType) {
|
||||||
// TODO pass the impl block's generics?
|
// TODO pass the impl block's generics?
|
||||||
let generics = &Generics::default();
|
let generics = &GenericParams::default();
|
||||||
return Ty::from_hir_opt(
|
return Ty::from_hir_opt(
|
||||||
db,
|
db,
|
||||||
module,
|
module,
|
||||||
@ -397,7 +397,7 @@ fn substs_from_path(
|
|||||||
// the scope of the segment...
|
// the scope of the segment...
|
||||||
module: &Module,
|
module: &Module,
|
||||||
impl_block: Option<&ImplBlock>,
|
impl_block: Option<&ImplBlock>,
|
||||||
outer_generics: &Generics,
|
outer_generics: &GenericParams,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
resolved: DefId,
|
resolved: DefId,
|
||||||
) -> Substs {
|
) -> Substs {
|
||||||
@ -408,10 +408,10 @@ fn substs_from_path(
|
|||||||
.last()
|
.last()
|
||||||
.expect("path should have at least one segment");
|
.expect("path should have at least one segment");
|
||||||
let (def_generics, segment) = match def {
|
let (def_generics, segment) = match def {
|
||||||
Def::Struct(s) => (s.generics(db), last),
|
Def::Struct(s) => (s.generic_params(db), last),
|
||||||
Def::Enum(e) => (e.generics(db), last),
|
Def::Enum(e) => (e.generic_params(db), last),
|
||||||
Def::Function(f) => (f.generics(db), last),
|
Def::Function(f) => (f.generic_params(db), last),
|
||||||
Def::Trait(t) => (t.generics(db), last),
|
Def::Trait(t) => (t.generic_params(db), last),
|
||||||
Def::EnumVariant(ev) => {
|
Def::EnumVariant(ev) => {
|
||||||
// the generic args for an enum variant may be either specified
|
// the generic args for an enum variant may be either specified
|
||||||
// on the segment referring to the enum, or on the segment
|
// on the segment referring to the enum, or on the segment
|
||||||
@ -426,7 +426,7 @@ fn substs_from_path(
|
|||||||
// Option::None::<T>
|
// Option::None::<T>
|
||||||
last
|
last
|
||||||
};
|
};
|
||||||
(ev.parent_enum(db).generics(db), segment)
|
(ev.parent_enum(db).generic_params(db), segment)
|
||||||
}
|
}
|
||||||
_ => return Substs::empty(),
|
_ => return Substs::empty(),
|
||||||
};
|
};
|
||||||
@ -607,7 +607,7 @@ fn type_for_fn(db: &impl HirDatabase, f: Function) -> Ty {
|
|||||||
let signature = f.signature(db);
|
let signature = f.signature(db);
|
||||||
let module = f.module(db);
|
let module = f.module(db);
|
||||||
let impl_block = f.impl_block(db);
|
let impl_block = f.impl_block(db);
|
||||||
let generics = f.generics(db);
|
let generics = f.generic_params(db);
|
||||||
let input = signature
|
let input = signature
|
||||||
.params()
|
.params()
|
||||||
.iter()
|
.iter()
|
||||||
@ -624,7 +624,7 @@ fn type_for_fn(db: &impl HirDatabase, f: Function) -> Ty {
|
|||||||
Ty::FnPtr(Arc::new(sig))
|
Ty::FnPtr(Arc::new(sig))
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_substs(generics: &Generics) -> Substs {
|
fn make_substs(generics: &GenericParams) -> Substs {
|
||||||
Substs(
|
Substs(
|
||||||
generics
|
generics
|
||||||
.params
|
.params
|
||||||
@ -636,7 +636,7 @@ fn make_substs(generics: &Generics) -> Substs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Ty {
|
fn type_for_struct(db: &impl HirDatabase, s: Struct) -> Ty {
|
||||||
let generics = s.generics(db);
|
let generics = s.generic_params(db);
|
||||||
Ty::Adt {
|
Ty::Adt {
|
||||||
def_id: s.def_id(),
|
def_id: s.def_id(),
|
||||||
name: s.name(db).unwrap_or_else(Name::missing),
|
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 {
|
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 {
|
Ty::Adt {
|
||||||
def_id: s.def_id(),
|
def_id: s.def_id(),
|
||||||
name: s.name(db).unwrap_or_else(Name::missing),
|
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> {
|
pub(super) fn type_for_field(db: &impl HirDatabase, def_id: DefId, field: Name) -> Option<Ty> {
|
||||||
let def = def_id.resolve(db);
|
let def = def_id.resolve(db);
|
||||||
let (variant_data, generics) = match def {
|
let (variant_data, generics) = match def {
|
||||||
Def::Struct(s) => (s.variant_data(db), s.generics(db)),
|
Def::Struct(s) => (s.variant_data(db), s.generic_params(db)),
|
||||||
Def::EnumVariant(ev) => (ev.variant_data(db), ev.parent_enum(db).generics(db)),
|
Def::EnumVariant(ev) => (ev.variant_data(db), ev.parent_enum(db).generic_params(db)),
|
||||||
// TODO: unions
|
// TODO: unions
|
||||||
_ => panic!(
|
_ => panic!(
|
||||||
"trying to get type for field in non-struct/variant {:?}",
|
"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 {
|
fn make_ty(&mut self, type_ref: &TypeRef) -> Ty {
|
||||||
// TODO provide generics of function
|
// TODO provide generics of function
|
||||||
let generics = Generics::default();
|
let generics = GenericParams::default();
|
||||||
let ty = Ty::from_hir(
|
let ty = Ty::from_hir(
|
||||||
self.db,
|
self.db,
|
||||||
&self.module,
|
&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 remove the duplication between here and `Ty::from_path`?
|
||||||
// TODO provide generics of function
|
// TODO provide generics of function
|
||||||
let generics = Generics::default();
|
let generics = GenericParams::default();
|
||||||
let substs = Ty::substs_from_path(
|
let substs = Ty::substs_from_path(
|
||||||
self.db,
|
self.db,
|
||||||
&self.module,
|
&self.module,
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
HirDatabase, DefId, module_tree::ModuleId, Module, Crate, Name, Function,
|
HirDatabase, DefId, module_tree::ModuleId, Module, Crate, Name, Function,
|
||||||
impl_block::{ImplId, ImplBlock, ImplItem},
|
impl_block::{ImplId, ImplBlock, ImplItem},
|
||||||
generics::Generics
|
generics::GenericParams
|
||||||
};
|
};
|
||||||
use super::Ty;
|
use super::Ty;
|
||||||
|
|
||||||
@ -69,7 +69,7 @@ fn collect_recursive(&mut self, db: &impl HirDatabase, module: Module) {
|
|||||||
// ignore for now
|
// ignore for now
|
||||||
} else {
|
} else {
|
||||||
// TODO provide generics of impl
|
// TODO provide generics of impl
|
||||||
let generics = Generics::default();
|
let generics = GenericParams::default();
|
||||||
let target_ty = Ty::from_hir(
|
let target_ty = Ty::from_hir(
|
||||||
db,
|
db,
|
||||||
&module,
|
&module,
|
||||||
|
@ -129,7 +129,7 @@ impl hir::db::HirDatabase {
|
|||||||
fn body_hir() for hir::db::BodyHirQuery;
|
fn body_hir() for hir::db::BodyHirQuery;
|
||||||
fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery;
|
fn body_syntax_mapping() for hir::db::BodySyntaxMappingQuery;
|
||||||
fn fn_signature() for hir::db::FnSignatureQuery;
|
fn fn_signature() for hir::db::FnSignatureQuery;
|
||||||
fn generics() for hir::db::GenericsQuery;
|
fn generic_params() for hir::db::GenericParamsQuery;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user