Skip to content

Commit

Permalink
Remove scan pass
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Jul 19, 2024
1 parent 4e2c08d commit 84e75e4
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 336 deletions.
8 changes: 2 additions & 6 deletions compiler/noirc_frontend/src/elaborator/expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,10 +709,8 @@ impl<'context> Elaborator<'context> {
let (block, _typ) = self.elaborate_block_expression(block);

self.check_and_pop_function_context();
let mut interpreter_errors = vec![];
let mut interpreter = self.setup_interpreter(&mut interpreter_errors);
let mut interpreter = self.setup_interpreter();
let value = interpreter.evaluate_block(block);
self.include_interpreter_errors(interpreter_errors);
let (id, typ) = self.inline_comptime_value(value, span);

let location = self.interner.id_location(id);
Expand Down Expand Up @@ -796,8 +794,7 @@ impl<'context> Elaborator<'context> {
};

let file = self.file;
let mut interpreter_errors = vec![];
let mut interpreter = self.setup_interpreter(&mut interpreter_errors);
let mut interpreter = self.setup_interpreter();
let mut comptime_args = Vec::new();
let mut errors = Vec::new();

Expand All @@ -813,7 +810,6 @@ impl<'context> Elaborator<'context> {

let bindings = interpreter.interner.get_instantiation_bindings(func).clone();
let result = interpreter.call_function(function, comptime_args, bindings, location);
self.include_interpreter_errors(interpreter_errors);

if !errors.is_empty() {
self.errors.append(&mut errors);
Expand Down
25 changes: 4 additions & 21 deletions compiler/noirc_frontend/src/elaborator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1210,13 +1210,11 @@ impl<'context> Elaborator<'context> {
self.handle_varargs_attribute(function, &mut arguments, location);
arguments.insert(0, (item, location));

let mut interpreter_errors = vec![];
let mut interpreter = self.setup_interpreter(&mut interpreter_errors);
let mut interpreter = self.setup_interpreter();

let value = interpreter
.call_function(function, arguments, TypeBindings::new(), location)
.map_err(|error| error.into_compilation_error_pair())?;
self.include_interpreter_errors(interpreter_errors);

if value != Value::Unit {
let items = value
Expand Down Expand Up @@ -1351,8 +1349,7 @@ impl<'context> Elaborator<'context> {
let global = self.interner.get_global(global_id);
let definition_id = global.definition_id;
let location = global.location;
let mut interpreter_errors = vec![];
let mut interpreter = self.setup_interpreter(&mut interpreter_errors);
let mut interpreter = self.setup_interpreter();

if let Err(error) = interpreter.evaluate_let(let_statement) {
self.errors.push(error.into_compilation_error_pair());
Expand All @@ -1367,7 +1364,6 @@ impl<'context> Elaborator<'context> {

self.interner.get_global_mut(global_id).value = Some(value);
}
self.include_interpreter_errors(interpreter_errors);
}

fn define_function_metas(
Expand Down Expand Up @@ -1461,10 +1457,6 @@ impl<'context> Elaborator<'context> {
}
}

fn include_interpreter_errors(&mut self, errors: Vec<InterpreterError>) {
self.errors.extend(errors.into_iter().map(InterpreterError::into_compilation_error_pair));
}

/// True if we're currently within a `comptime` block, function, or global
fn in_comptime_context(&self) -> bool {
// The first context is the global context, followed by the function-specific context.
Expand Down Expand Up @@ -1634,17 +1626,8 @@ impl<'context> Elaborator<'context> {
}
}

fn setup_interpreter<'a>(
&'a mut self,
interpreter_errors: &'a mut Vec<InterpreterError>,
) -> Interpreter {
Interpreter::new(
self.interner,
&mut self.comptime_scopes,
self.crate_id,
self.debug_comptime_in_file,
interpreter_errors,
)
fn setup_interpreter(&mut self) -> Interpreter {
Interpreter::new(self.interner, &mut self.comptime_scopes, self.crate_id)
}

fn debug_comptime<T: Display, F: FnMut(&mut NodeInterner) -> T>(
Expand Down
11 changes: 2 additions & 9 deletions compiler/noirc_frontend/src/elaborator/patterns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -460,16 +460,9 @@ impl<'context> Elaborator<'context> {
// Comptime variables must be replaced with their values
if let Some(definition) = self.interner.try_definition(definition_id) {
if definition.comptime && !self.in_comptime_context() {
let mut interpreter_errors = vec![];
let mut interpreter = Interpreter::new(
self.interner,
&mut self.comptime_scopes,
self.crate_id,
self.debug_comptime_in_file,
&mut interpreter_errors,
);
let mut interpreter =
Interpreter::new(self.interner, &mut self.comptime_scopes, self.crate_id);
let value = interpreter.evaluate(id);
self.include_interpreter_errors(interpreter_errors);
return self.inline_comptime_value(value, span);
}
}
Expand Down
4 changes: 1 addition & 3 deletions compiler/noirc_frontend/src/elaborator/statements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -445,11 +445,9 @@ impl<'context> Elaborator<'context> {
let span = statement.span;
let (hir_statement, _typ) = self.elaborate_statement(statement);
self.check_and_pop_function_context();
let mut interpreter_errors = vec![];
let mut interpreter = self.setup_interpreter(&mut interpreter_errors);
let mut interpreter = self.setup_interpreter();
let value = interpreter.evaluate_statement(hir_statement);
let (expr, typ) = self.inline_comptime_value(value, span);
self.include_interpreter_errors(interpreter_errors);

let location = self.interner.id_location(hir_statement);
self.debug_comptime(location, |interner| expr.to_display_ast(interner).kind);
Expand Down
16 changes: 1 addition & 15 deletions compiler/noirc_frontend/src/hir/comptime/interpreter.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::{collections::hash_map::Entry, rc::Rc};

use acvm::{acir::AcirField, FieldElement};
use fm::FileId;
use im::Vector;
use iter_extended::try_vecmap;
use noirc_errors::Location;
Expand Down Expand Up @@ -52,10 +51,6 @@ pub struct Interpreter<'interner> {

crate_id: CrateId,

/// The scope of --debug-comptime, or None if unset
pub(super) debug_comptime_in_file: Option<FileId>,
pub(super) debug_comptime_evaluations: &'interner mut Vec<InterpreterError>,

in_loop: bool,
}

Expand All @@ -65,17 +60,8 @@ impl<'a> Interpreter<'a> {
interner: &'a mut NodeInterner,
scopes: &'a mut Vec<HashMap<DefinitionId, Value>>,
crate_id: CrateId,
debug_comptime_in_file: Option<FileId>,
debug_comptime_evaluations: &'a mut Vec<InterpreterError>,
) -> Self {
Self {
interner,
scopes,
crate_id,
debug_comptime_in_file,
debug_comptime_evaluations,
in_loop: false,
}
Self { interner, scopes, crate_id, in_loop: false }
}

pub(crate) fn call_function(
Expand Down
1 change: 0 additions & 1 deletion compiler/noirc_frontend/src/hir/comptime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
mod errors;
mod hir_to_display_ast;
mod interpreter;
mod scan;
mod tests;
mod value;

Expand Down
Loading

0 comments on commit 84e75e4

Please sign in to comment.