Repository navigation
JSON.stringify under -mm=own; json.ts runs under every model - #85
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
tests/json.tswas marked// not own, so it never ran under-mm=own. Compiling it there showed three problems. Two were inJSON.stringifyand are fixed here. The third is a compiler limit.JSON.stringifyusedvalueon two code paths (with and without aspace), andowncounts it as moved on the first. It now calls the conversion once.JsonValuepassed in. Strings are now copied. Underownonly, aJsonValueis copied with a newJsonValue.clone(), a deep copy declared inlib.d.ts. The other memory models still use the value directly, as before.own,set()andpush()return a borrow of the object they're called on, soJsonValue.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.tsnow builds its values one step at a time and runs under every model. The// not ownmarker is gone.json.ts, inside anif (__MEMORY_MODEL__ != "own")block that the compiler leaves out underown. They still run under the other three models.gc, withmain's generics too, so I didn't use one.I rebuilt the four libraries on the current compiler and ran:
jsonandjson_readundergc,rc,noneandown, compiled and under the JIT: all pass;message_queueandcatch_library_errortests under all four: all pass;own, compiled: 199 passed, 6 skipped, none failed.Not run locally:
scripts/check_declarations.ps1: it hangs on this machine,main's sources included, so I added theclone()declaration by hand. CI doesn't run it.README
JSON.stringifytakes only numbers and strings underown.clone()is listed with the otherJsonValuemethods.set()/push()is named as the remainingownlimit.🤖 Generated with Claude Code