Skip to content
Merged
Show file tree
Hide file tree
Changes from 14 commits
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
21 changes: 21 additions & 0 deletions compiler/noirc_frontend/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,18 @@ pub enum IntegerBitSize {
SixtyFour,
}

impl IntegerBitSize {
pub fn bit_size(&self) -> u8 {
match self {
IntegerBitSize::One => 1,
IntegerBitSize::Eight => 8,
IntegerBitSize::Sixteen => 16,
IntegerBitSize::ThirtyTwo => 32,
IntegerBitSize::SixtyFour => 64,
}
}
}

impl IntegerBitSize {
pub fn allowed_sizes() -> Vec<Self> {
vec![Self::One, Self::Eight, Self::ThirtyTwo, Self::SixtyFour]
Expand Down Expand Up @@ -297,6 +309,15 @@ pub enum Signedness {
Signed,
}

impl Signedness {
pub fn to_bool(&self) -> bool {
Comment thread
asterite marked this conversation as resolved.
Outdated
match self {
Signedness::Unsigned => false,
Signedness::Signed => true,
}
}
}

impl UnresolvedTypeExpression {
// This large error size is justified because it improves parsing speeds by around 40% in
// release mode. See `ParserError` definition for further explanation.
Expand Down
30 changes: 18 additions & 12 deletions compiler/noirc_frontend/src/hir/comptime/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -328,21 +328,27 @@ impl<'local, 'interner> Interpreter<'local, 'interner> {
let argument = Value::Pointer(Shared::new(argument), true);
self.define_pattern(pattern, typ, argument, location)
}
HirPattern::Tuple(pattern_fields, _) => match (argument, typ) {
(Value::Tuple(fields), Type::Tuple(type_fields))
if fields.len() == pattern_fields.len() =>
{
for ((pattern, typ), argument) in
pattern_fields.iter().zip(type_fields).zip(fields)
HirPattern::Tuple(pattern_fields, _) => {
let typ = &typ.follow_bindings();
Comment thread
asterite marked this conversation as resolved.

match (argument, typ) {
(Value::Tuple(fields), Type::Tuple(type_fields))
if fields.len() == pattern_fields.len() =>
{
self.define_pattern(pattern, typ, argument, location)?;
for ((pattern, typ), argument) in
pattern_fields.iter().zip(type_fields).zip(fields)
{
self.define_pattern(pattern, typ, argument, location)?;
}
Ok(())
}
Ok(())
}
(value, _) => {
Err(InterpreterError::TypeMismatch { expected: typ.clone(), value, location })
(value, actual_type) => Err(InterpreterError::TypeMismatch {
expected: typ.clone(),
value,
location,
}),
}
},
}
HirPattern::Struct(struct_type, pattern_fields, _) => {
self.push_scope();

Expand Down
Loading