Skip to content

Conversation

@nsajko
Copy link
Member

@nsajko nsajko commented Aug 25, 2025

Make the temporary existing_kinds::Vector infer concretely.

NB: a more thorough solution might do away with the construction of existing_kinds altogether, however this seems like an OK quick fix.

(cherry picked from commit 2774125)

xref:

Make the temporary `existing_kinds::Vector` infer concretely.

NB: a more thorough solution might do away with the construction of
`existing_kinds` altogether, however this seems like an OK quick fix.

(cherry picked from commit 2774125)
@nsajko
Copy link
Member Author

nsajko commented Aug 26, 2025

These sysimage invalidations in particular are at least some of those that are eliminated:

Click to expand

{
    "method_instance": {
        "method": "(::Base.JuliaSyntax.var\"#Kind##0#Kind##1\")() @ Base.JuliaSyntax ~/tmp/jl/julia-git/playground/upstream/base/JuliaSyntax/src/kinds.jl:47",
        "method_instance": "MethodInstance for (::Base.JuliaSyntax.var\"#Kind##0#Kind##1\"{<:AbstractString})()"
    },
    "children": [
        {
            "method_instance": {
                "method": "get(default::Union{Function, Type}, h::Dict{K, V}, key) where {K, V} @ Base dict.jl:526",
                "method_instance": "MethodInstance for get(::Base.JuliaSyntax.var\"#Kind##0#Kind##1\"{<:AbstractString}, ::Dict{String, UInt16}, ::AbstractString)"
            },
            "children": [
                {
                    "method_instance": {
                        "method": "Base.JuliaSyntax.Kind(s::AbstractString) @ Base.JuliaSyntax ~/tmp/jl/julia-git/playground/upstream/base/JuliaSyntax/src/kinds.jl:45",
                        "method_instance": "MethodInstance for Base.JuliaSyntax.Kind(::AbstractString)"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "(::Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\")(n) @ Base.JuliaSyntax none:0",
                                "method_instance": "MethodInstance for (::Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}})(::String)"
                            },
                            "children": [
                                {
                                    "method_instance": {
                                        "method": "iterate(g::Base.Generator, s...) @ Base generator.jl:43",
                                        "method_instance": "MethodInstance for iterate(::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}})"
                                    },
                                    "children": [
                                        {
                                            "method_instance": {
                                                "method": "_iterator_upper_bound(itr) @ Base array.jl:768",
                                                "method_instance": "MethodInstance for Base._iterator_upper_bound(::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}})"
                                            },
                                            "children": [
                                                {
                                                    "method_instance": {
                                                        "method": "collect(itr::Base.Generator) @ Base array.jl:796",
                                                        "method_instance": "MethodInstance for collect(::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}})"
                                                    },
                                                    "children": [
                                                        {
                                                            "method_instance": {
                                                                "method": "_register_kinds!(kind_modules, int_to_kindstr, kind_str_to_int, mod, module_id, names) @ Base.JuliaSyntax ~/tmp/jl/julia-git/playground/upstream/base/JuliaSyntax/src/kinds.jl:78",
                                                                "method_instance": "MethodInstance for Base.JuliaSyntax._register_kinds!(::Dict{Int64, Union{Module, Symbol}}, ::Dict{UInt16, String}, ::Dict{String, UInt16}, ::Module, ::Int64, ::Vector{String})"
                                                            },
                                                            "children": [
                                                                {
                                                                    "method_instance": {
                                                                        "method": "register_kinds!(mod, module_id, names) @ Base.JuliaSyntax ~/tmp/jl/julia-git/playground/upstream/base/JuliaSyntax/src/kinds.jl:145",
                                                                        "method_instance": "MethodInstance for Base.JuliaSyntax.register_kinds!(::Module, ::Int64, ::Vector{String})"
                                                                    },
                                                                    "children": [
                                                                    ]
                                                                }
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "method_instance": {
                                                "method": "collect(itr::Base.Generator) @ Base array.jl:796",
                                                "method_instance": "MethodInstance for collect(::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}})"
                                            },
                                            "children": [
                                            ]
                                        }
                                    ]
                                },
                                {
                                    "method_instance": {
                                        "method": "iterate(g::Base.Generator, s...) @ Base generator.jl:43",
                                        "method_instance": "MethodInstance for iterate(::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}}, ::Int64)"
                                    },
                                    "children": [
                                        {
                                            "method_instance": {
                                                "method": "_iterator_upper_bound(itr) @ Base array.jl:768",
                                                "method_instance": "MethodInstance for Base._iterator_upper_bound(::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}})"
                                            },
                                            "children": [
                                            ]
                                        },
                                        {
                                            "method_instance": {
                                                "method": "collect_to!(dest::AbstractArray{T}, itr, offs, st) where T @ Base array.jl:856",
                                                "method_instance": "MethodInstance for Base.collect_to!(::Vector{Base.JuliaSyntax.Kind}, ::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}}, ::Int64, ::Int64)"
                                            },
                                            "children": [
                                            ]
                                        },
                                        {
                                            "method_instance": {
                                                "method": "collect_to!(dest::AbstractArray{T}, itr, offs, st) where T @ Base array.jl:856",
                                                "method_instance": "MethodInstance for Base.collect_to!(::Vector{Nothing}, ::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}}, ::Int64, ::Int64)"
                                            },
                                            "children": [
                                            ]
                                        },
                                        {
                                            "method_instance": {
                                                "method": "collect_to!(dest::AbstractArray{T}, itr, offs, st) where T @ Base array.jl:856",
                                                "method_instance": "MethodInstance for Base.collect_to!(::Vector{Union{Nothing, Base.JuliaSyntax.Kind}}, ::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}}, ::Int64, ::Int64)"
                                            },
                                            "children": [
                                                {
                                                    "method_instance": {
                                                        "method": "collect_to!(dest::AbstractArray{T}, itr, offs, st) where T @ Base array.jl:856",
                                                        "method_instance": "MethodInstance for Base.collect_to!(::Vector{Base.JuliaSyntax.Kind}, ::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}}, ::Int64, ::Int64)"
                                                    },
                                                    "children": [
                                                        {
                                                            "method_instance": {
                                                                "method": "collect_to_with_first!(dest::AbstractArray, v1, itr, st) @ Base array.jl:836",
                                                                "method_instance": "MethodInstance for Base.collect_to_with_first!(::Vector{Base.JuliaSyntax.Kind}, ::Base.JuliaSyntax.Kind, ::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}}, ::Int64)"
                                                            },
                                                            "children": [
                                                                {
                                                                    "method_instance": {
                                                                        "method": "collect(itr::Base.Generator) @ Base array.jl:796",
                                                                        "method_instance": "MethodInstance for collect(::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}})"
                                                                    },
                                                                    "children": [
                                                                    ]
                                                                }
                                                            ]
                                                        }
                                                    ]
                                                },
                                                {
                                                    "method_instance": {
                                                        "method": "collect_to!(dest::AbstractArray{T}, itr, offs, st) where T @ Base array.jl:856",
                                                        "method_instance": "MethodInstance for Base.collect_to!(::Vector{Nothing}, ::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}}, ::Int64, ::Int64)"
                                                    },
                                                    "children": [
                                                        {
                                                            "method_instance": {
                                                                "method": "collect_to_with_first!(dest::AbstractArray, v1, itr, st) @ Base array.jl:836",
                                                                "method_instance": "MethodInstance for Base.collect_to_with_first!(::Vector{Nothing}, ::Nothing, ::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}}, ::Int64)"
                                                            },
                                                            "children": [
                                                                {
                                                                    "method_instance": {
                                                                        "method": "collect(itr::Base.Generator) @ Base array.jl:796",
                                                                        "method_instance": "MethodInstance for collect(::Base.Generator{Vector{String}, Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}}})"
                                                                    },
                                                                    "children": [
                                                                    ]
                                                                }
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

Before this change, on master, they happen when executing something like this:

struct S <: AbstractString end
function Base.show(::IO, ::S) end

@nsajko
Copy link
Member Author

nsajko commented Aug 26, 2025

The PR also eliminates these invalidations:

{
    "method_instance": {
        "method": "print_to_string(xs...) @ Base strings/io.jl:136",
        "method_instance": "MethodInstance for Base.print_to_string(::String, ::Integer)"
    },
    "children": [
        {
            "method_instance": {
                "method": "string(xs...) @ Base strings/io.jl:189",
                "method_instance": "MethodInstance for string(::String, ::Integer)"
            },
            "children": [
                {
                    "method_instance": {
                        "method": "Base.JuliaSyntax.Kind(x::Integer) @ Base.JuliaSyntax ~/tmp/jl/julia-git/playground/upstream/base/JuliaSyntax/src/kinds.jl:38",
                        "method_instance": "MethodInstance for Base.JuliaSyntax.Kind(::Integer)"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "(::Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\")(n) @ Base.JuliaSyntax none:0",
                                "method_instance": "MethodInstance for (::Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}})(::String)"
                            },
                            "children": [
                            ]
                        },
                        {
                            "method_instance": {
                                "method": "(::Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\")(n) @ Base.JuliaSyntax none:0",
                                "method_instance": "MethodInstance for (::Base.JuliaSyntax.var\"#_register_kinds!##0#_register_kinds!##1\"{Dict{String, UInt16}})(::String)"
                            },
                            "children": [
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

Reproducer:

struct I <: Integer end
function Base.promote_rule(::Type{Bool}, ::Type{I}) end

Some more:

{
    "method_instance": {
        "method": "promote_type(::Type{T}, ::Type{S}) where {T, S} @ Base promotion.jl:315",
        "method_instance": "MethodInstance for promote_type(::Type{Int64}, ::Type{<:Integer})"
    },
    "children": [
        {
            "method_instance": {
                "method": "promote_typeof(x, y) @ Base promotion.jl:382",
                "method_instance": "MethodInstance for Base.promote_typeof(::Int64, ::Integer)"
            },
            "children": [
                {
                    "method_instance": {
                        "method": "|(a::Integer, b::Integer) @ Base int.jl:1016",
                        "method_instance": "MethodInstance for |(::Int64, ::Integer)"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "_register_kinds!(kind_modules, int_to_kindstr, kind_str_to_int, mod, module_id, names) @ Base.JuliaSyntax ~/tmp/jl/julia-git/playground/upstream/base/JuliaSyntax/src/kinds.jl:78",
                                "method_instance": "MethodInstance for Base.JuliaSyntax._register_kinds!(::Dict{Int64, Union{Module, Symbol}}, ::Dict{UInt16, String}, ::Dict{String, UInt16}, ::Module, ::Int64, ::Vector{String})"
                            },
                            "children": [
                            ]
                        },
                        {
                            "method_instance": {
                                "method": "_register_kinds!(kind_modules, int_to_kindstr, kind_str_to_int, mod, module_id, names) @ Base.JuliaSyntax ~/tmp/jl/julia-git/playground/upstream/base/JuliaSyntax/src/kinds.jl:78",
                                "method_instance": "MethodInstance for Base.JuliaSyntax._register_kinds!(::Dict{Int64, Union{Module, Symbol}}, ::Dict{UInt16, String}, ::Dict{String, UInt16}, ::Module, ::Int64, ::Vector{String})"
                            },
                            "children": [
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

Reproducer:

struct I <: Integer end
function Base.promote_rule(::Type{Int}, ::Type{I}) end

@nsajko
Copy link
Member Author

nsajko commented Aug 26, 2025

I suppose this is not important enough to be backported together with the other PR.

@nsajko nsajko closed this Aug 26, 2025
@nsajko nsajko deleted the backport_pr_587 branch August 26, 2025 08:56
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.

1 participant