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

feat: add Type::is_field and Type::as_integer #5670

Merged
merged 17 commits into from
Aug 2, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@
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 @@ -117,7 +129,7 @@
/*env:*/ Box<UnresolvedType>,
),

// The type of quoted code for metaprogramming

Check warning on line 132 in compiler/noirc_frontend/src/ast/mod.rs

View workflow job for this annotation

GitHub Actions / Code

Unknown word (metaprogramming)
Quoted(crate::QuotedType),

/// An already resolved type. These can only be parsed if they were present in the token stream
Expand Down Expand Up @@ -297,6 +309,15 @@
Signed,
}

impl Signedness {
pub fn is_signed(&self) -> bool {
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
34 changes: 21 additions & 13 deletions compiler/noirc_frontend/src/hir/comptime/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -339,22 +339,30 @@ 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();
asterite marked this conversation as resolved.
Show resolved Hide 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(())
}
(value, _) => {
let actual = value.get_type().into_owned();
Err(InterpreterError::TypeMismatch {
expected: typ.clone(),
actual,
location,
})
}
Ok(())
}
(value, _) => {
let actual = value.get_type().into_owned();
Err(InterpreterError::TypeMismatch { expected: typ.clone(), actual, location })
}
},
}
HirPattern::Struct(struct_type, pattern_fields, _) => {
self.push_scope();

Expand Down
Loading
Loading