From 80e64d22c969b0756c05b08e116f9dc043a1e2c7 Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Tue, 23 Apr 2024 12:58:19 -0500 Subject: [PATCH] Revert CompTime back to Comptime --- compiler/noirc_frontend/src/ast/expression.rs | 4 ++-- compiler/noirc_frontend/src/hir/comptime/errors.rs | 3 +-- compiler/noirc_frontend/src/hir/comptime/hir_to_ast.rs | 2 +- .../noirc_frontend/src/hir/comptime/interpreter.rs | 2 +- compiler/noirc_frontend/src/hir/comptime/mod.rs | 10 ---------- compiler/noirc_frontend/src/hir/comptime/scan.rs | 2 +- compiler/noirc_frontend/src/hir/comptime/value.rs | 2 +- compiler/noirc_frontend/src/hir/resolution/resolver.rs | 2 +- compiler/noirc_frontend/src/hir/type_check/expr.rs | 2 +- compiler/noirc_frontend/src/hir_def/expr.rs | 2 +- compiler/noirc_frontend/src/monomorphization/mod.rs | 2 +- compiler/noirc_frontend/src/parser/parser.rs | 2 +- tooling/nargo_fmt/src/rewrite/expr.rs | 2 +- 13 files changed, 13 insertions(+), 24 deletions(-) diff --git a/compiler/noirc_frontend/src/ast/expression.rs b/compiler/noirc_frontend/src/ast/expression.rs index fc2a3897b85..5659de46588 100644 --- a/compiler/noirc_frontend/src/ast/expression.rs +++ b/compiler/noirc_frontend/src/ast/expression.rs @@ -28,7 +28,7 @@ pub enum ExpressionKind { Lambda(Box), Parenthesized(Box), Quote(BlockExpression), - CompTime(BlockExpression), + Comptime(BlockExpression), Error, } @@ -505,7 +505,7 @@ impl Display for ExpressionKind { Lambda(lambda) => lambda.fmt(f), Parenthesized(sub_expr) => write!(f, "({sub_expr})"), Quote(block) => write!(f, "quote {block}"), - CompTime(block) => write!(f, "comptime {block}"), + Comptime(block) => write!(f, "comptime {block}"), Error => write!(f, "Error"), } } diff --git a/compiler/noirc_frontend/src/hir/comptime/errors.rs b/compiler/noirc_frontend/src/hir/comptime/errors.rs index 1d55a906303..d3db7fcaee9 100644 --- a/compiler/noirc_frontend/src/hir/comptime/errors.rs +++ b/compiler/noirc_frontend/src/hir/comptime/errors.rs @@ -5,9 +5,8 @@ use noirc_errors::Location; use super::value::Value; /// The possible errors that can halt the interpreter. -#[allow(unused)] #[derive(Debug)] -pub(crate) enum InterpreterError { +pub enum InterpreterError { ArgumentCountMismatch { expected: usize, actual: usize, call_location: Location }, TypeMismatch { expected: Type, value: Value, location: Location }, NoValueForId { id: DefinitionId, location: Location }, diff --git a/compiler/noirc_frontend/src/hir/comptime/hir_to_ast.rs b/compiler/noirc_frontend/src/hir/comptime/hir_to_ast.rs index fdfc9540892..dd23edf0004 100644 --- a/compiler/noirc_frontend/src/hir/comptime/hir_to_ast.rs +++ b/compiler/noirc_frontend/src/hir/comptime/hir_to_ast.rs @@ -170,7 +170,7 @@ impl ExprId { ExpressionKind::Lambda(Box::new(Lambda { parameters, return_type, body })) } HirExpression::Error => ExpressionKind::Error, - HirExpression::CompTime(block) => ExpressionKind::CompTime(block.into_ast(interner)), + HirExpression::Comptime(block) => ExpressionKind::Comptime(block.into_ast(interner)), HirExpression::Quote(block) => ExpressionKind::Quote(block), // A macro was evaluated here! diff --git a/compiler/noirc_frontend/src/hir/comptime/interpreter.rs b/compiler/noirc_frontend/src/hir/comptime/interpreter.rs index f4aeaba4a2c..c6d508a581e 100644 --- a/compiler/noirc_frontend/src/hir/comptime/interpreter.rs +++ b/compiler/noirc_frontend/src/hir/comptime/interpreter.rs @@ -313,7 +313,7 @@ impl<'a> Interpreter<'a> { HirExpression::Tuple(tuple) => self.evaluate_tuple(tuple), HirExpression::Lambda(lambda) => self.evaluate_lambda(lambda, id), HirExpression::Quote(block) => Ok(Value::Code(Rc::new(block))), - HirExpression::CompTime(block) => self.evaluate_block(block), + HirExpression::Comptime(block) => self.evaluate_block(block), HirExpression::Unquote(block) => { // An Unquote expression being found is indicative of a macro being // expanded within another comptime fn which we don't currently support. diff --git a/compiler/noirc_frontend/src/hir/comptime/mod.rs b/compiler/noirc_frontend/src/hir/comptime/mod.rs index f5e13875a25..26e05d675b3 100644 --- a/compiler/noirc_frontend/src/hir/comptime/mod.rs +++ b/compiler/noirc_frontend/src/hir/comptime/mod.rs @@ -1,5 +1,3 @@ -use crate::{macros_api::NodeInterner, node_interner::FuncId}; - mod errors; mod hir_to_ast; mod interpreter; @@ -8,11 +6,3 @@ mod tests; mod value; pub use interpreter::Interpreter; - -/// Scan through a function, evaluating any CompTime nodes found. -/// These nodes will be modified in place, replaced with the -/// result of their evaluation. -pub fn scan_function(function: FuncId, interner: &mut NodeInterner) { - let mut interpreter = Interpreter::new(interner); - interpreter.scan_function(function); -} diff --git a/compiler/noirc_frontend/src/hir/comptime/scan.rs b/compiler/noirc_frontend/src/hir/comptime/scan.rs index 4b415b1ac53..d4fa355627f 100644 --- a/compiler/noirc_frontend/src/hir/comptime/scan.rs +++ b/compiler/noirc_frontend/src/hir/comptime/scan.rs @@ -58,7 +58,7 @@ impl<'interner> Interpreter<'interner> { HirExpression::If(if_) => self.scan_if(if_), HirExpression::Tuple(tuple) => self.scan_tuple(tuple), HirExpression::Lambda(lambda) => self.scan_lambda(lambda), - HirExpression::CompTime(block) => { + HirExpression::Comptime(block) => { let location = self.interner.expr_location(&expr); let new_expr = self.evaluate_block(block)?.into_expression(self.interner, location)?; diff --git a/compiler/noirc_frontend/src/hir/comptime/value.rs b/compiler/noirc_frontend/src/hir/comptime/value.rs index 123dac29b4a..89102344b09 100644 --- a/compiler/noirc_frontend/src/hir/comptime/value.rs +++ b/compiler/noirc_frontend/src/hir/comptime/value.rs @@ -18,7 +18,7 @@ use super::errors::{IResult, InterpreterError}; #[allow(unused)] #[derive(Debug, Clone, PartialEq, Eq)] -pub(crate) enum Value { +pub enum Value { Unit, Bool(bool), Field(FieldElement), diff --git a/compiler/noirc_frontend/src/hir/resolution/resolver.rs b/compiler/noirc_frontend/src/hir/resolution/resolver.rs index ea0e9042982..8d2cb17189b 100644 --- a/compiler/noirc_frontend/src/hir/resolution/resolver.rs +++ b/compiler/noirc_frontend/src/hir/resolution/resolver.rs @@ -1602,7 +1602,7 @@ impl<'a> Resolver<'a> { // The quoted expression isn't resolved since we don't want errors if variables aren't defined ExpressionKind::Quote(block) => HirExpression::Quote(block), - ExpressionKind::CompTime(block) => HirExpression::CompTime(self.resolve_block(block)), + ExpressionKind::Comptime(block) => HirExpression::Comptime(self.resolve_block(block)), }; // If these lines are ever changed, make sure to change the early return diff --git a/compiler/noirc_frontend/src/hir/type_check/expr.rs b/compiler/noirc_frontend/src/hir/type_check/expr.rs index e94ac73d5a2..0bc7673e105 100644 --- a/compiler/noirc_frontend/src/hir/type_check/expr.rs +++ b/compiler/noirc_frontend/src/hir/type_check/expr.rs @@ -309,7 +309,7 @@ impl<'interner> TypeChecker<'interner> { Type::Function(params, Box::new(lambda.return_type), Box::new(env_type)) } HirExpression::Quote(_) => Type::Code, - HirExpression::CompTime(block) => self.check_block(block), + HirExpression::Comptime(block) => self.check_block(block), // Unquote should be inserted & removed by the comptime interpreter. // Even if we allowed it here, we wouldn't know what type to give to the result. diff --git a/compiler/noirc_frontend/src/hir_def/expr.rs b/compiler/noirc_frontend/src/hir_def/expr.rs index 6175e11d38e..bf7d9b7b4ba 100644 --- a/compiler/noirc_frontend/src/hir_def/expr.rs +++ b/compiler/noirc_frontend/src/hir_def/expr.rs @@ -33,7 +33,7 @@ pub enum HirExpression { Lambda(HirLambda), Quote(crate::ast::BlockExpression), Unquote(crate::ast::BlockExpression), - CompTime(HirBlockExpression), + Comptime(HirBlockExpression), Error, } diff --git a/compiler/noirc_frontend/src/monomorphization/mod.rs b/compiler/noirc_frontend/src/monomorphization/mod.rs index 81aa75567ee..d92b6c65d7a 100644 --- a/compiler/noirc_frontend/src/monomorphization/mod.rs +++ b/compiler/noirc_frontend/src/monomorphization/mod.rs @@ -524,7 +524,7 @@ impl<'interner> Monomorphizer<'interner> { HirExpression::Unquote(_) => { unreachable!("unquote expression remaining in runtime code") } - HirExpression::CompTime(_) => { + HirExpression::Comptime(_) => { unreachable!("comptime expression remaining in runtime code") } }; diff --git a/compiler/noirc_frontend/src/parser/parser.rs b/compiler/noirc_frontend/src/parser/parser.rs index 9c21d40b935..858e5c4838c 100644 --- a/compiler/noirc_frontend/src/parser/parser.rs +++ b/compiler/noirc_frontend/src/parser/parser.rs @@ -548,7 +548,7 @@ fn comptime_expr<'a, S>(statement: S) -> impl NoirParser + 'a where S: NoirParser + 'a, { - keyword(Keyword::CompTime).ignore_then(block(statement)).map(ExpressionKind::CompTime) + keyword(Keyword::CompTime).ignore_then(block(statement)).map(ExpressionKind::Comptime) } fn declaration<'a, P>(expr_parser: P) -> impl NoirParser + 'a diff --git a/tooling/nargo_fmt/src/rewrite/expr.rs b/tooling/nargo_fmt/src/rewrite/expr.rs index e7a00f26672..6b7dca6c5c7 100644 --- a/tooling/nargo_fmt/src/rewrite/expr.rs +++ b/tooling/nargo_fmt/src/rewrite/expr.rs @@ -159,7 +159,7 @@ pub(crate) fn rewrite( } ExpressionKind::Lambda(_) | ExpressionKind::Variable(_) => visitor.slice(span).to_string(), ExpressionKind::Quote(block) => format!("quote {}", rewrite_block(visitor, block, span)), - ExpressionKind::CompTime(block) => { + ExpressionKind::Comptime(block) => { format!("comptime {}", rewrite_block(visitor, block, span)) } ExpressionKind::Error => unreachable!(),