Skip to content

Commit

Permalink
visibility and nits
Browse files Browse the repository at this point in the history
  • Loading branch information
aborgna-q committed Dec 3, 2024
1 parent 751e4ad commit 88d8b25
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 20 deletions.
13 changes: 7 additions & 6 deletions hugr-core/src/extension/resolution/ops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,13 @@ pub(crate) fn update_op_extensions<'e>(
.into());
};

let ext_op = ExtensionOp::new_with_cached(def.clone(), opaque.args(), opaque, extensions)
.map_err(|e| OpaqueOpError::SignatureError {
node,
name: opaque.name().clone(),
cause: e,
})?;
let ext_op =
ExtensionOp::new_with_cached(def.clone(), opaque.args().to_vec(), opaque, extensions)
.map_err(|e| OpaqueOpError::SignatureError {
node,
name: opaque.name().clone(),
cause: e,
})?;

if opaque.signature() != ext_op.signature() {
return Err(OpaqueOpError::SignatureMismatch {
Expand Down
10 changes: 2 additions & 8 deletions hugr-core/src/extension/resolution/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::sync::Arc;
use super::{ExtensionRegistry, ExtensionResolutionError};
use crate::ops::OpType;
use crate::types::type_row::TypeRowBase;
use crate::types::{CustomType, MaybeRV, Signature, SumType, TypeBase, TypeEnum};
use crate::types::{MaybeRV, Signature, SumType, TypeBase, TypeEnum};
use crate::Node;

/// Replace the dangling extension pointer in the [`CustomType`]s inside a
Expand Down Expand Up @@ -157,13 +157,7 @@ fn update_type_exts<RV: MaybeRV>(
// Add the extension to the used extensions registry,
// and update the CustomType with the valid pointer.
used_extensions.register_updated_ref(ext);
*custom = CustomType::new(
custom.name().clone(),
custom.args(),
custom.extension().clone(),
custom.bound(),
&Arc::downgrade(ext),
);
custom.update_extension(Arc::downgrade(ext));
}
TypeEnum::Function(f) => {
update_type_row_exts(node, &mut f.input, extensions, used_extensions)?;
Expand Down
8 changes: 4 additions & 4 deletions hugr-core/src/ops/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ impl ExtensionOp {
/// If OpDef is missing binary computation, trust the cached signature.
pub(crate) fn new_with_cached(
def: Arc<OpDef>,
args: impl Into<Vec<TypeArg>>,
args: impl IntoIterator<Item = TypeArg>,
opaque: &OpaqueOp,
exts: &ExtensionRegistry,
) -> Result<Self, SignatureError> {
let args: Vec<TypeArg> = args.into();
let args: Vec<TypeArg> = args.into_iter().collect();
// TODO skip computation depending on config
// see https://github.com/CQCL/hugr/issues/1363
let signature = match def.compute_signature(&args, exts) {
Expand Down Expand Up @@ -113,7 +113,7 @@ impl ExtensionOp {
}

/// Returns a mutable reference to the cached signature of the operation.
pub(crate) fn signature_mut(&mut self) -> &mut Signature {
pub fn signature_mut(&mut self) -> &mut Signature {
&mut self.signature
}
}
Expand Down Expand Up @@ -209,7 +209,7 @@ impl OpaqueOp {
}

/// Returns a mutable reference to the signature of the operation.
pub(crate) fn signature_mut(&mut self) -> &mut Signature {
pub fn signature_mut(&mut self) -> &mut Signature {
&mut self.signature
}
}
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ impl<RV: MaybeRV> TypeBase<RV> {

/// Report a mutable reference to the component TypeEnum.
#[inline(always)]
pub(crate) fn as_type_enum_mut(&mut self) -> &mut TypeEnum<RV> {
pub fn as_type_enum_mut(&mut self) -> &mut TypeEnum<RV> {
&mut self.0
}

Expand Down
5 changes: 5 additions & 0 deletions hugr-core/src/types/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ impl CustomType {
pub fn extension_ref(&self) -> Weak<Extension> {
self.extension_ref.clone()
}

/// Update the internal extension reference with a new weak pointer.
pub fn update_extension(&mut self, extension_ref: Weak<Extension>) {
self.extension_ref = extension_ref;
}
}

impl Display for CustomType {
Expand Down
2 changes: 1 addition & 1 deletion hugr-core/src/types/poly_func.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ impl<RV: MaybeRV> PolyFuncTypeBase<RV> {
}

/// Returns a mutable reference to the body of the function type.
pub(crate) fn body_mut(&mut self) -> &mut FuncTypeBase<RV> {
pub fn body_mut(&mut self) -> &mut FuncTypeBase<RV> {
&mut self.body
}
}
Expand Down

0 comments on commit 88d8b25

Please sign in to comment.