Repository navigation
fix: Compile and lower comptime functions with fully qualified names #2517
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
maximilianruesch
merged 7 commits into
Quantinuum:main
from
manav4u:fix/comptime-qualified-names-2319
Nov 11, 2026
Merged
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
5ea1926
fix: use qualified names for comptime functions
manav4u 1c20034
fix: use qualified names for comptime functions
manav4u dceab5b
fix: use qualified names for comptime functions
manav4u b9b5b22
fix: use qualified names for comptime functions
manav4u c796873
fix: use qualified names for comptime functions
manav4u a404384
test: move comptime name checks into link-name integration tests
manav4u 1f0d109
test: move comptime name checks into link-name integration tests
manav4u 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
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,86 @@ | ||
| """Comptime functions use the same qualified names as checked Guppy functions.""" | ||
|
|
||
| from guppylang import guppy | ||
| from hugr.ops import FuncDefn | ||
|
|
||
|
|
||
| def function_names(package): | ||
| hugr = package.modules[0] | ||
| return [ | ||
| hugr[n].op.f_name | ||
| for n in hugr.children(hugr.module_root) | ||
| if isinstance(hugr[n].op, FuncDefn) | ||
| ] | ||
|
|
||
|
|
||
| def test_comptime_qualified_name(): | ||
| @guppy.comptime | ||
| def function() -> None: | ||
| pass | ||
|
|
||
| names = function_names(function.with_minimal_opt().compile()) | ||
| assert f"{__name__}.test_comptime_qualified_name.<locals>.function" in names | ||
|
|
||
|
|
||
| def test_comptime_generic_names_are_distinct(): | ||
| @guppy.comptime | ||
| def identity[T](value: T) -> T: | ||
| return value | ||
|
|
||
| @guppy | ||
| def main() -> None: | ||
| _ = identity(1) | ||
| _ = identity(True) | ||
|
|
||
| names = function_names(main.with_minimal_opt().compile()) | ||
| prefix = f"{__name__}.test_comptime_generic_names_are_distinct.<locals>.identity" | ||
| assert f"{prefix}$int" in names | ||
| assert f"{prefix}$bool" in names | ||
|
|
||
|
|
||
| def test_comptime_constant_names(): | ||
| from guppylang.std.array import array | ||
|
|
||
| n = guppy.nat_var("n") | ||
|
|
||
| @guppy.comptime | ||
| def values() -> array[int, n]: | ||
| return list(range(n)) | ||
|
|
||
| @guppy | ||
| def main() -> None: | ||
| _ = values[2]() | ||
| _ = values[3]() | ||
|
|
||
| names = function_names(main.with_minimal_opt().compile()) | ||
| prefix = f"{__name__}.test_comptime_constant_names.<locals>.values" | ||
| assert f"{prefix}$2" in names | ||
| assert f"{prefix}$3" in names | ||
|
|
||
|
|
||
| def test_comptime_same_name_different_scopes(): | ||
| def first_scope(): | ||
| @guppy.comptime | ||
| def same_name() -> int: | ||
| return 1 | ||
|
|
||
| return same_name | ||
|
|
||
| def second_scope(): | ||
| @guppy.comptime | ||
| def same_name() -> int: | ||
| return 2 | ||
|
|
||
| return same_name | ||
|
|
||
| first = first_scope() | ||
| second = second_scope() | ||
|
|
||
| @guppy | ||
| def main() -> int: | ||
| return first() + second() | ||
|
|
||
| names = function_names(main.with_minimal_opt().compile()) | ||
| prefix = f"{__name__}.test_comptime_same_name_different_scopes.<locals>" | ||
| assert f"{prefix}.first_scope.<locals>.same_name" in names | ||
| assert f"{prefix}.second_scope.<locals>.same_name" in names |
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.
There is no reason this needs to be a top level file, especially since this is doing some integration / end-to-end testing. Please move these tests to the existing
tests.integration.test_link_namemodule. You should be able to reuse some functions (such as the function name extractor) from there.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.
Moved the four comptime name tests into
tests.integration.test_link_name, reused_func_namesand thequalifierfixture, and removed the top-level file and its duplicate extractor. The production fix is unchanged. The 17 link-name tests pass, and the four moved regressions still fail without the production fix.