Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Remove the remainder of legacy code #5525

Merged
merged 17 commits into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 14 additions & 28 deletions aztec_macros/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
use iter_extended::vecmap;
use noirc_errors::Location;
use noirc_frontend::ast;
use noirc_frontend::elaborator::Elaborator;
use noirc_frontend::hir::def_collector::dc_crate::{
CollectedItems, UnresolvedFunctions, UnresolvedGlobal,
};
use noirc_frontend::macros_api::{HirExpression, HirLiteral};
use noirc_frontend::node_interner::{NodeInterner, TraitImplKind};
use noirc_frontend::{
graph::CrateId,
hir::{
def_map::{LocalModuleId, ModuleId},
resolution::{path_resolver::StandardPathResolver, resolver::Resolver},
type_check::type_check_func,
},
hir::def_map::{LocalModuleId, ModuleId},
macros_api::{FileId, HirContext, MacroError, ModuleDefId, StructId},
node_interner::{FuncId, TraitId},
Shared, StructType, Type,
Expand Down Expand Up @@ -190,24 +190,17 @@
span: None,
})?;

let def_maps = &mut context.def_maps;

let path_resolver =
StandardPathResolver::new(ModuleId { local_id: module_id, krate: *crate_id });

let resolver = Resolver::new(&mut context.def_interner, &path_resolver, def_maps, file_id);

let (hir_func, meta, _) = resolver.resolve_function(func, func_id);
let mut items = CollectedItems::default();
let functions = vec![(module_id, func_id, func)];
let trait_id = None;
items.functions.push(UnresolvedFunctions { file_id, functions, trait_id, self_type: None });

context.def_interner.push_fn_meta(meta, func_id);
context.def_interner.update_fn(func_id, hir_func);

let errors = type_check_func(&mut context.def_interner, func_id);
let errors = Elaborator::elaborate(context, *crate_id, items, None);

if !errors.is_empty() {
return Err(MacroError {
primary_message: "Failed to type check autogenerated function".to_owned(),
secondary_message: Some(errors.iter().map(|err| err.to_string()).collect::<String>()),
secondary_message: Some(errors.iter().map(|err| err.0.to_string()).collect::<String>()),
span: None,
});
}
Expand Down Expand Up @@ -243,17 +236,10 @@
)
});

let def_maps = &mut context.def_maps;

let path_resolver =
StandardPathResolver::new(ModuleId { local_id: module_id, krate: *crate_id });

let mut resolver = Resolver::new(&mut context.def_interner, &path_resolver, def_maps, file_id);

let hir_stmt = resolver.resolve_global_let(global, global_id);
let mut items = CollectedItems::default();
items.globals.push(UnresolvedGlobal { file_id, module_id, global_id, stmt_def: global });

let statement_id = context.def_interner.get_global(global_id).let_statement;
context.def_interner.replace_statement(statement_id, hir_stmt);
let _errors = Elaborator::elaborate(context, *crate_id, items, None);
}

pub fn fully_qualified_note_path(context: &HirContext, note_id: StructId) -> Option<String> {
Expand Down Expand Up @@ -347,7 +333,7 @@
}
}

pub fn get_global_numberic_const(

Check warning on line 336 in aztec_macros/src/utils/hir_utils.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (numberic)
context: &HirContext,
const_name: &str,
) -> Result<u128, MacroError> {
Expand Down
10 changes: 1 addition & 9 deletions compiler/noirc_driver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,6 @@ pub struct CompileOptions {
#[arg(long, hide = true)]
pub force_brillig: bool,

/// Use the deprecated name resolution & type checking passes instead of the elaborator
#[arg(long, hide = true)]
pub use_legacy: bool,

/// Enable printing results of comptime evaluation: provide a path suffix
/// for the module to debug, e.g. "package_name/src/main.nr"
#[arg(long)]
Expand Down Expand Up @@ -262,15 +258,13 @@ pub fn check_crate(
crate_id: CrateId,
deny_warnings: bool,
disable_macros: bool,
use_legacy: bool,
debug_comptime_in_file: Option<&str>,
) -> CompilationResult<()> {
let macros: &[&dyn MacroProcessor] =
if disable_macros { &[] } else { &[&aztec_macros::AztecMacro as &dyn MacroProcessor] };

let mut errors = vec![];
let diagnostics =
CrateDefMap::collect_defs(crate_id, context, use_legacy, debug_comptime_in_file, macros);
let diagnostics = CrateDefMap::collect_defs(crate_id, context, debug_comptime_in_file, macros);
errors.extend(diagnostics.into_iter().map(|(error, file_id)| {
let diagnostic = CustomDiagnostic::from(&error);
diagnostic.in_file(file_id)
Expand Down Expand Up @@ -307,7 +301,6 @@ pub fn compile_main(
crate_id,
options.deny_warnings,
options.disable_macros,
options.use_legacy,
options.debug_comptime_in_file.as_deref(),
)?;

Expand Down Expand Up @@ -349,7 +342,6 @@ pub fn compile_contract(
crate_id,
options.deny_warnings,
options.disable_macros,
options.use_legacy,
options.debug_comptime_in_file.as_deref(),
)?;

Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_driver/tests/stdlib_warnings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ fn stdlib_does_not_produce_constant_warnings() -> Result<(), ErrorsAndWarnings>
let root_crate_id = prepare_crate(&mut context, file_name);

let ((), warnings) =
noirc_driver::check_crate(&mut context, root_crate_id, false, false, false, None)?;
noirc_driver::check_crate(&mut context, root_crate_id, false, false, None)?;

assert_eq!(warnings, Vec::new(), "stdlib is producing {} warnings", warnings.len());

Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/ast/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use super::{
BlockExpression, Expression, ExpressionKind, IndexExpression, MemberAccessExpression,
MethodCallExpression, UnresolvedType,
};
use crate::hir::resolution::resolver::SELF_TYPE_NAME;
use crate::elaborator::types::SELF_TYPE_NAME;
use crate::lexer::token::SpannedToken;
use crate::macros_api::SecondaryAttribute;
use crate::parser::{ParserError, ParserErrorReason};
Expand Down
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/elaborator/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{
},
hir::{
comptime::{self, InterpreterError},
resolution::{errors::ResolverError, resolver::LambdaContext},
resolution::errors::ResolverError,
type_check::TypeCheckError,
},
hir_def::{
Expand All @@ -32,7 +32,7 @@ use crate::{
QuotedType, Shared, StructType, Type,
};

use super::Elaborator;
use super::{Elaborator, LambdaContext};

impl<'context> Elaborator<'context> {
pub(super) fn elaborate_expression(&mut self, expr: Expression) -> (ExprId, Type) {
Expand Down
17 changes: 13 additions & 4 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ use crate::{
dc_mod,
errors::DuplicateType,
},
resolution::{errors::ResolverError, path_resolver::PathResolver, resolver::LambdaContext},
resolution::{errors::ResolverError, path_resolver::PathResolver},
scope::ScopeForest as GenericScopeForest,
type_check::{check_trait_impl_method_matches_declaration, TypeCheckError},
type_check::TypeCheckError,
},
hir_def::{
expr::HirIdent,
expr::{HirCapturedVar, HirIdent},
function::{FunctionBody, Parameters},
traits::TraitConstraint,
types::{Generics, Kind, ResolvedGeneric},
Expand Down Expand Up @@ -67,14 +67,16 @@ mod patterns;
mod scope;
mod statements;
mod traits;
mod types;
pub mod types;
mod unquote;

use fm::FileId;
use iter_extended::vecmap;
use noirc_errors::{Location, Span};
use rustc_hash::{FxHashMap as HashMap, FxHashSet as HashSet};

use self::traits::check_trait_impl_method_matches_declaration;

/// ResolverMetas are tagged onto each definition to track how many times they are used
#[derive(Debug, PartialEq, Eq)]
pub struct ResolverMeta {
Expand All @@ -85,6 +87,13 @@ pub struct ResolverMeta {

type ScopeForest = GenericScopeForest<String, ResolverMeta>;

pub struct LambdaContext {
pub captures: Vec<HirCapturedVar>,
/// the index in the scope tree
/// (sometimes being filled by ScopeTree's find method)
pub scope_index: usize,
}

pub struct Elaborator<'context> {
scopes: ScopeForest,

Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/elaborator/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use noirc_errors::{Location, Spanned};
use crate::ast::ERROR_IDENT;
use crate::hir::def_map::{LocalModuleId, ModuleId};
use crate::hir::resolution::path_resolver::{PathResolver, StandardPathResolver};
use crate::hir::resolution::resolver::SELF_TYPE_NAME;
use crate::hir::scope::{Scope as GenericScope, ScopeTree as GenericScopeTree};
use crate::macros_api::Ident;
use crate::{
Expand All @@ -21,6 +20,7 @@ use crate::{
};
use crate::{Type, TypeAlias};

use super::types::SELF_TYPE_NAME;
use super::{Elaborator, ResolverMeta};

type Scope = GenericScope<String, ResolverMeta>;
Expand Down
Loading
Loading