-
Notifications
You must be signed in to change notification settings - Fork 4
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
fix handling of very long sequences/choices #20
fix handling of very long sequences/choices #20
Conversation
WalkthroughThis pull request introduces two macros, Changes
Possibly related PRs
Suggested reviewers
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Actionable comments posted: 0
🧹 Outside diff range and nitpick comments (3)
core/src/sequence.rs (1)
Line range hint
1-3
: Update documentation to includeSequence16
The documentation mentions that generated sequence types have 2 to 15 fields, but the code now includes
Sequence16
. Please update the documentation to reflect this addition.core/src/choice.rs (2)
Line range hint
1-3
: Update documentation to includeChoice16
The documentation states that generated choice types have 2 to 15 variants, but the code actually generates
Choice2
up toChoice16
. Please update the documentation to accurately reflect the range of variants.Apply this diff to correct the documentation:
-//! and generated choice types that has 2 to 15 variants, +//! and generated choice types that have 2 to 16 variants,
Line range hint
1-169
: Consider adding unit tests for generated choice typesWhile the macro generates the choice types as intended, adding unit tests for each generated
ChoiceN
type could help ensure their correctness and assist future maintenance.Would you like assistance in generating sample unit tests for these types?
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
📒 Files selected for processing (4)
- core/src/choice.rs (1 hunks)
- core/src/sequence.rs (1 hunks)
- derive/tests/grammar.pest (1 hunks)
- generator/src/typed/output.rs (1 hunks)
🧰 Additional context used
🔇 Additional comments (8)
derive/tests/grammar.pest (4)
50-51
: LGTM: Well-structured test cases for 16-element choices and sequences.These rules effectively test the handling of choices and sequences with exactly 16 elements, which aligns with the PR objective of fixing handling for long sequences and choices. The rules are well-formatted and easy to read.
52-53
: Excellent: Critical test cases for 17-element choices and sequences.These rules are crucial for testing the PR's objective. They check the handling of choices and sequences with 17 elements, which is just beyond the previous limit of 16. This ensures that the fix works for the first case exceeding the old limit.
54-55
: Good addition: Test cases for 19-element choices and sequences.These rules effectively test the handling of choices and sequences with 19 elements, which is well beyond the previous limit of 16. This helps ensure the robustness of the fix for even longer sequences and choices.
Could you explain the reasoning behind choosing 19 elements for these test cases? Is there a specific significance to this number, or was it chosen arbitrarily to test beyond the critical case of 17?
50-55
: Summary: Comprehensive test cases added for long choices and sequences.The new rules provide a progressive set of test cases for choices and sequences with 16, 17, and 19 elements. This aligns well with the PR objectives and should provide good coverage for testing the fix for handling long sequences and choices.
To ensure these new rules are being utilized effectively:
Could you please run the following script to verify that these new rules are actually used in test cases?
This will help confirm that the new grammar rules are being properly tested in the codebase.
generator/src/typed/output.rs (1)
97-115
: Improved clarity and fixed off-by-one errorThe changes in this segment effectively address the PR objectives and improve the code quality:
- The separate mapping for
field
,the_type
, andtrivia_or_getter
enhances clarity and reduces redundancy.- Changing the condition from
len >= 16
tolen > 16
fixes the off-by-one error mentioned in the PR objectives, ensuring thatSequence16
andChoice16
are not skipped.- The more explicit generation of identifiers improves code readability.
These modifications successfully fix the handling of very long sequences/choices as intended.
core/src/sequence.rs (1)
103-103
: Exposesequence_type
macro publiclyThe addition of
pub use sequence_type;
makes thesequence_type
macro publicly accessible, which is appropriate for users who need to generate custom sequence types.core/src/choice.rs (2)
103-103
: Re-exporting thechoice_type
macroThe
pub use choice_type;
statement correctly re-exports thechoice_type
macro, making it accessible to users of the crate.
Line range hint
104-169
: Consistency and correctness in macro invocationsThe invocations of the
choice_type!
macro to generateChoice2
throughChoice16
are consistent and correctly structured. This ensures that choice types with varying numbers of variants are properly defined.
In previous versions, I've added a support for sequences/choices longer than 15 by generating a new sequence/choice type, but it seems that it's not tested and has broken by re-factoring of the crate structure. Maybe let us take a glance at the test coverage results later? @Tartasprint Thank you for mentioning and fixing it. |
Looking at code for sequences and choices it looked like sequences and choices were limited to at most 16.
Turns out the generator was already auto-generating types for longer cases, but there were two small things breaking it.
First was an off by one typo, skipping the built-ins
Sequence16
andChoice16
.The other is due to some inconsistency between the calls to the generating macros and the spec of these macros.
I added a test case in
derive/tests/grammar.pest
Summary by CodeRabbit
New Features
Bug Fixes
Documentation