Skip to content

Conversation

nsajko
Copy link
Member

@nsajko nsajko commented Mar 30, 2025

Makes the sysimage more resistant to method invalidation, when defining a new Integer subtype with a right bitshift method.

Should make the sysimage more resistant to method invalidation.
@nsajko nsajko added invalidations display and printing Aesthetics and correctness of printed representations of objects. labels Mar 30, 2025
@nsajko
Copy link
Member Author

nsajko commented Mar 30, 2025

Eliminates all (47 on current master) invalidations that arise when running the following:

struct I <: Integer end
function Base.:(>>)(::I, ::UInt8) end
function Base.:(>>)(::I, ::Int) end

Reproduce with:

./julia -E 'using SnoopCompileCore; i = (@snoop_invalidations (struct I <: Integer end; function Base.:(>>)(::I, ::UInt8) end; function Base.:(>>)(::I, ::Int) end)); using SnoopCompile; length(uinvalidated(i))'

The eliminated invalidations:

{
    "method": ">>(::Main.RawInvalidations.I, ::Int64) @ Main.RawInvalidations ~/invalidations/script/reproducer.jl:34",
    "reason": "inserting",
    "mt_backedges": [
    ],
    "backedges": [
        {
            "method_instance": {
                "method": ">>(x::Integer, c::Int64) @ Base operators.jl:761",
                "method_instance": "MethodInstance for >>(::Integer, ::Int64)"
            },
            "children": [
                {
                    "method_instance": {
                        "method": ">>(x::Integer, c::Integer) @ Base operators.jl:752",
                        "method_instance": "MethodInstance for >>(::Integer, ::UInt8)"
                    },
                    "children": [
                    ]
                },
                {
                    "method_instance": {
                        "method": ">>(x::Integer, c::Integer) @ Base operators.jl:752",
                        "method_instance": "MethodInstance for >>(::Integer, ::UInt8)"
                    },
                    "children": [
                    ]
                }
            ]
        }
    ],
    "mt_cache": [
    ],
    "mt_disable": [
    ]
}
{
    "method": ">>(::Main.RawInvalidations.I, ::UInt8) @ Main.RawInvalidations ~/invalidations/script/reproducer.jl:34",
    "reason": "inserting",
    "mt_backedges": [
        {
            "type": "Tuple{typeof(>>), Any, UInt8}",
            "tree": {
                "method_instance": {
                    "method": "append_c_digits(olength::Int64, digits::Unsigned, buf, pos::Int64) @ Base intfuncs.jl:843",
                    "method_instance": "MethodInstance for Base.append_c_digits(::Int64, ::Unsigned, ::Memory{UInt8}, ::Int64)"
                },
                "children": [
                    {
                        "method_instance": {
                            "method": "append_c_digits_fast(olength::Int64, digits::Unsigned, buf, pos::Int64) @ Base intfuncs.jl:871",
                            "method_instance": "MethodInstance for Base.append_c_digits_fast(::Int64, ::Unsigned, ::Memory{UInt8}, ::Int64)"
                        },
                        "children": [
                        ]
                    },
                    {
                        "method_instance": {
                            "method": "append_nine_digits(digits::Unsigned, buf, pos::Int64) @ Base intfuncs.jl:860",
                            "method_instance": "MethodInstance for Base.append_nine_digits(::Unsigned, ::Memory{UInt8}, ::Int64)"
                        },
                        "children": [
                            {
                                "method_instance": {
                                    "method": "append_c_digits_fast(olength::Int64, digits::Unsigned, buf, pos::Int64) @ Base intfuncs.jl:871",
                                    "method_instance": "MethodInstance for Base.append_c_digits_fast(::Int64, ::Unsigned, ::Memory{UInt8}, ::Int64)"
                                },
                                "children": [
                                    {
                                        "method_instance": {
                                            "method": "dec(x::Unsigned, pad::Int64, neg::Bool) @ Base intfuncs.jl:889",
                                            "method_instance": "MethodInstance for Base.dec(::Unsigned, ::Int64, ::Bool)"
                                        },
                                        "children": [
                                        ]
                                    }
                                ]
                            }
                        ]
                    }
                ]
            }
        }
    ],
    "backedges": [
        {
            "method_instance": {
                "method": ">>(x::Integer, c::Integer) @ Base operators.jl:752",
                "method_instance": "MethodInstance for >>(::Integer, ::UInt8)"
            },
            "children": [
                {
                    "method_instance": {
                        "method": "append_c_digits(olength::Int64, digits::Unsigned, buf, pos::Int64) @ Base intfuncs.jl:843",
                        "method_instance": "MethodInstance for Base.append_c_digits(::Int64, ::Unsigned, ::Memory{UInt8}, ::Int64)"
                    },
                    "children": [
                    ]
                }
            ]
        }
    ],
    "mt_cache": [
    ],
    "mt_disable": [
    ]
}

@nsajko nsajko added backport 1.10 Change should be backported to the 1.10 release backport 1.11 Change should be backported to release-1.11 backport 1.12 Change should be backported to release-1.12 labels Mar 30, 2025
@KristofferC
Copy link
Member

Why can't this be inferred?

This was referenced Mar 31, 2025
@topolarity
Copy link
Member

Why can't this be inferred?

divrem infers poorly:

julia> code_typed(Base.divrem, (Unsigned, typeof(0x64)))
1-element Vector{Any}:
 CodeInfo(
1%1 = Base.divrem(x, y, Base.RoundToZero)::Tuple{Any, Any}
└──      return %1
) => Tuple{Any, Any}

@oscardssmith
Copy link
Member

Unsigned is an abstract type.

@KristofferC
Copy link
Member

Unsigned is an abstract type.

Yes, a lot of inference runs with abstract types.

@KristofferC KristofferC merged commit 69a22cf into JuliaLang:master Apr 1, 2025
11 of 13 checks passed
@nsajko nsajko deleted the invalidations__append_c_digits__typeassert_Int__right_bitshift branch April 1, 2025 08:13
KristofferC pushed a commit that referenced this pull request Apr 4, 2025
Makes the sysimage more resistant to method invalidation, when defining
a new `Integer` subtype with a right bitshift method.

(cherry picked from commit 69a22cf)
@KristofferC KristofferC mentioned this pull request Apr 4, 2025
51 tasks
KristofferC pushed a commit that referenced this pull request Apr 4, 2025
Makes the sysimage more resistant to method invalidation, when defining
a new `Integer` subtype with a right bitshift method.

(cherry picked from commit 69a22cf)
@KristofferC KristofferC removed the backport 1.11 Change should be backported to release-1.11 label Apr 10, 2025
@KristofferC KristofferC removed the backport 1.12 Change should be backported to release-1.12 label Apr 25, 2025
KristofferC pushed a commit that referenced this pull request Jun 4, 2025
Makes the sysimage more resistant to method invalidation, when defining
a new `Integer` subtype with a right bitshift method.

(cherry picked from commit 69a22cf)
@KristofferC KristofferC mentioned this pull request Jun 4, 2025
75 tasks
KristofferC pushed a commit that referenced this pull request Jun 5, 2025
Makes the sysimage more resistant to method invalidation, when defining
a new `Integer` subtype with a right bitshift method.

(cherry picked from commit 69a22cf)
KristofferC pushed a commit that referenced this pull request Jul 3, 2025
Makes the sysimage more resistant to method invalidation, when defining
a new `Integer` subtype with a right bitshift method.

(cherry picked from commit 69a22cf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport 1.10 Change should be backported to the 1.10 release display and printing Aesthetics and correctness of printed representations of objects. invalidations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants