Skip to content
Open
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
2 changes: 1 addition & 1 deletion hugr-core/src/builder/dataflow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -931,7 +931,7 @@ pub(crate) mod test {
FunctionBuilder::new(
"bad_eval",
PolyFuncType::new(
[TypeParam::new_list_type(TypeBound::Copyable)],
[TypeParam::new_list_kind(TypeBound::Copyable)],
Signature::new(
[Type::new_function(FuncValueType::new(
[usize_t()],
Expand Down
24 changes: 12 additions & 12 deletions hugr-core/src/export.rs
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ impl<'a> Context<'a> {
var: Option<(table::NodeId, table::VarIndex)>,
) -> table::TermId {
match t {
Term::RuntimeType(b) => {
Term::TypeKind(b) => {
if let (Some((node, index)), TypeBound::Copyable) = (var, b) {
let term = self.make_term(table::Term::Var(table::VarId(node, index)));
let non_linear = self.make_term_apply(model::CORE_NON_LINEAR, &[term]);
Expand All @@ -950,23 +950,23 @@ impl<'a> Context<'a> {

self.make_term_apply(model::CORE_TYPE, &[])
}
Term::BoundedNatType(_) => self.make_term_apply(model::CORE_NAT_TYPE, &[]),
Term::StringType => self.make_term_apply(model::CORE_STR_TYPE, &[]),
Term::BytesType => self.make_term_apply(model::CORE_BYTES_TYPE, &[]),
Term::FloatType => self.make_term_apply(model::CORE_FLOAT_TYPE, &[]),
Term::ListType(item_type) => {
Term::BoundedNatKind(_) => self.make_term_apply(model::CORE_NAT_TYPE, &[]),
Term::StringKind => self.make_term_apply(model::CORE_STR_TYPE, &[]),
Term::BytesKind => self.make_term_apply(model::CORE_BYTES_TYPE, &[]),
Term::FloatKind => self.make_term_apply(model::CORE_FLOAT_TYPE, &[]),
Term::ListKind(item_type) => {
let item_type = self.export_term(item_type, None);
self.make_term_apply(model::CORE_LIST_TYPE, &[item_type])
}
Term::TupleType(item_types) => {
Term::TupleKind(item_types) => {
let item_types = self.export_term(item_types, None);
self.make_term_apply(model::CORE_TUPLE_TYPE, &[item_types])
}
Term::RuntimeExtension(ext) => self.export_custom_type(ext),
Term::RuntimeFunction(func) => {
Term::ExtensionType(ext) => self.export_custom_type(ext),
Term::FunctionType(func) => {
self.export_func_type(func, |this, trv| this.export_term(trv, None))
}
Term::RuntimeSum(sum) => self.export_sum_type(sum),
Term::SumType(sum) => self.export_sum_type(sum),

Term::BoundedNat(value) => self.make_term(model::Literal::Nat(*value).into()),
Term::String(value) => self.make_term(model::Literal::Str(value.into()).into()),
Expand Down Expand Up @@ -1005,8 +1005,8 @@ impl<'a> Context<'a> {
self.make_term(table::Term::Tuple(parts))
}
Term::Variable(v) => self.export_type_arg_var(v),
Term::StaticType => self.make_term_apply(model::CORE_STATIC, &[]),
Term::ConstType(ty) => {
Term::StaticKind => self.make_term_apply(model::CORE_STATIC, &[]),
Term::ConstKind(ty) => {
let ty = self.export_type(ty);
self.make_term_apply(model::CORE_CONST, &[ty])
}
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/extension/declarative/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,6 @@ impl TypeParamDeclaration {
_extension: &Extension,
_ctx: DeclarationContext<'_>,
) -> Result<TypeParam, ExtensionDeclarationError> {
Ok(TypeParam::StringType)
Ok(TypeParam::StringKind)
}
}
16 changes: 8 additions & 8 deletions hugr-core/src/extension/op_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use crate::Hugr;
use crate::envelope::serde_with::AsBinaryEnvelope;
use crate::ops::{OpName, OpNameRef};
use crate::package::Package;
use crate::types::type_param::{TypeArg, TypeParam, check_term_types};
use crate::types::type_param::{TypeArg, TypeParam, check_term_kinds};
use crate::types::{FuncValueType, PolyFuncType, PolyFuncTypeRV, Signature};
mod serialize_signature_func;

Expand Down Expand Up @@ -254,7 +254,7 @@ impl SignatureFunc {
let static_params = func.static_params();
let (static_args, other_args) = args.split_at(min(static_params.len(), args.len()));

check_term_types(static_args, static_params)?;
check_term_kinds(static_args, static_params)?;
temp = func.compute_signature(static_args, def)?;
(&temp, other_args)
}
Expand Down Expand Up @@ -406,7 +406,7 @@ impl OpDef {
let (static_args, other_args) =
args.split_at(min(custom.static_params().len(), args.len()));
static_args.iter().try_for_each(|ta| ta.validate(&[]))?;
check_term_types(static_args, custom.static_params())?;
check_term_kinds(static_args, custom.static_params())?;
temp = custom.compute_signature(static_args, self)?;
(&temp, other_args)
}
Expand All @@ -416,7 +416,7 @@ impl OpDef {
}
};
args.iter().try_for_each(|ta| ta.validate(var_decls))?;
check_term_types(args, pf.params())?;
check_term_kinds(args, pf.params())?;
Ok(())
}

Expand Down Expand Up @@ -716,7 +716,7 @@ pub(super) mod test {
const OP_NAME: OpName = OpName::new_inline("Reverse");

let ext = Extension::try_new_test_arc(EXT_ID, |ext, extension_ref| {
const TP: TypeParam = TypeParam::RuntimeType(TypeBound::Linear);
const TP: TypeParam = TypeParam::TypeKind(TypeBound::Linear);
let list_of_var =
Type::new_extension(list_def.instantiate(vec![TypeArg::new_var_use(0, TP)])?);
let type_scheme = PolyFuncTypeRV::new(vec![TP], Signature::new_endo([list_of_var]));
Expand Down Expand Up @@ -762,7 +762,7 @@ pub(super) mod test {
&self,
arg_values: &[TypeArg],
) -> Result<PolyFuncTypeRV, SignatureError> {
const TP: TypeParam = TypeParam::RuntimeType(TypeBound::Linear);
const TP: TypeParam = TypeParam::TypeKind(TypeBound::Linear);
let [TypeArg::BoundedNat(n)] = arg_values else {
return Err(SignatureError::InvalidTypeArgs);
};
Expand All @@ -777,7 +777,7 @@ pub(super) mod test {
}

fn static_params(&self) -> &[TypeParam] {
const MAX_NAT: &[TypeParam] = &[TypeParam::max_nat_type()];
const MAX_NAT: &[TypeParam] = &[TypeParam::max_nat_kind()];
MAX_NAT
}
}
Expand Down Expand Up @@ -820,7 +820,7 @@ pub(super) mod test {
);

// First arg must be concrete, not a variable
let kind = TypeParam::bounded_nat_type(NonZeroU64::new(5).unwrap());
let kind = TypeParam::bounded_nat_kind(NonZeroU64::new(5).unwrap());
let args = [TypeArg::new_var_use(0, kind.clone()), usize_t().into()];
// We can't prevent this from getting into our compute_signature implementation:
assert_eq!(
Expand Down
8 changes: 4 additions & 4 deletions hugr-core/src/extension/prelude.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ pub static PRELUDE: LazyLock<Arc<Extension>> = LazyLock::new(|| {
.unwrap();
let panic_exit_sig = PolyFuncTypeRV::new(
[
TypeParam::new_list_type(TypeBound::Linear),
TypeParam::new_list_type(TypeBound::Linear),
TypeParam::new_list_kind(TypeBound::Linear),
TypeParam::new_list_kind(TypeBound::Linear),
],
FuncValueType::new(
TypeRowRV::from([Type::new_extension(error_type.clone())])
Expand Down Expand Up @@ -624,7 +624,7 @@ impl MakeOpDef for TupleOpDef {
let rv = TypeRowRV::new_var_use(0, TypeBound::Linear);
let tuple_type = Type::new_tuple(rv.clone());

let param = TypeParam::new_list_type(TypeBound::Linear);
let param = TypeParam::new_list_kind(TypeBound::Linear);
match self {
TupleOpDef::MakeTuple => {
PolyFuncTypeRV::new([param], FuncValueType::new(rv, [tuple_type]))
Expand Down Expand Up @@ -893,7 +893,7 @@ impl MakeOpDef for BarrierDef {

fn init_signature(&self, _extension_ref: &Weak<Extension>) -> SignatureFunc {
PolyFuncTypeRV::new(
vec![TypeParam::new_list_type(TypeBound::Linear)],
vec![TypeParam::new_list_kind(TypeBound::Linear)],
FuncValueType::new_endo(TypeRowRV::new_var_use(0, TypeBound::Linear)),
)
.into()
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/extension/prelude/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl MakeOpDef for LoadNatDef {

fn init_signature(&self, _extension_ref: &Weak<Extension>) -> SignatureFunc {
let usize_t: Type = usize_custom_t(_extension_ref).into();
let params = vec![TypeParam::max_nat_type()];
let params = vec![TypeParam::max_nat_kind()];
PolyFuncTypeRV::new(params, FuncValueType::new(type_row![], vec![usize_t])).into()
}

Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/extension/resolution/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ fn resolve_custom_const(#[case] custom_const: impl CustomConst) {
#[rstest]
fn resolve_call() {
let dummy_fn_sig = PolyFuncType::new(
vec![TypeParam::RuntimeType(TypeBound::Linear)],
vec![TypeParam::TypeKind(TypeBound::Linear)],
Signature::new(vec![], vec![bool_t()]),
);

Expand Down
26 changes: 13 additions & 13 deletions hugr-core/src/extension/resolution/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ pub(crate) fn collect_term_exts(
missing_extensions: &mut ExtensionSet,
) {
match term {
Term::RuntimeExtension(custom) => {
Term::ExtensionType(custom) => {
for arg in custom.args() {
collect_term_exts(arg, used_extensions, missing_extensions);
}
Expand All @@ -201,16 +201,16 @@ pub(crate) fn collect_term_exts(
}
}
}
Term::RuntimeFunction(f) => {
Term::FunctionType(f) => {
collect_term_exts(&f.input, used_extensions, missing_extensions);
collect_term_exts(&f.output, used_extensions, missing_extensions);
}
Term::RuntimeSum(SumType::General { rows }) => {
Term::SumType(SumType::General { rows }) => {
for row in rows {
collect_term_exts(row, used_extensions, missing_extensions);
}
}
Term::ConstType(ty) => collect_term_exts(ty, used_extensions, missing_extensions),
Term::ConstKind(ty) => collect_term_exts(ty, used_extensions, missing_extensions),
Term::List(elems) => {
for elem in elems.iter() {
collect_term_exts(elem, used_extensions, missing_extensions);
Expand All @@ -221,10 +221,10 @@ pub(crate) fn collect_term_exts(
collect_term_exts(elem, used_extensions, missing_extensions);
}
}
Term::ListType(item_type) => {
Term::ListKind(item_type) => {
collect_term_exts(item_type, used_extensions, missing_extensions)
}
Term::TupleType(item_types) => {
Term::TupleKind(item_types) => {
collect_term_exts(item_types, used_extensions, missing_extensions)
}
Term::ListConcat(lists) => {
Expand All @@ -238,17 +238,17 @@ pub(crate) fn collect_term_exts(
}
}
Term::Variable(_)
| Term::RuntimeType(_)
| Term::StaticType
| Term::BoundedNatType(_)
| Term::StringType
| Term::BytesType
| Term::FloatType
| Term::TypeKind(_)
| Term::StaticKind
| Term::BoundedNatKind(_)
| Term::StringKind
| Term::BytesKind
| Term::FloatKind
| Term::BoundedNat(_)
| Term::String(_)
| Term::Bytes(_)
| Term::Float(_)
| Term::RuntimeSum(SumType::Unit { .. }) => {}
| Term::SumType(SumType::Unit { .. }) => {}
}
}

Expand Down
26 changes: 13 additions & 13 deletions hugr-core/src/extension/resolution/types_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,18 @@ pub(super) fn resolve_term_exts(
used_extensions: &mut WeakExtensionRegistry,
) -> Result<(), ExtensionResolutionError> {
match term {
Term::RuntimeExtension(custom) => {
Term::ExtensionType(custom) => {
resolve_custom_type_exts(node, custom, extensions, used_extensions)?;
}
Term::RuntimeFunction(f) => {
Term::FunctionType(f) => {
resolve_func_type_exts(node, &mut *f, extensions, used_extensions)?;
}
Term::RuntimeSum(SumType::General { rows }) => {
Term::SumType(SumType::General { rows }) => {
for row in rows.iter_mut() {
resolve_typerow_rv_exts(node, row, extensions, used_extensions)?;
}
}
Term::ConstType(ty) => resolve_type_exts(node, ty, extensions, used_extensions)?,
Term::ConstKind(ty) => resolve_type_exts(node, ty, extensions, used_extensions)?,
Term::List(children)
| Term::ListConcat(children)
| Term::Tuple(children)
Expand All @@ -257,24 +257,24 @@ pub(super) fn resolve_term_exts(
resolve_term_exts(node, child, extensions, used_extensions)?;
}
}
Term::ListType(item_type) => {
Term::ListKind(item_type) => {
resolve_term_exts(node, item_type.as_mut(), extensions, used_extensions)?;
}
Term::TupleType(item_types) => {
Term::TupleKind(item_types) => {
resolve_term_exts(node, item_types.as_mut(), extensions, used_extensions)?;
}
Term::Variable(_)
| Term::RuntimeType(_)
| Term::StaticType
| Term::BoundedNatType(_)
| Term::StringType
| Term::BytesType
| Term::FloatType
| Term::TypeKind(_)
| Term::StaticKind
| Term::BoundedNatKind(_)
| Term::StringKind
| Term::BytesKind
| Term::FloatKind
| Term::BoundedNat(_)
| Term::String(_)
| Term::Bytes(_)
| Term::Float(_)
| Term::RuntimeSum(SumType::Unit { .. }) => {}
| Term::SumType(SumType::Unit { .. }) => {}
}
Ok(())
}
Expand Down
10 changes: 5 additions & 5 deletions hugr-core/src/extension/type_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use super::{Extension, ExtensionId, SignatureError};

use crate::types::{CustomType, TypeName, least_upper_bound};

use crate::types::type_param::{TypeArg, check_term_types};
use crate::types::type_param::{TypeArg, check_term_kinds};

use crate::types::type_param::TypeParam;

Expand Down Expand Up @@ -79,7 +79,7 @@ pub struct TypeDef {
impl TypeDef {
/// Check provided type arguments are valid against parameters.
pub fn check_args(&self, args: &[TypeArg]) -> Result<(), SignatureError> {
Ok(check_term_types(args, &self.params)?)
Ok(check_term_kinds(args, &self.params)?)
}

/// Check [`CustomType`] is a valid instantiation of this definition.
Expand All @@ -102,7 +102,7 @@ impl TypeDef {
));
}

check_term_types(custom.type_args(), &self.params)?;
check_term_kinds(custom.type_args(), &self.params)?;

let calc_bound = self.bound(custom.args());
if calc_bound == custom.bound() {
Expand All @@ -123,7 +123,7 @@ impl TypeDef {
/// valid instances of the type parameters.
pub fn instantiate(&self, args: impl Into<Vec<TypeArg>>) -> Result<CustomType, SignatureError> {
let args = args.into();
check_term_types(&args, &self.params)?;
check_term_kinds(&args, &self.params)?;
let bound = self.bound(&args);
Ok(CustomType::new(
self.name().clone(),
Expand Down Expand Up @@ -249,7 +249,7 @@ mod test {
fn test_instantiate_typedef() {
let def = TypeDef {
name: "MyType".into(),
params: vec![TypeParam::RuntimeType(TypeBound::Copyable)],
params: vec![TypeParam::TypeKind(TypeBound::Copyable)],
extension: "MyRsrc".try_into().unwrap(),
// Dummy extension. Will return `None` when trying to upgrade it into an `Arc`.
extension_ref: Default::default(),
Expand Down
Loading
Loading