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

fix(frontend): Error on unsupported integer annotation #2778

Merged
merged 2 commits into from
Sep 22, 2023
Merged
Changes from 1 commit
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
Prev Previous commit
move unsupported integer size to lexer
  • Loading branch information
vezenovm committed Sep 22, 2023
commit 5f61a232073ff2a69f1436e4b63233b308ceb8dd
5 changes: 1 addition & 4 deletions compiler/noirc_frontend/src/hir/type_check/errors.rs
Original file line number Diff line number Diff line change
@@ -108,8 +108,6 @@ pub enum TypeCheckError {
parameter_span: Span,
parameter_index: usize,
},
#[error("Integer annotation specifies {num_bits:?} bits which is over the max supported size of {max_num_bits:?}")]
UnsupportedIntegerSize { num_bits: u32, max_num_bits: u32, span: Span },
}

impl TypeCheckError {
@@ -196,8 +194,7 @@ impl From<TypeCheckError> for Diagnostic {
| TypeCheckError::FieldComparison { span, .. }
| TypeCheckError::AmbiguousBitWidth { span, .. }
| TypeCheckError::IntegerAndFieldBinaryOperation { span }
| TypeCheckError::OverflowingAssignment { span, .. }
| TypeCheckError::UnsupportedIntegerSize { span, .. } => {
| TypeCheckError::OverflowingAssignment { span, .. } => {
Diagnostic::simple_error(error.to_string(), String::new(), span)
}
TypeCheckError::PublicReturnType { typ, span } => Diagnostic::simple_error(
14 changes: 2 additions & 12 deletions compiler/noirc_frontend/src/hir/type_check/stmt.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use acvm::FieldElement;
use iter_extended::vecmap;
use noirc_errors::{Location, Span};

@@ -266,17 +265,8 @@ impl<'interner> TypeChecker<'interner> {
expr_span,
}
});
if let Some(bit_size) = annotated_type.bit_size() {
let max_integer_bit_size = FieldElement::max_num_bits() / 2;
if bit_size > max_integer_bit_size {
self.errors.push(TypeCheckError::UnsupportedIntegerSize {
num_bits: bit_size,
max_num_bits: max_integer_bit_size,
span: expr_span,
});
} else if annotated_type.is_unsigned() {
self.lint_overflowing_uint(&rhs_expr, &annotated_type);
}
if annotated_type.is_unsigned() {
self.lint_overflowing_uint(&rhs_expr, &annotated_type);
}
annotated_type
} else {
8 changes: 0 additions & 8 deletions compiler/noirc_frontend/src/hir_def/types.rs
Original file line number Diff line number Diff line change
@@ -446,14 +446,6 @@ impl Type {
matches!(self.follow_bindings(), Type::FieldElement)
}

// Return the bit size of an integer type, otherwise return `None`
pub fn bit_size(&self) -> Option<u32> {
match self.follow_bindings() {
Type::Integer(_, bit_size) => Some(bit_size),
_ => None,
}
}

pub fn is_signed(&self) -> bool {
matches!(self.follow_bindings(), Type::Integer(Signedness::Signed, _))
}
2 changes: 1 addition & 1 deletion compiler/noirc_frontend/src/lexer/token.rs
Original file line number Diff line number Diff line change
@@ -302,7 +302,7 @@ impl IntType {
Err(_) => return Ok(None),
};

let max_bits = FieldElement::max_num_bits();
let max_bits = FieldElement::max_num_bits() / 2;

if str_as_u32 > max_bits {
return Err(LexerErrorKind::TooManyBits { span, max: max_bits, got: str_as_u32 });