-
Notifications
You must be signed in to change notification settings - Fork 83
feat(ffi): Update schema-tree-node-insertion IR unit's handler signature to receive the updated schema tree. #726
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
feat(ffi): Update schema-tree-node-insertion IR unit's handler signature to receive the updated schema tree. #726
Conversation
WalkthroughThis pull request updates the schema tree node insertion process by adding a new parameter to the Changes
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
Possibly related PRs
Suggested reviewers
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ Context from checks skipped due to timeout of 90000ms (12)
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 whetherschema_treecan 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
📒 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}: - Preferfalse == <expression>rather than!<expression>.
components/core/src/clp/ffi/ir_stream/IrUnitHandlerInterface.hppcomponents/core/src/clp/ffi/ir_stream/Deserializer.hppcomponents/core/src/clp_s/JsonParser.cppcomponents/core/tests/test-ir_encoding_methods.cppcomponents/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 forstd::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 theschema_treeas astd::shared_ptrby 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 handlingstd::shared_ptr.
24-25: Signature expansion is consistent.
Addingschema_tree_node_locatorandstd::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 anIRErrorCode.components/core/tests/test-ffi_IrUnitHandlerInterface.cpp (1)
43-44: Method signature matches the interface changes.
The additionalschema_treeparameter 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:
- The node is guaranteed to exist in the tree when the handler is called
- 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:
- Accepts
schema_tree_node_locatorby value as required by the interface- Uses
std::shared_ptr<const T> const&for the schema tree parameter, which is appropriate for shared ownership
| 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; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| 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; | |
| } |
| {SchemaTree::cRootId, cTestSchemaTreeNodeKeyName, SchemaTree::Node::Type::Obj}, | ||
| nullptr |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
| {SchemaTree::cRootId, cTestSchemaTreeNodeKeyName, SchemaTree::Node::Type::Obj}, | |
| nullptr | |
| {SchemaTree::cRootId, cTestSchemaTreeNodeKeyName, SchemaTree::Node::Type::Obj}, | |
| std::make_shared<SchemaTree const>() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor docstring clarifications.
Co-authored-by: kirkrodrigues <[email protected]>
There was a problem hiding this 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.
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
breaking change.
Validation performed
Summary by CodeRabbit
Bug Fixes
Tests