Skip to content

feat(rf): phantom rate Signal<R> with compile-time rate checking - #397

Merged
godofecht merged 1 commit into
mainfrom
feat/phantom-rate-signal
Aug 10, 2026
Merged

godofecht merged 1 commit into
mainfrom
feat/phantom-rate-signal

Conversation

@godofecht

Copy link
Copy Markdown
Contributor

Summary

  • Signal<R> generic struct with phantom type parameter R that tags sample rate at compile time
  • signal_mix<R> requires both inputs to have the same R, so mixing signals at different rates is a compile-time error
  • Rate marker distinct types: Hz1000, Hz8000, Hz16000, Hz22050, Hz24000, Hz32000, Hz44100, Hz48000, Hz96000, Hz1M, Hz2_4M, Hz10M
  • All signal functions made generic: signal_new<R>, signal_free<R>, signal_set<R>, signal_get<R>, signal_mix<R>, signal_scale<R>, signal_magnitude_spectrum<R>
  • Runtime sample_rate field kept for runtime use; R provides compile-time safety
  • Updated examples/rf/sdr_receiver.flow to use Signal<Hz8000>
  • 11 tests including test_signal_mix_different_rate_rejected verifying the compiler rejects signal_mix<Hz44100>(a: Signal<Hz44100>, b: Signal<Hz48000>)

This completes the W0 roadmap item for compile-time phantom rate checking.

Test plan

  • 1260 unit tests pass locally
  • examples/rf/sdr_receiver.flow compiles and runs correctly
  • test_signal_mix_different_rate_rejected confirms compile-time rejection
  • CI passes

Generated with Devin

Make Signal generic with a phantom type parameter R that tags the
sample rate. signal_mix<R> requires both inputs to have the same R,
so mixing signals at different rates is a compile-time error.

Changes to lib/stdlib/rf.flow:
- Signal<R> generic struct (R is phantom, not in fields)
- Rate marker distinct types: Hz1000, Hz8000, Hz16000, Hz22050,
  Hz24000, Hz32000, Hz44100, Hz48000, Hz96000, Hz1M, Hz2_4M, Hz10M
- All signal functions made generic: signal_new<R>, signal_free<R>,
  signal_set<R>, signal_get<R>, signal_mix<R>, signal_scale<R>,
  signal_magnitude_spectrum<R>
- Runtime sample_rate field kept for runtime use

Update examples/rf/sdr_receiver.flow to use Signal<Hz8000> with
explicit type arguments.

Update tests/unit/test_rf_types.py: 11 tests including
test_signal_mix_different_rate_rejected which verifies the compiler
rejects mixing Signal<Hz44100> with Signal<Hz48000>.

Update ROADMAP, CHANGELOG, types.md.

Generated with [Devin](https://devin.ai)

Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@cursor

cursor Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Bugbot is not enabled for your account, so this pull request was not reviewed.

Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs.

@godofecht
godofecht merged commit 7c06c6a into main Aug 10, 2026
17 checks passed
@godofecht
godofecht deleted the feat/phantom-rate-signal branch August 10, 2026 13:57
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.

1 participant