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: Add polymorphism #61

Merged
merged 97 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 96 commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
414dbf1
Factor out checking code
mark-koch Nov 21, 2023
bba9c96
Factor out graph generation code
mark-koch Nov 21, 2023
eb1a327
Update cfg
mark-koch Nov 21, 2023
4390ddd
Update files
mark-koch Nov 21, 2023
d48a149
Add statement compiler
mark-koch Nov 21, 2023
a5d51e1
Moves custom AST nodes to separate file
mark-koch Nov 21, 2023
3edaa00
Add custom funcs, replacing extensions
mark-koch Nov 21, 2023
de2508f
Factor out decorator from module code
mark-koch Nov 21, 2023
f9033fd
Reimplement prelude
mark-koch Nov 21, 2023
5fb37d0
Remove unused files
mark-koch Nov 21, 2023
18222ed
Fix tests
mark-koch Nov 21, 2023
6db0327
Remove unused imports
mark-koch Nov 21, 2023
8616f6b
Run formatting
mark-koch Nov 21, 2023
de454bd
Rename guppy_types to types
mark-koch Nov 21, 2023
4dba8a7
Make node optional for type building
mark-koch Nov 21, 2023
3b0d0f4
Get rid of NotImplementedCompiler
mark-koch Nov 22, 2023
b7ccf59
Make base_checker in ReversingChecker optional
mark-koch Nov 22, 2023
c4bcbea
Add unsupported builtins
mark-koch Nov 22, 2023
ab599bc
Rename types to gtypes
mark-koch Nov 22, 2023
f7be21d
Split up into multiple PRs
mark-koch Nov 22, 2023
871b14c
Add type checking code
mark-koch Nov 22, 2023
aa33857
Add _internal file
mark-koch Nov 22, 2023
aabc6ca
Fix formatting
mark-koch Nov 22, 2023
21585fa
Work on polymorphism
mark-koch Nov 24, 2023
b0f482e
Merge remote-tracking branch 'origin/refactor/compilation-stages' int…
mark-koch Nov 24, 2023
497cd23
refactor: Move graph generation code (#59)
mark-koch Nov 24, 2023
0f1c428
Merge remote-tracking branch 'origin/refactor/compilation-stages' int…
mark-koch Nov 24, 2023
62dbf26
Merge remote-tracking branch 'origin/stages/check' into feat/poly
mark-koch Nov 24, 2023
a3ba236
Fix add_input_with_ports
mark-koch Nov 24, 2023
0851fd6
Merge remote-tracking branch 'origin/refactor/compilation-stages' int…
mark-koch Nov 24, 2023
0b4ee03
Make CustomCallChecker.check abstract again
mark-koch Nov 24, 2023
babe9be
Merge remote-tracking branch 'origin/stages/check' into feat/poly
mark-koch Nov 24, 2023
c26aa2e
Fix type parsing
mark-koch Nov 24, 2023
35739a8
Compile TypeApply as dummy node
mark-koch Nov 24, 2023
8cf7e1e
Try synthesis before checking calls
mark-koch Nov 27, 2023
a9238ec
Fix annotated assign statement
mark-koch Nov 27, 2023
708ab55
Merge remote-tracking branch 'origin/refactor/compilation-stages' int…
mark-koch Nov 27, 2023
96d96b1
Merge remote-tracking branch 'origin/stages/check' into feat/poly
mark-koch Nov 27, 2023
3af488f
Factor out polymorphic checking code
mark-koch Nov 27, 2023
ed23fa3
Fix polymorphic type parsing
mark-koch Nov 27, 2023
d252bca
Run formatting
mark-koch Nov 27, 2023
1dd9d2b
Improve docstrings and specialise inference error
mark-koch Nov 27, 2023
4eba3dc
feat: Add builtins module (#60)
mark-koch Nov 27, 2023
d6982d5
Fix mypy issues
mark-koch Nov 27, 2023
3e89ac8
Run formatting
mark-koch Nov 27, 2023
6ea1df5
Merge remote-tracking branch 'origin/refactor/compilation-stages' int…
mark-koch Nov 27, 2023
ebd9e88
Merge remote-tracking branch 'origin/stages/check' into feat/poly
mark-koch Nov 27, 2023
b9c81ef
Add missing check method
mark-koch Nov 27, 2023
867e982
Merge remote-tracking branch 'origin/refactor/compilation-stages' int…
mark-koch Nov 27, 2023
0945904
Merge remote-tracking branch 'origin/stages/check' into feat/poly
mark-koch Nov 27, 2023
2aed4bf
Add some tests
mark-koch Nov 27, 2023
9e89ce1
Merge remote-tracking branch 'origin/main' into refactor/compilation-…
mark-koch Nov 27, 2023
d09ce09
Merge remote-tracking branch 'origin/refactor/compilation-stages' int…
mark-koch Nov 27, 2023
a39389c
Fix add_input_with_ports
mark-koch Nov 27, 2023
8aea545
Remove unused import
mark-koch Nov 27, 2023
05dc741
Merge branch 'refactor/compilation-stages' into stages/check
mark-koch Nov 27, 2023
b2ad478
Remove unused import
mark-koch Nov 27, 2023
022ef1a
Merge remote-tracking branch 'origin/stages/check' into feat/poly
mark-koch Nov 27, 2023
c3b1228
Fix small issues
mark-koch Nov 27, 2023
a83fff5
Make everything work with Hugr
mark-koch Nov 27, 2023
559469b
Add type args to CoercingChecker
mark-koch Nov 27, 2023
8da2b4a
Make non-linear args copyable
mark-koch Nov 27, 2023
9a0647f
Protect instantiated tuples from being turned into rows
mark-koch Nov 28, 2023
05fe2e5
Add more tests
mark-koch Nov 28, 2023
9bbfc86
Run formatting
mark-koch Nov 28, 2023
b1bdbe6
Store free vars in set instead of dict
mark-koch Nov 28, 2023
b52230b
Respect linearity
mark-koch Nov 28, 2023
506398f
Add more tests
mark-koch Nov 28, 2023
61e2cba
Detect unused linear expressions
mark-koch Nov 28, 2023
aface01
Fix UnknownFunctionType
mark-koch Nov 30, 2023
7269ea3
Run formatting
mark-koch Nov 30, 2023
302e2aa
Improve synthesize_call docstring
mark-koch Nov 30, 2023
145c6aa
Add module docstrings
mark-koch Nov 30, 2023
6b833cb
Rename cfg to containing_cfg
mark-koch Nov 30, 2023
29c6009
Improve check for entry BB
mark-koch Nov 30, 2023
2a3d01b
Merge branch 'stages/check' into feat/poly
mark-koch Nov 30, 2023
f982901
Use booly value of list
mark-koch Dec 4, 2023
55d7271
Use contextlib suppress
mark-koch Dec 4, 2023
6e3c2f3
Fix typo
mark-koch Dec 4, 2023
dacc31f
Clarify comment
mark-koch Dec 4, 2023
a872eed
Clarify docstring
mark-koch Dec 4, 2023
43e25e3
Align op table
mark-koch Dec 4, 2023
4de95e8
Specify type: ignore
mark-koch Dec 4, 2023
34db487
Improve error message wording
mark-koch Dec 4, 2023
c522771
Use pattern matches
mark-koch Dec 4, 2023
f930ecc
Turn assert into exception
mark-koch Dec 4, 2023
f5e60cf
Specify type: ignore
mark-koch Dec 4, 2023
2f29f2f
Fix CI
mark-koch Dec 4, 2023
e09dda1
Merge branch 'stages/check' into feat/poly
mark-koch Dec 5, 2023
6765fd8
Merge remote-tracking branch 'origin/main' into feat/poly
mark-koch Dec 5, 2023
91bb0eb
Merge remote-tracking branch 'origin/main' into feat/poly
mark-koch Dec 11, 2023
325dd25
Fix linting
mark-koch Dec 11, 2023
f29ae3c
Improve ExprChecker docstring
mark-koch Jan 3, 2024
40bd94a
Fix error column offset
mark-koch Jan 3, 2024
3eedefb
Merge remote-tracking branch 'origin/main' into feat/poly
mark-koch Jan 9, 2024
876a5de
Rename FreeTypeVar to ExistentialTypeVar and free_vars to unsolved_vars
mark-koch Jan 9, 2024
618f20b
Clarify TypeApplication docstring
mark-koch Jan 9, 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
16 changes: 14 additions & 2 deletions guppy/checker/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
FunctionType,
GuppyType,
NoneType,
Subst,
SumType,
TupleType,
)
Expand All @@ -33,7 +34,7 @@ class CallableVariable(ABC, Variable):
@abstractmethod
def check_call(
self, args: list[ast.expr], ty: GuppyType, node: AstNode, ctx: "Context"
) -> ast.expr:
) -> tuple[ast.expr, Subst]:
"""Checks the return type of a function call against a given type."""

@abstractmethod
Expand All @@ -43,6 +44,14 @@ def synthesize_call(
"""Synthesizes the return type of a function call."""


@dataclass
class TypeVarDecl:
"""A declared type variable."""

name: str
linear: bool


class Globals(NamedTuple):
"""Collection of names that are available on module-level.

Expand All @@ -52,6 +61,7 @@ class Globals(NamedTuple):

values: dict[str, Variable]
types: dict[str, type[GuppyType]]
type_vars: dict[str, TypeVarDecl]

@staticmethod
def default() -> "Globals":
Expand All @@ -63,7 +73,7 @@ def default() -> "Globals":
NoneType.name: NoneType,
BoolType.name: BoolType,
}
return Globals({}, tys)
return Globals({}, tys, {})

def get_instance_func(self, ty: GuppyType, name: str) -> CallableVariable | None:
"""Looks up an instance function with a given name for a type.
Expand All @@ -81,11 +91,13 @@ def __or__(self, other: "Globals") -> "Globals":
return Globals(
self.values | other.values,
self.types | other.types,
self.type_vars | other.type_vars,
)

def __ior__(self, other: "Globals") -> "Globals": # noqa: PYI034
self.values.update(other.values)
self.types.update(other.types)
self.type_vars.update(other.type_vars)
return self


Expand Down
Loading