Skip to content

Commit

Permalink
Remove comptime more thoroughly
Browse files Browse the repository at this point in the history
  • Loading branch information
jfecher committed Aug 8, 2023
1 parent 38bf134 commit 1a6e691
Show file tree
Hide file tree
Showing 9 changed files with 8 additions and 43 deletions.
2 changes: 1 addition & 1 deletion crates/noirc_evaluator/src/ssa/opt/unrolling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
7 changes: 0 additions & 7 deletions crates/noirc_frontend/src/hir/resolution/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -206,11 +204,6 @@ impl From<ResolverError> 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}"
Expand Down
11 changes: 0 additions & 11 deletions crates/noirc_frontend/src/hir/type_check/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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}")]
Expand Down Expand Up @@ -165,9 +157,6 @@ impl From<TypeCheckError> 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, .. }
Expand Down
1 change: 0 additions & 1 deletion crates/noirc_frontend/src/hir/type_check/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 2 additions & 5 deletions crates/noirc_frontend/src/hir/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions crates/noirc_frontend/src/hir_def/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(),
Expand Down
1 change: 0 additions & 1 deletion crates/noirc_frontend/src/monomorphization/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
9 changes: 2 additions & 7 deletions crates/noirc_frontend/src/monomorphization/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
10 changes: 2 additions & 8 deletions crates/noirc_frontend/src/parser/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ fn global_declaration() -> impl NoirParser<TopLevelStatement> {
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)
Expand Down Expand Up @@ -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<UnresolvedType> {
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<UnresolvedType> + 'a {
ignore_then_commit(just(Token::Colon), parse_type())
.or_not()
Expand Down

0 comments on commit 1a6e691

Please sign in to comment.