Skip to content
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

iobuffer: copyline: type assert Int to prevent invalidation #57848

Conversation

nsajko
Copy link
Contributor

@nsajko nsajko commented Mar 21, 2025

Should prevent invalidation stemming from MethodInstances for

  • readline()
  • readlines()
  • Base.run_fallback_repl(::Bool)
    • Base.repl_main(::Any)
      • Base._start()

In each case the issue is the use of the nonconcretely-typed global variable stdin::IO.

Should prevent much invalidation stemming from `MethodInstance`s for
* `readline()`
* `readlines()`
* `Base.run_fallback_repl(::Bool)`
    * `Base.repl_main(::Any)`
        * `Base._start()`

In each case the issue is the access of the nonconcretely-typed global
variable `stdin::IO`.
@nsajko nsajko added io Involving the I/O subsystem: libuv, read, write, etc. invalidations labels Mar 21, 2025
@nsajko
Copy link
Contributor Author

nsajko commented Mar 21, 2025

These invalidations on loading the package TypeDomainNaturalNumber v7.0.0 are fixed by the change:

{
    "method_instance": {
        "method": "var\"#_copyline#393\"(keep::Bool, ::typeof(Base._copyline), out::IO, io::Base.GenericIOBuffer) @ Base iobuffer.jl:642",
        "method_instance": "MethodInstance for Base.var\"#_copyline#393\"(::Bool, ::typeof(Base._copyline), ::IOBuffer, ::Base.GenericIOBuffer)"
    },
    "children": [
        {
            "method_instance": {
                "method": "kwcall(::NamedTuple, ::typeof(Base._copyline), out::IO, io::Base.GenericIOBuffer) @ Base iobuffer.jl:642",
                "method_instance": "MethodInstance for Core.kwcall(::@NamedTuple{keep::Bool}, ::typeof(Base._copyline), ::IOBuffer, ::Base.GenericIOBuffer)"
            },
            "children": [
                {
                    "method_instance": {
                        "method": "var\"#copyline#395\"(keep::Bool, ::typeof(copyline), out::Base.GenericIOBuffer, io::Base.GenericIOBuffer) @ Base iobuffer.jl:656",
                        "method_instance": "MethodInstance for Base.var\"#copyline#395\"(::Bool, ::typeof(copyline), ::IOBuffer, ::Base.GenericIOBuffer)"
                    },
                    "children": [
                        {
                            "method_instance": {
                                "method": "kwcall(::NamedTuple, ::typeof(copyline), out::Base.GenericIOBuffer, io::Base.GenericIOBuffer) @ Base iobuffer.jl:656",
                                "method_instance": "MethodInstance for Core.kwcall(::@NamedTuple{keep::Bool}, ::typeof(copyline), ::IOBuffer, ::Base.GenericIOBuffer)"
                            },
                            "children": [
                                {
                                    "method_instance": {
                                        "method": "var\"#readline#353\"(keep::Bool, ::typeof(readline), s::IO) @ Base io.jl:619",
                                        "method_instance": "MethodInstance for Base.var\"#readline#353\"(::Bool, ::typeof(readline), ::IO)"
                                    },
                                    "children": [
                                        {
                                            "method_instance": {
                                                "method": "kwcall(::NamedTuple, ::typeof(readline), s::IO) @ Base io.jl:619",
                                                "method_instance": "MethodInstance for Core.kwcall(::@NamedTuple{keep::Bool}, ::typeof(readline), ::IO)"
                                            },
                                            "children": [
                                                {
                                                    "method_instance": {
                                                        "method": "iterate(itr::Base.EachLine, state) @ Base io.jl:1234",
                                                        "method_instance": "MethodInstance for iterate(::Base.EachLine, ::Nothing)"
                                                    },
                                                    "children": [
                                                        {
                                                            "method_instance": {
                                                                "method": "_collect(cont, itr, ::Base.HasEltype, isz::Base.SizeUnknown) @ Base array.jl:737",
                                                                "method_instance": "MethodInstance for Base._collect(::UnitRange{Int64}, ::Base.EachLine, ::Base.HasEltype, ::Base.SizeUnknown)"
                                                            },
                                                            "children": [
                                                            ]
                                                        },
                                                        {
                                                            "method_instance": {
                                                                "method": "iterate(itr::Base.EachLine) @ Base io.jl:1234",
                                                                "method_instance": "MethodInstance for iterate(::Base.EachLine)"
                                                            },
                                                            "children": [
                                                                {
                                                                    "method_instance": {
                                                                        "method": "_collect(cont, itr, ::Base.HasEltype, isz::Base.SizeUnknown) @ Base array.jl:737",
                                                                        "method_instance": "MethodInstance for Base._collect(::UnitRange{Int64}, ::Base.EachLine, ::Base.HasEltype, ::Base.SizeUnknown)"
                                                                    },
                                                                    "children": [
                                                                        {
                                                                            "method_instance": {
                                                                                "method": "collect(itr) @ Base array.jl:728",
                                                                                "method_instance": "MethodInstance for collect(::Base.EachLine)"
                                                                            },
                                                                            "children": [
                                                                                {
                                                                                    "method_instance": {
                                                                                        "method": "var\"#readlines#363\"(kw::Base.Pairs{Symbol, V, NTuple{N, Symbol}, NamedTuple{names, T}} where {V, N, names, T<:NTuple{N, Any}}, ::typeof(readlines), s) @ Base io.jl:708",
                                                                                        "method_instance": "MethodInstance for Base.var\"#readlines#363\"(::Base.Pairs{Symbol, Union{}, Tuple{}, @NamedTuple{}}, ::typeof(readlines), ::IO)"
                                                                                    },
                                                                                    "children": [
                                                                                        {
                                                                                            "method_instance": {
                                                                                                "method": "readlines(s; kw...) @ Base io.jl:708",
                                                                                                "method_instance": "MethodInstance for readlines(::IO)"
                                                                                            },
                                                                                            "children": [
                                                                                                {
                                                                                                    "method_instance": {
                                                                                                        "method": "readlines(; ...) @ Base io.jl:708",
                                                                                                        "method_instance": "MethodInstance for readlines()"
                                                                                                    },
                                                                                                    "children": [
                                                                                                    ]
                                                                                                }
                                                                                            ]
                                                                                        }
                                                                                    ]
                                                                                }
                                                                            ]
                                                                        }
                                                                    ]
                                                                }
                                                            ]
                                                        }
                                                    ]
                                                },
                                                {
                                                    "method_instance": {
                                                        "method": "run_fallback_repl(interactive::Bool) @ Base client.jl:426",
                                                        "method_instance": "MethodInstance for Base.run_fallback_repl(::Bool)"
                                                    },
                                                    "children": [
                                                    ]
                                                },
                                                {
                                                    "method_instance": {
                                                        "method": "run_fallback_repl(interactive::Bool) @ Base client.jl:426",
                                                        "method_instance": "MethodInstance for Base.run_fallback_repl(::Bool)"
                                                    },
                                                    "children": [
                                                    ]
                                                },
                                                {
                                                    "method_instance": {
                                                        "method": "run_fallback_repl(interactive::Bool) @ Base client.jl:426",
                                                        "method_instance": "MethodInstance for Base.run_fallback_repl(::Bool)"
                                                    },
                                                    "children": [
                                                    ]
                                                },
                                                {
                                                    "method_instance": {
                                                        "method": "run_fallback_repl(interactive::Bool) @ Base client.jl:426",
                                                        "method_instance": "MethodInstance for Base.run_fallback_repl(::Bool)"
                                                    },
                                                    "children": [
                                                        {
                                                            "method_instance": {
                                                                "method": "run_main_repl(interactive::Bool, quiet::Bool, banner::Symbol, history_file::Bool) @ Base client.jl:498",
                                                                "method_instance": "MethodInstance for Base.run_main_repl(::Bool, ::Bool, ::Symbol, ::Bool)"
                                                            },
                                                            "children": [
                                                                {
                                                                    "method_instance": {
                                                                        "method": "repl_main(::Any) @ Base client.jl:585",
                                                                        "method_instance": "MethodInstance for Base.repl_main(::Vector{String})"
                                                                    },
                                                                    "children": [
                                                                        {
                                                                            "method_instance": {
                                                                                "method": "_start() @ Base client.jl:553",
                                                                                "method_instance": "MethodInstance for Base._start()"
                                                                            },
                                                                            "children": [
                                                                            ]
                                                                        }
                                                                    ]
                                                                }
                                                            ]
                                                        }
                                                    ]
                                                }
                                            ]
                                        },
                                        {
                                            "method_instance": {
                                                "method": "readline(s::IO; keep) @ Base io.jl:619",
                                                "method_instance": "MethodInstance for readline(::IO)"
                                            },
                                            "children": [
                                                {
                                                    "method_instance": {
                                                        "method": "readline(; ...) @ Base io.jl:619",
                                                        "method_instance": "MethodInstance for readline()"
                                                    },
                                                    "children": [
                                                    ]
                                                }
                                            ]
                                        }
                                    ]
                                }
                            ]
                        }
                    ]
                }
            ]
        }
    ]
}

@nsajko nsajko added backport 1.12 Change should be backported to release-1.12 backport 1.11 Change should be backported to release-1.11 merge me PR is reviewed. Merge when all tests are passing labels Mar 21, 2025
@vtjnash vtjnash merged commit eed18bd into JuliaLang:master Mar 21, 2025
12 of 14 checks passed
@giordano giordano removed the merge me PR is reviewed. Merge when all tests are passing label Mar 21, 2025
@nsajko nsajko deleted the invalidations_type_stability_IOBuffer_copyline_type_assert_Int branch March 21, 2025 23:25
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 io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants