Skip to content

JSON.stringify under -mm=own; json.ts runs under every model - #85

Merged
ASDAlexander77 merged 1 commit into
mainfrom
json-own
Nov 9, 2026
Merged

ASDAlexander77 merged 1 commit into
mainfrom
json-own

Conversation

@ASDAlexander77

Copy link
Copy Markdown
Owner

What

tests/json.ts was marked // not own, so it never ran under -mm=own. Compiling it there showed three problems. Two were in JSON.stringify and are fixed here. The third is a compiler limit.

  1. JSON.stringify used value on two code paths (with and without a space), and own counts it as moved on the first. It now calls the conversion once.
  2. The conversion took over values it was only lent: the strings in an array, and a JsonValue passed in. Strings are now copied. Under own only, a JsonValue is copied with a new JsonValue.clone(), a deep copy declared in lib.d.ts. The other memory models still use the value directly, as before.
  3. Chained building is not fixed. Under own, set() and push() return a borrow of the object they're called on, so JsonValue.newObject().set(...).set(...) can't be kept. The compiler has no way to say a method gives that object back as an owned value, so this needs a compiler change.

Tests

  • tests/json.ts now builds its values one step at a time and runs under every model. The // not own marker is gone.
  • The chained cases stay in json.ts, inside an if (__MEMORY_MODEL__ != "own") block that the compiler leaves out under own. They still run under the other three models.
  • A separate file for the chained cases hit an unrelated "can't instantiate function" compiler error under gc, with main's generics too, so I didn't use one.

I rebuilt the four libraries on the current compiler and ran:

  • json and json_read under gc, rc, none and own, compiled and under the JIT: all pass;
  • the worker, message_queue and catch_library_error tests under all four: all pass;
  • the whole suite under own, compiled: 199 passed, 6 skipped, none failed.

Not run locally:

  • The debug configuration: this machine's compiler debug runtime is out of date, so CI runs it first.
  • scripts/check_declarations.ps1: it hangs on this machine, main's sources included, so I added the clone() declaration by hand. CI doesn't run it.

README

  • It no longer says JSON.stringify takes only numbers and strings under own.
  • clone() is listed with the other JsonValue methods.
  • Chained set() / push() is named as the remaining own limit.

🤖 Generated with Claude Code

tests/json.ts was skipped under -mm=own. Compiled there it showed three
things:

- JSON.stringify used `value` on two paths (stringify() with and
  without a space): own counts it moved on the first. It now calls
  toValue once.
- toValue took over what it was only lent: an array's string elements,
  and a JsonValue given as it is. Strings are copied; under own a
  JsonValue is copied with the new JsonValue.clone() (a deep copy,
  declared in lib.d.ts). The other models share it, as before.
- Chained set() / push() (JsonValue.newObject().set(...).set(...)):
  their result borrows the value they were called on, so a chain from
  a new value can't be kept. Not fixable here: the compiler has no way
  to say that a method gives its receiver back.

json.ts builds its values one step at a time, so it runs under every
model; the chained cases stay in it, in a branch only compiled when
__MEMORY_MODEL__ != "own". README: JSON.stringify takes everything it
supports under own too, clone() is listed, and chains are named as the
remaining own limit.

json and json_read pass under gc, rc, none and own, release, compiled
and under the JIT; the whole suite passes under own (199 passed, 6
skipped). Debug not built locally; scripts/check_declarations.ps1
hangs here, so the clone() declaration was added by hand.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ASDAlexander77
ASDAlexander77 merged commit 916cd07 into main Nov 9, 2026
10 checks passed
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.

1 participant