-
-
Notifications
You must be signed in to change notification settings - Fork 18
Prototype a new LoopItemsObjectProperties instruction
#725
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ inline auto is_noop_without_children(const InstructionIndex type) noexcept | |
| case InstructionIndex::LoopItems: | ||
| case InstructionIndex::LoopItemsFrom: | ||
| case InstructionIndex::LoopItemsUnevaluated: | ||
| case InstructionIndex::LoopItemsObjectProperties: | ||
| case InstructionIndex::LoopContains: | ||
| case InstructionIndex::ControlGroupWhenDefines: | ||
| case InstructionIndex::ControlGroupWhenDefinesDirect: | ||
|
|
@@ -417,7 +418,65 @@ inline auto postprocess(std::vector<Instructions> &targets, | |
| } | ||
| } | ||
|
|
||
| std::size_t loop_items_object_candidate{SIZE_MAX}; | ||
| std::size_t type_array_candidate{SIZE_MAX}; | ||
| for (std::size_t scan = 0; scan < current->size(); scan++) { | ||
| const auto &scan_instruction{(*current)[scan]}; | ||
| if ((scan_instruction.type == InstructionIndex::LoopItems || | ||
| (scan_instruction.type == InstructionIndex::LoopItemsFrom && | ||
| std::get<ValueUnsignedInteger>(scan_instruction.value) == 0)) && | ||
| scan_instruction.children.size() == 1 && | ||
| scan_instruction.children.front().type == | ||
| InstructionIndex::AssertionObjectPropertiesSimple) { | ||
| loop_items_object_candidate = scan; | ||
| } | ||
|
|
||
| if ((scan_instruction.type == InstructionIndex::AssertionTypeStrict || | ||
| scan_instruction.type == InstructionIndex::AssertionType || | ||
| scan_instruction.type == | ||
| InstructionIndex::AssertionPropertyTypeStrict || | ||
| scan_instruction.type == | ||
| InstructionIndex::AssertionPropertyType) && | ||
| std::get<ValueType>(scan_instruction.value) == | ||
| sourcemeta::core::JSON::Type::Array) { | ||
| type_array_candidate = scan; | ||
| } | ||
| } | ||
|
|
||
| const bool fuse_loop_items_object{loop_items_object_candidate != | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In Severity: medium 🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage. |
||
| SIZE_MAX && | ||
| type_array_candidate != SIZE_MAX}; | ||
|
|
||
| for (auto &instruction : *current) { | ||
| if (fuse_loop_items_object) { | ||
| if (&instruction == &(*current)[type_array_candidate]) { | ||
| changed = true; | ||
| continue; | ||
| } | ||
|
|
||
| if (&instruction == &(*current)[loop_items_object_candidate]) { | ||
| auto &child{instruction.children.front()}; | ||
| const auto new_extra_index{extra.size()}; | ||
| auto &parent_meta{extra[instruction.extra_index]}; | ||
| auto &child_meta{extra[child.extra_index]}; | ||
| extra.push_back( | ||
| {.relative_schema_location = | ||
| parent_meta.relative_schema_location.concat( | ||
| child_meta.relative_schema_location), | ||
| .keyword_location = std::move(child_meta.keyword_location), | ||
| .schema_resource = child_meta.schema_resource}); | ||
| result.push_back(Instruction{ | ||
| .type = InstructionIndex::LoopItemsObjectProperties, | ||
| .relative_instance_location = | ||
| std::move(instruction.relative_instance_location), | ||
| .value = std::move(child.value), | ||
| .children = std::move(child.children), | ||
| .extra_index = new_extra_index}); | ||
| changed = true; | ||
| continue; | ||
| } | ||
| } | ||
|
|
||
| if (!fusion_covered_properties.empty()) { | ||
| switch (instruction.type) { | ||
| case InstructionIndex::AssertionDefinesAllStrict: | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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.
In
src/compiler/postprocess.h:43, treatingInstructionIndex::LoopItemsObjectPropertiesas a no-op whenchildren.empty()looks incorrect: the instruction still enforces that the target is an array and each item is an object, and it can also enforce required properties encoded invalueeven with zero children.Severity: high
🤖 Was this useful? React with 👍 or 👎, or 🚀 if it prevented an incident/outage.