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 comptime scanning pass #5569

Merged
merged 1 commit into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
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 @@

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 @@
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 Expand Up @@ -165,7 +151,7 @@
}
} else {
let name = self.interner.function_name(&function);
unreachable!("Non-builtin, lowlevel or oracle builtin fn '{name}'")

Check warning on line 154 in compiler/noirc_frontend/src/hir/comptime/interpreter.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (lowlevel)
}
}

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
Loading