Repository navigation
feat(rf): phantom rate Signal<R> with compile-time rate checking - #397
Merged
Merged
Conversation
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>
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. |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Signal<R>generic struct with phantom type parameterRthat tags sample rate at compile timesignal_mix<R>requires both inputs to have the sameR, so mixing signals at different rates is a compile-time errorsignal_new<R>,signal_free<R>,signal_set<R>,signal_get<R>,signal_mix<R>,signal_scale<R>,signal_magnitude_spectrum<R>sample_ratefield kept for runtime use;Rprovides compile-time safetyexamples/rf/sdr_receiver.flowto useSignal<Hz8000>test_signal_mix_different_rate_rejectedverifying the compiler rejectssignal_mix<Hz44100>(a: Signal<Hz44100>, b: Signal<Hz48000>)This completes the W0 roadmap item for compile-time phantom rate checking.
Test plan
examples/rf/sdr_receiver.flowcompiles and runs correctlytest_signal_mix_different_rate_rejectedconfirms compile-time rejectionGenerated with Devin