Skip to content

Cleanup number_t interface and implementation #689

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

Merged
merged 6 commits into from
Sep 26, 2024
Merged

Conversation

elazarg
Copy link
Collaborator

@elazarg elazarg commented Sep 25, 2024

Summary by CodeRabbit

  • New Features

    • Added standardized truncation methods for improved clarity and type safety in numerical operations.
    • Updated method signatures and type definitions to enhance type consistency throughout the application.
  • Bug Fixes

    • Removed the Hasher struct from the variable_t class, which may affect hashing behavior.
  • Refactor

    • Renamed the z_number class to number_t, streamlining type handling and improving flexibility in arithmetic operations.
    • Renamed the bound_t class to extended_number and moved it to num_extended.hpp.
    • Updated include directives to reflect new dependencies.
  • Documentation

    • Updated comments and documentation to reflect the changes in type definitions and method signatures.

Copy link

coderabbitai bot commented Sep 25, 2024

Warning

Rate limit exceeded

@elazarg has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 14 minutes and 16 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Files that changed from the base of the PR and between 213e5ba and 365c047.

Walkthrough

The changes involve a comprehensive renaming of the z_number class to number_t throughout the codebase. This includes updates to method signatures, type definitions, and variable types to reflect the new naming convention. Additionally, the modifications enhance type consistency and streamline method calls related to numerical operations, particularly in truncation methods. A new class, extended_number, has also been introduced to represent numbers that can be finite or infinite. The overall structure and logic of the code remain intact, with a focus on improving clarity and maintainability.

Changes

Files Change Summary
src/crab_utils/num_big.hpp Introduced number_t class for arbitrary precision integers, including various arithmetic and bitwise operations, type conversions, and error handling.
src/asm_ostream.cpp Method signature updated from std::string crab::z_number::to_string() const to std::string crab::number_t::to_string() const.
src/crab/array_domain.cpp Variable type changed from z_number to number_t for fullwidth in the load method.
src/crab/ebpf_domain.cpp Replaced truncation method calls for signed and unsigned integers with template-based methods like truncate_to<int32_t> and truncate_to<uint32_t>.
src/crab/split_dbm.cpp Updated convert_NtoW methods in SafeInt64DefaultParams and Z_NumberDefaultParams to accept number_t instead of z_number. Simplified membership checking in operator[] and standardized truncation method calls.
src/crab/split_dbm.hpp Type alias updated from z_number to number_t in Z_NumberDefaultParams and SafeInt64DefaultParams.
src/crab/variable.hpp Removed nested struct Hasher from variable_t class.
src/crab_utils/adapt_sgraph.hpp Type alias for Weight changed from z_number to number_t in AdaptGraph class.
src/crab_utils/bignums.hpp Renamed z_number class to number_t, with updates to all method signatures and operator overloads reflecting the new name.
src/crab_utils/safeint.hpp Constructor in safe_i64 class updated to accept number_t instead of z_number.
src/crab_utils/num_extended.hpp Introduced extended_number class to represent finite and infinite numbers, including various arithmetic operations and state checks.
src/crab/interval.hpp Removed bound_t class, which managed finite and infinite bounds, and updated header inclusions.

Poem

🐇 In the code we hop and play,
With number_t leading the way.
From z_number we take our flight,
Making types clearer and bright.
With each change, our code will sing,
A joyful dance, let’s code and spring! 🌼


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: 10

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 3d14be0 and 35e2274.

📒 Files selected for processing (9)
  • src/asm_ostream.cpp (1 hunks)
  • src/crab/array_domain.cpp (1 hunks)
  • src/crab/ebpf_domain.cpp (17 hunks)
  • src/crab/split_dbm.cpp (4 hunks)
  • src/crab/split_dbm.hpp (2 hunks)
  • src/crab/variable.hpp (0 hunks)
  • src/crab_utils/adapt_sgraph.hpp (1 hunks)
  • src/crab_utils/bignums.hpp (5 hunks)
  • src/crab_utils/safeint.hpp (1 hunks)
💤 Files not reviewed due to no reviewable changes (1)
  • src/crab/variable.hpp
🔇 Additional comments not posted (15)
src/crab_utils/safeint.hpp (2)

77-77: Ensure all usages of this constructor are updated.

While the change to the constructor is correct, it's crucial to verify that all usages of this constructor throughout the codebase have been updated to use number_t instead of z_number.

Let's check for any remaining usages of the old constructor signature:

#!/bin/bash
# Description: Check for any remaining usages of the old constructor signature

# Test: Search for safe_i64 constructor calls with z_number. Expect: No results
rg --type cpp 'safe_i64\s*\(\s*(?:const\s+)?z_number\s*&'

Additionally, there are several TODO comments in this file regarding handling overflow in arithmetic operations. While unrelated to this change, addressing these in future updates could improve the robustness of the safe_i64 class.


77-77: 🧹 Nitpick (assertive)

Approved: Constructor signature updated correctly.

The constructor signature has been updated from z_number to number_t, which is consistent with the renaming mentioned in the PR summary. The implementation remains unchanged, maintaining the existing behavior.

Consider using a C++ style cast for better type safety:

-    safe_i64(const number_t& n) : m_num((int64_t)n) {}
+    safe_i64(const number_t& n) : m_num(static_cast<int64_t>(n)) {}

Let's verify that there are no remaining usages of z_number in the codebase:

✅ Verification successful

Verified: No remaining usages of z_number found.

The comprehensive search indicates that z_number is no longer used in the codebase, confirming that the renaming to number_t has been fully implemented without impacting other components.

Consider using a C++ style cast for better type safety:

-    safe_i64(const number_t& n) : m_num((int64_t)n) {}
+    safe_i64(const number_t& n) : m_num(static_cast<int64_t>(n)) {}
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining usages of z_number in the codebase

# Test: Search for z_number. Expect: No results
rg --type cpp 'z_number'

Length of output: 59


Script:

#!/bin/bash
# Description: Perform a comprehensive search for any remaining usages of z_number in the codebase

# Test: Search for z_number in all C++ files. Expect: No results
rg --type cpp 'z_number'

Length of output: 24

src/crab/split_dbm.hpp (3)

67-67: LGTM. Consistent type usage.

The change from const z_number& to const number_t& in the convert_NtoW method signature is consistent with the previous update to the Weight type alias. This change maintains type consistency within the Z_NumberDefaultParams struct.


70-70: LGTM. Please clarify the rationale for different type choices.

The change from z_number to safe_i64 for the Weight type alias in SafeInt64DefaultParams is consistent with the struct name and suggests a focus on safe integer operations. However, this differs from the number_t used in Z_NumberDefaultParams.

Could you please clarify the reasoning behind using different types (number_t vs safe_i64) for these two structs? This will help ensure that the type choices are intentional and appropriate for their respective use cases.


65-65: LGTM. Verify impact on dependent code.

The change from z_number to number_t for the Weight type alias is consistent with the PR objective. This update improves type consistency across the codebase.

To ensure this change doesn't introduce any issues, please run the following script to check for any remaining uses of z_number in the codebase:

src/crab_utils/adapt_sgraph.hpp (1)

148-148: LGTM. Verify compatibility and update related code.

The change from z_number to number_t for the Weight type alias aligns with the PR objectives of cleaning up the number_t interface. This change appears to be part of a larger refactoring effort to standardize on number_t.

To ensure a smooth transition:

  1. Verify that number_t is fully compatible with all operations previously performed on z_number within the AdaptGraph class and its usage contexts.
  2. Check for any potential performance implications of this change, especially if number_t has different characteristics than z_number.
  3. Review and update other parts of the codebase that interact with AdaptGraph to ensure they are compatible with the new number_t type.

To help verify the impact of this change, you can run the following script:

This script will help identify areas of the codebase that might need attention due to the type change.

✅ Verification successful

Verified: Compatibility confirmed and no issues found.

The change from z_number to number_t for the Weight type alias has been thoroughly verified. No occurrences of z_number remain in the codebase, and number_t is consistently used across all relevant modules. This ensures full compatibility and aligns with the refactoring objectives.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all occurrences of z_number and number_t in the codebase
# to ensure consistent usage and identify potential areas needing updates.

echo "Searching for z_number occurrences:"
rg --type cpp 'z_number'

echo -e "\nSearching for number_t occurrences:"
rg --type cpp 'number_t'

echo -e "\nSearching for AdaptGraph usage:"
rg --type cpp 'AdaptGraph'

Length of output: 38482

src/asm_ostream.cpp (1)

568-568: LGTM: Class renamed from z_number to number_t.

The change is consistent with the PR objective of cleaning up the number_t interface. The method's functionality remains unchanged, which is good for maintaining consistency.

To ensure this change is consistent across the codebase, please run the following script:

This script will help identify any inconsistencies in the renaming process across the codebase.

✅ Verification successful

Verified: Renaming of z_number to number_t is consistent across the codebase.

The shell script results indicate:

  • No remaining occurrences of z_number.
  • Proper usage of number_t throughout the codebase.
  • No mismatched occurrences where both z_number and number_t are used together.

This confirms that the renaming aligns with the PR objectives and maintains code consistency.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the renaming of z_number to number_t across the codebase.

# Test 1: Check for any remaining occurrences of z_number
echo "Checking for any remaining occurrences of z_number:"
rg --type cpp "z_number"

# Test 2: Verify the usage of number_t
echo "Verifying the usage of number_t:"
rg --type cpp "number_t"

# Test 3: Check for any mismatched occurrences (e.g., z_number used with number_t methods)
echo "Checking for any mismatched occurrences:"
rg --type cpp "(z_number.*number_t|number_t.*z_number)"

Length of output: 37615


Script:

#!/bin/bash
# Description: Re-verify the renaming of z_number to number_t across the codebase.

# Test 1: Check for any remaining occurrences of z_number
echo "Checking for any remaining occurrences of z_number:"
rg --type cpp "z_number"

# Test 2: Verify the usage of number_t
echo "Verifying the usage of number_t:"
rg --type cpp "number_t"

# Test 3: Check for any mismatched occurrences (e.g., z_number used with number_t methods)
echo "Checking for any mismatched occurrences:"
rg --type cpp "(z_number.*number_t|number_t.*z_number)"

Length of output: 37615

src/crab/array_domain.cpp (1)

753-755: LGTM. Verify implications of type change.

The change from z_number to number_t for the fullwidth variable looks good and is likely part of a larger refactoring for consistency. The calculation logic remains the same.

To ensure this change doesn't have unintended consequences, please run the following script to check for any other occurrences of z_number in the codebase:

This will help verify that the transition from z_number to number_t is complete and consistent across the project.

✅ Verification successful

Type Change Verified Successfully

The z_number type has been completely removed and replaced with number_t across all relevant files, ensuring consistency and eliminating the previous type.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for remaining occurrences of z_number in the codebase

# Search for z_number in all files
rg --type cpp --type hpp 'z_number'

# Check if number_t is properly defined and imported
rg --type cpp --type hpp 'number_t'

Length of output: 127


Script:

#!/bin/bash
# Description: Check for remaining occurrences of z_number and verify number_t definitions in .cpp and .hpp files

# Search for z_number in all .cpp and .hpp files
rg 'z_number' --glob '*.cpp' --glob '*.hpp'

# Search for number_t in all .cpp and .hpp files
rg 'number_t' --glob '*.cpp' --glob '*.hpp'

Length of output: 37316

src/crab/split_dbm.cpp (4)

57-57: LGTM. Consistent with previous change.

This change aligns with the update in the SafeInt64DefaultParams class and maintains consistency in the use of number_t.


911-911: LGTM. Potential performance improvement.

The change from find to contains for set membership checking is a good optimization. The contains method is generally more efficient for this purpose, potentially improving performance.


1289-1290: LGTM. Verify consistent usage of new truncation method names.

The updates to the truncation method names (truncate_to_uint and truncate_to_sint) improve code readability while maintaining clarity of purpose. This change is part of the cleanup effort mentioned in the PR objectives.

To ensure these changes are applied consistently throughout the codebase, run the following script:

#!/bin/bash
# Verify consistent usage of new truncation method names

# Check for any remaining usage of old method names
rg --type cpp 'truncate_to_(un)?signed_finite_width'

# Check for usage of new method names
rg --type cpp 'truncate_to_(u|s)int'

Also applies to: 1293-1294


48-48: LGTM. Verify consistent usage of number_t.

The change from z_number to number_t is in line with the PR objective. This update improves consistency in the number type usage.

To ensure this change is applied consistently, run the following script:

✅ Verification successful

Number type refactoring verified

The usage of z_number has been successfully removed and replaced with number_t across the codebase. No instances of z_number were found, and number_t is used consistently.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Verify that z_number is not used anymore and number_t is used consistently

# Check for any remaining usage of z_number
rg --type cpp 'z_number'

# Check for usage of number_t
rg --type cpp 'number_t'

Length of output: 1312

src/crab_utils/bignums.hpp (1)

102-104: Verify correct masking in truncate_to function

In the truncate_to function on lines 102-104, the mask is set to std::numeric_limits<U>::max(), which masks all bits of the type U. If the intention is to truncate _n to the bit width of T, this works correctly. However, if truncation to a specific smaller bit width is required, the mask should be adjusted accordingly. Please confirm that the current implementation meets the truncation requirements.

src/crab/ebpf_domain.cpp (2)

226-227: Verify default value assignment in lih_ub

At line 226, when left_interval.ub().number() is null, lih_ub is assigned -1:

number_t lih_ub = left_interval.ub().number() ? left_interval.ub().number()->truncate_to<int64_t>() : -1;

Ensure that -1 is the appropriate default value in this context and that it does not introduce logical errors downstream.


2616-2617: Ensure safe casting in cast_to_sint with variable finite_width

In lines 2616-2617 and 2709-2710, cast_to_sint(finite_width) is used:

number_t lb_w = lb.cast_to_sint(finite_width);
number_t ub_w = ub.cast_to_sint(finite_width);

Verify that cast_to_sint correctly handles all possible values of finite_width and that it does not introduce undefined behavior or incorrect casting, especially when finite_width is not 32 or 64.

Also applies to: 2709-2710

@coveralls
Copy link

coveralls commented Sep 25, 2024

Coverage Status

coverage: 90.397% (+0.03%) from 90.367%
when pulling 365c047 on number_t-cleanup
into 3d14be0 on main.

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: 18

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 35e2274 and 4bbf1cc.

📒 Files selected for processing (10)
  • scripts/.check-license.ignore (1 hunks)
  • src/crab/cfg.hpp (1 hunks)
  • src/crab/interval.hpp (1 hunks)
  • src/crab/split_dbm.cpp (17 hunks)
  • src/crab/split_dbm.hpp (3 hunks)
  • src/crab/variable.hpp (1 hunks)
  • src/crab_utils/adapt_sgraph.hpp (2 hunks)
  • src/crab_utils/num_big.hpp (1 hunks)
  • src/crab_utils/num_extended.hpp (1 hunks)
  • src/crab_utils/num_safeint.hpp (2 hunks)
🔇 Additional comments not posted (12)
src/crab/variable.hpp (2)

Line range hint 1-124: Verify the removal of the Hasher struct and its impact.

The AI summary mentions the removal of a Hasher struct from the variable_t class, but this change is not visible in the provided code. This discrepancy needs to be addressed.

Please run the following script to verify the removal of the Hasher struct and assess its impact:

#!/bin/bash
# Description: Verify the removal of the Hasher struct and its impact.

# Test 1: Check for any remaining references to the Hasher struct
echo "Checking for any remaining references to the Hasher struct:"
rg --type cpp "struct\s+Hasher"

# Test 2: Look for potential usage of hash functionality related to variable_t
echo "Looking for potential usage of hash functionality related to variable_t:"
rg --type cpp "variable_t.*hash|hash.*variable_t"

# Test 3: Check for any custom hash implementations for variable_t in other files
echo "Checking for any custom hash implementations for variable_t in other files:"
rg --type cpp "namespace\s+std\s*\{[^}]*hash<.*variable_t.*\>[^}]*\}"

If the Hasher struct has indeed been removed, please ensure that:

  1. Any code relying on the Hasher struct has been updated accordingly.
  2. The removal doesn't break any existing functionality or introduce any unintended side effects.
  3. If the hashing functionality is still needed, verify that an alternative implementation is in place.

11-11: Verify the consistency of the header file change.

The include statement has been updated from "crab_utils/bignums.hpp" to "crab_utils/num_big.hpp". This change suggests a renaming or restructuring of the header files.

Please run the following script to ensure this change is consistent across the codebase and doesn't introduce any unintended side effects:

✅ Verification successful

Re-verify the header file changes with corrected scripts.

The previous verification script encountered errors. Please run the following updated script to ensure the consistency of the header file change and that no unintended references remain:


Header file renaming verified successfully.

All references to bignums.hpp have been removed, and num_big.hpp is consistently used across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the consistency of the header file change and its impact.

# Test 1: Check if the old header file still exists
echo "Checking if the old header file still exists:"
fd --type f "bignums.hpp" --exec echo "Old header file found: {}"

# Test 2: Check for any remaining references to the old header file
echo "Checking for any remaining references to the old header file:"
rg --type cpp "bignums\.hpp"

# Test 3: Verify that the new header file exists
echo "Verifying that the new header file exists:"
fd --type f "num_big.hpp" --exec echo "New header file found: {}"

# Test 4: Check for consistent usage of the new header file
echo "Checking for consistent usage of the new header file:"
rg --type cpp "num_big\.hpp"

Length of output: 861


Script:

#!/bin/bash
# Description: Re-verify the consistency of the header file change and its impact.

# Test 1: Check if the old header file still exists
echo "Checking if the old header file 'bignums.hpp' still exists:"
fd --type f "bignums.hpp" --exec echo "Old header file found: {}"

# Test 2: Check for any remaining references to the old header file
echo "Checking for any remaining references to 'bignums.hpp':"
rg --type cpp "bignums\.hpp"

# Test 3: Verify that the new header file exists
echo "Verifying that the new header file 'num_big.hpp' exists:"
fd --type f "num_big.hpp" --exec echo "New header file found: {}"

# Test 4: Check for consistent usage of the new header file
echo "Checking for consistent usage of 'num_big.hpp':"
rg --type cpp "num_big\.hpp"

Length of output: 1098

src/crab_utils/num_safeint.hpp (3)

15-15: Verify the new header file.

The include statement has been updated from "crab_utils/bignums.hpp" to "crab_utils/num_big.hpp". This change appears to be part of a larger renaming or restructuring effort.

Please run the following script to ensure the new header file exists and contains the necessary declarations:


Line range hint 1-141: Ensure consistency across the codebase and update related documentation.

The changes in this file are part of a larger renaming effort from z_number to number_t. While the changes in this file are minimal and straightforward, it's crucial to ensure consistency across the entire codebase.

Please run the following script to check for any remaining instances of z_number and to identify any documentation that might need updating:

After running these checks:

  1. Update any remaining instances of z_number to number_t.
  2. Update relevant documentation to reflect the new number_t terminology.
  3. Address any TODOs or FIXMEs related to this renaming effort.

77-77: Approve the constructor signature change and verify number_t interface.

The constructor signature has been updated from safe_i64(const z_number& n) to safe_i64(const number_t& n), which is consistent with the renaming effort mentioned in the summary.

To ensure the change doesn't introduce any issues, please run the following script to verify the interface of number_t:

Make sure that number_t provides the same interface as z_number, particularly the operator int64_t() const method, which is used in this constructor.

src/crab/cfg.hpp (1)

27-27: Approve header change and suggest verification

The change from crab_utils/bignums.hpp to crab_utils/num_big.hpp looks good and aligns with the PR objective of cleaning up the number_t interface. However, it's important to ensure this change doesn't break any existing functionality.

To verify the impact of this change across the codebase, please run the following script:

This script will help ensure that the header file change has been consistently applied across the codebase and that the new header file exists. It will also help identify any potential uses of big number types or functions that might need to be updated.

✅ Verification successful

Header inclusion change verified successfully

All references to crab_utils/bignums.hpp have been removed, the new header crab_utils/num_big.hpp exists, and the inclusion has been correctly updated across the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check for any remaining references to the old header file and verify the existence of the new one.

# Check if there are any remaining references to the old header
echo "Checking for remaining references to bignums.hpp:"
rg "crab_utils/bignums\.hpp"

# Verify the existence of the new header file
echo "Verifying the existence of num_big.hpp:"
fd "num_big.hpp"

# Check for any uses of types or functions that might have changed
echo "Checking for potential uses of big number types or functions:"
rg -i "bignum|big_num|num_big"

Length of output: 789

src/crab_utils/num_extended.hpp (2)

140-143: ⚠️ Potential issue

Review casting negative numbers to unsigned types in UDiv.

In the UDiv method, negative numbers are cast to unsigned types using dividend.cast_to<M>(). Casting negative values to unsigned types might lead to unexpected behavior due to integer underflow. Ensure that this casting correctly represents the intended unsigned computation, and consider adding checks or assertions to handle negative inputs appropriately.

Run the following script to identify any usage of UDiv with potential negative operands:


98-106: ⚠️ Potential issue

Verify correctness of multiplication involving zero and infinity.

In the operator*, when multiplying zero with infinity, the current implementation returns zero. Mathematically, zero multiplied by infinity is undefined. Ensure that this behavior aligns with the intended mathematical model and consider handling this case explicitly if necessary.

Run the following script to check for multiplication cases involving zero and infinity:

✅ Verification successful

Multiplication Handling Verified

The operator* for extended_number correctly manages cases involving zero and infinity as per the current implementation.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Find all multiplication operations involving extended_number instances.

# Test: Search for multiplication operations with extended_number.
rg --type cpp 'extended_number.*\*' --glob '!src/crab_utils/num_extended.hpp'

Length of output: 79


Script:

#!/bin/bash
# Description: Find all explicit and implicit multiplication operations involving extended_number instances.

# Search for explicit use of operator* with extended_number
rg --type cpp 'operator\*' --glob '!src/crab_utils/num_extended.hpp'

# Search for implicit multiplication involving extended_number by looking for '*' where operands could be extended_number
rg --type cpp '\bextended_number\b\s*\*\s*\b' --glob '!src/crab_utils/num_extended.hpp'

Length of output: 2050

src/crab/split_dbm.hpp (2)

35-36: Includes for numerical utilities are appropriately added.

The inclusion of "crab_utils/num_big.hpp" and "crab_utils/num_safeint.hpp" ensures that the necessary numerical utilities are available for handling big numbers and safe integer operations.


51-52: Type aliases updated for clarity and consistency.

The graph_t and Weight type aliases are now directly associated with AdaptGraph and AdaptGraph::Weight, respectively. This enhances readability and aligns the SplitDBM class more closely with the underlying graph implementation.

src/crab_utils/adapt_sgraph.hpp (1)

9-9: LGTM on updating the include directive

The inclusion of "crab_utils/num_safeint.hpp" is appropriate given the change to number_t. This ensures that all necessary definitions are available.

src/crab/interval.hpp (1)

14-15: Verify the removal of obsolete header and update dependencies

The inclusion of crab_utils/num_big.hpp and crab_utils/num_extended.hpp suggests that crab_utils/bignums.hpp has been replaced. Ensure that all references to crab_utils/bignums.hpp are removed and the codebase is updated to use the new numerical utilities.

Run the following script to verify that there are no remaining references to the obsolete header:

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: 4

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 4bbf1cc and cd1e24b.

📒 Files selected for processing (2)
  • src/crab/ebpf_domain.cpp (15 hunks)
  • src/crab_utils/num_big.hpp (1 hunks)
🧰 Additional context used
📓 Learnings (1)
src/crab/ebpf_domain.cpp (1)
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.
🔇 Additional comments not posted (18)
src/crab_utils/num_big.hpp (5)

143-148: Division operator correctly handles division by zero

The operator/ method appropriately checks for division by zero and throws an error if necessary. The implementation is correct.


150-155: Modulo operator correctly handles division by zero

The operator% method correctly checks for division by zero and throws an error if necessary. The implementation is sound.


228-236: Shift operators are correctly implemented

The operator<< method now properly checks for negative shift amounts and ensures the shift value fits into an int32_t. This prevents undefined behavior.


238-246: Right shift operator correctly handles negative shift amounts

The operator>> method includes checks for negative shift amounts and verifies that the shift value fits into an int32_t, preventing undefined behavior.


188-208: Increment and decrement operators are properly defined

The pre-increment, post-increment, pre-decrement, and post-decrement operators are correctly implemented with lvalue reference qualifiers. This ensures that these operators cannot be called on rvalues, preventing unintended modifications to temporaries.

src/crab/ebpf_domain.cpp (13)

208-209: Use of explicit truncation to int32_t

The truncation of intervals to int32_t enhances type clarity and ensures values are correctly confined to 32-bit signed integers.


223-223: Verify the default value when upper bound is absent

In line 223, a default value of -1 is used if the upper bound is not available:

number_t lih_ub = left_interval.ub().number() ? left_interval.ub().number()->truncate_to<int64_t>() : -1;

Ensure that using -1 as the default does not introduce errors in subsequent computations, especially when lih_ub is intended to represent an upper bound.


231-232: Consistent truncation to int64_t

The truncation to int64_t maintains consistency for 64-bit signed intervals, enhancing code reliability.


253-254: Use of explicit truncation to uint32_t

Truncating intervals to uint32_t ensures that values are correctly confined to 32-bit unsigned integers.


267-268: Clarify usage of number_t{-1} for unsigned intervals

Previous feedback on lines 267-268 about using number_t{UINT64_MAX} instead of number_t{-1} remains applicable.


275-276: Consistent truncation to uint64_t

The consistent use of truncate_to<uint64_t>() for unsigned 64-bit intervals improves code clarity and type safety.


319-319: Ensure safe truncation to int32_t

At line 319:

auto lpub = left_interval_positive.truncate_to<int32_t>().ub();

Verify that left_interval_positive does not contain values outside the int32_t range before truncation to prevent potential data loss or incorrect upper bounds.


347-347: Ensure safe truncation to int64_t

In line 347:

auto lpub = left_interval_positive.truncate_to<int64_t>().ub();

Confirm that the truncation to int64_t is appropriate and that the interval values fit within the 64-bit signed integer range to avoid unexpected behavior.


Line range hint 478-489: Check truncation to uint64_t for interval bounds

Lines 478 and 489 involve truncating intervals to uint64_t:

auto lllb = left_interval_low.truncate_to<uint64_t>().lb();
...
auto lhlb = left_interval_high.truncate_to<uint64_t>().lb();

Ensure that the intervals being truncated are within the valid range of uint64_t to prevent incorrect lower bounds.


502-502: Confirm upper bound after truncation to uint64_t

At line 502:

auto llub = left_interval_low.truncate_to<uint64_t>().ub();

Verify that the upper bound llub accurately reflects the intended value and that truncation does not result in unintended wrap-around or data loss.


556-557: Validate truncation and bounds calculations

In lines 556-557:

auto rlb = right_interval.lb();
auto llub = left_interval_low.truncate_to<uint64_t>().ub();

Ensure that truncating to uint64_t is appropriate and that calculations involving rlb and llub are correct.


1380-1384: Review truncation sequence for correctness

Lines 1380-1384 perform a sequence of truncations:

number_t lb = lb_value.truncate_to_uint(finite_width);
number_t ub = ub_value.truncate_to_uint(finite_width);
...
lb = lb.truncate_to<int64_t>();
ub = ub.truncate_to<int64_t>();

Ensure that this sequence maintains the correct value transformations and that truncating from unsigned to signed integers does not introduce errors, especially when values exceed the signed integer range.


2604-2605: Ensure safe casting with cast_to_sint

In lines 2604-2605:

number_t lb_w = lb.cast_to_sint(finite_width);
number_t ub_w = ub.cast_to_sint(finite_width);

Confirm that the values of lb and ub are within the valid range before casting to signed integers to prevent potential overflows or undefined behavior.

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

📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between cd1e24b and 213e5ba.

📒 Files selected for processing (1)
  • src/crab_utils/num_big.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 not posted (9)
src/crab_utils/num_big.hpp (9)

27-31: Constructors are well-defined and handle various initialization cases

The constructors appropriately handle initialization from different types, including cpp_int, integral types, enums, and strings. Casting enums to int64_t is intentional and aligns with the retrieved learnings.


33-39: Correct implementation of type conversion operator

The explicit conversion operator template properly checks if the value fits into the target type before casting, ensuring that out-of-range errors are caught.


44-46: Efficient hashing by utilizing existing hash_value function

The hash_value friend function delegates hashing to the hash_value of _n, which avoids unnecessary conversions and leverages the existing hash implementation for cpp_int.


51-52: Accurate range checking in fits method

The fits method correctly determines if the internal value _n fits within the limits of type T, ensuring safe conversions without data loss.


60-71: Robust implementation of cast_to method with comprehensive checks

The cast_to method attempts to cast the internal value to the desired type or its opposite signedness, providing flexibility while ensuring that the value fits to prevent undefined behavior.


227-235: Shift operators correctly handle edge cases

The operator<< method includes necessary checks for negative shift amounts and ensures the shift value fits into an int32_t, preventing undefined behavior.


237-245: Right shift operator implementation is sound

Similar to the left shift operator, the operator>> method properly checks for negative shift amounts and validates the shift value's range.


248-253: Use of msb function in fill_ones method is appropriate

The fill_ones method utilizes msb to compute the most significant bit. As per retrieved learnings, since msb is defined in the included headers, there is no issue.


23-259: Overall well-structured and comprehensive implementation

The number_t class provides extensive support for arbitrary precision arithmetic with appropriate operator overloads, error handling, and type conversions. The code is clean, follows best practices, and is ready for integration.

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