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

feat: Allow calling a tensor of functions #196

Merged
merged 46 commits into from
May 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
126468b
feat: Allow calling a tensor of functions
croyzor Apr 16, 2024
0943e68
cleanup: Remove redundant method
croyzor Apr 16, 2024
ead0212
refactor: Remove `FunctionTensor`
croyzor Apr 17, 2024
67b6b67
new: More robust function tensor types
croyzor May 1, 2024
1c45d47
Merge remote-tracking branch 'origin/main' into feat/tensor-call-only
croyzor May 1, 2024
525d028
Merge remote-tracking branch 'origin/main' into feat/tensor-call-only
croyzor May 1, 2024
8a49a3a
[fix] Substitution logic for checking tuples of functions
croyzor May 3, 2024
99e22d5
docs: Update comments
croyzor May 7, 2024
23b2769
refactor: Don't do anything special synthesising tuples
croyzor May 7, 2024
3744106
Merge remote-tracking branch 'origin/main' into feat/tensor-call-only
croyzor May 7, 2024
12153ca
fix: Revert `is_function` change for building hugr
croyzor May 7, 2024
a21a481
[refactor] Use type<->row helpers
croyzor May 7, 2024
e71321c
cleanup: Redundant code handled by generic_visit
croyzor May 7, 2024
d08e212
refactor: Remove redundant parse tensor calls
croyzor May 8, 2024
b5d5026
fix: Return the right substitution
croyzor May 8, 2024
d2267cb
fix: Throw user errors when unification fails
croyzor May 8, 2024
661f7e1
fix: More subst fixes
croyzor May 9, 2024
990d95f
fix: Use check_call instead of making a GlobalCall
croyzor May 9, 2024
bf73897
fix: Subst fix fixes
croyzor May 9, 2024
d7fb0ed
Simplify function tuple semantics: (f) != f
croyzor May 9, 2024
8c6ac05
cleanup: Remove redundant test
croyzor May 9, 2024
2e38476
cleanup: Remove redundant test
croyzor May 9, 2024
497daf9
fix: Bug in compiling calls of tuples
croyzor May 9, 2024
e70a7ac
cleanup: Remove special case for function tuples
croyzor May 9, 2024
88c4bf3
test: Add tests of calling tuple variables
croyzor May 9, 2024
39a9d72
new: Handle nested function tuples when compiling
croyzor May 9, 2024
69b8c59
Complain when we have to instantiate in tuple call
croyzor May 9, 2024
70e3db3
cleanup: Remove TensorCall node
croyzor May 9, 2024
7a87729
Merge remote-tracking branch 'origin/main' into feat/tensor-call-only
croyzor May 9, 2024
7a12f75
cleanup: Undo changes adding _with_leftovers fns
croyzor May 9, 2024
87f404c
test: Add tests for function tensor errors
croyzor May 9, 2024
16fd3b5
Update guppylang/compiler/expr_compiler.py
croyzor May 9, 2024
22f2cc6
big_subst -> subst
croyzor May 9, 2024
b3fe317
refactor: check for parametrized fns earlier
croyzor May 10, 2024
34c1953
Revert "cleanup: Remove TensorCall node"
croyzor May 10, 2024
b0de9a8
refactor: Bring back a TensorCall for compiling
croyzor May 10, 2024
e1a9bfa
Merge remote-tracking branch 'origin/main' into feat/tensor-call-only
croyzor May 14, 2024
219fd96
fix: Add out_tys to TensorCall; pack correct types
croyzor May 14, 2024
b89275d
tests: Add a test
croyzor May 14, 2024
e68fe5c
fix: Add missing loc to poly tensor errors
croyzor May 14, 2024
45b62b4
fix: Remove file path in golden test
croyzor May 14, 2024
611b84d
Update guppylang/checker/expr_checker.py
croyzor May 14, 2024
f618f66
refactor: Simplify type synth logic for tuple calls
croyzor May 14, 2024
36d98df
feat: Change check_call location for better errors
croyzor May 14, 2024
7c73c10
fix: Add missing out_tys param in synth TensorCall
croyzor May 14, 2024
0373dc6
cleanup: Remove duplicate checks
croyzor May 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions guppylang/checker/expr_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,9 @@ def visit_Call(self, node: ast.Call, ty: Type) -> tuple[ast.expr, Subst]:
node.func = instantiate_poly(node.func, func_ty, inst)
return with_loc(node, LocalCall(func=node.func, args=args)), return_ty

if isinstance(func_ty, TupleType) and parse_function_tensor(func_ty):
function_elements = parse_function_tensor(func_ty)
if isinstance(func_ty, TupleType) and (
function_elements := parse_function_tensor(func_ty)
):
Comment on lines +245 to +247
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing to note: An empty function_elements lists also evaluate to False which means we can't call empty tuples. But I think that's fine, the expression ()() isn't that useful :D

assert isinstance(function_elements, list)
croyzor marked this conversation as resolved.
Show resolved Hide resolved
tensor_ty = function_tensor_signature(function_elements)
mark-koch marked this conversation as resolved.
Show resolved Hide resolved

Expand Down Expand Up @@ -572,12 +573,11 @@ def visit_Call(self, node: ast.Call) -> tuple[ast.expr, Type]:
return with_loc(node, LocalCall(func=node.func, args=args)), return_ty
elif (
isinstance(ty, TupleType)
and parse_function_tensor(ty)
and (function_elems := parse_function_tensor(ty))
and isinstance(node.func, ast.Tuple)
):
# Note: None of the function types in a tuple of functions will have
# overlapping type arguments.
function_elems = parse_function_tensor(ty)
assert isinstance(function_elems, list)
func_ty = function_tensor_signature(function_elems)
remaining_args = node.args
Expand Down