Repository navigation
Let typed parses with a custom read style compile under juliac --trim - #555
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #555 +/- ##
==========================================
+ Coverage 94.14% 94.21% +0.06%
==========================================
Files 8 8
Lines 2324 2333 +9
==========================================
+ Hits 2188 2198 +10
+ Misses 136 135 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merged
quinnj-bot
Bot
force-pushed
the
claude/trim-custom-style-parse
branch
from
October 30, 2026 18:00
2e42bc7 to
70650b0
Compare
Since #543, a typed `JSON.parse` with a custom `StructStyle` builds nested objects and arrays with the style's hooks. Under `juliac --trim` that path failed verification, and in an unsafe build it threw `MethodError(indexed_iterate, ...)` at run time: - the "cannot parse" error message interpolated the `LazyValue`, which pulled `show(::LazyValue)` into the image; - a custom style's values, untyped because its hooks can return anything, were handed to callbacks (`ObjectClosure`'s value closure, `lift`'s `ValueClosure`), which is a dynamic call; - objects were built through `_makeobject`, whose fallback into StructUtils' generic `make` sits among the recursive calls; with it, `juliac` couldn't compile those calls (Julia 1.14) or, on 1.13, a later default-style `Dict{String,Any}` parse in the same program. For a custom style, `make(st, Any, x)` and `lift` now build objects and arrays with their concrete types (`_makecontainer`), objects without that fallback (`_makeobjectvalue`), and `ObjectClosure` takes `Any` values from `make` instead of a callback. Default-style code paths are unchanged. The trim entry-point test parses with a custom style, including `Any` fields, nested values and a `Dict` target, before the default-style parses. The docs say that `dicttype=` can't be used under `juliac --trim`. Fixes #553. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
quinnj-bot
Bot
force-pushed
the
claude/trim-custom-style-parse
branch
from
October 30, 2026 18:32
70650b0 to
ff4c43a
Compare
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Merged
quinnj
referenced
this pull request
Oct 30, 2026
Co-authored-by: Jacob Quinn <quinn.jacobd@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This was referenced Nov 2, 2026
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.
Fixes #553.
Since #543 (JSON 1.13.0), a typed
JSON.parsewith a custom read style failsjuliac --trimverification. The trimmed program can also fail at run time:"[1]"parsed intoInt64threwMethodError(indexed_iterate, ...)instead of theMethodError(convert, ...)the JIT throws.What was wrong:
LazyValue, which bringsshow(::LazyValue)and Base's array printing into the image.ObjectClosure's value closure,lift'sValueClosure), which is a dynamic call._makeobject. Its fallback into StructUtils' genericmake, for input that isn't an object, sits among the recursive calls. With it there,juliaccouldn't compile those calls on Julia 1.14. On 1.13 it couldn't compile a later default-styleJSON.parse(s, Dict{String,Any})in the same program: 2 unresolved invokes ofapplyobject, depending on which parse inference reached first. JSON 1.12.2 had neither problem.What changed:
make(st, Any, x)andliftbuild objects and arrays with their concrete types (_makecontainer). Objects go through_makeobjectvalue, which is_makeobjectwithout that fallback; the input is already known to be an object there.ObjectClosuretakes a custom style'sAnyvalues frommakeinstead of a callback._customstylechecks that fold away at compile time were added to them.dicttype=keyword can't be used underjuliac --trim. A type passed as a keyword reaches the parser as a plainDataType.--trim=safereports this, and an unsafe build fails at run time. There's nothing to fix in JSON for this.Test:
test/json_trim_public_entrypoints.jlgainsexercise_custom_style_parse:Anyfield holding nested objects, arrays, numbers including a BigInt, null and bools;Dict{String,Any}target;MethodError.It runs before the default-style parses, so it also covers the ordering problem.
Verification (macOS arm64, JuliaC 0.3.12,
--trim=safeunless noted):The new trim test fails on master and passes with this PR:
The issue's repro has no verifier errors with this PR. For
42,[1],{"a":1},"x",null,true,1.5and nested input, the trimmed program gives the same result or exception as the JIT.A custom-style parse followed by a default
Dict{String,Any}parse in one program builds clean on 1.12.7, 1.13.3 and 1.14.0-alpha2. That program is also clean on JSON 1.12.2 and on a7ec7ba, the commit before Fix Any-field lift and parse-option regressions; lift targets get the parse's options #543.Full test suite passes locally on Julia 1.10.12, 1.12.7 and 1.13.3. Trim compile is 7/7 on 1.12 and 1.13 and skipped on 1.10.
Default-style speed: the default style's code paths are the same as on master, including with
null=,dicttype=anderror_context=true. An earlier version that sent defaultnull=parses through_makecontainermeasured +4% to +12% on 1.13.3 forAnyfields, so default styles keep master's path.Independent review of the previous head: JIT results matched master in 53,493 cases (9 styles, 9 option sets, 26 targets, 22 inputs), and 19
--trim=safeprograms built and matched the JIT on 1.12.7, 1.13.3 and 1.14.0-alpha2. Custom-style parses use 22-69% fewer instructions, and an 8,000-keyAnyobject is still built in one pass. On this head, every custom-style program in that set builds clean on 1.13.3 and 1.14.0-alpha2.Not changed, and as on master: default-style
null=anderror_context=trueparses intoAnyfields aren't trim-safe yet (2 and 6 verifier errors on 1.13.3), and neither iserror_context=truewith a custom style.Note:
juliac --trim=unsafe-warnreported neither the dynamic callback call nor thedicttype=one.--trim=safereported both, and both failed at run time.🤖 Generated with Claude Code