Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into feat/py2
Browse files Browse the repository at this point in the history
  • Loading branch information
mark-koch committed Jan 10, 2024
2 parents ad24f00 + d0cf104 commit 7f32baf
Show file tree
Hide file tree
Showing 50 changed files with 1,625 additions and 190 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull-request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ jobs:
with:
command: build
sccache: 'true'
rust-toolchain: '1.75'
working-directory: validator

- name: Install Hugr validator
Expand Down
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


PyScope = dict[str, Any]


Expand All @@ -55,6 +64,7 @@ class Globals(NamedTuple):

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

@staticmethod
Expand All @@ -67,7 +77,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 @@ -85,12 +95,14 @@ def __or__(self, other: "Globals") -> "Globals":
return Globals(
self.values | other.values,
self.types | other.types,
self.type_vars | other.type_vars,
self.python_scope | other.python_scope,
)

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

0 comments on commit 7f32baf

Please sign in to comment.