Skip to content

Commit 05a03a5

Browse files
committed
Add invalidation barriers for displaysize and implicit_typeinfo
These are invalidated by our own stdlibs (Dates and REPL) unfortunately so we need to put this barrier in.
1 parent 952e952 commit 05a03a5

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

base/arrayshow.jl

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -545,6 +545,12 @@ typeinfo_eltype(typeinfo::Type{<:AbstractArray{T}}) where {T} = eltype(typeinfo)
545545
typeinfo_eltype(typeinfo::Type{<:AbstractDict{K,V}}) where {K,V} = eltype(typeinfo)
546546
typeinfo_eltype(typeinfo::Type{<:AbstractSet{T}}) where {T} = eltype(typeinfo)
547547

548+
# This is a fancy way to make de-specialize a call to `typeinfo_implicit(T)`
549+
# which is unfortunately invalidated by Dates
550+
# (https://github.com/JuliaLang/julia/issues/56080)
551+
#
552+
# This makes the call less efficient, but avoids being invalidated by Dates.
553+
_typeinfo_implicit(@nospecialize(T)) = Base.invoke_in_world(Base.tls_world_age(), typeinfo_implicit, T)::Bool
548554

549555
# types that can be parsed back accurately from their un-decorated representations
550556
function typeinfo_implicit(@nospecialize(T))
@@ -553,9 +559,9 @@ function typeinfo_implicit(@nospecialize(T))
553559
return true
554560
end
555561
return isconcretetype(T) &&
556-
((T <: Array && typeinfo_implicit(eltype(T))) ||
557-
((T <: Tuple || T <: NamedTuple || T <: Pair) && all(typeinfo_implicit, fieldtypes(T))) ||
558-
(T <: AbstractDict && typeinfo_implicit(keytype(T)) && typeinfo_implicit(valtype(T))))
562+
((T <: Array && _typeinfo_implicit(eltype(T))) ||
563+
((T <: Tuple || T <: NamedTuple || T <: Pair) && all(_typeinfo_implicit, fieldtypes(T))) ||
564+
(T <: AbstractDict && _typeinfo_implicit(keytype(T)) && _typeinfo_implicit(valtype(T))))
559565
end
560566

561567
# X not constrained, can be any iterable (cf. show_vector)
@@ -573,7 +579,7 @@ function typeinfo_prefix(io::IO, X)
573579
if X isa AbstractDict
574580
if eltype_X == eltype_ctx
575581
sprint(show_type_name, typeof(X).name; context=io), false
576-
elseif !isempty(X) && typeinfo_implicit(keytype(X)) && typeinfo_implicit(valtype(X))
582+
elseif !isempty(X) && _typeinfo_implicit(keytype(X)) && _typeinfo_implicit(valtype(X))
577583
sprint(show_type_name, typeof(X).name; context=io), true
578584
else
579585
sprint(print, typeof(X); context=io), false
@@ -582,7 +588,7 @@ function typeinfo_prefix(io::IO, X)
582588
# Types hard-coded here are those which are created by default for a given syntax
583589
if eltype_X == eltype_ctx
584590
"", false
585-
elseif !isempty(X) && typeinfo_implicit(eltype_X)
591+
elseif !isempty(X) && _typeinfo_implicit(eltype_X)
586592
"", true
587593
elseif print_without_params(eltype_X)
588594
sprint(show_type_name, unwrap_unionall(eltype_X).name; context=io), false # Print "Array" rather than "Array{T,N}"

base/logging/ConsoleLogger.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ function handle_message(logger::ConsoleLogger, level::LogLevel, message, _module
130130
if !(isopen(stream)::Bool)
131131
stream = stderr
132132
end
133-
dsize = displaysize(stream)::Tuple{Int,Int}
133+
dsize = Base.displaysize_(stream)::Tuple{Int,Int}
134134
nkwargs = length(kwargs)::Int
135135
if nkwargs > hasmaxlog
136136
valbuf = IOBuffer()

base/precompilation.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ function precompilepkgs(pkgs::Vector{String}=String[];
672672
n_print_rows = 0
673673
while !printloop_should_exit
674674
lock(print_lock) do
675-
term_size = Base.displaysize(io)::Tuple{Int,Int}
675+
term_size = Base.displaysize_(io)
676676
num_deps_show = max(term_size[1] - 3, 2) # show at least 2 deps
677677
pkg_queue_show = if !interrupted_or_done.set && length(pkg_queue) > num_deps_show
678678
last(pkg_queue, num_deps_show)
@@ -687,7 +687,7 @@ function precompilepkgs(pkgs::Vector{String}=String[];
687687
bar.max = n_total - n_already_precomp
688688
# when sizing to the terminal width subtract a little to give some tolerance to resizing the
689689
# window between print cycles
690-
termwidth = displaysize(io)[2] - 4
690+
termwidth = Base.displaysize_(io)[2] - 4
691691
if !final_loop
692692
str = sprint(io -> show_progress(io, bar; termwidth, carriagereturn=false); context=io)
693693
print(iostr, Base._truncate_at_width_or_chars(true, str, termwidth), "\n")

base/show.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ get(io::IO, key, default) = default
427427
keys(io::IOContext) = keys(io.dict)
428428
keys(io::IO) = keys(ImmutableDict{Symbol,Any}())
429429

430-
displaysize(io::IOContext) = haskey(io, :displaysize) ? io[:displaysize]::Tuple{Int,Int} : displaysize(io.io)
430+
displaysize(io::IOContext) = haskey(io, :displaysize) ? io[:displaysize]::Tuple{Int,Int} : Base.displaysize_(io.io)
431431

432432
show_circular(io::IO, @nospecialize(x)) = false
433433
function show_circular(io::IOContext, @nospecialize(x))
@@ -2622,7 +2622,7 @@ end
26222622
function type_limited_string_from_context(out::IO, str::String)
26232623
typelimitflag = get(out, :stacktrace_types_limited, nothing)
26242624
if typelimitflag isa RefValue{Bool}
2625-
sz = get(out, :displaysize, displaysize(out))::Tuple{Int, Int}
2625+
sz = get(out, :displaysize, Base.displaysize_(out))::Tuple{Int, Int}
26262626
str_lim = type_depth_limit(str, max(sz[2], 120))
26272627
if sizeof(str_lim) < sizeof(str)
26282628
typelimitflag[] = true

base/stream.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,13 @@ displaysize(io::IO) = displaysize()
569569
displaysize() = (parse(Int, get(ENV, "LINES", "24")),
570570
parse(Int, get(ENV, "COLUMNS", "80")))::Tuple{Int, Int}
571571

572+
# This is a fancy way to make de-specialize a call to `displaysize(io::IO)`
573+
# which is unfortunately invalidated by REPL
574+
# (https://github.com/JuliaLang/julia/issues/56080)
575+
#
576+
# This makes the call less efficient, but avoids being invalidated by REPL.
577+
displaysize_(io::IO) = Base.invoke_in_world(Base.tls_world_age(), displaysize, io)::Tuple{Int,Int}
578+
572579
function displaysize(io::TTY)
573580
check_open(io)
574581

0 commit comments

Comments
 (0)