@@ -8,7 +8,7 @@ use crate::{
8
8
GLEAM_CORE_PACKAGE_NAME ,
9
9
ast:: {
10
10
self , Arg , BitArrayOption , CustomType , Definition , DefinitionLocation , Function ,
11
- GroupedStatements , Import , ModuleConstant , Publicity , RecordConstructor ,
11
+ GroupedDefinitions , Import , ModuleConstant , Publicity , RecordConstructor ,
12
12
RecordConstructorArg , SrcSpan , Statement , TypeAlias , TypeAst , TypeAstConstructor ,
13
13
TypeAstFn , TypeAstHole , TypeAstTuple , TypeAstVar , TypedDefinition , TypedExpr ,
14
14
TypedFunction , TypedModule , UntypedArg , UntypedCustomType , UntypedFunction , UntypedImport ,
@@ -223,71 +223,80 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
223
223
}
224
224
. build ( ) ;
225
225
226
- let statements = GroupedStatements :: new ( module. into_iter_statements ( self . target ) ) ;
227
- let statements_count = statements . len ( ) ;
226
+ let definitions = GroupedDefinitions :: new ( module. into_iter_definitions ( self . target ) ) ;
227
+ let definitions_count = definitions . len ( ) ;
228
228
229
229
// Register any modules, types, and values being imported
230
230
// We process imports first so that anything imported can be referenced
231
231
// anywhere in the module.
232
- let mut env = Importer :: run ( self . origin , env, & statements . imports , & mut self . problems ) ;
232
+ let mut env = Importer :: run ( self . origin , env, & definitions . imports , & mut self . problems ) ;
233
233
234
234
// Register types so they can be used in constructors and functions
235
235
// earlier in the module.
236
- for t in & statements . custom_types {
237
- if let Err ( error) = self . register_types_from_custom_type ( t , & mut env) {
236
+ for type_ in & definitions . custom_types {
237
+ if let Err ( error) = self . register_types_from_custom_type ( type_ , & mut env) {
238
238
return self . all_errors ( error) ;
239
239
}
240
240
}
241
241
242
- let sorted_aliases = match sorted_type_aliases ( & statements . type_aliases ) {
243
- Ok ( it ) => it ,
242
+ let sorted_aliases = match sorted_type_aliases ( & definitions . type_aliases ) {
243
+ Ok ( sorted_aliases ) => sorted_aliases ,
244
244
Err ( error) => return self . all_errors ( error) ,
245
245
} ;
246
- for t in sorted_aliases {
247
- self . register_type_alias ( t , & mut env) ;
246
+ for type_alias in sorted_aliases {
247
+ self . register_type_alias ( type_alias , & mut env) ;
248
248
}
249
249
250
- for f in & statements . functions {
251
- self . register_value_from_function ( f , & mut env) ;
250
+ for function in & definitions . functions {
251
+ self . register_value_from_function ( function , & mut env) ;
252
252
}
253
253
254
254
// Infer the types of each statement in the module
255
- let mut typed_statements = Vec :: with_capacity ( statements_count ) ;
256
- for i in statements . imports {
257
- optionally_push ( & mut typed_statements , self . analyse_import ( i , & env) ) ;
255
+ let mut typed_definitions = Vec :: with_capacity ( definitions_count ) ;
256
+ for import in definitions . imports {
257
+ optionally_push ( & mut typed_definitions , self . analyse_import ( import , & env) ) ;
258
258
}
259
- for t in statements. custom_types {
260
- optionally_push ( & mut typed_statements, self . analyse_custom_type ( t, & mut env) ) ;
259
+ for type_ in definitions. custom_types {
260
+ optionally_push (
261
+ & mut typed_definitions,
262
+ self . analyse_custom_type ( type_, & mut env) ,
263
+ ) ;
261
264
}
262
- for t in statements . type_aliases {
263
- typed_statements . push ( analyse_type_alias ( t , & mut env) ) ;
265
+ for type_alias in definitions . type_aliases {
266
+ typed_definitions . push ( analyse_type_alias ( type_alias , & mut env) ) ;
264
267
}
265
268
266
- // Sort functions and constants into dependency order for inference. Definitions that do
267
- // not depend on other definitions are inferred first, then ones that depend
268
- // on those, etc.
269
+ // Sort functions and constants into dependency order for inference.
270
+ // Definitions that do not depend on other definitions are inferred
271
+ // first, then ones that depend on those, etc.
269
272
let definition_groups =
270
- match into_dependency_order ( statements . functions , statements . constants ) {
271
- Ok ( it ) => it ,
273
+ match into_dependency_order ( definitions . functions , definitions . constants ) {
274
+ Ok ( definition_groups ) => definition_groups ,
272
275
Err ( error) => return self . all_errors ( error) ,
273
276
} ;
274
277
let mut working_group = vec ! [ ] ;
275
278
276
279
for group in definition_groups {
277
- // A group may have multiple functions that depend on each other through
278
- // mutual recursion.
280
+ // A group may have multiple functions that depend on each other
281
+ // through mutual recursion.
279
282
280
283
for definition in group {
281
- let def = match definition {
282
- CallGraphNode :: Function ( f) => self . infer_function ( f, & mut env) ,
283
- CallGraphNode :: ModuleConstant ( c) => self . infer_module_constant ( c, & mut env) ,
284
+ let definition = match definition {
285
+ CallGraphNode :: Function ( function) => self . infer_function ( function, & mut env) ,
286
+ CallGraphNode :: ModuleConstant ( constant) => {
287
+ self . infer_module_constant ( constant, & mut env)
288
+ }
284
289
} ;
285
- working_group. push ( def ) ;
290
+ working_group. push ( definition ) ;
286
291
}
287
292
288
293
// Now that the entire group has been inferred, generalise their types.
289
294
for inferred in working_group. drain ( ..) {
290
- typed_statements. push ( generalise_statement ( inferred, & self . module_name , & mut env) ) ;
295
+ typed_definitions. push ( generalise_definition (
296
+ inferred,
297
+ & self . module_name ,
298
+ & mut env,
299
+ ) ) ;
291
300
}
292
301
}
293
302
@@ -335,7 +344,7 @@ impl<'a, A> ModuleAnalyzer<'a, A> {
335
344
let module = ast:: Module {
336
345
documentation : documentation. clone ( ) ,
337
346
name : self . module_name . clone ( ) ,
338
- definitions : typed_statements ,
347
+ definitions : typed_definitions ,
339
348
names : type_names,
340
349
unused_definition_positions,
341
350
type_info : ModuleInterface {
@@ -1686,19 +1695,19 @@ where
1686
1695
}
1687
1696
}
1688
1697
1689
- fn generalise_statement (
1690
- s : TypedDefinition ,
1698
+ fn generalise_definition (
1699
+ definition : TypedDefinition ,
1691
1700
module_name : & EcoString ,
1692
1701
environment : & mut Environment < ' _ > ,
1693
1702
) -> TypedDefinition {
1694
- match s {
1703
+ match definition {
1695
1704
Definition :: Function ( function) => generalise_function ( function, environment, module_name) ,
1696
1705
Definition :: ModuleConstant ( constant) => {
1697
1706
generalise_module_constant ( constant, environment, module_name)
1698
1707
}
1699
- statement @ ( Definition :: TypeAlias ( TypeAlias { .. } )
1708
+ definition @ ( Definition :: TypeAlias ( TypeAlias { .. } )
1700
1709
| Definition :: CustomType ( CustomType { .. } )
1701
- | Definition :: Import ( Import { .. } ) ) => statement ,
1710
+ | Definition :: Import ( Import { .. } ) ) => definition ,
1702
1711
}
1703
1712
}
1704
1713
0 commit comments