Skip to content
Merged
Changes from all commits
Commits
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
18 changes: 15 additions & 3 deletions guppylang/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import hugr.std.int
import hugr.std.logic
import hugr.std.prelude
from hugr.ext import Extension
from hugr.package import ModulePointer, Package

import guppylang
Expand Down Expand Up @@ -104,6 +105,7 @@ class CompilationEngine:
parsed: dict[DefId, ParsedDef]
checked: dict[DefId, CheckedDef]
compiled: dict[DefId, CompiledDef]
additional_extensions: list[Extension]

types_to_check_worklist: dict[DefId, ParsedDef]
to_check_worklist: dict[DefId, ParsedDef]
Expand All @@ -112,9 +114,15 @@ def reset(self) -> None:
"""Resets the compilation cache."""
self.parsed = {}
self.checked = {}
self.compiled = {}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

note to reviewers: this is a drive-by change, as the original omission of a self.compiled reset appeared accidental.

Please check whether or not this is the case. I don't want to cause a performance regression if resetting the compiled dictionary is avoided for e.g. caching.

self.additional_extensions = []
self.to_check_worklist = {}
self.types_to_check_worklist = {}

@pretty_errors
def register_extension(self, extension: Extension) -> None:
self.additional_extensions.append(extension)

def get_parsed(self, id: DefId) -> ParsedDef:
"""Look up the parsed version of a definition by its id.

Expand Down Expand Up @@ -212,13 +220,17 @@ def compile(self, id: DefId) -> ModulePointer:
ctx.compile(defn)
self.compiled = ctx.compiled

# TODO: Currently we just include a hardcoded list of extensions. We should
# compute this dynamically from the imported dependencies instead.
# TODO: Currently the list of extensions is manually managed by the user.
# We should compute this dynamically from the imported dependencies instead.
#
# The hugr prelude and std_extensions are implicit.
from guppylang.std._internal.compiler.tket2_exts import TKET2_EXTENSIONS

extensions = [*TKET2_EXTENSIONS, guppylang.compiler.hugr_extension.EXTENSION]
extensions = [
*TKET2_EXTENSIONS,
guppylang.compiler.hugr_extension.EXTENSION,
*self.additional_extensions,
]
# TODO replace with computed extensions after https://github.com/CQCL/guppylang/issues/550
all_used_extensions = [
*extensions,
Expand Down
Loading