Skip to content

Conversation

@mark-koch
Copy link
Collaborator

It't a lot nicer to have the name of function arguments in the same object as the type an flags instead of the separate list we have at the moment - not adding the name was more of an oversight when we introduced FuncInput 😅

BREAKING CHANGE: FunctionType constructor no longer accepts the input_names argument. Instead, input names should be provided as an optional argument to FuncInput

@mark-koch mark-koch requested a review from a team as a code owner October 3, 2025 14:07
@mark-koch mark-koch requested a review from acl-cqc October 3, 2025 14:07
@hugrbot
Copy link
Collaborator

hugrbot commented Oct 3, 2025

This PR contains breaking changes to the public Python API.

Breaking changes summary
guppylang-internals/src/guppylang_internals/tys/ty.py:400: FunctionType.__init__(input_names):
Parameter was removed

guppylang-internals/src/guppylang_internals/tys/ty.py:400: FunctionType.__init__(params):
Positional parameter was moved
Details: position: from 4 to 3 (-1)

guppylang-internals/src/guppylang_internals/tys/ty.py:400: FunctionType.__init__(comptime_args):
Positional parameter was moved
Details: position: from 5 to 4 (-1)


@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2025

🐰 Bencher Report

Branchrefactor/input-names
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
686,232.48 µs
(-6.04%)Baseline: 730,376.70 µs
766,895.54 µs
(89.48%)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
1,589,160.78 µs
(-32.99%)Baseline: 2,371,549.86 µs
2,490,127.35 µs
(63.82%)
tests/benchmarks/test_big_array.py::test_big_array_executable📈 view plot
🚷 view threshold
7,192,009.69 µs
(-12.29%)Baseline: 8,199,667.52 µs
8,609,650.90 µs
(83.53%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_check📈 view plot
🚷 view threshold
48,017.71 µs
(-37.16%)Baseline: 76,413.95 µs
80,234.65 µs
(59.85%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
85,463.57 µs
(-1.83%)Baseline: 87,053.78 µs
91,406.46 µs
(93.50%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_executable📈 view plot
🚷 view threshold
589,873.15 µs
(-6.44%)Baseline: 630,467.16 µs
661,990.52 µs
(89.11%)
tests/benchmarks/test_prelude.py::test_import_guppy📈 view plot
🚷 view threshold
24.87 µs
(-2.58%)Baseline: 25.53 µs
26.80 µs
(92.78%)
🐰 View full continuous benchmarking report in Bencher

@github-actions
Copy link
Contributor

github-actions bot commented Oct 3, 2025

🐰 Bencher Report

Branchrefactor/input-names
TestbedLinux

🚨 2 Alerts

BenchmarkMeasure
Units
ViewBenchmark Result
(Result Δ%)
Upper Boundary
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compilehugr_nodes
nodes x 1e3
📈 plot
🚷 threshold
🚨 alert (🔔)
6.59 x 1e3
(+14.98%)Baseline: 5.73 x 1e3
5.79 x 1e3
(113.84%)

tests/benchmarks/test_big_array.py::test_big_array_compilehugr_bytes
bytes x 1e3
📈 plot
🚷 threshold
🚨 alert (🔔)
142.66 x 1e3
(+5.00%)Baseline: 135.86 x 1e3
137.22 x 1e3
(103.96%)

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
🚨 view alert (🔔)
142.66 x 1e3
(+5.00%)Baseline: 135.86 x 1e3
137.22 x 1e3
(103.96%)

📈 view plot
🚷 view threshold
🚨 view alert (🔔)
6,590.00
(+14.98%)Baseline: 5,731.50
5,788.81
(113.84%)

tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
21.57 x 1e3
(-0.97%)Baseline: 21.78 x 1e3
22.00 x 1e3
(98.05%)
📈 view plot
🚷 view threshold
606.00
(-6.70%)Baseline: 649.50
656.00
(92.38%)
🐰 View full continuous benchmarking report in Bencher

@codecov-commenter
Copy link

codecov-commenter commented Oct 3, 2025

Codecov Report

❌ Patch coverage is 92.85714% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.50%. Comparing base (fe85018) to head (4fb6328).

Files with missing lines Patch % Lines
...pylang-internals/src/guppylang_internals/tys/ty.py 90.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1286      +/-   ##
==========================================
- Coverage   93.51%   93.50%   -0.01%     
==========================================
  Files         123      123              
  Lines       11513    11520       +7     
==========================================
+ Hits        10766    10772       +6     
- Misses        747      748       +1     

☔ 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.

@mark-koch mark-koch force-pushed the refactor/input-names branch from 6e6e2c2 to 4fb6328 Compare October 3, 2025 14:52

def signature_to_str(name: str, sig: FunctionType) -> str:
"""Displays a function signature in Python syntax including the function name."""
assert sig.input_names is not None
Copy link
Collaborator

Choose a reason for hiding this comment

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

this line shouldn't have to change

Copy link
Contributor

Choose a reason for hiding this comment

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

because input_names is a property of type Sequence[str] | None that returns None if any elements are unnamed...yes, true, but not necessarily that obvious . See comment on def input_names but maybe go with Craig ;)

Copy link
Contributor

@acl-cqc acl-cqc left a comment

Choose a reason for hiding this comment

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

Thanks @mark-koch, looks like a good change :). A couple of queries but generally happy to approve


def signature_to_str(name: str, sig: FunctionType) -> str:
"""Displays a function signature in Python syntax including the function name."""
assert sig.input_names is not None
Copy link
Contributor

Choose a reason for hiding this comment

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

because input_names is a property of type Sequence[str] | None that returns None if any elements are unnamed...yes, true, but not necessarily that obvious . See comment on def input_names but maybe go with Craig ;)


@cached_property
def input_names(self) -> Sequence[str] | None:
"""Names of all inputs or `None` if there are unnamed inputs."""
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth adding a def __post_init__ to check that either all have names or none have names? I'm not sure I see any cases where only some might be named....perhaps positional-only arguments??


#: Name of this input, or `None` if it is an unnamed argument (e.g. inside a
#: higher-order `Callable` type)
name: str | None = field(default=None, compare=False)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why compare=False? So function types are equal if one has names and the other does not? Not strictly correct - the former can be called with kwargs syntax whereas the latter does not - I'm not sure how much of that stays in guppy but if we do support that, it might be worth going to a more-full-blown FunctionType "generalizes" check allowing assignment of named to nameless but not the other way around?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Guppy currently doesn't support kwargs, so function names are irrelevant when it comes to calling. The same is also true when e.g. trying to unify to function types - we just ignore the names

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah! Very good. In that case quite right. Maybe worth a # not exposed to caller here then

inp.flags,
is_func_input=True,
)
for i, inp in enumerate(func_ty.inputs)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for i, inp in enumerate(func_ty.inputs)
for arg, inp in zip(func_def.args.args, func_ty.inputs)

possibly with strict=True

@mark-koch mark-koch requested review from acl-cqc and croyzor October 28, 2025 17:49
@mark-koch
Copy link
Collaborator Author

Apologies, totally forgot about this PR 😅

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.

6 participants