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

Clang-tidy fix clp::ffi namespace top level folder files and related test cases #509

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Bill-hbrhbr
Copy link
Contributor

Description

To be written

Validation performed

Verified that test cases still pass after necessary non-functional modifications.

@kirkrodrigues
Copy link
Member

@Bill-hbrhbr, can you fix the unit test failure before the review?

Copy link
Member

@LinZhihao-723 LinZhihao-723 left a comment

Choose a reason for hiding this comment

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

This will be the first round of the review. Talking to Kirk and we decided to also apply the latest coding standards even though they might not trigger a clang-tidy warning. This means there should be more stuff to be fixed in this PR. At some point we might need to draw the line that what are the stuff we want to include in this PR, but I guess we can start with these current comments. Note that some comments should be propagated to all the files, such as using {} for initialization whenever possible.

Comment on lines +48 to +65
class EncodingException : public TraceableException {
public:
// Constructors
EncodingException(
ErrorCode error_code,
char const* const filename,
int line_number,
std::string message
)
: TraceableException(error_code, filename, line_number),
m_message(std::move(message)) {}

// Methods
[[nodiscard]] auto what() const noexcept -> char const* override { return m_message.c_str(); }

private:
std::string m_message;
};
Copy link
Member

Choose a reason for hiding this comment

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

How about moving this class to a dedicated header?

Comment on lines +57 to +58
: TraceableException(error_code, filename, line_number),
m_message(std::move(message)) {}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
: TraceableException(error_code, filename, line_number),
m_message(std::move(message)) {}
: TraceableException{error_code, filename, line_number},
m_message{std::move(message)} {}

Copy link
Member

Choose a reason for hiding this comment

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

How about constants.hpp?

Comment on lines +14 to +46
/*
* These constants can be used by callers to store the version of the schemas and encoding methods
* they're using. At some point, we may update and/or add built-in schemas/encoding methods. So
* callers must store the versions they used for encoding to ensure that they can choose the same
* versions for decoding.
*
* We use versions which look like package names in anticipation of users writing their own custom
* schemas and encoding methods.
*/
constexpr std::string_view cVariableEncodingMethodsVersion
= "com.yscope.clp.VariableEncodingMethodsV1";
constexpr std::string_view cVariablesSchemaVersion = "com.yscope.clp.VariablesSchemaV2";

constexpr std::string_view cTooFewDictionaryVarsErrorMessage
= "There are fewer dictionary variables than dictionary variable placeholders in the "
"logtype.";
constexpr std::string_view cTooFewEncodedVarsErrorMessage
= "There are fewer encoded variables than encoded variable placeholders in the logtype.";
constexpr std::string_view cUnexpectedEscapeCharacterMessage
= "Unexpected escape character without escaped value at the end of the logtype.";
constexpr std::string_view cTooManyDigitsErrorMsg = "Encoded number of digits doesn't match "
"encoded digits in encoded float.";

constexpr size_t cMaxDigitsInRepresentableEightByteFloatVar = 16;
constexpr size_t cMaxDigitsInRepresentableFourByteFloatVar = 8;
constexpr uint64_t cEightByteEncodedFloatNumDigits = 54;
constexpr uint64_t cFourByteEncodedFloatNumDigits = 25;
constexpr uint64_t cEightByteEncodedFloatDigitsBitMask = (1ULL << 54) - 1;
constexpr uint32_t cFourByteEncodedFloatDigitsBitMask = (1UL << 25) - 1;

constexpr size_t cDecimalBase = 10;
constexpr uint32_t cLowerFourDigitsBitMask = (1UL << 4) - 1;
constexpr uint32_t cLowerThreeDigitsBitMask = (1UL << 3) - 1;
Copy link
Member

Choose a reason for hiding this comment

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

Can we use {} for initialization instead?

} // namespace clp::ffi

// TODO Refactor nested headers
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// TODO Refactor nested headers
// TODO: Refactor nested headers

Just wanna make sure: you will send a PR immediately after this one to get rid of .inc right?

uint8_t num_high_bits
= std::is_same_v<TestType, four_byte_encoded_variable_t> ? 1 : 2;
for (size_t high_bits = 0; high_bits < num_high_bits; ++high_bits) {
for (size_t high_bits{0}; high_bits < num_high_bits; ++high_bits) {
TestType test_encoded_var;
if (std::is_same_v<TestType, eight_byte_encoded_variable_t>) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if (std::is_same_v<TestType, eight_byte_encoded_variable_t>) {
if constexpr (std::is_same_v<TestType, eight_byte_encoded_variable_t>) {

uint8_t num_high_bits
= std::is_same_v<TestType, four_byte_encoded_variable_t> ? 1 : 2;
for (size_t high_bits = 0; high_bits < num_high_bits; ++high_bits) {
for (size_t high_bits{0}; high_bits < num_high_bits; ++high_bits) {
TestType test_encoded_var;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
TestType test_encoded_var;
TestType test_encoded_var{};

@@ -336,8 +266,8 @@ TEMPLATE_TEST_CASE(
);
// Since encode_float_properties erases the low bit of high_bits, we need to
// add it again manually
test_encoded_var
= (high_bits << 62) | (((1ULL << 62) - 1) & test_encoded_var);
test_encoded_var = (high_bits << num_low_bits)
Copy link
Member

Choose a reason for hiding this comment

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

The result is an unsigned integer no? I think we should use bit_cast for safety reasons

all_dictionary_vars.append(message.data() + begin_pos, message.data() + end_pos);
dictionary_var_end_offsets.push_back(all_dictionary_vars.length());
all_dictionary_vars.append(message, begin_pos, end_pos - begin_pos);
dictionary_var_end_offsets.emplace_back(all_dictionary_vars.length());
Copy link
Member

Choose a reason for hiding this comment

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

For fundamental types let's use push_back since no in-place constructors are needed

size_t all_dictionary_vars_length = 0;
size_t num_dictionary_vars = 0;
size_t all_dictionary_vars_length{0};
size_t num_dictionary_vars{0};
for (auto current = dictionary_var_bounds.cbegin(); dictionary_var_bounds.cend() != current;) {
Copy link
Member

Choose a reason for hiding this comment

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

We should assert the length is an even number, otherwise if a wrong size is given this loop will never end and segfault.

@kirkrodrigues kirkrodrigues marked this pull request as draft November 13, 2024 12:33
@kirkrodrigues kirkrodrigues added the on hold On hold temporarily label Nov 13, 2024
Copy link
Contributor

coderabbitai bot commented Nov 13, 2024

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


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.

@kirkrodrigues
Copy link
Member

On hold until we have resources to continue the effort. Potential action items:

  • Split the PR into smaller changes so that if there's any violation of our conventions, we don't need to apply the change in a lot of places.
  • Merge main to pick up the latest lint configs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on hold On hold temporarily
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants