-
Notifications
You must be signed in to change notification settings - Fork 6
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(tket2-hseries)!: Add tket2.wasm
extension
#737
base: main
Are you sure you want to change the base?
Conversation
BREAKING CHANGE: Change the signature of `FutureOpBuilder::add_read` to return a `Wire` instead of a `[Wire;1]`
tket2.wasm
extensiontket2.wasm
extension
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #737 +/- ##
==========================================
- Coverage 82.62% 82.33% -0.29%
==========================================
Files 62 63 +1
Lines 7234 7661 +427
Branches 6978 7405 +427
==========================================
+ Hits 5977 6308 +331
- Misses 883 963 +80
- Partials 374 390 +16
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @doug-q! It's always very fun to read your code, I learn a lot.
I don't have much useful feedback, other than that your design seems perfectly sound!
lazy_static! { | ||
/// The `tket2.wasm` extension. | ||
pub static ref EXTENSION: Arc<Extension> = Extension::new_arc(EXTENSION_ID, EXTENSION_VERSION, |ext, ext_ref| { | ||
ext.add_requirements(ExtensionSet::from_iter([futures::EXTENSION_ID, PRELUDE_ID])); | ||
add_wasm_type_defs(ext, ext_ref).unwrap(); | ||
WasmOpDef::load_all_ops(ext, ext_ref, ).unwrap(); | ||
}); | ||
|
||
/// A [Weak] reference to the `tket2.wasm` op. | ||
pub static ref EXTENSION_REF: Weak<Extension> = Arc::downgrade(&EXTENSION); | ||
|
||
/// Extension registry including the "tket2.wasm" extension and | ||
/// dependencies. | ||
pub static ref REGISTRY: ExtensionRegistry = ExtensionRegistry::new([ | ||
EXTENSION.to_owned(), | ||
futures::EXTENSION.to_owned(), | ||
PRELUDE.to_owned() | ||
]); | ||
|
||
/// The name of the `tket2.wasm.module` type. | ||
pub static ref MODULE_TYPE_NAME: SmolStr = SmolStr::new_inline("module"); | ||
/// The name of the `tket2.wasm.context` type. | ||
pub static ref CONTEXT_TYPE_NAME: SmolStr = SmolStr::new_inline("context"); | ||
/// The name of the `tket2.wasm.func` type. | ||
pub static ref FUNC_TYPE_NAME: SmolStr = SmolStr::new_inline("func"); | ||
|
||
/// The [TypeParam] of `tket2.wasm.lookup` specifying the name of the function. | ||
pub static ref NAME_PARAM: TypeParam = TypeParam::String; | ||
/// The [TypeParam] of various types and ops specifying the input signature of a function. | ||
pub static ref INPUTS_PARAM: TypeParam = TypeParam::List { param: Box::new(TypeBound::Any.into()) }; | ||
/// The [TypeParam] of various types and ops specifying the output signature of a function. | ||
pub static ref OUTPUTS_PARAM: TypeParam = TypeParam::List { param: Box::new(TypeBound::Any.into()) }; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might be that cargo fmt-ing this without the macro will break up some of the lines that are looking quite long at the moment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good tip, will do
/// | ||
/// This will fail if `arg` is of non-type kind (e.g. String), | ||
/// or if `arg` contains row variables. | ||
/// TODO move this to `impl TypeArg` in `hugr-core` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you leaving this here for the moment because you do not want to make changes to hugr-core
right now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's more that I don't to condition this PR on a hugr release. I'll update to reference CQCL/hugr#1837
INPUTS_PARAM.to_owned(), | ||
OUTPUTS_PARAM.to_owned(), | ||
], | ||
Signature::new(vec![module_type], vec![func_type]), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm a noob when it comes to define (parametrised) type signatures, so take this with a grain of salt. I notice that Self::lookup
and Self::call
use different ways to define the signatures returned, even though superficially they seem quite similar to me (Signature::new
vs FuncValueType::new
, Type
vs WasmType
etc)...
It would make it more readable if both code blocks were as similar as possible. If you can't use the same function calls & types for whatever reason, then maybe just put the respective function signatures in a comment -- it took me awhile to parse what they meant and had to refer several times back to the module docs (which were supremely useful btw).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add comments as you suggest. re Signature + FuncValueType: the difference is that FuncValueType is allowed to have row variables in its input/output rows, while Signature must not (because we need to be able to count its ports).
Lookup returns a FuncValueType, while the callee of Call must have a signature (so that call can have a matching signature.
It's not urgent for us to merge this. Before we merge:
|
The extension design looks good to me 👍 Just to clarify, the |
I had seen it as ordering all wasm calls (it's linear), but yes tracking global state too. For |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, add to
tket2/tket2-hseries/src/bin/tket2-hseries.rs
Lines 9 to 10 in 99c7678
CliArgs::GenExtensions(args) => { | |
let reg = ExtensionRegistry::new([ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would strongly prefer to separate out the breaking change in to a separate commit to main
Co-authored-by: Seyon Sivarajah <[email protected]>
Co-authored-by: Seyon Sivarajah <[email protected]>
BREAKING CHANGE: Change the signature of
FutureOpBuilder::add_read
to return aWire
instead of a[Wire;1]