[JuliaLowering] Switch to typed attribute API#61480
Open
topolarity wants to merge 5 commits intoJuliaLang:masterfrom
Open
[JuliaLowering] Switch to typed attribute API#61480topolarity wants to merge 5 commits intoJuliaLang:masterfrom
topolarity wants to merge 5 commits intoJuliaLang:masterfrom
Conversation
This API is more verbose, but I think the improvements in clarity and
type-stability justify the investment. In cases where attributes are
intentionally type-unstable (`:value`) this instability is much easier
to read / grep for.
The `::Type{T} where T` parameter should also allow us to experiment
with other SyntaxGraph attribute storage styles, such as determining
the type of the inner `Dict` based on the provided `T`.
I performed the changes to `JuliaSyntax` manually and then had Claude
roll out the remaining changes across `JuliaLowering` for me. I tried
to force the bot to be consistent about the types used when accessing
each attribute, so I don't expect major correct-ness issues but I do
plan to review the code for structure / formatting before merge.
---------
Co-authored-by: Claude <claude@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.
This PR proposes a switch to a more verbose attribute API which expects attribute types to be provided at the call-site, rather than leaving them implicit (or enforcing them by ad-hoc typeasserts). I believe this PR also fixes several pre-existing type-instabilities around our usage of
.scope_layerand.var_id, which were hard to spot otherwise.Changes:
Base.getproperty/Base.setproperty!overloads for SyntaxGraph / SyntaxTree::Type{T}first argument to all*attrmethodsThe
::Type{T} where Tparameter should also allow us to experiment with other SyntaxGraph attribute storage styles, such as using a Dict{NodeId, UInt16} for:flagsor a BitSet for:is_toplevel_thunkas well as the existing Dict{NodeId, Any} for "untyped" attributes like:value. As a side benefit, this makes it much easier to identify attribute accesses in the source code and see (at a glance) whether they are type-unstable.The main alternative would be to:
NamedTuple(or similar) type parameter toSyntaxGraphORwhich would avoid you needing to supply these types at the call-site. That would make it much harder for us to remove the
Attrstype-parameter forSyntaxGraphthough (if we ever choose to do that) and it would be less flexible.Dependent on #61425.
Co-authored-by: Claude claude@anthropic.com 🤖
I performed the changes to
JuliaSyntaxmanually and then had Claude roll out the remaining changes acrossJuliaLoweringfor me. I tried to force the bot to be consistent about the types used when accessing each attribute, so I don't expect major correctness issues but I do plan to review the code for structure / formatting before merge.