Skip to content

Add AnnotationEmitCollection instruction and format standard output annotations - #1014

Open
HarshPopat23 wants to merge 2 commits into
sourcemeta:mainfrom
HarshPopat23:feat-annotation-collection-instruction
Open

Add AnnotationEmitCollection instruction and format standard output annotations#1014
HarshPopat23 wants to merge 2 commits into
sourcemeta:mainfrom
HarshPopat23:feat-annotation-collection-instruction

Conversation

@HarshPopat23

@HarshPopat23 HarshPopat23 commented Aug 31, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR introduces the \AnnotationEmitCollection\ instruction to distinguish collection-shaped annotations (such as property names from the \properties\ keyword) from scalar/singleton annotations (such as metadata keywords \ itle, \description,
eadOnly, \default, and unknown keyword annotations under custom vocabularies).

This is the prerequisite PR requested in #978 to separate instruction design and standard output value wrapping from the official output test suite integration.

Changes

  1. Instruction & Dispatch:
    • Added \InstructionIndex::AnnotationEmitCollection\ (opcode 100) and \InstructionNames.
    • Added \is_annotation\ and \is_collection_annotation\ helpers.
    • Updated C++ dispatch table (\handlers[101]) with zero runtime overhead.
    • Added \AnnotationEmitCollection\ opcode and handler support to the JavaScript port (\opcodes.mjs, \describe.mjs, \index.mjs, \index.d.mts).
  2. Compiler:
    • Updated \default_compiler_draft3.h\ to emit \AnnotationEmitCollection\ for \properties\ keyword annotations.
  3. Standard Output:
    • Updated \output_simple.h\ / \output_simple.cc\ to track \is_collection\ per annotation entry.
    • Updated \output_standard.cc\ so collection annotations are formatted as arrays while scalar annotations are preserved as raw values.
  4. Tests:
    • Added unit tests for \is_annotation\ and \is_collection_annotation\ in \evaluator_test.cc.
    • Added unit tests for multiple properties, scalar metadata annotations, and custom dialect scalar annotations in \output_standard_basic_test.cc.
    • Updated trace assertions in \output_trace_test.cc\ and expectations in \output_standard_basic.json.

Ref: #978

…nnotations

Signed-off-by: HarshPopat23 <musichk61@gmail.com>
@HarshPopat23
HarshPopat23 force-pushed the feat-annotation-collection-instruction branch from d93eb41 to 2a161cf Compare August 31, 2026 20:03

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="test/output/output_standard_basic.json">

<violation number="1" location="test/output/output_standard_basic.json:42">
P2: The new `success_properties_multiple` test expects the `properties` collection annotation in alphabetical order `["bar", "foo"]`, but this file is the shared suite run by both the C++ and JavaScript ports via `output.test.mjs`. C++ produces alphabetical order (its `prettify_annotations_multiple` test matches), yet the JS `LoopProperties` handler in `ports/javascript/index.mjs` iterates instance keys with `for (const key in target)`, which for instance `{"foo":"a","bar":"b"}` yields `["foo","bar"]`. The two ports will serialize the same annotation in different orders, so this expectation cannot hold for both ports and the shared JS suite will diverge from the C++ expectation.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

"keywordLocation": "/properties",
"absoluteKeywordLocation": "#/properties",
"instanceLocation": "",
"annotation": [ "bar", "foo" ]

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: The new success_properties_multiple test expects the properties collection annotation in alphabetical order ["bar", "foo"], but this file is the shared suite run by both the C++ and JavaScript ports via output.test.mjs. C++ produces alphabetical order (its prettify_annotations_multiple test matches), yet the JS LoopProperties handler in ports/javascript/index.mjs iterates instance keys with for (const key in target), which for instance {"foo":"a","bar":"b"} yields ["foo","bar"]. The two ports will serialize the same annotation in different orders, so this expectation cannot hold for both ports and the shared JS suite will diverge from the C++ expectation.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At test/output/output_standard_basic.json, line 42:

<comment>The new `success_properties_multiple` test expects the `properties` collection annotation in alphabetical order `["bar", "foo"]`, but this file is the shared suite run by both the C++ and JavaScript ports via `output.test.mjs`. C++ produces alphabetical order (its `prettify_annotations_multiple` test matches), yet the JS `LoopProperties` handler in `ports/javascript/index.mjs` iterates instance keys with `for (const key in target)`, which for instance `{"foo":"a","bar":"b"}` yields `["foo","bar"]`. The two ports will serialize the same annotation in different orders, so this expectation cannot hold for both ports and the shared JS suite will diverge from the C++ expectation.</comment>

<file context>
@@ -20,6 +20,30 @@
+          "keywordLocation": "/properties",
+          "absoluteKeywordLocation": "#/properties",
+          "instanceLocation": "",
+          "annotation": [ "bar", "foo" ]
+        }
+      ]
</file context>
Suggested change
"annotation": [ "bar", "foo" ]
"annotation": [ "foo", "bar" ]

Comment thread ports/javascript/index.mjs Outdated
@HarshPopat23

Copy link
Copy Markdown
Collaborator Author

cc: @jviotti

ControlDynamicAnchorJump,
ControlJump};
ControlJump,
AnnotationEmitCollection};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can you put this one alongside the other annotation instructions and bump the template serialisation version instead?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done! I've placed AnnotationEmitWrapped alongside the other annotation instructions (index 51) and bumped JSON_VERSION from 6 to 7.

value);
}

INSTRUCTION_HANDLER(AnnotationEmitCollection) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The whole code looks good but I wonder if EmitCollection is the right name here. I think the idea of a "collection" here is a bit confusing to me. What about AnnotationEmitWrapped? I think that seems be more obvious to me? and you can rename the little helper in the standard output format and the variables accordingly?

Just a minor thing really, but I find "collection" confusing

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done! Renamed AnnotationEmitCollection to AnnotationEmitWrapped, is_collection_annotation to is_wrapped_annotation, and is_collection to is_wrapped across the C++ and JavaScript codebases.

@jviotti

jviotti commented Sep 1, 2026

Copy link
Copy Markdown
Member

Some minor comments, but looks very solid so far

@HarshPopat23
HarshPopat23 force-pushed the feat-annotation-collection-instruction branch from 1bf7745 to 79d2f53 Compare September 2, 2026 19:24

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 issues found across 14 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="src/evaluator/include/sourcemeta/blaze/evaluator.h">

<violation number="1" location="src/evaluator/include/sourcemeta/blaze/evaluator.h:49">
P2: The JSON_VERSION bump to 7 breaks the JS port's version tests in ports/javascript/official.test.mjs, which still expect the `'Only version 6 ...'` error message. With version 7, the `[7, false, false, [[]], [], []]` template is accepted as a valid version so `assert.throws` gets no error, and the `{}` case now throws `'Only version 7 ...'`, mismatching the asserted string. Update those two assertions (and the test template to an unsupported version such as 6) in ports/javascript/official.test.mjs to match the new version.</violation>
</file>

<file name="ports/javascript/opcodes.mjs">

<violation number="1" location="ports/javascript/opcodes.mjs:52">
P1: The rename leaves stale `ANNOTATION_EMIT_COLLECTION` references in the JavaScript callback and description paths. A `properties` annotation now uses opcode 51, so trace and standard-output validation throw `ReferenceError` instead of reporting the annotation; update those comparisons to `ANNOTATION_EMIT_WRAPPED`.</violation>
</file>

Tip: Review your code locally with the cubic CLI to iterate faster.

Re-trigger cubic

export const CONTROL_EVALUATE = 97;
export const CONTROL_DYNAMIC_ANCHOR_JUMP = 98;
export const CONTROL_JUMP = 99;
export const ANNOTATION_EMIT_WRAPPED = 51;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1: The rename leaves stale ANNOTATION_EMIT_COLLECTION references in the JavaScript callback and description paths. A properties annotation now uses opcode 51, so trace and standard-output validation throw ReferenceError instead of reporting the annotation; update those comparisons to ANNOTATION_EMIT_WRAPPED.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At ports/javascript/opcodes.mjs, line 52:

<comment>The rename leaves stale `ANNOTATION_EMIT_COLLECTION` references in the JavaScript callback and description paths. A `properties` annotation now uses opcode 51, so trace and standard-output validation throw `ReferenceError` instead of reporting the annotation; update those comparisons to `ANNOTATION_EMIT_WRAPPED`.</comment>

<file context>
@@ -49,56 +49,56 @@ export const ASSERTION_ARRAY_PREFIX = 47;
-export const CONTROL_DYNAMIC_ANCHOR_JUMP = 98;
-export const CONTROL_JUMP = 99;
-export const ANNOTATION_EMIT_COLLECTION = 100;
+export const ANNOTATION_EMIT_WRAPPED = 51;
+export const ANNOTATION_TO_PARENT = 52;
+export const ANNOTATION_BASENAME_TO_PARENT = 53;
</file context>

Comment thread ports/javascript/index.mjs
Comment thread ports/javascript/describe.mjs

/// @ingroup evaluator
constexpr std::size_t JSON_VERSION{6};
constexpr std::size_t JSON_VERSION{7};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: The JSON_VERSION bump to 7 breaks the JS port's version tests in ports/javascript/official.test.mjs, which still expect the 'Only version 6 ...' error message. With version 7, the [7, false, false, [[]], [], []] template is accepted as a valid version so assert.throws gets no error, and the {} case now throws 'Only version 7 ...', mismatching the asserted string. Update those two assertions (and the test template to an unsupported version such as 6) in ports/javascript/official.test.mjs to match the new version.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At src/evaluator/include/sourcemeta/blaze/evaluator.h, line 49:

<comment>The JSON_VERSION bump to 7 breaks the JS port's version tests in ports/javascript/official.test.mjs, which still expect the `'Only version 6 ...'` error message. With version 7, the `[7, false, false, [[]], [], []]` template is accepted as a valid version so `assert.throws` gets no error, and the `{}` case now throws `'Only version 7 ...'`, mismatching the asserted string. Update those two assertions (and the test template to an unsupported version such as 6) in ports/javascript/official.test.mjs to match the new version.</comment>

<file context>
@@ -46,7 +46,7 @@ struct Template {
 
 /// @ingroup evaluator
-constexpr std::size_t JSON_VERSION{6};
+constexpr std::size_t JSON_VERSION{7};
 
 /// @ingroup evaluator
</file context>

@HarshPopat23
HarshPopat23 force-pushed the feat-annotation-collection-instruction branch from 79d2f53 to cce674e Compare September 2, 2026 19:40
…plate version to 7

Rename instruction to AnnotationEmitWrapped and place alongside other annotation instructions.

Rename is_collection_annotation to is_wrapped_annotation and is_collection to is_wrapped.

Bump template serialization version JSON_VERSION from 6 to 7.

Update ports/javascript opcodes, handlers, and fastHandlers dispatch table.

Update evaluator describe, compiler, output formatters, and unit tests.

Signed-off-by: HarshPopat23 <musichk61@gmail.com>
@HarshPopat23
HarshPopat23 force-pushed the feat-annotation-collection-instruction branch from cce674e to 53e20e9 Compare September 2, 2026 20:10
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