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

Can you LoadConstant a FuncDefn? #829

Closed
doug-q opened this issue Feb 1, 2024 · 3 comments
Closed

Can you LoadConstant a FuncDefn? #829

doug-q opened this issue Feb 1, 2024 · 3 comments

Comments

@doug-q
Copy link
Collaborator

doug-q commented Feb 1, 2024

For now you can't. This means that there is no means to pass a FuncDefn to a higher order function.

One does have an alternative, to define the to-be-LoadConstant-ed FuncDefn in a Const node, and to LoadConstant that. One expects the result of this would be for frontends to never generate FuncDefns when they had the choice.

#788 describes a related problem, whether non-local edges can enter FuncDefns and if so, what the semantics of that are.

Suggested changes:

  • Remove scoped definitions. This solves all issues of non-local edges entering FuncDefns, as well as interpreting Type Args in scenarios with nested FuncDefns.
  • Allow LoadConstant's static input edge to point to a FuncDefn.
  • Consider whether we still need Const nodes constaining hugrs
@doug-q doug-q added the P-high label Feb 1, 2024
@acl-cqc
Copy link
Contributor

acl-cqc commented Feb 2, 2024

Indeed there is nothing in the spec at the moment to prevent a LoadConstant's Static input being a FuncDefn rather than a Const, and yes, that would require allocation+closures if FuncDefns may have nonlocal edges entering them :-(.

We've suggested on #285 that we might change Static edges into two kinds - static values (from Consts), and function values (from FuncDefns). I think this would solve the problem here (as well as allowing to simplify the Type hierarchy so that all functions are monomorphic). It would require that we kept Const nodes containing Hugrs, however, I think these could be Tierkreis-extension CustomConsts (and CallIndirect in the Tierkreis extension too); the spec of how to link these Hugrs-inside-Consts can then be left to the Tierkreis extension too (whereas ATM that belongs in the main spec and is missing).

Re. scoped definitions, these were included so that rewrites (adding new Defns) could be kept local, rather than having to add FuncDefn's into a global table. I don't think we want to change that (@ss2165 ?). However, I think it's reasonable to have a rule about nonlocal edges, i.e. that the nodes that nonlocal Value edges may enter (i.e. the nodes that are hierarchy-ancestors of the target but not the source) be limited to DFG, Conditional, TailLoop, CFG, BasicBlock -- that is, no Defns (edges into graphs inside Consts are already ruled out).

@acl-cqc
Copy link
Contributor

acl-cqc commented Apr 15, 2024

I think #904 / #906 resolved this: you cannot LoadConstant a FuncDefn.

@acl-cqc
Copy link
Contributor

acl-cqc commented Apr 16, 2024

And now #935 and #936 address the rest - shall we close @doug-q ?

@doug-q doug-q closed this as completed Apr 16, 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