Skip to content
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

Cleanup interval bound handling #692

Merged
merged 3 commits into from
Sep 27, 2024
Merged

Cleanup interval bound handling #692

merged 3 commits into from
Sep 27, 2024

Conversation

elazarg
Copy link
Collaborator

@elazarg elazarg commented Sep 27, 2024

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced new constructors and methods in the interval_t class for enhanced functionality, including a method to return interval bounds as a tuple.
  • Improvements

    • Refactored interval evaluations and simplified function signatures for better clarity and performance.
    • Enhanced type handling in the check_access_packet method with a parameter name change for improved clarity.
    • Updated handling of type intervals in join_over_types for better readability.
    • Move trim_interval to near its use.
  • Bug Fixes

    • Adjusted logical conditions and return statements to streamline code behavior.

Signed-off-by: Elazar Gershuni <[email protected]>
Copy link

coderabbitai bot commented Sep 27, 2024

Walkthrough

The changes primarily involve refactoring and enhancing the code in multiple files related to the ebpf_domain and interval handling. Key modifications include updating function signatures, improving interval evaluations, and introducing new methods and constructors. Additionally, several logical conditions have been streamlined, and the trim_interval function has been removed, indicating a shift in functionality.

Changes

File Change Summary
src/crab/ebpf_domain.cpp Refactored interval evaluations, simplified function signatures, adjusted logical conditions, and enhanced return statements.
src/crab/ebpf_domain.hpp Renamed parameters and modified method signatures to improve clarity and performance.
src/crab/interval.hpp Added new constructors and methods for interval_t, removed trim_interval function.

Possibly related PRs

  • Cleanup and modernize ebpf_domain #690: The changes in this PR involve modifications to the ebpf_domain component, including updates to method signatures and improvements in code clarity, which are directly related to the changes made in the main PR for src/crab/ebpf_domain.cpp and src/crab/ebpf_domain.hpp.
  • Use explicit width for finite width parameters #687: This PR focuses on enhancing type clarity and consistency in the code, which aligns with the main PR's emphasis on improving the clarity and efficiency of interval evaluations and function signatures in src/crab/ebpf_domain.cpp.

🐰 In the code where rabbits play,
New functions hop and leap today.
With intervals trimmed and signatures neat,
The code now dances, oh so sweet!
Errors caught with a gentle touch,
In this land of code, we love so much! 🐇


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?

❤️ 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • 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 generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @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 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.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 12

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between c50905b and 743c337.

📒 Files selected for processing (7)
  • src/crab/ebpf_domain.cpp (19 hunks)
  • src/crab/ebpf_domain.hpp (2 hunks)
  • src/crab/interval.hpp (2 hunks)
  • src/crab/split_dbm.cpp (1 hunks)
  • src/crab_utils/debug.hpp (1 hunks)
  • src/crab_utils/num_big.hpp (2 hunks)
  • src/string_constraints.hpp (1 hunks)
🧰 Additional context used
📓 Learnings (1)
src/crab_utils/num_big.hpp (1)
Learnt from: elazarg
PR: vbpf/ebpf-verifier#689
File: src/crab_utils/num_big.hpp:30-30
Timestamp: 2024-09-26T00:56:36.307Z
Learning: Casting enums to `int64_t` in the `number_t` constructor is intentional and should not be flagged.
🔇 Additional comments (7)
src/string_constraints.hpp (1)

35-35: LGTM! Formatting improvement.

The formatting change in the string_invariant constructor improves consistency with the coding style used in the rest of the file. It's a good practice to maintain consistent formatting throughout the codebase.

src/crab_utils/num_big.hpp (2)

30-30: Improved type safety for enum constructor

The updated constructor now uses std::underlying_type_t<decltype(n)> instead of int64_t for casting enum values. This change enhances type safety and provides better compatibility with different enum types, as it uses the actual underlying type of the enum.

While a previous learning suggested that casting to int64_t was intentional, this change appears to be an improvement in line with modern C++ practices.


Line range hint 30-44: Summary: Improved enum handling in number_t class

The changes in this file enhance the number_t class's handling of enumeration types:

  1. The constructor for enum types now uses std::underlying_type_t for more precise type conversion.
  2. A new cast_to() method allows for type-safe conversion from number_t back to enum types.

These improvements contribute to better type safety and more consistent handling of enum types throughout the codebase. The changes align well with the PR objective of cleaning up interval bound handling.

src/crab/ebpf_domain.hpp (3)

Line range hint 1-262: Summary of changes

The changes in this file improve code clarity and potentially performance:

  1. Renaming shared_region_size to packet_size in the check_access_packet method enhances readability and consistency.
  2. Changing the parameter type to NumAbsDomain&& in selectively_join_based_on_type method allows for move semantics, potentially improving performance.

Both changes are approved, but please ensure to run the provided verification scripts to check for any potential issues in the wider codebase.


252-252: Approve parameter type change for potential performance improvement.

The change from NumAbsDomain& to NumAbsDomain&& for the src parameter in the selectively_join_based_on_type method allows for rvalue references. This can potentially improve performance by enabling move semantics, suggesting that the src object is likely to be moved from rather than copied.

To ensure this change is implemented correctly and doesn't introduce any issues, please run the following script to check the method's implementation and its usage across the codebase:

#!/bin/bash
# Check the implementation of selectively_join_based_on_type
echo "Checking implementation:"
rg --type cpp -A 10 "void selectively_join_based_on_type\(NumAbsDomain& dst, NumAbsDomain&& src\)"

echo "\nChecking usage:"
# Check for calls to selectively_join_based_on_type
rg --type cpp "selectively_join_based_on_type\s*\("

Also, please ensure that:

  1. The method implementation takes advantage of move semantics where appropriate.
  2. All call sites are updated to pass rvalue references (e.g., using std::move) when necessary.

179-179: Approve parameter rename for improved clarity.

The rename from shared_region_size to packet_size in the check_access_packet method improves code clarity and consistency. It better reflects the method's purpose of checking packet access.

To ensure this change doesn't introduce any issues, please run the following script to check for any remaining occurrences of shared_region_size in relation to packet access:

✅ Verification successful

Verified: No remaining occurrences of shared_region_size found outside src/crab/ebpf_domain.hpp.

The parameter rename from shared_region_size to packet_size in the check_access_packet method has been successfully applied throughout the codebase without any lingering references.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for any remaining occurrences of 'shared_region_size' related to packet access
rg --type cpp "shared_region_size.*packet" -g '!src/crab/ebpf_domain.hpp'

Length of output: 1530

src/crab/split_dbm.cpp (1)

300-300: Use of trim_interval in add_univar_disequation enhances interval adjustment

Integrating trim_interval into add_univar_disequation simplifies the handling of intervals when adding univariate disequations. This change improves code clarity and ensures consistent interval adjustments.

src/string_constraints.hpp Show resolved Hide resolved
src/crab_utils/debug.hpp Outdated Show resolved Hide resolved
src/crab_utils/num_big.hpp Show resolved Hide resolved
src/crab/interval.hpp Show resolved Hide resolved
src/crab/interval.hpp Outdated Show resolved Hide resolved
src/crab/split_dbm.cpp Show resolved Hide resolved
src/crab/ebpf_domain.cpp Outdated Show resolved Hide resolved
src/crab/ebpf_domain.cpp Show resolved Hide resolved
src/crab/ebpf_domain.cpp Show resolved Hide resolved
src/crab/ebpf_domain.cpp Show resolved Hide resolved
Signed-off-by: Elazar Gershuni <[email protected]>
Signed-off-by: Elazar Gershuni <[email protected]>
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Outside diff range comments (1)
src/crab/ebpf_domain.cpp (1)

Line range hint 348-360: Possible Uninitialized Variable lpub Used

In the blocks starting at lines 348 and 359, the variable lpub is declared but may not be initialized before use if certain conditions are not met.

Ensure that lpub is properly initialized before it is used in any expressions to avoid undefined behavior.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 743c337 and 8d476cd.

📒 Files selected for processing (2)
  • src/crab/ebpf_domain.cpp (19 hunks)
  • src/crab/interval.hpp (2 hunks)
🧰 Additional context used
📓 Learnings (2)
src/crab/ebpf_domain.cpp (3)
Learnt from: elazarg
PR: vbpf/ebpf-verifier#692
File: src/crab/ebpf_domain.cpp:1366-1367
Timestamp: 2024-09-27T00:34:47.474Z
Learning: The project is compiled with C++20.
Learnt from: elazarg
PR: vbpf/ebpf-verifier#692
File: src/crab/ebpf_domain.cpp:641-642
Timestamp: 2024-09-27T00:33:26.772Z
Learning: The project uses the C++20 standard and supports C++20 features.
Learnt from: elazarg
PR: vbpf/ebpf-verifier#692
File: src/crab/ebpf_domain.cpp:884-893
Timestamp: 2024-09-27T00:36:08.058Z
Learning: When analyzing the `operator|=(ebpf_domain_t&& other)` method in `src/crab/ebpf_domain.cpp`, ensure to carefully read the control flow and verify whether the moved-from object `other` is actually used after `std::move`.
src/crab/interval.hpp (1)
Learnt from: elazarg
PR: vbpf/ebpf-verifier#692
File: src/crab/interval.hpp:89-94
Timestamp: 2024-09-27T00:32:54.738Z
Learning: In the `bound(T lb, T ub)` method within `interval_t`, safety when dereferencing optional values of `_lb.number()` and `_ub.number()` is ensured by the meet operation in the first line. Therefore, it's acceptable to dereference without checking for infinite bounds in this context.
🔇 Additional comments (7)
src/crab/interval.hpp (1)

99-104: ⚠️ Potential issue

Potential undefined behavior when casting to enum types

In the bound(T elb, T eub) const method, you are casting integral values back to the enum type T using static_cast<T>(lb) and static_cast<T>(ub). If the values lb and ub do not correspond to valid enumerators of T, this can lead to undefined behavior.

Consider adding a validation step to ensure that the casted values are valid enumerators of the enum T before returning them. Alternatively, you might return the underlying integral values or use a safer casting method that handles invalid values appropriately.

⛔ Skipped due to learnings
Learnt from: elazarg
PR: vbpf/ebpf-verifier#692
File: src/crab/interval.hpp:89-94
Timestamp: 2024-09-27T00:32:54.738Z
Learning: In the `bound(T lb, T ub)` method within `interval_t`, safety when dereferencing optional values of `_lb.number()` and `_ub.number()` is ensured by the meet operation in the first line. Therefore, it's acceptable to dereference without checking for infinite bounds in this context.
src/crab/ebpf_domain.cpp (6)

641-642: LGTM!

The use of structured bindings here is appropriate and enhances code readability. No issues identified.


884-884: Potential Use of Moved-From Object After std::move

In the operator|=(ebpf_domain_t&& other) method, after moving other into *this at line 884:

*this = std::move(other);

There are further uses of other at lines 891 and 893:

type_inv.selectively_join_based_on_type(m_inv, std::move(other.m_inv));
stack |= std::move(other.stack);

Since other has been moved, accessing its members may lead to undefined behavior. However, upon closer examination, the move occurs within a conditional block:

if (is_bottom()) {
    *this = std::move(other);
    return;
}

This means that if is_bottom() is true, we move other into *this and return immediately. In the subsequent code where other is used, it is guaranteed that is_bottom() is false, and thus other has not been moved yet. Therefore, the usage is safe.

Also applies to: 891-891, 893-893


1346-1346: LGTM!

The function has_type correctly returns whether the interval contains the specified type. No issues found.


1366-1367: LGTM!

The use of structured bindings and the for-loop to iterate over type encodings enhances code clarity. No issues identified.

Also applies to: 1370-1370


1454-1454: LGTM!

The addition of shared_region_size as a parameter and its use in the require function improves the function's correctness in checking bounds. No issues found.

Also applies to: 1457-1457


147-148: ⚠️ Potential issue

Potential Null Pointer Dereference in Interval Bounds Access

In the lines where left_svalue_interval.lb().number()->cast_to<int64_t>() and left_svalue_interval.ub().number()->cast_to<int64_t>() are called, there is a risk of dereferencing a null pointer if left_svalue_interval.lb().number() or left_svalue_interval.ub().number() returns nullptr. This can occur if the interval is unbounded or represents an empty interval.

To ensure safety, please add checks to verify that left_svalue_interval.lb().number() and left_svalue_interval.ub().number() are not nullptr before dereferencing.

Apply this diff to add null pointer checks:

 if (auto size = left_svalue_interval.finite_size()) {
-    int64_t lb = left_svalue_interval.lb().number()->cast_to<int64_t>();
+    auto lb_number = left_svalue_interval.lb().number();
+    if (!lb_number) {
+        // Handle the case where lb_number is null
+        // Possibly return or continue safely
+    }
+    int64_t lb = lb_number->cast_to<int64_t>();

    // ...

-    const int64_t ub = left_svalue_interval.ub().number()->cast_to<int64_t>();
+    auto ub_number = left_svalue_interval.ub().number();
+    if (!ub_number) {
+        // Handle the case where ub_number is null
+        // Possibly return or continue safely
+    }
+    int64_t ub = ub_number->cast_to<int64_t>();

Also applies to: 152-152, 166-166

⛔ Skipped due to learnings
Learnt from: elazarg
PR: vbpf/ebpf-verifier#689
File: src/crab/ebpf_domain.cpp:210-212
Timestamp: 2024-09-25T23:02:10.338Z
Learning: Always truncating intervals without checking if they are already within the desired range is acceptable and simplifies the code.

src/crab/ebpf_domain.cpp Show resolved Hide resolved
src/crab/ebpf_domain.cpp Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Sep 27, 2024

Coverage Status

coverage: 90.342% (-0.02%) from 90.365%
when pulling 8d476cd on bounds
into c50905b on main.

@elazarg elazarg merged commit 149a915 into main Sep 27, 2024
15 checks passed
@elazarg elazarg deleted the bounds branch September 27, 2024 07:52
@elazarg
Copy link
Collaborator Author

elazarg commented Sep 29, 2024

This PR introduces some 25% performance speedup to the CI.

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.

2 participants