Skip to content

Commit

Permalink
Revert CompTime back to Comptime
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Apr 23, 2024
1 parent 3863ff2 commit 80e64d2
Show file tree
Hide file tree
Showing 13 changed files with 13 additions and 24 deletions.
4 changes: 2 additions & 2 deletions compiler/noirc_frontend/src/ast/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub enum ExpressionKind {
Lambda(Box<Lambda>),
Parenthesized(Box<Expression>),
Quote(BlockExpression),
CompTime(BlockExpression),
Comptime(BlockExpression),
Error,
}

Expand Down Expand Up @@ -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"),
}
}
Expand Down
3 changes: 1 addition & 2 deletions compiler/noirc_frontend/src/hir/comptime/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/comptime/hir_to_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/comptime/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 0 additions & 10 deletions compiler/noirc_frontend/src/hir/comptime/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use crate::{macros_api::NodeInterner, node_interner::FuncId};

mod errors;
mod hir_to_ast;
mod interpreter;
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/comptime/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/comptime/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/resolution/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir/type_check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/hir_def/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ pub enum HirExpression {
Lambda(HirLambda),
Quote(crate::ast::BlockExpression),
Unquote(crate::ast::BlockExpression),
CompTime(HirBlockExpression),
Comptime(HirBlockExpression),
Error,
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ fn comptime_expr<'a, S>(statement: S) -> impl NoirParser<ExpressionKind> + 'a
where
S: NoirParser<StatementKind> + '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<StatementKind> + 'a
Expand Down
2 changes: 1 addition & 1 deletion tooling/nargo_fmt/src/rewrite/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
Expand Down

0 comments on commit 80e64d2

Please sign in to comment.