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

hopefully fix invalidations of REPL from HDF5.jl #46486

Merged
merged 2 commits into from
Aug 29, 2022

Conversation

ranocha
Copy link
Member

@ranocha ranocha commented Aug 26, 2022

I'm new to fixing invalidations, so please help me understand whether I'm doing it correctly.

I ran the following code on Julia v1.8.0:

julia> using Pkg; Pkg.activate(temp=true); Pkg.add("HDF5")

julia> using SnoopCompileCore

julia> invalidations = @snoopr using HDF5;

julia> using SnoopCompile

julia> length(uinvalidated(invalidations))
385

julia> trees = invalidation_trees(invalidations);

julia> trees[end]
inserting write(obj::HDF5.Dataset, x) in HDF5 at /home/hendrik/.julia/packages/HDF5/T4H0V/src/datasets.jl:296 invalidated:
   mt_backedges: 1: signature Tuple{typeof(write), Any, String} triggered MethodInstance for Base.create_expr_cache(::Base.PkgId, ::String, ::String, ::Vector{Pair{Base.PkgId, UInt64}}, ::IOBuffer, ::Base.DevNull) (1 children)
                 2: signature Tuple{typeof(write), Any, String} triggered MethodInstance for Base.create_expr_cache(::Base.PkgId, ::String, ::String, ::Vector{Pair{Base.PkgId, UInt64}}, ::IO, ::IO) (21 children)
                 3: signature Tuple{typeof(write), Any, String} triggered MethodInstance for REPL.LineEdit.write_prompt(::Any, ::Union{AbstractString, Function}, ::Bool) (435 children)

julia> method_invalidations = trees[end];

julia> root = method_invalidations.mt_backedges[end][2]
MethodInstance for REPL.LineEdit.write_prompt(::Any, ::Union{AbstractString, Function}, ::Bool) at depth 0 with 435 children

julia> ascend(root)
Choose a call for analysis (q to quit):
     write_prompt(::Any, ::Union{AbstractString, Function}, ::Bool)
 >     write_prompt(::REPL.Terminals.AbstractTerminal, ::REPL.LineEdit.Prompt, ::Bool)
         write_prompt(::REPL.Terminals.TerminalBuffer, ::REPL.LineEdit.PrefixSearchState, ::Bool)
           #refresh_multi_line#16(::Int64, ::Bool, ::typeof(REPL.LineEdit.refresh_multi_line), ::REPL.Terminals.T
             (::REPL.LineEdit.var"#refresh_multi_line##kw")(::NamedTuple{(:indent, :region_active), Tuple{Int64,
               #refresh_multi_line#41(::Bool, ::typeof(REPL.LineEdit.refresh_multi_line), ::REPL.Terminals.Termin
                 (::REPL.LineEdit.var"#refresh_multi_line##kw")(::NamedTuple{names, T} where {N, names, T<:Tuple{
                   #refresh_multi_line#14(::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T}}
                     #refresh_multi_line#15(::Base.Pairs{Symbol, V, Tuple{Vararg{Symbol, N}}, NamedTuple{names, T
v                      refresh_multi_line(::REPL.Terminals.TerminalBuffer, ::REPL.Terminals.UnixTerminal, ::REPL.

Choose possible caller of MethodInstance for REPL.LineEdit.write_prompt(::Any, ::Union{AbstractString, Function}, ::Bool) or proceed to typed code:
 > "/cache/build/default-amdci4-3/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/LineEdit.jl", write_prompt: lines [1346]
   Browse typed code

As far as I understand,

  • the invalidations happen since terminal is not specified further in the method I changed here
  • this method is only called from
    function write_prompt(terminal::AbstractTerminal, p::Prompt, color::Bool)
    prefix = prompt_string(p.prompt_prefix)
    suffix = prompt_string(p.prompt_suffix)
    write(terminal, prefix)
    color && write(terminal, Base.text_colors[:bold])
    width = write_prompt(terminal, p.prompt, color)
    color && write(terminal, Base.text_colors[:normal])
    write(terminal, suffix)
    return width
    end

    where terminal::AbstractTerminal
  • restricting the method I changed to terminal::AbstractTerminal does not limit its current use and should fix the invalidations

Did I understand this correctly? Or is there something better we should do to fix these invalidations?

@timholy
Copy link
Member

timholy commented Aug 29, 2022

Yep, this is perfect. Note that the entire REPL module is defined with @nospecialize, so any argument that doesn't have a type-annotation is treated as Any.

@timholy timholy merged commit 431071b into JuliaLang:master Aug 29, 2022
@timholy timholy added compiler:latency Compiler latency backport 1.8 Change should be backported to release-1.8 labels Aug 29, 2022
@ranocha ranocha deleted the patch-5 branch August 30, 2022 04:43
ranocha added a commit to ranocha/julia that referenced this pull request Aug 30, 2022
KristofferC pushed a commit that referenced this pull request Aug 30, 2022
@KristofferC KristofferC removed the backport 1.8 Change should be backported to release-1.8 label Sep 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:latency Compiler latency
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants