-
Notifications
You must be signed in to change notification settings - Fork 3
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: New type representation with parameters #174
Conversation
return UnknownFunctionType() | ||
# If we don't have a specified type, then the extension writer has to | ||
# provide their own type-checking code. Therefore, it doesn't matter which | ||
# type we return here since it will never be inspected. | ||
return FunctionType([], NoneType()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got rid of UnknownFunctionType
since it was very hacky. It's fine to return an arbitrary function type here since the actual checking logic is delegated to the extension writer
@@ -142,48 +142,9 @@ def type( | |||
|
|||
def dec(c: type) -> type: | |||
_name = name or c.__name__ | |||
|
|||
@dataclass(frozen=True) | |||
class NewType(GuppyType): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getting rid of this dynamic class creation is one of the big wins of this PR
class UndefinedPort(OutPortV): | ||
"""Dummy port for undefined variables. | ||
|
||
Raises an `InternalGuppyError` if one tries to access one of its properties. | ||
""" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This class was actually unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lots of changes, but LGTM 👍
"""Abstract base class for a type visitor that transforms types.""" | ||
|
||
@abstractmethod | ||
def visit(self, arg: Any, /) -> bool: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the positional-only arguments here, but not in the other ABCs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed, they should be everywhere 👍
guppylang/tys/printing.py
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How does the "Improved pretty printing of types" look now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some additional parentheses in some cases to disambiguate, for example (T -> T) -> T
was incorrectly printed as T -> T -> T
before.
Also, if multiple type variables have the name chosen by the user, they now get disambiguated as T
, T'1
, T'2
, ...
🤖 I have created a release *beep* *boop* --- ## 0.2.0 (2024-04-11) ### ⚠ BREAKING CHANGES * Make `qubit` type lower case ([#165](#165)) ### Features * Local implicit modules for `@guppy` ([#105](#105)) ([f52a5de](f52a5de)) * New type representation with parameters ([#174](#174)) ([73e29f2](73e29f2)) ### Bug Fixes * Make ZZMax a dyadic operation ([#168](#168)) ([152485f](152485f)), closes [#154](#154) * Stop exiting interpreter on error ([#140](#140)) ([728e449](728e449)) * Use correct TK2 gate names ([#190](#190)) ([df92642](df92642)) ### Documentation * add reference to runner to readme ([#129](#129)) ([45c2bf0](45c2bf0)) * Add short description and simplify readme for pypi ([#136](#136)) ([667bba3](667bba3)) ### Code Refactoring * Make `qubit` type lower case ([#165](#165)) ([0a42097](0a42097)) ### Continuous Integration * Use `release-please bootstrap`'s default config ([#187](#187)) ([72e666a](72e666a)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Mark Koch <[email protected]>
🤖 I have created a release *beep* *boop* --- ## 0.2.0 (2024-04-11) ### ⚠ BREAKING CHANGES * Make `qubit` type lower case ([#165](#165)) ### Features * Local implicit modules for `@guppy` ([#105](#105)) ([f52a5de](f52a5de)) * New type representation with parameters ([#174](#174)) ([73e29f2](73e29f2)) ### Bug Fixes * Make ZZMax a dyadic operation ([#168](#168)) ([152485f](152485f)), closes [#154](#154) * Stop exiting interpreter on error ([#140](#140)) ([728e449](728e449)) * Use correct TK2 gate names ([#190](#190)) ([df92642](df92642)) ### Documentation * add reference to runner to readme ([#129](#129)) ([45c2bf0](45c2bf0)) * Add short description and simplify readme for pypi ([#136](#136)) ([667bba3](667bba3)) ### Code Refactoring * Make `qubit` type lower case ([#165](#165)) ([0a42097](0a42097)) ### Continuous Integration * Use `release-please bootstrap`'s default config ([#187](#187)) ([72e666a](72e666a)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Mark Koch <[email protected]>
Most of the diff lines are just moving things to new files, so it's not as bad as it looks :D (see comments below)
These are the main new things:
Parameter
s andArgument
s that can be either types or constants (seetys/param.py
andtys/arg.py
).ConstParam
andConstArg
will follow in the futuretys/printing.py
)TypeDefinition
(seetys/definition.py
) that replaces the ad-hoc creation of Python classes to define new typesBoolType
is no longer aSumType
. This was a hugr implementation detail and not relevant for the Guppy type system.Drive by renaming:
args/return
toinputs/output
sinceargs
is already used nowGuppyType
toType