Skip to content

Commit

Permalink
Unordered -> SortedModule
Browse files Browse the repository at this point in the history
  • Loading branch information
f01dab1e committed Oct 5, 2023
1 parent fbe2a6b commit 4115d07
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 23 deletions.
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/hir/def_collector/dc_crate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use crate::node_interner::{
FuncId, NodeInterner, StmtId, StructId, TraitId, TraitImplKey, TypeAliasId,
};

use crate::parser::{ParserError, UnorderParsedModule};
use crate::parser::{ParserError, SortedModule};
use crate::{
ExpressionKind, Generics, Ident, LetStatement, Literal, NoirFunction, NoirStruct, NoirTrait,
NoirTypeAlias, Path, Shared, StructType, TraitItem, Type, TypeBinding, TypeVariableKind,
Expand Down Expand Up @@ -193,7 +193,7 @@ impl DefCollector {
pub fn collect(
mut def_map: CrateDefMap,
context: &mut Context,
ast: UnorderParsedModule,
ast: SortedModule,
root_file_id: FileId,
) -> Vec<(CompilationError, FileId)> {
let mut errors: Vec<(CompilationError, FileId)> = vec![];
Expand Down
8 changes: 4 additions & 4 deletions compiler/noirc_frontend/src/hir/def_collector/dc_mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
graph::CrateId,
hir::def_collector::dc_crate::{UnresolvedStruct, UnresolvedTrait},
node_interner::TraitId,
parser::{SubModule, UnorderParsedModule},
parser::{SubModule, SortedModule},
FunctionDefinition, Ident, LetStatement, NoirFunction, NoirStruct, NoirTrait, NoirTraitImpl,
NoirTypeAlias, TraitImplItem, TraitItem, TypeImpl,
};
Expand Down Expand Up @@ -35,7 +35,7 @@ struct ModCollector<'a> {
/// This performs the entirety of the definition collection phase of the name resolution pass.
pub fn collect_defs(
def_collector: &mut DefCollector,
ast: UnorderParsedModule,
ast: SortedModule,
file_id: FileId,
module_id: LocalModuleId,
crate_id: CrateId,
Expand Down Expand Up @@ -404,7 +404,7 @@ impl<'a> ModCollector<'a> {
Ok(child) => {
errors.extend(collect_defs(
self.def_collector,
submodule.contents.into_unorder(),
submodule.contents.into_sorted(),
file_id,
child,
crate_id,
Expand Down Expand Up @@ -462,7 +462,7 @@ impl<'a> ModCollector<'a> {

// Parse the AST for the module we just found and then recursively look for it's defs
let (ast, parsing_errors) = parse_file(&context.file_manager, child_file_id);
let ast = ast.into_unorder();
let ast = ast.into_sorted();

errors.extend(
parsing_errors.iter().map(|e| (e.clone().into(), child_file_id)).collect::<Vec<_>>(),
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/def_map/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ impl CrateDefMap {
// First parse the root file.
let root_file_id = context.crate_graph[crate_id].root_file_id;
let (ast, parsing_errors) = parse_file(&context.file_manager, root_file_id);
let ast = ast.into_unorder();
let ast = ast.into_sorted();

#[cfg(feature = "aztec")]
let ast = match aztec_library::transform(ast, &crate_id, context) {
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ mod test {
}

let mut errors = Vec::new();
for func in program.into_unorder().functions {
for func in program.into_sorted().functions {
let id = interner.push_test_function_definition(func.name().to_string());

let resolver = Resolver::new(&mut interner, &path_resolver, &def_maps, file);
Expand All @@ -1658,7 +1658,7 @@ mod test {
init_src_code_resolution(src);

let mut all_captures: Vec<Vec<String>> = Vec::new();
for func in program.into_unorder().functions {
for func in program.into_sorted().functions {
let name = func.name().to_string();
let id = interner.push_test_function_definition(name);
path_resolver.insert_func(func.name().to_owned(), id);
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ mod test {
},
);

let func_meta = vecmap(program.into_unorder().functions, |nf| {
let func_meta = vecmap(program.into_sorted().functions, |nf| {
let resolver = Resolver::new(&mut interner, &path_resolver, &def_maps, file);
let (hir_func, func_meta, resolver_errors) = resolver.resolve_function(nf, main_id);
assert_eq!(resolver_errors, vec![]);
Expand Down
26 changes: 13 additions & 13 deletions compiler/noirc_frontend/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ fn force<'a, T: 'a>(parser: impl NoirParser<T> + 'a) -> impl NoirParser<Option<T
}

#[derive(Default)]
pub struct UnorderParsedModule {
pub struct SortedModule {
pub imports: Vec<ImportStatement>,
pub functions: Vec<NoirFunction>,
pub types: Vec<NoirStruct>,
Expand All @@ -242,8 +242,8 @@ pub struct ParsedModule {
}

impl ParsedModule {
pub fn into_unorder(self) -> UnorderParsedModule {
let mut module = UnorderParsedModule::default();
pub fn into_sorted(self) -> SortedModule {
let mut module = SortedModule::default();

for item in self.items {
match item.kind {
Expand Down Expand Up @@ -293,7 +293,7 @@ pub struct SubModule {
pub is_contract: bool,
}

impl UnorderParsedModule {
impl SortedModule {
fn push_function(&mut self, func: NoirFunction) {
self.functions.push(func);
}
Expand Down Expand Up @@ -539,37 +539,37 @@ impl std::fmt::Display for TopLevelStatement {

impl std::fmt::Display for ParsedModule {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let legacy = self.clone().into_unorder();
let module = self.clone().into_sorted();

for decl in &legacy.module_decls {
for decl in &module.module_decls {
writeln!(f, "mod {decl};")?;
}

for import in &legacy.imports {
for import in &module.imports {
write!(f, "{import}")?;
}

for global_const in &legacy.globals {
for global_const in &module.globals {
write!(f, "{global_const}")?;
}

for type_ in &legacy.types {
for type_ in &module.types {
write!(f, "{type_}")?;
}

for function in &legacy.functions {
for function in &module.functions {
write!(f, "{function}")?;
}

for impl_ in &legacy.impls {
for impl_ in &module.impls {
write!(f, "{impl_}")?;
}

for type_alias in &legacy.type_aliases {
for type_alias in &module.type_aliases {
write!(f, "{type_alias}")?;
}

for submodule in &legacy.submodules {
for submodule in &module.submodules {
write!(f, "{submodule}")?;
}

Expand Down

0 comments on commit 4115d07

Please sign in to comment.