Skip to content

Commit

Permalink
Put the three polymorphic kinds into a single variant
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Jul 30, 2024
1 parent 4aa899a commit cb18816
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 124 deletions.
19 changes: 12 additions & 7 deletions compiler/noirc_driver/src/abi_gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use noirc_frontend::{
macros_api::{HirExpression, HirLiteral},
node_interner::{FuncId, NodeInterner},
};
use noirc_frontend::{TypeBinding, TypeVariableKind};
use noirc_frontend::{PolymorphicKind, TypeBinding, TypeVariableKind};

/// Arranges a function signature and a generated circuit's return witnesses into a
/// `noirc_abi::Abi`.
Expand Down Expand Up @@ -68,13 +68,18 @@ pub(super) fn abi_type_from_hir_type(context: &Context, typ: &Type) -> AbiType {

AbiType::Integer { sign, width: (*bit_width).into() }
}
Type::TypeVariable(binding, TypeVariableKind::IntegerOrField)
| Type::TypeVariable(binding, TypeVariableKind::Integer) => match &*binding.borrow() {
TypeBinding::Bound(typ) => abi_type_from_hir_type(context, typ),
TypeBinding::Unbound(_) => {
abi_type_from_hir_type(context, &Type::default_int_or_field_type())
Type::TypeVariable(
binding,
TypeVariableKind::Polymorphic(PolymorphicKind::IntegerOrField),
)
| Type::TypeVariable(binding, TypeVariableKind::Polymorphic(PolymorphicKind::Integer)) => {
match &*binding.borrow() {
TypeBinding::Bound(typ) => abi_type_from_hir_type(context, typ),
TypeBinding::Unbound(_) => {
abi_type_from_hir_type(context, &Type::default_int_or_field_type())
}
}
},
}
Type::Bool => AbiType::Boolean,
Type::String(size) => {
let size = size
Expand Down
3 changes: 1 addition & 2 deletions compiler/noirc_frontend/src/elaborator/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -783,8 +783,7 @@ impl<'context> Elaborator<'context> {
match from.follow_bindings() {
Type::Integer(..)
| Type::FieldElement
| Type::TypeVariable(_, TypeVariableKind::IntegerOrField)
| Type::TypeVariable(_, TypeVariableKind::Integer)
| Type::TypeVariable(_, TypeVariableKind::Polymorphic(..))
| Type::Bool => (),

Type::TypeVariable(binding, TypeVariableKind::Normal) => {
Expand Down
14 changes: 11 additions & 3 deletions compiler/noirc_frontend/src/hir/comptime/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use crate::monomorphization::{
undo_instantiation_bindings,
};
use crate::token::Tokens;
use crate::TypeVariable;
use crate::{
hir_def::{
expr::{
Expand All @@ -36,6 +35,7 @@ use crate::{
node_interner::{DefinitionId, DefinitionKind, ExprId, FuncId, StmtId},
Shared, Type, TypeBinding, TypeBindings, TypeVariableKind,
};
use crate::{PolymorphicKind, TypeVariable};

use super::errors::{IResult, InterpreterError};
use super::value::{unwrap_rc, Value};
Expand Down Expand Up @@ -661,9 +661,17 @@ impl<'local, 'interner> Interpreter<'local, 'interner> {
Ok(Value::I64(value))
}
}
} else if let Type::TypeVariable(variable, TypeVariableKind::IntegerOrField) = &typ {
} else if let Type::TypeVariable(
variable,
TypeVariableKind::Polymorphic(PolymorphicKind::IntegerOrField),
) = &typ
{
Ok(Value::Field(value))
} else if let Type::TypeVariable(variable, TypeVariableKind::Integer) = &typ {
} else if let Type::TypeVariable(
variable,
TypeVariableKind::Polymorphic(PolymorphicKind::Integer),
) = &typ
{
let value: u64 = value
.try_to_u64()
.ok_or(InterpreterError::IntegerOutOfRangeForType { value, typ, location })?;
Expand Down
Loading

0 comments on commit cb18816

Please sign in to comment.