Skip to content

Commit

Permalink
builder fn call takes TypeArgs - and ExtensionRegistry, ugh
Browse files Browse the repository at this point in the history
  • Loading branch information
acl-cqc committed Nov 13, 2023
1 parent b781155 commit c56e8c2
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
15 changes: 12 additions & 3 deletions src/builder/build_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ use crate::{
};

use crate::extension::{ExtensionRegistry, ExtensionSet, PRELUDE_REGISTRY};
use crate::types::{FunctionType, PolyFuncType, Type, TypeRow};
use crate::types::{FunctionType, PolyFuncType, Type, TypeArg, TypeRow};

use itertools::Itertools;

Expand Down Expand Up @@ -595,7 +595,9 @@ pub trait Dataflow: Container {
fn call<const DEFINED: bool>(
&mut self,
function: &FuncID<DEFINED>,
type_args: &[TypeArg],
input_wires: impl IntoIterator<Item = Wire>,
exts: &ExtensionRegistry, // TODO remove?
) -> Result<BuildHandle<DataflowOpID>, BuildError> {
let hugr = self.hugr();
let def_op = hugr.get_optype(function.node());
Expand All @@ -609,9 +611,16 @@ pub trait Dataflow: Container {
})
}
};
let signature = type_scheme.body;
// TODO either some way of returning a SignatureError without a node (as its not
// constructed yet) - or, preferably, a way to "instantiate" the PolyFuncType without
// validating against an ExtensionRegistry.
let signature = type_scheme.instantiate(type_args, exts).map_err(|e| {
BuildError::InvalidHUGR(ValidationError::SignatureError {
node: function.node(),
cause: e,
})
})?;
let const_in_port = signature.output.len();
// TODO ALAN this is totally broken for polymorphic functions. Need to TypeApply here.
let op_id = self.add_dataflow_op(ops::Call { signature }, input_wires)?;
let src_port = self.hugr_mut().num_outputs(function.node()) - 1;

Expand Down
7 changes: 4 additions & 3 deletions src/builder/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod test {
test::{n_identity, NAT},
Dataflow, DataflowSubContainer,
},
extension::EMPTY_REG,
extension::{EMPTY_REG, PRELUDE_REGISTRY},
type_row,
types::FunctionType,
};
Expand All @@ -186,7 +186,7 @@ mod test {
)?;

let mut f_build = module_builder.define_declaration(&f_id)?;
let call = f_build.call(&f_id, f_build.input_wires())?;
let call = f_build.call(&f_id, &[], f_build.input_wires(), &PRELUDE_REGISTRY)?;

f_build.finish_with_outputs(call.outputs())?;
module_builder.finish_prelude_hugr()
Expand Down Expand Up @@ -234,7 +234,8 @@ mod test {
let [wire] = local_build.input_wires_arr();
let f_id = local_build.finish_with_outputs([wire])?;

let call = f_build.call(f_id.handle(), f_build.input_wires())?;
let call =
f_build.call(f_id.handle(), &[], f_build.input_wires(), &PRELUDE_REGISTRY)?;

f_build.finish_with_outputs(call.outputs())?;
module_builder.finish_prelude_hugr()
Expand Down

0 comments on commit c56e8c2

Please sign in to comment.