Skip to content

refactor/shrink roland comments#353

Merged
KtorZ merged 4 commits into
mainfrom
stevan/shrink-roland-comments
Aug 5, 2025
Merged

refactor/shrink roland comments#353
KtorZ merged 4 commits into
mainfrom
stevan/shrink-roland-comments

Conversation

@stevana

@stevana stevana commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

Address @rkuhn's comments in #345 (review).

Summary by CodeRabbit

  • Refactor

    • Standardized generator functions to accept size and random number generator at invocation time, improving consistency across simulation utilities.
    • Updated property-checking functions to operate on references rather than owned history objects, reducing unnecessary cloning and improving performance.
    • Consolidated and simplified test message generation and property logic for easier reuse and maintenance.
  • Bug Fixes

    • Improved partition shrinking logic to ensure minimum partition count is maintained, preventing invalid or degenerate cases during simulation.

stevana added 3 commits July 31, 2025 10:49
Signed-off-by: Stevan A <stevana@users.noreply.github.com>
Signed-off-by: Stevan A <stevana@users.noreply.github.com>
Signed-off-by: Stevan A <stevana@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Jul 31, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Alrighty mate, here’s the lowdown: Generator functions in the simulator got a facelift, now using closures that take size and RNG at call time—much tidier! Function signatures across several modules were updated for consistency, especially around property-based testing, and a small tweak in the shrink logic ensures partitions never drop below two. No wild plot twists, just a classic refactor montage.

Changes

Cohort / File(s) Change Summary
Generator Function Refactor
simulation/amaru-sim/src/simulator/generate.rs
Refactored generator functions (generate_arrival_times, generate_vec, generate_zip_with) to return closures that accept both size and RNG at invocation. Updated all call sites and tests accordingly.
Property Function Ownership Update
simulation/amaru-sim/src/simulator/mod.rs,
simulation/amaru-sim/src/simulator/simulate.rs
Changed property function signatures to take references to History instead of ownership. Updated usage and tests to match, consolidated message generator logic into a constant.
Shrink Logic Adjustment
simulation/amaru-sim/src/simulator/shrink.rs
Changed decrement logic to ensure partition count never falls below two during shrinking. No API changes.

Sequence Diagram(s)

sequenceDiagram
    participant TestRunner
    participant GeneratorClosure
    participant RNG

    TestRunner->>GeneratorClosure: call(size, &mut RNG)
    GeneratorClosure->>RNG: generate values
    GeneratorClosure-->>TestRunner: return Vec<...>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • rkuhn
  • abailly

Poem

🍀
Refactors roll in like a Mario Kart drift,
Closures and RNGs, what a nifty gift!
Shrinking’s now safer, no more lonely two,
Properties borrowed, not owned—too true!
Code’s tidied up, like Link’s inventory—
Now grab a Guinness, mate, and bask in this glory!
🚀

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30639ca and d1994c9.

📒 Files selected for processing (1)
  • simulation/amaru-sim/src/simulator/simulate.rs (8 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • simulation/amaru-sim/src/simulator/simulate.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (9)
  • GitHub Check: End-to-end snapshot tests (preprod, 1, 10.1.4)
  • GitHub Check: Build x86_64/windows
  • GitHub Check: Build aarch64/macos
  • GitHub Check: Build x86_64/linux
  • GitHub Check: Build aarch64/linux
  • GitHub Check: Build riscv32
  • GitHub Check: Test coverage
  • GitHub Check: clippy
  • GitHub Check: Analyze (rust)
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch stevan/shrink-roland-comments

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@stevana stevana requested a review from rkuhn July 31, 2025 09:06
@codecov

codecov Bot commented Jul 31, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.07843% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
simulation/amaru-sim/src/simulator/simulate.rs 92.85% 2 Missing ⚠️
Files with missing lines Coverage Δ
simulation/amaru-sim/src/simulator/generate.rs 99.38% <100.00%> (ø)
simulation/amaru-sim/src/simulator/mod.rs 61.29% <100.00%> (ø)
simulation/amaru-sim/src/simulator/shrink.rs 98.09% <100.00%> (ø)
simulation/amaru-sim/src/simulator/simulate.rs 73.49% <92.85%> (+3.07%) ⬆️

... and 72 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

)
}

const ECHO_GENERATOR: fn(&mut StdRng) -> Vec<Reverse<Entry<EchoMessage>>> = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any particular reason to use a const here and not just a plain function?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed, thanks!

last_error = result;
input = complement;
n = n.max(2) - 1;
n = (n - 1).max(2);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Couldn't n become < 1 due to the !some_complement_is_failing branch below?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

No? n is initial 2 and while input.len() >= 2 we potentially update it, in the branch you mention, to n = (n * 2).min(input.len()).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ah! My bad; I missed the while input.len() >= 2 🤦

Signed-off-by: Stevan A <stevana@users.noreply.github.com>
@KtorZ KtorZ merged commit 9f0dad2 into main Aug 5, 2025
28 checks passed
@KtorZ KtorZ deleted the stevan/shrink-roland-comments branch August 5, 2025 08:24
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.

3 participants