@@ -4,7 +4,7 @@ use cairo_lang_defs::db::DefsGroup;
4
4
use cairo_lang_defs:: ids:: {
5
5
ExternTypeId , GenericKind , LanguageElementId , LookupItemId , ModuleItemId ,
6
6
} ;
7
- use cairo_lang_diagnostics:: { Diagnostics , Maybe } ;
7
+ use cairo_lang_diagnostics:: { Diagnostics , Maybe , MaybeAsRef } ;
8
8
use cairo_lang_proc_macros:: DebugWithDb ;
9
9
use cairo_lang_syntax:: attribute:: structured:: { Attribute , AttributeListStructurize } ;
10
10
use cairo_lang_syntax:: node:: { TypedStablePtr , TypedSyntaxNode } ;
@@ -26,48 +26,12 @@ mod test;
26
26
// Declaration.
27
27
#[ derive( Clone , Debug , PartialEq , Eq , DebugWithDb , salsa:: Update ) ]
28
28
#[ debug_db( dyn Database ) ]
29
- pub struct ExternTypeDeclarationData < ' db > {
29
+ struct ExternTypeDeclarationData < ' db > {
30
30
diagnostics : Diagnostics < ' db , SemanticDiagnostic < ' db > > ,
31
31
generic_params : Vec < GenericParam < ' db > > ,
32
32
attributes : Vec < Attribute < ' db > > ,
33
33
}
34
34
35
- // Selectors.
36
- /// Implementation of [ExternTypeSemantic::extern_type_declaration_diagnostics].
37
- fn extern_type_declaration_diagnostics < ' db > (
38
- db : & ' db dyn Database ,
39
- extern_type_id : ExternTypeId < ' db > ,
40
- ) -> Diagnostics < ' db , SemanticDiagnostic < ' db > > {
41
- db. priv_extern_type_declaration_data ( extern_type_id)
42
- . map ( |data| data. diagnostics )
43
- . unwrap_or_default ( )
44
- }
45
-
46
- /// Query implementation of [ExternTypeSemantic::extern_type_declaration_diagnostics].
47
- #[ salsa:: tracked]
48
- fn extern_type_declaration_diagnostics_tracked < ' db > (
49
- db : & ' db dyn Database ,
50
- extern_type_id : ExternTypeId < ' db > ,
51
- ) -> Diagnostics < ' db , SemanticDiagnostic < ' db > > {
52
- extern_type_declaration_diagnostics ( db, extern_type_id)
53
- }
54
- /// Implementation of [ExternTypeSemantic::extern_type_declaration_generic_params].
55
- fn extern_type_declaration_generic_params < ' db > (
56
- db : & ' db dyn Database ,
57
- extern_type_id : ExternTypeId < ' db > ,
58
- ) -> Maybe < Vec < GenericParam < ' db > > > {
59
- Ok ( db. extern_type_declaration_generic_params_data ( extern_type_id) ?. generic_params )
60
- }
61
-
62
- /// Query implementation of [ExternTypeSemantic::extern_type_declaration_generic_params].
63
- #[ salsa:: tracked]
64
- fn extern_type_declaration_generic_params_tracked < ' db > (
65
- db : & ' db dyn Database ,
66
- extern_type_id : ExternTypeId < ' db > ,
67
- ) -> Maybe < Vec < GenericParam < ' db > > > {
68
- extern_type_declaration_generic_params ( db, extern_type_id)
69
- }
70
-
71
35
// Computation.
72
36
/// Implementation of [ExternTypeSemantic::extern_type_declaration_generic_params_data].
73
37
fn extern_type_declaration_generic_params_data < ' db > (
@@ -110,25 +74,28 @@ fn extern_type_declaration_generic_params_data_tracked<'db>(
110
74
extern_type_declaration_generic_params_data ( db, extern_type_id)
111
75
}
112
76
113
- /// Implementation of [ExternTypeSemantic::priv_extern_type_declaration_data].
114
- fn priv_extern_type_declaration_data < ' db > (
77
+ /// Returns the declaration data of an extern type.
78
+ #[ salsa:: tracked( returns( ref) ) ]
79
+ fn extern_type_declaration_data < ' db > (
115
80
db : & ' db dyn Database ,
116
81
extern_type_id : ExternTypeId < ' db > ,
117
82
) -> Maybe < ExternTypeDeclarationData < ' db > > {
118
83
let mut diagnostics = SemanticDiagnostics :: default ( ) ;
119
84
let extern_type_syntax = db. module_extern_type_by_id ( extern_type_id) ?;
120
85
121
86
// Generic params.
122
- let generic_params_data = extern_type_declaration_generic_params_data ( db, extern_type_id) ?;
123
- let generic_params = generic_params_data. generic_params ;
87
+ let generic_params_data_result =
88
+ extern_type_declaration_generic_params_data ( db, extern_type_id) ;
89
+ let generic_params_data = generic_params_data_result. maybe_as_ref ( ) ?;
90
+ let generic_params = generic_params_data. generic_params . clone ( ) ;
124
91
let inference_id = InferenceId :: LookupItemDeclaration ( LookupItemId :: ModuleItem (
125
92
ModuleItemId :: ExternType ( extern_type_id) ,
126
93
) ) ;
127
94
let mut resolver = Resolver :: with_data (
128
95
db,
129
96
( * generic_params_data. resolver_data ) . clone_with_inference_id ( db, inference_id) ,
130
97
) ;
131
- diagnostics. extend ( generic_params_data. diagnostics ) ;
98
+ diagnostics. extend ( generic_params_data. diagnostics . clone ( ) ) ;
132
99
let attributes = extern_type_syntax. attributes ( db) . structurize ( db) ;
133
100
134
101
// Check fully resolved.
@@ -140,56 +107,27 @@ fn priv_extern_type_declaration_data<'db>(
140
107
Ok ( ExternTypeDeclarationData { diagnostics : diagnostics. build ( ) , generic_params, attributes } )
141
108
}
142
109
143
- /// Query implementation of [ExternTypeSemantic::priv_extern_type_declaration_data].
144
- #[ salsa:: tracked]
145
- fn priv_extern_type_declaration_data_tracked < ' db > (
146
- db : & ' db dyn Database ,
147
- extern_type_id : ExternTypeId < ' db > ,
148
- ) -> Maybe < ExternTypeDeclarationData < ' db > > {
149
- priv_extern_type_declaration_data ( db, extern_type_id)
150
- }
151
-
152
- /// Implementation of [ExternTypeSemantic::extern_type_attributes].
153
- fn extern_type_attributes < ' db > (
154
- db : & ' db dyn Database ,
155
- extern_type_id : ExternTypeId < ' db > ,
156
- ) -> Maybe < Vec < Attribute < ' db > > > {
157
- Ok ( db. priv_extern_type_declaration_data ( extern_type_id) ?. attributes )
158
- }
159
-
160
- /// Query implementation of [ExternTypeSemantic::extern_type_attributes].
161
- #[ salsa:: tracked]
162
- fn extern_type_attributes_tracked < ' db > (
163
- db : & ' db dyn Database ,
164
- extern_type_id : ExternTypeId < ' db > ,
165
- ) -> Maybe < Vec < Attribute < ' db > > > {
166
- extern_type_attributes ( db, extern_type_id)
167
- }
168
-
169
110
/// Trait for extern type-related semantic queries.
170
111
pub trait ExternTypeSemantic < ' db > : Database {
171
- /// Private query to compute data about an extern type declaration. An extern type has
172
- /// no body, and thus only has a declaration.
173
- fn priv_extern_type_declaration_data (
174
- & ' db self ,
175
- type_id : ExternTypeId < ' db > ,
176
- ) -> Maybe < ExternTypeDeclarationData < ' db > > {
177
- priv_extern_type_declaration_data_tracked ( self . as_dyn_database ( ) , type_id)
178
- }
179
112
/// Returns the semantic diagnostics of an extern type declaration. An extern type has
180
113
/// no body, and thus only has a declaration.
181
114
fn extern_type_declaration_diagnostics (
182
115
& ' db self ,
183
116
extern_type_id : ExternTypeId < ' db > ,
184
117
) -> Diagnostics < ' db , SemanticDiagnostic < ' db > > {
185
- extern_type_declaration_diagnostics_tracked ( self . as_dyn_database ( ) , extern_type_id)
118
+ let db = self . as_dyn_database ( ) ;
119
+ extern_type_declaration_data ( db, extern_type_id)
120
+ . as_ref ( )
121
+ . map ( |data| data. diagnostics . clone ( ) )
122
+ . unwrap_or_default ( )
186
123
}
187
124
/// Returns the generic params of an extern type.
188
125
fn extern_type_declaration_generic_params (
189
126
& ' db self ,
190
127
extern_type_id : ExternTypeId < ' db > ,
191
128
) -> Maybe < Vec < GenericParam < ' db > > > {
192
- extern_type_declaration_generic_params_tracked ( self . as_dyn_database ( ) , extern_type_id)
129
+ let db = self . as_dyn_database ( ) ;
130
+ Ok ( extern_type_declaration_data ( db, extern_type_id) . maybe_as_ref ( ) ?. generic_params . clone ( ) )
193
131
}
194
132
/// Returns the generic params data of an extern type.
195
133
fn extern_type_declaration_generic_params_data (
@@ -203,7 +141,8 @@ pub trait ExternTypeSemantic<'db>: Database {
203
141
& ' db self ,
204
142
extern_type_id : ExternTypeId < ' db > ,
205
143
) -> Maybe < Vec < Attribute < ' db > > > {
206
- extern_type_attributes_tracked ( self . as_dyn_database ( ) , extern_type_id)
144
+ let db = self . as_dyn_database ( ) ;
145
+ Ok ( extern_type_declaration_data ( db, extern_type_id) . maybe_as_ref ( ) ?. attributes . clone ( ) )
207
146
}
208
147
}
209
148
impl < ' db , T : Database + ?Sized > ExternTypeSemantic < ' db > for T { }
0 commit comments