Skip to content

feat: Add compiler warning framework with opt-in rich warning rendering#1659

Draft
ss2165 wants to merge 8 commits intomainfrom
ss/push-kvqpqswszwxo
Draft

feat: Add compiler warning framework with opt-in rich warning rendering#1659
ss2165 wants to merge 8 commits intomainfrom
ss/push-kvqpqswszwxo

Conversation

@ss2165
Copy link
Copy Markdown
Member

@ss2165 ss2165 commented Apr 13, 2026

Closes #1654

This adds the base compiler warning framework for guppylang. Warnings are now first-class non-fatal diagnostics that are buffered across a top-level check() or compile() operation, deduplicated within that operation, and emitted through Python’s warnings system as guppylang.GuppyWarning.

The change also adds an opt-in rich warning mode via with guppylang.rich_warnings(): .... In that mode, Guppy still emits the normal Python warning for filtering/tooling compatibility, and additionally renders the full warning diagnostic with source context to stderr.

What’s included:

  • warning session plumbing in the diagnostics/error layer;
  • public guppylang.GuppyWarning;
  • public guppylang.rich_warnings() context manager;
  • single-flush behaviour across nested compiler entrypoints and GuppyLibrary multi-call flows;
  • framework, integration, renderer, and notebook coverage for the new warning surfaces.

Unreachable-code warning production in follow up: #1660

Developed iteratively with Codex, see individual commits for steps.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2026

🐰 Bencher Report

Branchss/push-kvqpqswszwxo
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
662,369.80 µs
(-26.13%)Baseline: 896,642.24 µs
941,474.36 µs
(70.35%)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
1,951,226.64 µs
(-2.56%)Baseline: 2,002,456.76 µs
2,102,579.60 µs
(92.80%)
tests/benchmarks/test_big_array.py::test_big_array_executable📈 view plot
🚷 view threshold
8,611,560.05 µs
(+1.40%)Baseline: 8,492,709.08 µs
8,917,344.53 µs
(96.57%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_check📈 view plot
🚷 view threshold
98,985.74 µs
(-7.37%)Baseline: 106,855.86 µs
112,198.66 µs
(88.22%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
221,032.94 µs
(-5.38%)Baseline: 233,604.41 µs
245,284.63 µs
(90.11%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_executable📈 view plot
🚷 view threshold
964,152.76 µs
(-24.02%)Baseline: 1,268,885.61 µs
1,332,329.89 µs
(72.37%)
tests/benchmarks/test_prelude.py::test_import_guppy📈 view plot
🚷 view threshold
44.42 µs
(-13.93%)Baseline: 51.60 µs
54.18 µs
(81.97%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_benchmark📈 view plot
🚷 view threshold
480,429.96 µs
(+1.55%)Baseline: 473,098.74 µs
496,753.68 µs
(96.71%)
tests/benchmarks/test_queue_push_pop.py::test_queue_push_pop_benchmark📈 view plot
🚷 view threshold
633,318.87 µs
(+2.20%)Baseline: 619,709.84 µs
650,695.33 µs
(97.33%)
🐰 View full continuous benchmarking report in Bencher

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 13, 2026

🐰 Bencher Report

Branchss/push-kvqpqswszwxo
TestbedLinux
Click to view all benchmark results
Benchmarkhugr_bytesBenchmark Result
bytes x 1e3
(Result Δ%)
Upper Boundary
bytes x 1e3
(Limit %)
hugr_nodesBenchmark Result
nodes x 1e3
(Result Δ%)
Upper Boundary
nodes x 1e3
(Limit %)
tests/benchmarks/test_big_array.py::test_big_array_compile📈 view plot
🚷 view threshold
158.77 x 1e3
(0.00%)Baseline: 158.77 x 1e3
160.36 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
6.64 x 1e3
(0.00%)Baseline: 6.64 x 1e3
6.71 x 1e3
(99.01%)
tests/benchmarks/test_ctrl_flow.py::test_many_ctrl_flow_compile📈 view plot
🚷 view threshold
27.53 x 1e3
(0.00%)Baseline: 27.53 x 1e3
27.81 x 1e3
(99.01%)
📈 view plot
🚷 view threshold
1.07 x 1e3
(0.00%)Baseline: 1.07 x 1e3
1.08 x 1e3
(99.01%)
🐰 View full continuous benchmarking report in Bencher

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 13, 2026

Codecov Report

❌ Patch coverage is 92.56198% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 93.55%. Comparing base (8900c4c) to head (7dcbcc3).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
...ylang-internals/src/guppylang_internals/warning.py 94.39% 6 Missing ⚠️
guppylang/src/guppylang/defs.py 57.14% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1659      +/-   ##
==========================================
+ Coverage   93.54%   93.55%   +0.01%     
==========================================
  Files         133      134       +1     
  Lines       12640    12757     +117     
==========================================
+ Hits        11824    11935     +111     
- Misses        816      822       +6     

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

@ss2165 ss2165 force-pushed the ss/push-kvqpqswszwxo branch from a9570d0 to a4a1b20 Compare April 14, 2026 13:31
@ss2165 ss2165 force-pushed the ss/push-kvqpqswszwxo branch from a4a1b20 to 74aefe0 Compare April 14, 2026 13:51
@ss2165 ss2165 marked this pull request as ready for review April 14, 2026 13:57
@ss2165 ss2165 requested a review from a team as a code owner April 14, 2026 13:57
@ss2165 ss2165 requested a review from tatiana-s April 14, 2026 13:57
Comment thread guppylang-internals/src/guppylang_internals/warning.py Outdated
@ss2165 ss2165 requested a review from tatiana-s April 15, 2026 10:28
Comment on lines +22 to +27
# File path passed through to Python's warning machinery, if available.
filename: str | None
# 1-based source line passed through to Python's warning machinery, if available.
lineno: int | None
# 0-based source column used only for deduplicating distinct warnings on one line.
column: int | None
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider using the existing Span class instead


rich_warnings: bool = False
pending_warnings: list[PendingWarning] = field(default_factory=list)
seen_warnings: set[_WarningKey] = field(default_factory=set)
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It would be very cool if we could use set[Warning] here, it already includes the span and the message

This would require hashability, but maybe we can just force the new Warning subclass to be hashable instead of all Diagnostics?

@ss2165 ss2165 marked this pull request as draft April 20, 2026 14:17
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.

[Feature]: Add a general compiler warning framework

4 participants