Add source-side make plumbing hooks#58
Draft
quinnj wants to merge 3 commits into
Draft
Conversation
extract(style, T, source, tags) is the boundary between the make recursion and leaf-value conversion. Format packages overload it for source types they own; users keep overloading lift with (style, target-type) and may return plain values (normalized here, absorbing JSON.jl's _liftresult). preparekey lets source packages normalize internal key representations (e.g. JSON.jl's PtrString) before liftkey sees them. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Without this, deeply nested struct targets explode compile time: after Julia's recursion limiter widens the target type mid-recursion, abstract extract call sites match 2-3 methods and inference explores the large lazy-driver body per context (JSON.jl's Store benchmark struct: 1065s). With @max_methods 1, abstract sites bail to Any immediately while every concrete site (the entire static hot path) still infers precisely — making nested-struct compile times faster than the pre-extract design (Store: 17s -> 2.4s). Also add extract/preparekey unit tests. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Add handleunknownfield as a source-side dispatch point that delegates to the existing user-facing unknownfield hook by default. This lets source packages enforce source-local unknown-field policy without defining opposite-axis methods on unknownfield itself.
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.
Summary
StructUtils.extractas the source-side leaf conversion boundary used bymake.StructUtils.preparekeyso source packages can normalize internal key representations beforeliftkey.StructUtils.handleunknownfieldso source packages can enforce source-local unknown-field policy without overloading the user-facingunknownfieldhook.2.9.0for the new hooks.Why
This gives format/source packages a clean place to handle source-owned representations and traversal state while keeping user extension hooks focused on style and target type dispatch. The
handleunknownfieldhook specifically avoids opposite-axis ambiguities between source-specific unknown-field policy and user-definedunknownfield(::MyStyle, ::Type{T}, ...)methods.Validation
julia --startup-file=no --project=. -e 'using Pkg; Pkg.test()'Pkg.test("JSON")julia +1.9 --startup-file=no --project=. -e 'using StructUtils'julia +1.10 --startup-file=no --project=. -e 'using StructUtils'Co-authored by Codex