-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
[JuliaLowering] Tidy up node creation functions #60191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
We currently use keyword arguments as arbitrary key-value pairs in a number of
places, which I've realized isn't really how they're intended to be used.
This change fixes this and reduces the JuliaLowering package image size by
about 20% on my machine from `26.910 MiB -> 21.701 MiB`, or when compiled
into sysbase.dylib, `+55MB -> +45MB`. Unfortunately no change to
precompile time as I had hoped, but I figured this is worth doing anyway.
I've just used `Vector{Pair}` or explicit `setattr` calls, but let me know if
there's a better way of doing this.
Also let me know if you have a reason for the difference in size when compiled
into Base---I don't think I'm accidentally producing two copies, but you
never know.
| function set_scope_layer(ctx, ex, layer_id, force) | ||
| k = kind(ex) | ||
| scope_layer = force ? layer_id : get(ex, :scope_layer, layer_id) | ||
| attrs = [:scope_layer=>(force ? layer_id : get(ex, :scope_layer, layer_id))] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| attrs = [:scope_layer=>(force ? layer_id : get(ex, :scope_layer, layer_id))] | |
| attrs = Pair{Symbol,LayerId}[ | |
| :scope_layer=>(force ? layer_id : get(ex, :scope_layer, layer_id)) | |
| ] |
if you're really trying to be strict about specializations, it can be a good idea to explicitly type most arrays, since:
Pairover-specializes just likeNamedTuple(so the strict array type will eitherconvertthis away or push you to fix the type instability), and- Whether this vector ends up well-typed depends on inference /
Base._return_type(esp. bad for recursive functions)
| elseif k == K"." | ||
| makenode(ctx, ex, ex, set_scope_layer(ctx, ex[1], layer_id, force), ex[2], | ||
| scope_layer=scope_layer) | ||
| children = [set_scope_layer(ctx, ex[1], layer_id, force), ex[2]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| children = [set_scope_layer(ctx, ex[1], layer_id, force), ex[2]] | |
| children = NodeId[set_scope_layer(ctx, ex[1], layer_id, force), ex[2]] |
see above
| elseif !is_leaf(ex) | ||
| mapchildren(e->set_scope_layer(ctx, e, layer_id, force), ctx, ex; | ||
| scope_layer=scope_layer) | ||
| mapchildren(e->set_scope_layer(ctx, e, layer_id, force), ctx, ex, attrs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this method doesn't exist, unless I misread something?
| function mapchildren(f::Function, ctx, ex::SyntaxTree, mapped_children::AbstractVector{<:Integer}; | ||
| extra_attrs...) | ||
| function mapchildren(f::Function, ctx, ex::SyntaxTree, | ||
| mapped_children::AbstractVector{<:Integer}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
narrowing this to Vector{NodeId} would be a good idea, if it's possible
|
|
||
| function makenode(ctx, srcref, proto, children...; attrs...) | ||
| _makenode(ctx, srcref, proto, _node_ids(syntax_graph(ctx), children...); attrs...) | ||
| function makeleaf(ctx, srcref, proto, @nospecialize(attrs::AbstractVector)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another normalization trick you might consider trying out at some point is:
@noinline function _makeleaf(..., attrs::Vector{Any})
# ... (complicated function)
end
@inline function makeleaf(..., @nospecialize(attrs::AbstractVector))
return _makeleaf(..., convert(Vector{Any}, attrs))
endThis preserves "good" codegen, while trying to limit specialized code to the caller side. Ofc, it's even better if we can avoid the Vector type explosion to begin with.
We currently use keyword arguments as arbitrary key-value pairs in a number of
places, which I've realized isn't really how they're intended to be used.
This change fixes this and reduces the JuliaLowering package image size by
about 20% on my machine from
26.910 MiB -> 21.701 MiB, or when compiledinto sysbase.dylib,
+55MB -> +45MB. Unfortunately no change toprecompile time as I had hoped, but I figured this is worth doing anyway.
Lowering performance looks unchanged.
I've just used
Vector{Pair}or explicitsetattrcalls, but let me know ifthere's a better way of doing this.
Also let me know if you have a reason for the difference in size when compiled
into Base---I don't think I'm accidentally producing two copies, but you
never know.