Skip to content
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

bug: Two call nodes for the same function must have matching resources #695

Closed
croyzor opened this issue Nov 15, 2023 · 4 comments
Closed
Assignees

Comments

@croyzor
Copy link
Contributor

croyzor commented Nov 15, 2023

Because of the way FuncDefns are handled in extension inference, they have extension sets which will try to be matched with the extensions at their call sites. Meaning that if there are two calls of the same function, the FuncDefn's extensions will be solved to match one of the call nodes, and the other will probably throw an error.

The branch call-bug adds a test case demonstrating the erroneous behaviour.

@acl-cqc
Copy link
Contributor

acl-cqc commented Nov 17, 2023

So I think one possible/suggested solution was to split EdgeKind::Static into EdgeKind::Function (ignored during inference) and EdgeKind::Const (generating Equals constraints), not sure how easy/workable that is tho

@acl-cqc
Copy link
Contributor

acl-cqc commented Nov 17, 2023

A very similar situation exists if I have a Const and two LoadConstants - the two must have the same extensions. However - unlike the case with Call - in the LoadConstant case we can work around the problem by adding a Lift node after the LoadConstant (on the Value out-edge, not the Static in-edge), because there are no other inputs whose extensions may conflict.

@acl-cqc
Copy link
Contributor

acl-cqc commented Nov 17, 2023

....but the best way to look at that may be - if we have a good solution for Call then perhaps we can generalize to handle LoadConstant (which is a lot like a 0-args Call) the same way, potentially avoiding the need for Lift nodes after LoadConstant

github-merge-queue bot pushed a commit that referenced this issue Nov 21, 2023
* Change FuncDecl and FuncDefn from storing FunctionType to PolyFuncType
* Change `declare_function` and other builder methods to take
PolyFuncType rather than Signature. The input-extensions of the
Signature were only used for the FuncDefn node itself and it seems
saner, and tests pass ok, for the builder to set the input-extensions of
the FuncDefn node itself to pure==empty in all cases. Note this makes
#695 slightly even more severe, but I feel we should just take this into
account when fixing that bug.
* Much of the bulk of the PR is thus changing
(someFunctionType)`.pure()` to `.into()`...
* Restructure validation. Break out the op-type specific checks that
type args were declared, into a hierarchical traversal (rather than
iterating over the Hugr's nodes), so they can gather binders from the
nearest enclosing FuncDefn (potentially several levels above in the
hierarchy). Move `validate_port` (and hence `validate_edge`) here
because ports/edges inside a FuncDefn may have types using its
parameters.
* Also do not allow Static edges to refer to TVs declared outside. (The
Static edge from a polymorphic FuncDefn contains a PolyFuncType i.e.
declaring its own type vars, so they are not free.)
* Update OpDef to properly check_args etc. reflecting that we may need
to pass some args to the binary function and then more args to the
*returned* PolyFuncType.
   * Also drop `impl TypeParametrised for OpDef`
* Add TypeArgs to Call, and builder `fn call()`; also give the latter an
ExtensionRegistry argument
* Finally add `impl From<TypeBound> for TypeParam`, which we probably
should have done much earlier.
@acl-cqc acl-cqc assigned acl-cqc and unassigned croyzor Jun 13, 2024
@acl-cqc
Copy link
Contributor

acl-cqc commented Jun 13, 2024

I believe this was fixed by #1142

@acl-cqc acl-cqc closed this as completed Jun 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants