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
+
1
5
use hir:: {
2
6
hir_def:: {
3
7
scope_graph:: ScopeId , FieldDef , ImplTrait , Trait , TraitRefId , TypeAlias , TypeId as HirTyId ,
@@ -25,13 +29,23 @@ use super::{
25
29
constraint:: { collect_super_traits, AssumptionListId , SuperTraitCycle } ,
26
30
constraint_solver:: { is_goal_satisfiable, GoalSatisfiability } ,
27
31
diagnostics:: { TraitConstraintDiag , TraitLowerDiag , TyDiagCollection , TyLowerDiag } ,
28
- trait_ :: { ingot_trait_env, Implementor , TraitDef } ,
32
+ trait_def :: { ingot_trait_env, Implementor , TraitDef } ,
29
33
trait_lower:: { lower_trait, lower_trait_ref, TraitRefLowerError } ,
30
34
ty_def:: { AdtDef , AdtRefId , TyId } ,
31
35
ty_lower:: { lower_adt, lower_hir_ty, lower_kind} ,
32
36
visitor:: { walk_ty, TyVisitor } ,
33
37
} ;
34
38
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.
35
49
#[ salsa:: tracked]
36
50
pub fn analyze_adt ( db : & dyn HirAnalysisDb , adt_ref : AdtRefId ) {
37
51
let analyzer = DefAnalyzer :: for_adt ( db, adt_ref) ;
@@ -46,6 +60,13 @@ pub fn analyze_adt(db: &dyn HirAnalysisDb, adt_ref: AdtRefId) {
46
60
}
47
61
}
48
62
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.
49
70
#[ salsa:: tracked]
50
71
pub fn analyze_trait ( db : & dyn HirAnalysisDb , trait_ : Trait ) {
51
72
let analyzer = DefAnalyzer :: for_trait ( db, trait_) ;
@@ -56,6 +77,17 @@ pub fn analyze_trait(db: &dyn HirAnalysisDb, trait_: Trait) {
56
77
}
57
78
}
58
79
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.
59
91
#[ salsa:: tracked]
60
92
pub fn analyze_impl_trait ( db : & dyn HirAnalysisDb , impl_trait : ImplTrait ) {
61
93
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) {
76
108
}
77
109
}
78
110
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.
79
120
#[ salsa:: tracked]
80
121
pub fn analyze_type_alias ( db : & dyn HirAnalysisDb , alias : TypeAlias ) {
81
122
let Some ( hir_ty) = alias. ty ( db. as_hir_db ( ) ) . to_opt ( ) else {
@@ -360,6 +401,10 @@ impl<'db> Visitor for DefAnalyzer<'db> {
360
401
self . current_ty = Some ( ( self . def . trait_self_param ( self . db ) , name_span) ) ;
361
402
walk_super_trait_list ( self , ctxt, super_traits) ;
362
403
}
404
+
405
+ fn visit_func ( & mut self , _ctxt : & mut VisitorCtxt < ' _ , LazyFuncSpan > , _func : hir:: hir_def:: Func ) {
406
+ // TODO:
407
+ }
363
408
}
364
409
365
410
#[ salsa:: tracked( recovery_fn = check_recursive_adt_impl) ]
@@ -502,7 +547,7 @@ impl DefKind {
502
547
}
503
548
}
504
549
505
- /// This function analyzes
550
+ /// This function analyzes the trait impl specific error.
506
551
/// 1. If the trait ref is well-formed except for the satisfiability.
507
552
/// 2. If implementor type is well-formed except for the satisfiability.
508
553
/// 3. If the ingot contains impl trait is the same as the ingot which contains
0 commit comments