-
Notifications
You must be signed in to change notification settings - Fork 18
feat: Declare WASM modules in guppy #942
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
Merged
Merged
Changes from 17 commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
426a5e6
feat: add wasm module (WIP)
qartik 2da0811
Bits and pieces (WIP)
croyzor 219e293
Maintain uniqueness of WASM contexts for a module
croyzor 7361fe2
Add discard; make progress
croyzor d5c570f
Unification of WasmModuleTypes
croyzor af7f7d8
Redundant comment
croyzor 95b1cb2
Oups - add missing file
croyzor cc8aef1
Associate WASM functions with modules
croyzor caf37f4
Let more types be wasmable
croyzor c8a7b71
Add dummy WASM decorators for sphinx
croyzor c6d66d8
Add ConstStringArg
croyzor fe23a6c
checkpoint
croyzor 55805ee
yeee
croyzor 8de275a
Remove array from test file
croyzor c0f70b9
cleanup
croyzor 07e1f62
Merge remote-tracking branch 'origin/main' into 755-add-support-for-wasm
croyzor 9b3bf0b
cleanup
croyzor d355b67
Improve printing of WASM errors
croyzor 3f4bf50
Add tests for WASM errors
croyzor 46f6469
Take GuppyModule arg in WASM decorators
croyzor 50986f7
bad idea
croyzor 061a6ba
Merge remote-tracking branch 'origin/main' into 755-add-support-for-wasm
croyzor b2aef12
nth times a charm
croyzor 5ed8479
Merge remote-tracking branch 'origin/main' into 755-add-support-for-wasm
croyzor e27d362
tests: Update error tests
croyzor 147a73a
refactor: Move wasm type error into right file
croyzor 4ff1525
refactor: Use helper for itousize
croyzor 8a0a188
cleanup: Remove duplicate def of `WasmCallChecker`
croyzor 88b5b0c
cleanup: Remove duplicate defs
croyzor faadea6
refactor: Idiomatic usage of tket2 exts
croyzor 84ebbdb
cleanup: Undo addition of `cached_sig` field to GlobalCall
croyzor 1d09e45
refactor: Move ConstWasmModule to tket2_exts
croyzor 79beec5
cleanup: Remove commented function
croyzor 7aebba1
Update guppylang/tys/builtin.py
croyzor 3b584d3
Update guppylang/checker/errors/wasm.py
croyzor 9ea17ec
tests: Add backticks and update test
croyzor 5b3f43d
Update comments
croyzor e24e3f5
Revert uv lock file
croyzor e677be2
remove ConstStringArg
croyzor 3fafda6
Restrict allowed types in WASM signatures
croyzor 9482b31
Add test with comptime interaction
croyzor 925c22d
Update wasm call checker
croyzor 8488e33
Parse wasm functions; move type signature sanity check out of checking
croyzor c65d4a0
Add test case
croyzor 277182c
Add missing backticks
croyzor c73ef71
Remove redundant assert
croyzor 3aa675f
Merge remote-tracking branch 'origin/main' into 755-add-support-for-wasm
croyzor cba859c
Undo uv.lock changes
croyzor 4565fb9
Remove redundant check + error
croyzor File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,34 @@ | ||||||||
| from dataclasses import dataclass | ||||||||
| from typing import ClassVar | ||||||||
|
|
||||||||
| from guppylang.diagnostic import Error | ||||||||
| from guppylang.tys.ty import Type | ||||||||
|
|
||||||||
|
|
||||||||
| class WasmError(Error): | ||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| title: ClassVar[str] = "WASM signature error" | ||||||||
|
|
||||||||
|
|
||||||||
| @dataclass(frozen=True) | ||||||||
| class FirstArgNotModule(WasmError): | ||||||||
| span_label: ClassVar[str] = ( | ||||||||
| "First argument to WASM function should be a reference to a WASM module" | ||||||||
| "Instead, found {ty}" | ||||||||
| ) | ||||||||
| ty: Type | ||||||||
|
|
||||||||
|
|
||||||||
| @dataclass(frozen=True) | ||||||||
| class UnWasmableType(WasmError): | ||||||||
| span_label: ClassVar[str] = ( | ||||||||
| "WASM function signature contained an unsupported type: {ty}" | ||||||||
croyzor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||||
| ) | ||||||||
| ty: Type | ||||||||
|
|
||||||||
|
|
||||||||
| @dataclass(frozen=True) | ||||||||
| class NonFunctionWasmType(WasmError): | ||||||||
| span_label: ClassVar[str] = ( | ||||||||
| "WASM function didn't have a function type, instead found {ty}" | ||||||||
|
||||||||
| "WASM function didn't have a function type, instead found {ty}" | |
| "WASM function didn't have a function type, instead found `{ty}`" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -15,15 +15,22 @@ | |||||
|
|
||||||
| import guppylang | ||||||
| from guppylang.ast_util import annotate_location | ||||||
| from guppylang.checker.core import Globals | ||||||
| from guppylang.compiler.core import GlobalConstId | ||||||
| from guppylang.definition.common import DefId | ||||||
| from guppylang.definition.const import RawConstDef | ||||||
| from guppylang.definition.custom import ( | ||||||
| CustomCallChecker, | ||||||
| CustomFunctionDef, | ||||||
| CustomInoutCallCompiler, | ||||||
| DefaultCallChecker, | ||||||
| NotImplementedCallCompiler, | ||||||
| OpCompiler, | ||||||
| RawCustomFunctionDef, | ||||||
| WasmCallChecker, | ||||||
| WasmModuleCallCompiler, | ||||||
| WasmModuleDiscardCompiler, | ||||||
| WasmModuleInitCompiler, | ||||||
| ) | ||||||
| from guppylang.definition.extern import RawExternDef | ||||||
| from guppylang.definition.function import ( | ||||||
|
|
@@ -38,7 +45,7 @@ | |||||
| ) | ||||||
| from guppylang.definition.struct import RawStructDef | ||||||
| from guppylang.definition.traced import RawTracedFunctionDef | ||||||
| from guppylang.definition.ty import OpaqueTypeDef, TypeDef | ||||||
| from guppylang.definition.ty import OpaqueTypeDef, TypeDef, WasmModule | ||||||
| from guppylang.error import MissingModuleError, pretty_errors | ||||||
| from guppylang.ipython_inspect import ( | ||||||
| get_ipython_globals, | ||||||
|
|
@@ -56,9 +63,16 @@ | |||||
| from guppylang.span import Loc, SourceMap, Span | ||||||
| from guppylang.tracing.object import GuppyDefinition | ||||||
| from guppylang.tys.arg import Argument | ||||||
| from guppylang.tys.builtin import option_type | ||||||
| from guppylang.tys.param import Parameter | ||||||
| from guppylang.tys.subst import Inst | ||||||
| from guppylang.tys.ty import NumericType | ||||||
| from guppylang.tys.ty import ( | ||||||
| FuncInput, | ||||||
| FunctionType, | ||||||
| InputFlags, | ||||||
| NoneType, | ||||||
| NumericType, | ||||||
| ) | ||||||
|
|
||||||
| S = TypeVar("S") | ||||||
| T = TypeVar("T") | ||||||
|
|
@@ -99,6 +113,7 @@ class _Guppy: | |||||
| def __init__(self) -> None: | ||||||
| self._modules = {} | ||||||
| self._sources = SourceMap() | ||||||
| self._next_wasm_context = 0 | ||||||
|
|
||||||
| @overload | ||||||
| def __call__(self, arg: F) -> F: ... | ||||||
|
|
@@ -582,6 +597,77 @@ def load_pytket( | |||||
| mod.register_def(defn) | ||||||
| return GuppyDefinition(defn) | ||||||
|
|
||||||
| def wasm_module( | ||||||
| self, filename: str, filehash: int | ||||||
| ) -> Decorator[PyClass, GuppyDefinition]: | ||||||
croyzor marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| # N.B. Only one module per file and vice-versa | ||||||
| guppy_module = self.get_module() | ||||||
| ctx_id = guppy_module._get_next_wasm_context() | ||||||
| assert guppy_module._instance_func_buffer is None | ||||||
| guppy_module._instance_func_buffer = {} | ||||||
|
|
||||||
| def dec(cls: PyClass) -> GuppyDefinition: | ||||||
| wasm_module = WasmModule( | ||||||
| DefId.fresh(guppy_module), | ||||||
| cls.__name__, | ||||||
| None, | ||||||
| filename, | ||||||
| filehash, | ||||||
| ctx_id, | ||||||
| ) | ||||||
| wasm_module_ty = wasm_module.check_instantiate([], Globals.default(), None) | ||||||
| guppy_module.register_def(wasm_module) | ||||||
| # Add a __call__ to the class | ||||||
|
||||||
| # Add a __call__ to the class | |
| # Add a constructor to the class |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Should this be in
errors/wasm.py?