Skip to content

[JuliaLowering] Switch to typed attribute API#61480

Open
topolarity wants to merge 5 commits intoJuliaLang:masterfrom
topolarity:ct/JL-typed-attrs
Open

[JuliaLowering] Switch to typed attribute API#61480
topolarity wants to merge 5 commits intoJuliaLang:masterfrom
topolarity:ct/JL-typed-attrs

Conversation

@topolarity
Copy link
Copy Markdown
Member

@topolarity topolarity commented Apr 2, 2026

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_layer and .var_id, which were hard to spot otherwise.

Changes:

  1. Remove Base.getproperty / Base.setproperty! overloads for SyntaxGraph / SyntaxTree
  2. Add ::Type{T} first argument to all *attr methods

The ::Type{T} where T parameter should also allow us to experiment with other SyntaxGraph attribute storage styles, such as using a Dict{NodeId, UInt16} for :flags or a BitSet for :is_toplevel_thunk as 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:

  1. Encode this type information as a separate NamedTuple (or similar) type parameter to SyntaxGraph OR
  2. Hard-code the expected types globally for each attribute

which would avoid you needing to supply these types at the call-site. That would make it much harder for us to remove the Attrs type-parameter for SyntaxGraph though (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 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 correctness issues but I do plan to review the code for structure / formatting before merge.

mlechu and others added 5 commits April 1, 2026 09:23
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>
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.

2 participants