1+ //! This module contains analysis for the definition of the type/trait.
2+ //! This module is the only module in `ty` module which is allowed to emit
3+ //! diagnostics.
4+
15use hir:: {
26 hir_def:: {
37 scope_graph:: ScopeId , FieldDef , ImplTrait , Trait , TraitRefId , TypeAlias , TypeId as HirTyId ,
@@ -25,13 +29,23 @@ use super::{
2529 constraint:: { collect_super_traits, AssumptionListId , SuperTraitCycle } ,
2630 constraint_solver:: { is_goal_satisfiable, GoalSatisfiability } ,
2731 diagnostics:: { TraitConstraintDiag , TraitLowerDiag , TyDiagCollection , TyLowerDiag } ,
28- trait_ :: { ingot_trait_env, Implementor , TraitDef } ,
32+ trait_def :: { ingot_trait_env, Implementor , TraitDef } ,
2933 trait_lower:: { lower_trait, lower_trait_ref, TraitRefLowerError } ,
3034 ty_def:: { AdtDef , AdtRefId , TyId } ,
3135 ty_lower:: { lower_adt, lower_hir_ty, lower_kind} ,
3236 visitor:: { walk_ty, TyVisitor } ,
3337} ;
3438
39+ /// This function implements analysis for the ADT definition.
40+ /// The analysis includes the following:
41+ /// - Check if the types in the ADT is well-formed.
42+ /// - Check if the trait instantiation appears in the ADT is well-formed.
43+ /// - Check if the field types are fully applied(i.e., these types should have
44+ /// `*` kind).
45+ /// - Check if the types in the ADT satisfies the constraints which is required
46+ /// in type application.
47+ /// - Check if the trait instantiations in the ADT satisfies the constraints.
48+ /// - Check if the recursive types has indirect type wrapper like pointer.
3549#[ salsa:: tracked]
3650pub fn analyze_adt ( db : & dyn HirAnalysisDb , adt_ref : AdtRefId ) {
3751 let analyzer = DefAnalyzer :: for_adt ( db, adt_ref) ;
@@ -46,6 +60,13 @@ pub fn analyze_adt(db: &dyn HirAnalysisDb, adt_ref: AdtRefId) {
4660 }
4761}
4862
63+ /// This function implements analysis for the trait definition.
64+ /// The analysis includes the following:
65+ /// - Check if the types appear in the trait is well-formed.
66+ /// - Check if the trait instantiation appears in the trait is well-formed.
67+ /// - Check if the types in the trait satisfy the constraints which is required
68+ /// in type application.
69+ /// - Check if the trait instantiations in the trait satisfies the constraints.
4970#[ salsa:: tracked]
5071pub fn analyze_trait ( db : & dyn HirAnalysisDb , trait_ : Trait ) {
5172 let analyzer = DefAnalyzer :: for_trait ( db, trait_) ;
@@ -56,6 +77,17 @@ pub fn analyze_trait(db: &dyn HirAnalysisDb, trait_: Trait) {
5677 }
5778}
5879
80+ /// This function implements analysis for the trait implementation definition.
81+ /// The analysis include the following:
82+ /// - Check if the types appear in the trait impl is well-formed.
83+ /// - Check if the trait instantiation appears in the trait impl is well-formed.
84+ /// - Check if the types in the trait impl satisfy the constraints which is
85+ /// required in type application.
86+ /// - Check if the trait instantiations in the trait impl satisfies the
87+ /// constraints.
88+ /// - Check if the conflict doesn't occur.
89+ /// - Check if the trait or type is included in the ingot which contains the
90+ /// impl trait.
5991#[ salsa:: tracked]
6092pub fn analyze_impl_trait ( db : & dyn HirAnalysisDb , impl_trait : ImplTrait ) {
6193 let implementor = match analyze_trait_impl_specific_error ( db, impl_trait) {
@@ -76,6 +108,15 @@ pub fn analyze_impl_trait(db: &dyn HirAnalysisDb, impl_trait: ImplTrait) {
76108 }
77109}
78110
111+ /// This function implements analysis for the type alias definition.
112+ /// The analysis includes the following:
113+ /// - Check if the type alias is not recursive.
114+ /// - Check if the type in the type alias is well-formed.
115+ ///
116+ /// NOTE: This function doesn't check the satisfiability of the type since our
117+ /// type system treats the alias as kind of macro, meaning type alias doesn't
118+ /// included in the type system. Satisfiability is checked where the type alias
119+ /// is used.
79120#[ salsa:: tracked]
80121pub fn analyze_type_alias ( db : & dyn HirAnalysisDb , alias : TypeAlias ) {
81122 let Some ( hir_ty) = alias. ty ( db. as_hir_db ( ) ) . to_opt ( ) else {
@@ -360,6 +401,10 @@ impl<'db> Visitor for DefAnalyzer<'db> {
360401 self . current_ty = Some ( ( self . def . trait_self_param ( self . db ) , name_span) ) ;
361402 walk_super_trait_list ( self , ctxt, super_traits) ;
362403 }
404+
405+ fn visit_func ( & mut self , _ctxt : & mut VisitorCtxt < ' _ , LazyFuncSpan > , _func : hir:: hir_def:: Func ) {
406+ // TODO:
407+ }
363408}
364409
365410#[ salsa:: tracked( recovery_fn = check_recursive_adt_impl) ]
@@ -502,7 +547,7 @@ impl DefKind {
502547 }
503548}
504549
505- /// This function analyzes
550+ /// This function analyzes the trait impl specific error.
506551/// 1. If the trait ref is well-formed except for the satisfiability.
507552/// 2. If implementor type is well-formed except for the satisfiability.
508553/// 3. If the ingot contains impl trait is the same as the ingot which contains
0 commit comments