From 1a6e6916db94687d6012fd3c4465f9728cf1dabb Mon Sep 17 00:00:00 2001 From: Jake Fecher Date: Tue, 8 Aug 2023 15:08:55 -0500 Subject: [PATCH] Remove comptime more thoroughly --- crates/noirc_evaluator/src/ssa/opt/unrolling.rs | 2 +- crates/noirc_frontend/src/hir/resolution/errors.rs | 7 ------- crates/noirc_frontend/src/hir/type_check/errors.rs | 11 ----------- crates/noirc_frontend/src/hir/type_check/expr.rs | 1 - crates/noirc_frontend/src/hir/type_check/mod.rs | 7 ++----- crates/noirc_frontend/src/hir_def/types.rs | 3 +-- crates/noirc_frontend/src/monomorphization/ast.rs | 1 - crates/noirc_frontend/src/monomorphization/mod.rs | 9 ++------- crates/noirc_frontend/src/parser/parser.rs | 10 ++-------- 9 files changed, 8 insertions(+), 43 deletions(-) diff --git a/crates/noirc_evaluator/src/ssa/opt/unrolling.rs b/crates/noirc_evaluator/src/ssa/opt/unrolling.rs index b0c405c0d76..ac38f102712 100644 --- a/crates/noirc_evaluator/src/ssa/opt/unrolling.rs +++ b/crates/noirc_evaluator/src/ssa/opt/unrolling.rs @@ -577,7 +577,7 @@ mod tests { // } // The final block count is not 1 because unrolling creates some unnecessary jmps. // If a simplify cfg pass is ran afterward, the expected block count will be 1. - let ssa = ssa.unroll_loops().unwrap(); + let ssa = ssa.unroll_loops().expect("All loops should be unrolled"); assert_eq!(ssa.main().reachable_blocks().len(), 5); } diff --git a/crates/noirc_frontend/src/hir/resolution/errors.rs b/crates/noirc_frontend/src/hir/resolution/errors.rs index e9cf8f31393..1215d897eda 100644 --- a/crates/noirc_frontend/src/hir/resolution/errors.rs +++ b/crates/noirc_frontend/src/hir/resolution/errors.rs @@ -42,8 +42,6 @@ pub enum ResolverError { NecessaryPub { ident: Ident }, #[error("'distinct' keyword can only be used with main method")] DistinctNotAllowed { ident: Ident }, - #[error("Expected const value where non-constant value was used")] - ExpectedComptimeVariable { name: String, span: Span }, #[error("Missing expression for declared constant")] MissingRhsExpr { name: String, span: Span }, #[error("Expression invalid in an array length context")] @@ -206,11 +204,6 @@ impl From for Diagnostic { diag.add_note("The `distinct` keyword is only valid when used on the main function of a program, as its only purpose is to ensure that all witness indices that occur in the abi are unique".to_owned()); diag } - ResolverError::ExpectedComptimeVariable { name, span } => Diagnostic::simple_error( - format!("expected constant variable where non-constant variable {name} was used"), - "expected const variable".to_string(), - span, - ), ResolverError::MissingRhsExpr { name, span } => Diagnostic::simple_error( format!( "no expression specifying the value stored by the constant variable {name}" diff --git a/crates/noirc_frontend/src/hir/type_check/errors.rs b/crates/noirc_frontend/src/hir/type_check/errors.rs index 8b3623db3c3..84bf511d314 100644 --- a/crates/noirc_frontend/src/hir/type_check/errors.rs +++ b/crates/noirc_frontend/src/hir/type_check/errors.rs @@ -47,14 +47,6 @@ pub enum TypeCheckError { AccessUnknownMember { lhs_type: Type, field_name: String, span: Span }, #[error("Function expects {expected} parameters but {found} given")] ParameterCountMismatch { expected: usize, found: usize, span: Span }, - #[error("The value is non-comptime because of this expression, which uses another non-comptime value")] - NotCompTime { span: Span }, - #[error( - "The value is comptime because of this expression, which forces the value to be comptime" - )] - CompTime { span: Span }, - #[error("Cannot cast to a comptime type, argument to cast is not known at compile-time")] - CannotCastToComptimeType { span: Span }, #[error("Only integer and Field types may be casted to")] UnsupportedCast { span: Span }, #[error("Index {index} is out of bounds for this tuple {lhs_type} of length {length}")] @@ -165,9 +157,6 @@ impl From for Diagnostic { TypeCheckError::InvalidCast { span, .. } | TypeCheckError::ExpectedFunction { span, .. } | TypeCheckError::AccessUnknownMember { span, .. } - | TypeCheckError::CompTime { span } - | TypeCheckError::NotCompTime { span } - | TypeCheckError::CannotCastToComptimeType { span } | TypeCheckError::UnsupportedCast { span } | TypeCheckError::TupleIndexOutOfBounds { span, .. } | TypeCheckError::VariableMustBeMutable { span, .. } diff --git a/crates/noirc_frontend/src/hir/type_check/expr.rs b/crates/noirc_frontend/src/hir/type_check/expr.rs index f0c1adf761b..99b312adb0d 100644 --- a/crates/noirc_frontend/src/hir/type_check/expr.rs +++ b/crates/noirc_frontend/src/hir/type_check/expr.rs @@ -882,7 +882,6 @@ impl<'interner> TypeChecker<'interner> { } // Given a binary operator and another type. This method will produce the output type - // XXX: Review these rules. In particular, the interaction between integers, comptime and private/public variables fn infix_operand_type_rules( &mut self, lhs_type: &Type, diff --git a/crates/noirc_frontend/src/hir/type_check/mod.rs b/crates/noirc_frontend/src/hir/type_check/mod.rs index 76e59ef5eab..8768120af2f 100644 --- a/crates/noirc_frontend/src/hir/type_check/mod.rs +++ b/crates/noirc_frontend/src/hir/type_check/mod.rs @@ -4,11 +4,8 @@ //! the HIR of each function and outputs the inferred type of each HIR node into the NodeInterner, //! keyed by the ID of the node. //! -//! The algorithm for checking and inferring types itself is somewhat ad-hoc. It includes both -//! unification and subtyping, with the only difference between the two being how CompTime -//! is handled (See note on CompTime and make_subtype_of for details). Additionally, although -//! this algorithm features inference via TypeVariables, there is no generalization step as -//! all functions are required to give their full signatures. Closures are inferred but are +//! Although this algorithm features inference via TypeVariables, there is no generalization step +//! as all functions are required to give their full signatures. Closures are inferred but are //! never generalized and thus cannot be used polymorphically. mod errors; mod expr; diff --git a/crates/noirc_frontend/src/hir_def/types.rs b/crates/noirc_frontend/src/hir_def/types.rs index 545310d3f44..d938421cb0e 100644 --- a/crates/noirc_frontend/src/hir_def/types.rs +++ b/crates/noirc_frontend/src/hir_def/types.rs @@ -675,8 +675,7 @@ impl Type { } /// Try to bind a PolymorphicInt variable to self, succeeding if self is an integer, field, - /// other PolymorphicInt type, or type variable. If use_subtype is true, the CompTime fields - /// of each will be checked via sub-typing rather than unification. + /// other PolymorphicInt type, or type variable. pub fn try_bind_to_polymorphic_int(&self, var: &TypeVariable) -> Result<(), UnificationError> { let target_id = match &*var.borrow() { TypeBinding::Bound(_) => unreachable!(), diff --git a/crates/noirc_frontend/src/monomorphization/ast.rs b/crates/noirc_frontend/src/monomorphization/ast.rs index 7c276657769..b26db6e1afb 100644 --- a/crates/noirc_frontend/src/monomorphization/ast.rs +++ b/crates/noirc_frontend/src/monomorphization/ast.rs @@ -208,7 +208,6 @@ pub struct Function { /// - All type variables and generics removed /// - Concrete lengths for each array and string /// - Several other variants removed (such as Type::Constant) -/// - No CompTime /// - All structs replaced with tuples #[derive(Debug, PartialEq, Eq, Clone)] pub enum Type { diff --git a/crates/noirc_frontend/src/monomorphization/mod.rs b/crates/noirc_frontend/src/monomorphization/mod.rs index 2c92c1fc849..b93c95efe07 100644 --- a/crates/noirc_frontend/src/monomorphization/mod.rs +++ b/crates/noirc_frontend/src/monomorphization/mod.rs @@ -959,14 +959,9 @@ impl<'interner> Monomorphizer<'interner> { ast::Expression::Assign(ast::Assign { expression, lvalue }) } - fn lvalue( - &mut self, - lvalue: HirLValue, - ) -> ast::LValue { + fn lvalue(&mut self, lvalue: HirLValue) -> ast::LValue { match lvalue { - HirLValue::Ident(ident, _) => { - ast::LValue::Ident(self.local_ident(&ident).unwrap()) - } + HirLValue::Ident(ident, _) => ast::LValue::Ident(self.local_ident(&ident).unwrap()), HirLValue::MemberAccess { object, field_index, .. } => { let field_index = field_index.unwrap(); let object = Box::new(self.lvalue(*object)); diff --git a/crates/noirc_frontend/src/parser/parser.rs b/crates/noirc_frontend/src/parser/parser.rs index f83e4cad3c0..232aff618b0 100644 --- a/crates/noirc_frontend/src/parser/parser.rs +++ b/crates/noirc_frontend/src/parser/parser.rs @@ -125,7 +125,7 @@ fn global_declaration() -> impl NoirParser { keyword(Keyword::Global).labelled(ParsingRuleLabel::Global), ident().map(Pattern::Identifier), ); - let p = then_commit(p, global_type_annotation()); + let p = then_commit(p, optional_type_annotation()); let p = then_commit_ignore(p, just(Token::Assign)); let p = then_commit(p, literal_or_collection(expression()).map_with_span(Expression::new)); p.map(LetStatement::new_let).map(TopLevelStatement::Global) @@ -548,13 +548,7 @@ fn check_statements_require_semicolon( }) } -/// Parse an optional ': type' and implicitly add a 'comptime' to the type -fn global_type_annotation() -> impl NoirParser { - ignore_then_commit(just(Token::Colon), parse_type()) - .or_not() - .map(|opt| opt.unwrap_or(UnresolvedType::Unspecified)) -} - +/// Parse an optional ': type' fn optional_type_annotation<'a>() -> impl NoirParser + 'a { ignore_then_commit(just(Token::Colon), parse_type()) .or_not()