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

FuncDefn uses wrong extension_reqs delta in inference #673

Closed
acl-cqc opened this issue Nov 10, 2023 · 1 comment · Fixed by #688
Closed

FuncDefn uses wrong extension_reqs delta in inference #673

acl-cqc opened this issue Nov 10, 2023 · 1 comment · Fixed by #688
Assignees
Labels
bug Something isn't working

Comments

@acl-cqc
Copy link
Contributor

acl-cqc commented Nov 10, 2023

  1. FuncDefn stores a FunctionType (inputs, outputs, extension_reqs) as the type of the function declared. This FunctionType is what you get from the static_output of the FuncDefn node.

  2. The FuncDefn node also has its own signature: FunctionType for its dataflow ports. Since it's not a dataflow node, this is:

    hugr/src/ops.rs

    Lines 189 to 191 in b256c2b

    fn signature(&self) -> FunctionType {
    Default::default()
    }

i.e. no ports, and empty-set extension reqs.

  1. In extension inference, we make the input/output extensions of the FuncDefn node equal to the extensions of the Input/Output nodes beneath it (FuncDefn is a DataflowParent just like BasicBlock, Dfg, etc.):

    hugr/src/extension/infer.rs

    Lines 277 to 284 in b256c2b

    if let Some([input, output]) = hugr.get_io(node) {
    for dir in Direction::BOTH {
    let m_input_node = self.make_or_get_meta(input, dir);
    self.add_constraint(m_input_node, Constraint::Equal(m_input));
    let m_output_node = self.make_or_get_meta(output, dir);
    self.add_constraint(m_output_node, Constraint::Equal(m_output));
    }
    }

  2. Also in inference, we use the FunctionType from step 2 (not step 1) to constrain the input/output extensions of the FuncDefn node:

    hugr/src/extension/infer.rs

    Lines 305 to 315 in b256c2b

    match node_type.signature() {
    // Input extensions are open
    None => {
    let delta = node_type.op_signature().extension_reqs;
    let c = if delta.is_empty() {
    Constraint::Equal(m_input)
    } else {
    Constraint::Plus(delta, m_input)
    };
    self.add_constraint(m_output, c);
    }

Putting 2,3,4 together we have that the body of the function must have a zero extension delta (Input and Output nodes of a FuncDefn are constrained to have equal extension requirements), ooops

@acl-cqc
Copy link
Contributor Author

acl-cqc commented Nov 10, 2023

To be honest I find it quite confusing that you can even get a value for input_extensions or delta/extension_reqs for a FuncDefn node....

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants