Skip to content

feat(json): enumerate JSON object members (hpm_json_object_len/_key) - #799

Draft
hyperpolymath wants to merge 3 commits into
claude/gifted-lamport-k0mc5lfrom
claude/gifted-lamport-k0mc5l-json-objects
Draft

hyperpolymath wants to merge 3 commits into
claude/gifted-lamport-k0mc5lfrom
claude/gifted-lamport-k0mc5l-json-objects

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Depends on: #798

Split from #798 on the owner's ruling after review. That review found that the new object branch of to_json calls two externs with no Zig export yet, so a native build linking to_json would fail on unresolved symbols.

What

  • hpm_json_object_len and hpm_json_object_key let to_json materialise objects; on main it returns None for them, the gap json.affine documents.
  • They are lowered on Bun-ESM. Index 0 snapshots the object's own keys and later indices reuse the snapshot, so a walk does one Object.keys (review: it was one per key).
  • Integer-like keys: JavaScript lists them first, while std.json keeps document order. The externs document that callers must not rely on that relative order.

Why this waits

The matching hpm-json-rsr Zig exports (hpm_json_object_len, hpm_json_object_key) must land first, and the owner requires atoma to verify them before the consumer leaves alpha. This session could not run a downloaded Zig binary; Guix is being set up to provide Zig 0.15.2. A PR on hyperpolymath/hpm-json-rsr will be linked here, and this stays a draft until it merges.

Consumer: metadatastician/consent-aware-inspector pins this branch's head, because its manifest validation enumerates policy keys.

Tests

  • tests/codegen-bun/json_object_keys: keys in order, nested round-trip, escaped keys, own keys only, an inherited enumerable key excluded, non-finite members rejected.
  • json_escapes: objects now convert.

Local runs on this branch: dune runtest passes 594 tests; the Bun harnesses pass (7 plus negative controls); the codegen-deno corpus passes 39 harnesses and the WASM corpus 38.

Known, tracked separately: to_json accumulates with acc ++ [x] (O(n²) for very large objects). The owner chose to fix that with an affine in-place push in the stdlib, as its own PR.

Commits are unsigned. This container's signing shim is inactive.


Generated by Claude Code

Split from #798 on the owner's ruling. to_json materialises objects
instead of returning None: hpm_json_object_len / hpm_json_object_key,
lowered on Bun-ESM (one Object.keys snapshot per walk). Native targets need
the matching hpm-json-rsr Zig exports; this PR waits for them, so no native
build meets an unresolved symbol.

Tests: tests/codegen-bun/json_object_keys (keys, nesting, escaped keys,
own keys only, inherited enumerable key, non-finite values) and
json_escapes (objects now convert).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDiosfvobXq67wbduuK
@coderabbitai

coderabbitai Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

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.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 18e03daa-9925-48d6-9d81-94667030e0fe

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

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

A Wasm module that imports json's externs (`use json::*`) now imports
hpm_json_object_len and hpm_json_object_key as well: 13 hpm_json_*
imports instead of 11, under the `json` module. A host supplying only
the v0.3 set fails with a LinkError at instantiation (checked with
Bun's WebAssembly on this commit). The spec now says so, and how a host
can stub the two until hpm-json-rsr exports them.

Answers the outside-diff finding on stdlib/json.affine in the CodeRabbit
review of #798; the externs moved to this PR.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01J4QvDiosfvobXq67wbduuK
@sonarqubecloud

Copy link
Copy Markdown

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