Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@LinZhihao-723
Copy link
Member

@LinZhihao-723 LinZhihao-723 commented Feb 20, 2025

Description

As required by clp-ffi-js, we realized the schema-tree-node-insertion IR unit handler needs a reference to the schema tree to identify a path in the tree that contains the inserted node. This PR updates the IR unit handler signature to receive the schema tree as a shared ptr, thus allowing the handler to access the inserted tree.
Notice that we decided to pass a shared ptr instead of a raw reference because we don't have any promises of the schema tree's lifetime.

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • Ensure all workflows passed.
  • Update the unit test to ensure the inserted node can be found in the given tree.

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced the process for handling schema tree node insertions, introducing specific error codes for various failure scenarios to improve robustness and error detection.
  • Tests

    • Updated test scenarios to validate the new error handling logic and ensure compliance with the updated method signatures, contributing to overall system stability and reliability.

@LinZhihao-723 LinZhihao-723 requested a review from a team as a code owner February 20, 2025 22:03
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 20, 2025

Walkthrough

This pull request updates the schema tree node insertion process by adding a new parameter to the handle_schema_tree_node_insertion method across various components. The changes affect both the interface and implementation, altering method signatures to include a shared pointer to a constant schema tree. Additionally, the call ordering in the deserialization process is modified so that the handler processes the node insertion before the actual insertion call is made. Test cases have been updated accordingly with enhanced error handling and adjusted method invocations.

Changes

File(s) Change Summary
components/core/src/clp/ffi/ir_stream/Deserializer.hpp Updated deserialize_next_ir_unit to pass an additional schema_tree parameter to handle_schema_tree_node_insertion and repositioned the insertion call post handler processing.
components/core/src/clp/ffi/ir_stream/IrUnitHandlerInterface.hpp,
components/core/src/clp_s/JsonParser.cpp
Modified the handle_schema_tree_node_insertion method signature to include std::shared_ptr<SchemaTree const>, ensuring that the associated schema tree is provided.
components/core/tests/test-ffi_IrUnitHandlerInterface.cpp,
components/core/tests/test-ir_encoding_methods.cpp
Updated the test implementations to conform to the revised method signature and added error handling logic for schema tree node validation.

Sequence Diagram(s)

sequenceDiagram
    participant Caller as Caller
    participant Deserializer as Deserializer
    participant Handler as IR Unit Handler
    participant Inserter as Node Inserter

    Caller->>Deserializer: call deserialize_next_ir_unit()
    Deserializer->>Handler: handle_schema_tree_node_insertion(is_auto_generated, node_locator, schema_tree)
    Handler->>Inserter: execute node insertion
    Inserter-->>Handler: return insertion result
    Handler-->>Deserializer: return handler outcome
Loading

Possibly related PRs

Suggested reviewers

  • kirkrodrigues
  • davidlion

📜 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 da95801 and 040cd20.

📒 Files selected for processing (1)
  • components/core/tests/test-ir_encoding_methods.cpp (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • components/core/tests/test-ir_encoding_methods.cpp
⏰ Context from checks skipped due to timeout of 90000ms (12)
  • GitHub Check: ubuntu-focal-static-linked-bins
  • GitHub Check: ubuntu-jammy-static-linked-bins
  • GitHub Check: centos-stream-9-static-linked-bins
  • GitHub Check: ubuntu-focal-dynamic-linked-bins
  • GitHub Check: ubuntu-jammy-dynamic-linked-bins
  • GitHub Check: centos-stream-9-dynamic-linked-bins
  • GitHub Check: build-macos (macos-14, false)
  • GitHub Check: lint-check (ubuntu-latest)
  • GitHub Check: build-macos (macos-13, false)
  • GitHub Check: build-macos (macos-13, true)
  • GitHub Check: lint-check (macos-latest)
  • GitHub Check: build (macos-latest)

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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
Contributor

@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

🧹 Nitpick comments (1)
components/core/src/clp/ffi/ir_stream/IrUnitHandlerInterface.hpp (1)

50-50: Specify nullability in the doc comment.
Clarify whether schema_tree can be null. Currently, the documentation states it “contains the inserted node,” implying non-null.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a554d05 and da95801.

📒 Files selected for processing (5)
  • components/core/src/clp/ffi/ir_stream/Deserializer.hpp (1 hunks)
  • components/core/src/clp/ffi/ir_stream/IrUnitHandlerInterface.hpp (3 hunks)
  • components/core/src/clp_s/JsonParser.cpp (1 hunks)
  • components/core/tests/test-ffi_IrUnitHandlerInterface.cpp (2 hunks)
  • components/core/tests/test-ir_encoding_methods.cpp (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}`: - Prefer `false == ...

**/*.{cpp,hpp,java,js,jsx,tpp,ts,tsx}: - Prefer false == <expression> rather than !<expression>.

  • components/core/src/clp/ffi/ir_stream/IrUnitHandlerInterface.hpp
  • components/core/src/clp/ffi/ir_stream/Deserializer.hpp
  • components/core/src/clp_s/JsonParser.cpp
  • components/core/tests/test-ir_encoding_methods.cpp
  • components/core/tests/test-ffi_IrUnitHandlerInterface.cpp
🧠 Learnings (4)
components/core/src/clp/ffi/ir_stream/IrUnitHandlerInterface.hpp (2)
Learnt from: LinZhihao-723
PR: y-scope/clp#549
File: components/core/tests/test-ir_encoding_methods.cpp:110-110
Timestamp: 2024-11-10T16:46:58.543Z
Learning: The function `handle_schema_tree_node_insertion` in `IrUnitHandler` must accept `clp::ffi::SchemaTree::NodeLocator` by value to match the `IrUnitHandlerInterface`.
Learnt from: LinZhihao-723
PR: y-scope/clp#549
File: components/core/tests/test-ir_encoding_methods.cpp:108-113
Timestamp: 2024-11-10T16:46:53.300Z
Learning: The method `handle_schema_tree_node_insertion` must be a member function to implement `IrUnitHandlerInterface`.
components/core/src/clp_s/JsonParser.cpp (1)
Learnt from: LinZhihao-723
PR: y-scope/clp#549
File: components/core/tests/test-ir_encoding_methods.cpp:110-110
Timestamp: 2024-11-10T16:46:58.543Z
Learning: The function `handle_schema_tree_node_insertion` in `IrUnitHandler` must accept `clp::ffi::SchemaTree::NodeLocator` by value to match the `IrUnitHandlerInterface`.
components/core/tests/test-ir_encoding_methods.cpp (2)
Learnt from: LinZhihao-723
PR: y-scope/clp#549
File: components/core/tests/test-ir_encoding_methods.cpp:110-110
Timestamp: 2024-11-10T16:46:58.543Z
Learning: The function `handle_schema_tree_node_insertion` in `IrUnitHandler` must accept `clp::ffi::SchemaTree::NodeLocator` by value to match the `IrUnitHandlerInterface`.
Learnt from: LinZhihao-723
PR: y-scope/clp#549
File: components/core/tests/test-ir_encoding_methods.cpp:108-113
Timestamp: 2024-11-10T16:46:53.300Z
Learning: The method `handle_schema_tree_node_insertion` must be a member function to implement `IrUnitHandlerInterface`.
components/core/tests/test-ffi_IrUnitHandlerInterface.cpp (2)
Learnt from: LinZhihao-723
PR: y-scope/clp#549
File: components/core/tests/test-ir_encoding_methods.cpp:110-110
Timestamp: 2024-11-10T16:46:58.543Z
Learning: The function `handle_schema_tree_node_insertion` in `IrUnitHandler` must accept `clp::ffi::SchemaTree::NodeLocator` by value to match the `IrUnitHandlerInterface`.
Learnt from: LinZhihao-723
PR: y-scope/clp#549
File: components/core/tests/test-ir_encoding_methods.cpp:108-113
Timestamp: 2024-11-10T16:46:53.300Z
Learning: The method `handle_schema_tree_node_insertion` must be a member function to implement `IrUnitHandlerInterface`.
⏰ Context from checks skipped due to timeout of 90000ms (10)
  • GitHub Check: ubuntu-jammy-static-linked-bins
  • GitHub Check: centos-stream-9-static-linked-bins
  • GitHub Check: ubuntu-focal-static-linked-bins
  • GitHub Check: ubuntu-focal-dynamic-linked-bins
  • GitHub Check: ubuntu-jammy-dynamic-linked-bins
  • GitHub Check: centos-stream-9-dynamic-linked-bins
  • GitHub Check: build-macos (macos-14, false)
  • GitHub Check: build-macos (macos-14, true)
  • GitHub Check: build-macos (macos-13, false)
  • GitHub Check: build-macos (macos-13, true)
🔇 Additional comments (10)
components/core/tests/test-ir_encoding_methods.cpp (3)

4-4: No issues with adding <memory>.
Including the header is necessary for std::shared_ptr.


114-123: Documentation block aligns well with the new parameter.
The doc comments clearly mention the new parameter’s role in the process.


126-127: Function signature update is coherent.
Accepting the schema_tree as a std::shared_ptr by const reference is a good practice to avoid unnecessary copies.

components/core/src/clp/ffi/ir_stream/IrUnitHandlerInterface.hpp (3)

5-5: Header inclusion is consistent with usage.
Including <memory> is appropriate for handling std::shared_ptr.


24-25: Signature expansion is consistent.
Adding schema_tree_node_locator and std::shared_ptr<SchemaTree const> to the concept matches the updated insertion logic.


54-58: Concept check updated correctly.
The concept lines up with the revised interface, ensuring it returns an IRErrorCode.

components/core/tests/test-ffi_IrUnitHandlerInterface.cpp (1)

43-44: Method signature matches the interface changes.
The additional schema_tree parameter enables handling node insertions with context, although consider verifying non-null usage where applicable.

components/core/src/clp/ffi/ir_stream/Deserializer.hpp (2)

239-244: LGTM! The changes improve the handler's functionality and error handling.

The reordering of operations and addition of the schema tree parameter provide two key benefits:

  1. The node is guaranteed to exist in the tree when the handler is called
  2. The handler has access to the schema tree context for path identification

235-237: LGTM! Robust error handling for duplicate nodes.

The code properly validates node existence before insertion, preventing potential schema tree corruption.

components/core/src/clp_s/JsonParser.cpp (1)

55-61: LGTM! The handler signature follows the required parameter passing conventions.

The implementation correctly:

  1. Accepts schema_tree_node_locator by value as required by the interface
  2. Uses std::shared_ptr<const T> const& for the schema tree parameter, which is appropriate for shared ownership

Comment on lines +129 to +135
auto const optional_node_id{schema_tree->try_get_node_id(schema_tree_node_locator)};
if (false == optional_node_id.has_value()) {
return IRErrorCode::IRErrorCode_Decode_Error;
}
if (optional_node_id.value() != schema_tree->get_size() - 1) {
return IRErrorCode::IRErrorCode_Corrupted_IR;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Check for null pointer before dereferencing schema_tree.
The code unconditionally invokes schema_tree->try_get_node_id(...), risking undefined behaviour if schema_tree is null. Consider returning an appropriate error code in that scenario.

Below is one potential fix:

+ if (!schema_tree) {
+     return IRErrorCode::IRErrorCode_Decode_Error;
+ }
  auto const optional_node_id{schema_tree->try_get_node_id(schema_tree_node_locator)};
  if (false == optional_node_id.has_value()) {
      return IRErrorCode::IRErrorCode_Decode_Error;
  }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
auto const optional_node_id{schema_tree->try_get_node_id(schema_tree_node_locator)};
if (false == optional_node_id.has_value()) {
return IRErrorCode::IRErrorCode_Decode_Error;
}
if (optional_node_id.value() != schema_tree->get_size() - 1) {
return IRErrorCode::IRErrorCode_Corrupted_IR;
}
if (!schema_tree) {
return IRErrorCode::IRErrorCode_Decode_Error;
}
auto const optional_node_id{schema_tree->try_get_node_id(schema_tree_node_locator)};
if (false == optional_node_id.has_value()) {
return IRErrorCode::IRErrorCode_Decode_Error;
}
if (optional_node_id.value() != schema_tree->get_size() - 1) {
return IRErrorCode::IRErrorCode_Corrupted_IR;
}

Comment on lines +115 to +116
{SchemaTree::cRootId, cTestSchemaTreeNodeKeyName, SchemaTree::Node::Type::Obj},
nullptr
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Passing nullptr may cause runtime issues.
Currently, the handler would dereference the pointer without a null check. Tests should confirm handling of null or switch to passing a valid pointer.

You could address it by adding a null check in the handler or by passing a real tree instance. For example:

-              nullptr
+              std::make_shared<SchemaTree const>()
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
{SchemaTree::cRootId, cTestSchemaTreeNodeKeyName, SchemaTree::Node::Type::Obj},
nullptr
{SchemaTree::cRootId, cTestSchemaTreeNodeKeyName, SchemaTree::Node::Type::Obj},
std::make_shared<SchemaTree const>()

Copy link
Member

@kirkrodrigues kirkrodrigues left a comment

Choose a reason for hiding this comment

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

Minor docstring clarifications.

Copy link
Member

@kirkrodrigues kirkrodrigues left a comment

Choose a reason for hiding this comment

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

For the PR title, how about:

feat(ffi): Update schema-tree-node-insertion IR unit's handler signature to receive the updated schema tree.

@LinZhihao-723 LinZhihao-723 changed the title feat(ffi): Update schema-tree-node-insertion IR unit's handler signature to receive the inserted schema tree. feat(ffi): Update schema-tree-node-insertion IR unit's handler signature to receive the updated schema tree. Feb 21, 2025
@LinZhihao-723 LinZhihao-723 merged commit 5dc26c2 into y-scope:main Feb 21, 2025
22 checks passed
@LinZhihao-723 LinZhihao-723 deleted the node-insertion-update branch June 5, 2025 14:59
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