Skip to content

Conversation

@nicolaassolini-qntm
Copy link
Contributor

  • Added a new module guppylang_internals/definition/enum.py containing RawEnumDef, ParsedEnumDef, and CheckedEnumDef(WIP)
  • Added a guppylang_internals/definition/util.py module with common function and classes used by enum.py, struct.py and function.py
  • Improved error diagnostics for unexpected statements in enum and struct definitions by adding contextual help messages

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

🐰 Bencher Report

Branchnats/parse-enum-definitions
TestbedLinux
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_check📈 view plot
🚷 view threshold
684,640.89 µs
(-8.33%)Baseline: 746,869.82 µs
784,213.31 µs
(87.30%)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
1,741,899.11 µs
(+4.67%)Baseline: 1,664,199.33 µs
1,747,409.30 µs
(99.68%)
tests/benchmarks/test_big_array.py::test_big_array_executable📈 view plot
🚷 view threshold
7,615,848.35 µs
(+4.47%)Baseline: 7,290,127.27 µs
7,654,633.63 µs
(99.49%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_check📈 view plot
🚷 view threshold
52,838.97 µs
(+3.76%)Baseline: 50,923.62 µs
53,469.80 µs
(98.82%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
92,726.77 µs
(+3.05%)Baseline: 89,979.80 µs
94,478.78 µs
(98.15%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_executable📈 view plot
🚷 view threshold
618,909.86 µs
(+2.35%)Baseline: 604,673.14 µs
634,906.80 µs
(97.48%)
tests/benchmarks/test_prelude.py::test_import_guppy📈 view plot
🚷 view threshold
51.17 µs
(-0.63%)Baseline: 51.49 µs
54.06 µs
(94.64%)
🐰 View full continuous benchmarking report in Bencher

@github-actions
Copy link
Contributor

github-actions bot commented Jan 6, 2026

🐰 Bencher Report

Branchnats/parse-enum-definitions
TestbedLinux
Click to view all benchmark results
Benchmarkhugr_bytesBenchmark Result
bytes x 1e3
(Result Δ%)
Upper Boundary
bytes x 1e3
(Limit %)
hugr_nodesBenchmark Result
nodes
(Result Δ%)
Upper Boundary
nodes
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
143.70 x 1e3
(+0.10%)Baseline: 143.55 x 1e3
144.98 x 1e3
(99.11%)
📈 view plot
🚷 view threshold
6,590.00
(0.00%)Baseline: 6,590.00
6,655.90
(99.01%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
21.67 x 1e3
(0.00%)Baseline: 21.67 x 1e3
21.89 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
606.00
(0.00%)Baseline: 606.00
612.06
(99.01%)
🐰 View full continuous benchmarking report in Bencher

@nicolaassolini-qntm
Copy link
Contributor Author

mypy is failing due to the dummy implementation of CheckedEnumDef.check_instantiate() and ParsedEnumDef.check_instantiate()

@codecov-commenter
Copy link

codecov-commenter commented Jan 6, 2026

Codecov Report

❌ Patch coverage is 92.10526% with 18 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.46%. Comparing base (a7308fb) to head (f403867).
⚠️ Report is 7 commits behind head on feat/guppy-enum.

Files with missing lines Patch % Lines
...ternals/src/guppylang_internals/definition/enum.py 84.37% 15 Missing ⚠️
...ternals/src/guppylang_internals/definition/util.py 97.22% 3 Missing ⚠️
Additional details and impacted files
@@                 Coverage Diff                 @@
##           feat/guppy-enum    #1419      +/-   ##
===================================================
- Coverage            93.56%   93.46%   -0.11%     
===================================================
  Files                  128      129       +1     
  Lines                11476    11662     +186     
===================================================
+ Hits                 10738    10900     +162     
- Misses                 738      762      +24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nicolaassolini-qntm nicolaassolini-qntm marked this pull request as ready for review January 6, 2026 08:46
@nicolaassolini-qntm nicolaassolini-qntm requested a review from a team as a code owner January 6, 2026 08:46
@nicolaassolini-qntm nicolaassolini-qntm requested review from mark-koch and tatiana-s and removed request for a team January 6, 2026 08:46
Copy link
Contributor

@tatiana-s tatiana-s left a comment

Choose a reason for hiding this comment

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

Great work! Some mostly minor comments, otherwise do you think there is any way to make the dummy methods pass mypy so that the rest of CI can run?

…py:125

Co-authored-by: tatiana-s <tatiana.sedelnikov@quantinuum.com>
@nicolaassolini-qntm
Copy link
Contributor Author

nicolaassolini-qntm commented Jan 6, 2026

Great work! Some mostly minor comments, otherwise do you think there is any way to make the dummy methods pass mypy so that the rest of CI can run?

Done 👍

Copy link
Contributor

@tatiana-s tatiana-s left a comment

Choose a reason for hiding this comment

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

Some naming suggestions otherwise fine to merge into the feature branch I think 👍

Copy link
Collaborator

@mark-koch mark-koch left a comment

Choose a reason for hiding this comment

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

Looks good! Just leaving a couple of smaller suggestions

Also, can you mark this PR as breaking (for guppylang_internals) and list all your refactor changes as BREAKING CHANGE?

# need to store and check if any dependencies have changed.
self.reset()

self.to_check_worklist[id] = self.get_parsed(id)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you update the branch to pull in the merged #1410 instead of inlining the fix here

"""Chechks instantiation of this enum type."""

def generated_methods(self) -> list[CustomFunctionDef]:
# Generating methods to instantiate enum variants
Copy link
Collaborator

Choose a reason for hiding this comment

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

Sould this be a TODO? If yes, can you add it to the tracking issue?

Comment on lines +49 to +50
# TODO: Considering renaming to UncheckedField and CheckedField,
# and joining with UncheckedStructField and StructField
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think this would be a good idea 👍



@dataclass(frozen=True)
class EnumVariant:
Copy link
Collaborator

Choose a reason for hiding this comment

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

You could also consider merging the variant classes:

F = TypeVar("F", UncheckedField, CheckedField)

@dataclass(frozen=True)
class EnumVariant(Generic[F]):
    name: str
    fields: Sequence[F]

and then use EnumVariant[UncheckedField] and EnumVariant[CheckedField]?


defined_at: ast.ClassDef
params: Sequence[Parameter]
variants: Mapping[str, UncheckedEnumVariant]
Copy link
Collaborator

@mark-koch mark-koch Jan 8, 2026

Choose a reason for hiding this comment

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

Beware: We will need a unique ordering of enum variants when converting them to Hugr sum types. Now, technically this will be fine since Python dicts are insertion ordered, but it's a bit of a hidden invariant.

Maybe good to add a comment here, that the insertion order of variants determines the index of the variant? Or maybe even store the index in the variant class?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants