pub fn collect_defs(&mut self, context: &mut Context) -> Result<(), Vec<CollectedErrors>> {
        // First resolve the module declarations
        // XXX: to avoid clone, possibly destructure the AST and pass in `self` for mod collector instead of `&mut self`
        // Alternatively, pass in the AST as a reference
        for decl in self.ast.module_decls.clone() {
            self.parse_module_declaration(context, &decl)?
        }

        // Then add the imports to defCollector to resolve once all modules in the hierarchy have been resolved
        for import in self.ast.imports.clone() {
            self.def_collector.collected_imports.push(ImportDirective {
                module_id: self.module_id,
                path: import.path,
                alias: import.alias,
            });
        }

        // Then add functions to functionArena
        let mut unresolved_functions = UnresolvedFunctions {
            file_id: self.file_id,
            functions: Vec::new(),
        };
        for function in self.ast.functions.clone() {
            let name = function.name_ident().clone();
            let nf: NoirFunction = function;

            // First create dummy function in the DefInterner
            // So that we can get a FuncId
            let func_id = context.def_interner.push_empty_fn();

            // Now link this func_id to a crate level map with the noir function and the module id
            // Encountering a NoirFunction, we retrieve it's module_data to get the namespace
            // Once we have lowered it to a HirFunction, we retrieve it's Id from the DefInterner
            // and replace it
            // With this method we iterate each function in the Crate and not each module
            // This may not be great because we have to pull the module_data for each function
            unresolved_functions.push_fn(self.module_id, func_id, nf);

            // Add function to scope/ns of the module
            self.def_collector.def_map.modules[self.module_id.0]
                .scope
                .define_func_def(name, func_id)
                .map_err(|(first_def, second_def)| {
                    let err = DefCollectorErrorKind::DuplicateFunction {
                        first_def,
                        second_def,
                    };

                    vec![CollectedErrors {
                        file_id: self.file_id,
                        errors: vec![err.to_diagnostic()],
                    }]
                })?;
        }
        self.def_collector
            .collected_functions
            .push(unresolved_functions);

        Ok(())
    }
/// Walk a module and collect it's definitions
Walk a module and collect it's definitions
Walk a module and collect it ' s definitions
pub fn collect_defs(&mut self, context: &mut Context) -> Result<(), Vec<CollectedErrors>> {
        // First resolve the module declarations
        // XXX: to avoid clone, possibly destructure the AST and pass in `self` for mod collector instead of `&mut self`
        // Alternatively, pass in the AST as a reference
        for decl in self.ast.module_decls.clone() {
            self.parse_module_declaration(context, &decl)?
        }
        // Then add the imports to defCollector to resolve once all modules in the hierarchy have been resolved
        for import in self.ast.imports.clone() {
            self.def_collector.collected_imports.push(ImportDirective {
                module_id: self.module_id,
                path: import.path,
                alias: import.alias,
            });
        }
        // Then add functions to functionArena
        let mut unresolved_functions = UnresolvedFunctions {
            file_id: self.file_id,
            functions: Vec::new(),
        };
        for function in self.ast.functions.clone() {
            let name = function.name_ident().clone();
            let nf: NoirFunction = function;
            // First create dummy function in the DefInterner
            // So that we can get a FuncId
            let func_id = context.def_interner.push_empty_fn();
            // Now link this func_id to a crate level map with the noir function and the module id
            // Encountering a NoirFunction, we retrieve it's module_data to get the namespace
            // Once we have lowered it to a HirFunction, we retrieve it's Id from the DefInterner
            // and replace it
            // With this method we iterate each function in the Crate and not each module
            // This may not be great because we have to pull the module_data for each function
            unresolved_functions.push_fn(self.module_id, func_id, nf);
            // Add function to scope/ns of the module
            self.def_collector.def_map.modules[self.module_id.0]
                .scope
                .define_func_def(name, func_id)
                .map_err(|(first_def, second_def)| {
                    let err = DefCollectorErrorKind::DuplicateFunction {
                        first_def,
                        second_def,
                    };
                    vec![CollectedErrors {
                        file_id: self.file_id,
                        errors: vec![err.to_diagnostic()],
                    }]
                })?;
        }
        self.def_collector
            .collected_functions
            .push(unresolved_functions);
        Ok(())
    }
pub fn collect_defs ( & mut self , context : & mut Context ) -> Result < ( ) , Vec < CollectedErrors > > { // First resolve the module declarations // XXX: to avoid clone, possibly destructure the AST and pass in `self` for mod collector instead of `&mut self` // Alternatively, pass in the AST as a reference for decl in self . ast . module_decls . clone ( ) { self . parse_module_declaration ( context , & decl ) ? } // Then add the imports to defCollector to resolve once all modules in the hierarchy have been resolved for import in self . ast . imports . clone ( ) { self . def_collector . collected_imports . push ( ImportDirective { module_id : self . module_id , path : import . path , alias : import . alias , } ) ; } // Then add functions to functionArena let mut unresolved_functions = UnresolvedFunctions { file_id : self . file_id , functions : Vec :: new ( ) , } ; for function in self . ast . functions . clone ( ) { let name = function . name_ident ( ) . clone ( ) ; let nf : NoirFunction = function ; // First create dummy function in the DefInterner // So that we can get a FuncId let func_id = context . def_interner . push_empty_fn ( ) ; // Now link this func_id to a crate level map with the noir function and the module id // Encountering a NoirFunction, we retrieve it's module_data to get the namespace // Once we have lowered it to a HirFunction, we retrieve it's Id from the DefInterner // and replace it // With this method we iterate each function in the Crate and not each module // This may not be great because we have to pull the module_data for each function unresolved_functions . push_fn ( self . module_id , func_id , nf ) ; // Add function to scope/ns of the module self . def_collector . def_map . modules [ self . module_id . 0 ] . scope . define_func_def ( name , func_id ) . map_err ( | ( first_def , second_def ) | { let err = DefCollectorErrorKind :: DuplicateFunction { first_def , second_def , } ; vec ! [ CollectedErrors { file_id self file_id errors vec [ err to_diagnostic ( ) ] } ] } ) ? ; } self . def_collector . collected_functions . push ( unresolved_functions ) ; Ok ( ( ) ) }
Walk a module and collect it's definitions
Walk a module and collect it ' s definitions
&mut self
context
&mut Context
&mut self
context
&mut Context