Skip to content

Conversation

nsajko
Copy link
Member

@nsajko nsajko commented Sep 2, 2025

Add some concrete typeasserts to increase the resistance of the sysimage to invalidation by helping inference within the method body.

@nsajko nsajko added logging The logging framework invalidations backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 labels Sep 2, 2025
@nsajko
Copy link
Member Author

nsajko commented Sep 2, 2025

Some of the sysimage invalidation eliminated with this PR, appearing on master on running struct S <: AbstractString end; function Base.thisind(::S, ::Int) end:

{
    "method_instance": {
        "method": "chomp(s::AbstractString) @ Base strings/util.jl:338",
        "method_instance": "MethodInstance for chomp(::AbstractString)"
    },
    "children": [
        {
            "method_instance": {
                "method": "var\"#handle_message#6\"(kwargs::Base.Pairs{Symbol, V, Nothing, NT} where {V, NT<:NamedTuple}, ::typeof(Base.CoreLogging.handle_message), logger::Base.CoreLogging.ConsoleLogger, level::Base.CoreLogging.LogLevel, message, _module, group, id, filepath, line) @ Base.CoreLogging logging/ConsoleLogger.jl:110",
                "method_instance": "MethodInstance for Base.CoreLogging.var\"#handle_message#6\"(::Base.Pairs{Symbol, Union{}, Nothing, @NamedTuple{}}, ::typeof(Base.CoreLogging.handle_message), ::Base.CoreLogging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)"
            },
            "children": [
                {
                    "method_instance": {
                        "method": "handle_message(logger::Base.CoreLogging.ConsoleLogger, level::Base.CoreLogging.LogLevel, message, _module, group, id, filepath, line; kwargs...) @ Base.CoreLogging logging/ConsoleLogger.jl:110",
                        "method_instance": "MethodInstance for Base.CoreLogging.handle_message(::Base.CoreLogging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)"
                    },
                    "children": [
                    ]
                }
            ]
        },
        {
            "method_instance": {
                "method": "var\"#handle_message#6\"(kwargs::Base.Pairs{Symbol, V, Nothing, NT} where {V, NT<:NamedTuple}, ::typeof(Base.CoreLogging.handle_message), logger::Base.CoreLogging.ConsoleLogger, level::Base.CoreLogging.LogLevel, message, _module, group, id, filepath, line) @ Base.CoreLogging logging/ConsoleLogger.jl:110",
                "method_instance": "MethodInstance for Base.CoreLogging.var\"#handle_message#6\"(::Base.Pairs{Symbol, V, Nothing, NT} where {V, NT<:NamedTuple}, ::typeof(Base.CoreLogging.handle_message), ::Base.CoreLogging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)"
            },
            "children": [
                {
                    "method_instance": {
                        "method": "handle_message(logger::Base.CoreLogging.ConsoleLogger, level::Base.CoreLogging.LogLevel, message, _module, group, id, filepath, line; kwargs...) @ Base.CoreLogging logging/ConsoleLogger.jl:110",
                        "method_instance": "MethodInstance for Base.CoreLogging.handle_message(::Base.CoreLogging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)"
                    },
                    "children": [
                    ]
                },
                {
                    "method_instance": {
                        "method": "kwcall(::NamedTuple, ::typeof(Base.CoreLogging.handle_message), logger::Base.CoreLogging.ConsoleLogger, level::Base.CoreLogging.LogLevel, message, _module, group, id, filepath, line) @ Base.CoreLogging logging/ConsoleLogger.jl:110",
                        "method_instance": "MethodInstance for Core.kwcall(::NamedTuple, ::typeof(Base.CoreLogging.handle_message), ::Base.CoreLogging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "logging_error(logger, level, _module, group, id, filepath, line, err, real::Bool) @ Base.CoreLogging logging/logging.jl:496",
                                "method_instance": "MethodInstance for Base.CoreLogging.logging_error(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Bool)"
                            },
                            "children": [
                            ]
                        }
                    ]
                },
                {
                    "method_instance": {
                        "method": "kwcall(::NamedTuple, ::typeof(Base.CoreLogging.handle_message), logger::Base.CoreLogging.ConsoleLogger, level::Base.CoreLogging.LogLevel, message, _module, group, id, filepath, line) @ Base.CoreLogging logging/ConsoleLogger.jl:110",
                        "method_instance": "MethodInstance for Core.kwcall(::NamedTuple{(:exception,), <:Tuple{Tuple{Any, Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}}}}, ::typeof(Base.CoreLogging.handle_message), ::Base.CoreLogging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::LazyString, ::Any, ::Symbol, ::Any, ::Any, ::Any)"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "logging_error(logger, level, _module, group, id, filepath, line, err, real::Bool) @ Base.CoreLogging logging/logging.jl:496",
                                "method_instance": "MethodInstance for Base.CoreLogging.logging_error(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Bool)"
                            },
                            "children": [
                            ]
                        }
                    ]
                },
                {
                    "method_instance": {
                        "method": "kwcall(::NamedTuple, ::typeof(Base.CoreLogging.handle_message), logger::Base.CoreLogging.ConsoleLogger, level::Base.CoreLogging.LogLevel, message, _module, group, id, filepath, line) @ Base.CoreLogging logging/ConsoleLogger.jl:110",
                        "method_instance": "MethodInstance for Core.kwcall(::NamedTuple{(:exception,), <:Tuple{Tuple{Any, Vector{Union{Ptr{Nothing}, Base.InterpreterIP}}}}}, ::typeof(Base.CoreLogging.handle_message), ::Base.CoreLogging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::String, ::Any, ::Symbol, ::Any, ::Any, ::Any)"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "logging_error(logger, level, _module, group, id, filepath, line, err, real::Bool) @ Base.CoreLogging logging/logging.jl:496",
                                "method_instance": "MethodInstance for Base.CoreLogging.logging_error(::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any, ::Bool)"
                            },
                            "children": [
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

Another tree of invalidations with the same reproducer:

{
    "method_instance": {
        "method": "iterate(iter::Base.SplitIterator) @ Base strings/util.jl:741",
        "method_instance": "MethodInstance for iterate(::Base.SplitIterator{S, Base.Fix2{typeof(isequal), Char}} where S<:SubString)"
    },
    "children": [
        {
            "method_instance": {
                "method": "_collect(cont, itr, ::Base.HasEltype, isz::Base.SizeUnknown) @ Base array.jl:743",
                "method_instance": "MethodInstance for Base._collect(::UnitRange{Int64}, ::Base.SplitIterator{S, Base.Fix2{typeof(isequal), Char}} where S<:SubString, ::Base.HasEltype, ::Base.SizeUnknown)"
            },
            "children": [
                {
                    "method_instance": {
                        "method": "collect(itr) @ Base array.jl:734",
                        "method_instance": "MethodInstance for collect(::Base.SplitIterator{S, Base.Fix2{typeof(isequal), Char}} where S<:SubString)"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "var\"#split#431\"(limit::Integer, keepempty::Bool, ::typeof(split), str::T, splitter) where T<:AbstractString @ Base strings/util.jl:908",
                                "method_instance": "MethodInstance for Base.var\"#split#431\"(::Int64, ::Bool, ::typeof(split), ::SubString, ::Char)"
                            },
                            "children": [
                                {
                                    "method_instance": {
                                        "method": "split(str::T, splitter; limit, keepempty) where T<:AbstractString @ Base strings/util.jl:908",
                                        "method_instance": "MethodInstance for split(::SubString, ::Char)"
                                    },
                                    "children": [
                                        {
                                            "method_instance": {
                                                "method": "var\"#handle_message#6\"(kwargs::Base.Pairs{Symbol, V, Nothing, NT} where {V, NT<:NamedTuple}, ::typeof(Base.CoreLogging.handle_message), logger::Base.CoreLogging.ConsoleLogger, level::Base.CoreLogging.LogLevel, message, _module, group, id, filepath, line) @ Base.CoreLogging logging/ConsoleLogger.jl:110",
                                                "method_instance": "MethodInstance for Base.CoreLogging.var\"#handle_message#6\"(::Base.Pairs{Symbol, Union{}, Nothing, @NamedTuple{}}, ::typeof(Base.CoreLogging.handle_message), ::Base.CoreLogging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)"
                                            },
                                            "children": [
                                            ]
                                        },
                                        {
                                            "method_instance": {
                                                "method": "var\"#handle_message#6\"(kwargs::Base.Pairs{Symbol, V, Nothing, NT} where {V, NT<:NamedTuple}, ::typeof(Base.CoreLogging.handle_message), logger::Base.CoreLogging.ConsoleLogger, level::Base.CoreLogging.LogLevel, message, _module, group, id, filepath, line) @ Base.CoreLogging logging/ConsoleLogger.jl:110",
                                                "method_instance": "MethodInstance for Base.CoreLogging.var\"#handle_message#6\"(::Base.Pairs{Symbol, V, Nothing, NT} where {V, NT<:NamedTuple}, ::typeof(Base.CoreLogging.handle_message), ::Base.CoreLogging.ConsoleLogger, ::Base.CoreLogging.LogLevel, ::Any, ::Any, ::Any, ::Any, ::Any, ::Any)"
                                            },
                                            "children": [
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

@nsajko nsajko marked this pull request as ready for review September 2, 2025 18:32
Add some concrete `typeassert`s to increase the resistance of the
sysimage to invalidation by helping inference within the method body.
@nsajko nsajko force-pushed the CoreLogging-handle_message-prevent_AnnotatedString-related_type-instability_by_adding_concrete_typeasserts branch from ed264f4 to 1d26139 Compare September 2, 2025 20:10
@nsajko
Copy link
Member Author

nsajko commented Sep 5, 2025

bump

@nsajko
Copy link
Member Author

nsajko commented Sep 9, 2025

ping

Co-authored-by: Cody Tapscott <84105208+topolarity@users.noreply.github.com>
Copy link
Member

@topolarity topolarity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@topolarity topolarity added the merge me PR is reviewed. Merge when all tests are passing label Sep 17, 2025
…edString-related_type-instability_by_adding_concrete_typeasserts
@oscardssmith oscardssmith merged commit bb51d56 into JuliaLang:master Sep 19, 2025
7 checks passed
@oscardssmith oscardssmith removed the merge me PR is reviewed. Merge when all tests are passing label Sep 19, 2025
@nsajko nsajko deleted the CoreLogging-handle_message-prevent_AnnotatedString-related_type-instability_by_adding_concrete_typeasserts branch September 19, 2025 13:24
This was referenced Sep 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 invalidations logging The logging framework
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants