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

More invalidation fixes #35928

Merged
merged 8 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion base/Enums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Base.print(io::IO, x::Enum) = print(io, Symbol(x))

function Base.show(io::IO, x::Enum)
sym = Symbol(x)
if !get(io, :compact, false)
if !(get(io, :compact, false)::Bool)
Copy link
Member

Choose a reason for hiding this comment

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

Fortunately :: already binds tighter than !, but I can see how that might not be obvious to code readers.

Copy link
Member Author

Choose a reason for hiding this comment

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

i can change it, but I felt that obviousness was worth a few extra characters.

from = get(io, :module, Main)
def = typeof(x).name.module
if from === nothing || !Base.isvisible(sym, def, from)
Expand Down Expand Up @@ -159,6 +159,7 @@ macro enum(T, syms...)
else
throw(ArgumentError(string("invalid argument for Enum ", typename, ": ", s)))
end
s = s::Symbol
if !Base.isidentifier(s)
throw(ArgumentError("invalid name for Enum $typename; \"$s\" is not a valid identifier"))
end
Expand Down
3 changes: 3 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1064,6 +1064,7 @@ _getindex(::IndexStyle, A::AbstractArray, I...) =
error("getindex for $(typeof(A)) with types $(typeof(I)) is not supported")

## IndexLinear Scalar indexing: canonical method is one Int
_getindex(::IndexLinear, A::AbstractVector, i::Int) = (@_propagate_inbounds_meta; getindex(A, i)) # ambiguity resolution in case packages specialize this (to be avoided if at all possible, but see Interpolations.jl)
_getindex(::IndexLinear, A::AbstractArray, i::Int) = (@_propagate_inbounds_meta; getindex(A, i))
function _getindex(::IndexLinear, A::AbstractArray, I::Vararg{Int,M}) where M
@_inline_meta
Expand Down Expand Up @@ -2149,6 +2150,8 @@ end
# map on collections
map(f, A::AbstractArray) = collect_similar(A, Generator(f,A))

mapany(f, itr) = map!(f, Vector{Any}(undef, length(itr)), itr) # convenient for Expr.args

# default to returning an Array for `map` on general iterators
"""
map(f, c...) -> collection
Expand Down
2 changes: 1 addition & 1 deletion base/arrayshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ function print_matrix(io::IO, X::AbstractVecOrMat,
vdots::AbstractString = "\u22ee",
ddots::AbstractString = " \u22f1 ",
hmod::Integer = 5, vmod::Integer = 5)
if !get(io, :limit, false)
if !(get(io, :limit, false)::Bool)
screenheight = screenwidth = typemax(Int)
else
sz = displaysize(io)
Expand Down
2 changes: 1 addition & 1 deletion base/channels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,7 @@ show(io::IO, c::Channel) = print(io, typeof(c), "(", c.sz_max, ")")

function show(io::IO, ::MIME"text/plain", c::Channel)
show(io, c)
if !get(io, :compact, false)
if !(get(io, :compact, false)::Bool)
if !isopen(c)
print(io, " (closed)")
else
Expand Down
2 changes: 1 addition & 1 deletion base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ function show(io::IO, t::AbstractDict{K,V}) where V where K
recur_io = IOContext(io, :SHOWN_SET => t,
:typeinfo => eltype(t))

limit::Bool = get(io, :limit, false)
limit = get(io, :limit, false)::Bool
# show in a Julia-syntax-like form: Dict(k=>v, ...)
print(io, typeinfo_prefix(io, t)[1])
print(io, '(')
Expand Down
22 changes: 12 additions & 10 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ include("bindings.jl")

import .Base.Meta: quot, isexpr
import .Base: Callable, with_output_color
using .Base: RefValue
using .Base: RefValue, mapany
import ..CoreDocs: lazy_iterpolate

export doc
Expand All @@ -71,12 +71,13 @@ export doc

const modules = Module[]
const META = gensym(:meta)
const METAType = IdDict{Any,Any}

meta(m::Module) = isdefined(m, META) ? getfield(m, META) : IdDict()
meta(m::Module) = isdefined(m, META) ? getfield(m, META)::METAType : METAType()

function initmeta(m::Module)
if !isdefined(m, META)
Core.eval(m, :(const $META = $(IdDict())))
Core.eval(m, :(const $META = $(METAType())))
push!(modules, m)
end
nothing
Expand All @@ -95,7 +96,7 @@ function signature!(tv, expr::Expr)
push!(sig.args[end].args, argtype(arg))
end
if isexpr(expr.args[1], :curly) && isempty(tv)
append!(tv, tvar.(expr.args[1].args[2:end]))
append!(tv, mapany(tvar, expr.args[1].args[2:end]))
end
for i = length(tv):-1:1
push!(sig.args, :(Tuple{$(tv[i].args[1])}))
Expand All @@ -105,7 +106,7 @@ function signature!(tv, expr::Expr)
end
return sig
elseif isexpr(expr, :where)
append!(tv, tvar.(expr.args[2:end]))
append!(tv, mapany(tvar, expr.args[2:end]))
return signature!(tv, expr.args[1])
else
return signature!(tv, expr.args[1])
Expand Down Expand Up @@ -204,9 +205,9 @@ mutable struct MultiDoc
"Ordered (via definition order) vector of object signatures."
order::Vector{Type}
"Documentation for each object. Keys are signatures."
docs::IdDict{Any,Any}
docs::METAType

MultiDoc() = new(Type[], IdDict())
MultiDoc() = new(Type[], METAType())
end

# Docstring registration.
Expand Down Expand Up @@ -331,13 +332,14 @@ function metadata(__source__, __module__, expr, ismodule)
end
if isexpr(expr, :struct)
# Field docs for concrete types.
fields = []
P = Pair{Any,Any}
fields = P[]
last_docstr = nothing
for each in expr.args[3].args
if isa(each, Symbol) || isexpr(each, :(::))
# a field declaration
if last_docstr !== nothing
push!(fields, (namify(each), last_docstr))
push!(fields, P(namify(each), last_docstr))
last_docstr = nothing
end
elseif isexpr(each, :function) || isexpr(each, :(=))
Expand All @@ -348,7 +350,7 @@ function metadata(__source__, __module__, expr, ismodule)
last_docstr = each
end
end
dict = :($(Dict)($([:($(Pair)($(quot(f)), $d)) for (f, d) in fields]...)))
dict = :($(Dict)($([(:($(P)($(quot(f)), $d)))::Expr for (f, d) in fields]...)))
push!(args, :($(Pair)(:fields, $dict)))
end
return :($(Dict)($(args...)))
Expand Down
6 changes: 3 additions & 3 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ function pushmeta!(ex::Expr, sym::Symbol, args::Any...)
if isempty(args)
tag = sym
else
tag = Expr(sym, args...)
tag = Expr(sym, args...)::Expr
end

inner = ex
Expand All @@ -277,7 +277,7 @@ function pushmeta!(ex::Expr, sym::Symbol, args::Any...)
if idx != 0
push!(exargs[idx].args, tag)
else
body::Expr = inner.args[2]
body = inner.args[2]::Expr
pushfirst!(body.args, Expr(:meta, tag))
end
ex
Expand Down Expand Up @@ -333,7 +333,7 @@ end

function findmeta(ex::Expr)
if ex.head === :function || is_short_function_def(ex) || ex.head === :->
body::Expr = ex.args[2]
body = ex.args[2]::Expr
body.head === :block || error(body, " is not a block expression")
return findmeta_block(ex.args)
end
Expand Down
2 changes: 1 addition & 1 deletion base/fastmath.jl
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ function make_fastmath(expr::Expr)
end
end
end
Expr(make_fastmath(expr.head), map(make_fastmath, expr.args)...)
Expr(make_fastmath(expr.head), Base.mapany(make_fastmath, expr.args)...)
end
function make_fastmath(symb::Symbol)
fast_symb = get(fast_op, symb, :nothing)
Expand Down
2 changes: 1 addition & 1 deletion base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ it is always safe to read one byte after seeing `eof` return `false`. `eof` will
`false` as long as buffered data is still available, even if the remote end of a connection
is closed.
"""
eof(io::AbstractPipe) = eof(pipe_reader(io))
eof(io::AbstractPipe) = eof(pipe_reader(io)::IO)::Bool
reseteof(io::AbstractPipe) = reseteof(pipe_reader(io))


Expand Down
2 changes: 2 additions & 0 deletions base/libc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ dup(src::RawFD, target::RawFD) = systemerror("dup", -1 ==
ccall((@static Sys.iswindows() ? :_dup2 : :dup2), Int32,
(RawFD, RawFD), src, target))

show(io::IO, fd::RawFD) = print(io, "RawFD(", bitcast(UInt32, fd), ')') # avoids invalidation via show_default

# Wrapper for an OS file descriptor (for Windows)
if Sys.iswindows()
primitive type WindowsRawSocket sizeof(Ptr) * 8 end # On Windows file descriptors are HANDLE's and 64-bit on 64-bit Windows
Expand Down
3 changes: 2 additions & 1 deletion base/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ end

_invoked_min_enabled_level(@nospecialize(logger)) = invoke(min_enabled_level, Tuple{typeof(logger)}, logger)

_invoked_catch_exceptions(@nospecialize(logger)) = invoke(catch_exceptions, Tuple{typeof(logger)}, logger)

"""
NullLogger()
Expand Down Expand Up @@ -349,7 +350,7 @@ end
# Report an error in log message creation (or in the logger itself).
@noinline function logging_error(logger, level, _module, group, id,
filepath, line, @nospecialize(err))
if !catch_exceptions(logger)
if !_invoked_catch_exceptions(logger)
rethrow(err)
end
try
Expand Down
1 change: 0 additions & 1 deletion base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,6 @@ function print_range(io::IO, r::AbstractRange,
hdots::AbstractString = ",\u2026,") # horiz ellipsis
# This function borrows from print_matrix() in show.jl
# and should be called by show and display
limit = get(io, :limit, false)
sz = displaysize(io)
if !haskey(io, :compact)
io = IOContext(io, :compact => true)
Expand Down
2 changes: 1 addition & 1 deletion base/ryu/Ryu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function writeexp(x::T,
end

function Base.show(io::IO, x::T, forceuntyped::Bool=false, fromprint::Bool=false) where {T <: Base.IEEEFloat}
compact = get(io, :compact, false)
compact = get(io, :compact, false)::Bool
buf = Base.StringVector(neededdigits(T))
typed = !forceuntyped && !compact && get(io, :typeinfo, Any) != typeof(x)
pos = writeshortest(buf, 1, x, false, false, true, -1,
Expand Down
16 changes: 8 additions & 8 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function show(io::IO, ::MIME"text/plain", iter::Union{KeySet,ValueIterator})
summary(io, iter)
isempty(iter) && return
print(io, ". ", isa(iter,KeySet) ? "Keys" : "Values", ":")
limit::Bool = get(io, :limit, false)
limit = get(io, :limit, false)::Bool
if limit
sz = displaysize(io)
rows, cols = sz[1] - 3, sz[2]
Expand Down Expand Up @@ -79,7 +79,7 @@ function show(io::IO, ::MIME"text/plain", t::AbstractDict{K,V}) where {K,V}
isempty(t) && return show(io, t)
# show more descriptively, with one line per key/value pair
recur_io = IOContext(io, :SHOWN_SET => t)
limit::Bool = get(io, :limit, false)
limit = get(io, :limit, false)::Bool
if !haskey(io, :compact)
recur_io = IOContext(recur_io, :compact => true)
end
Expand Down Expand Up @@ -149,7 +149,7 @@ function show(io::IO, ::MIME"text/plain", t::AbstractSet{T}) where T
isempty(t) && return show(io, t)
# show more descriptively, with one line per value
recur_io = IOContext(io, :SHOWN_SET => t)
limit::Bool = get(io, :limit, false)
limit = get(io, :limit, false)::Bool

summary(io, t)
isempty(t) && return
Expand Down Expand Up @@ -450,11 +450,11 @@ function show_function(io::IO, f::Function, compact::Bool)
end
end

show(io::IO, f::Function) = show_function(io, f, get(io, :compact, false))
show(io::IO, f::Function) = show_function(io, f, get(io, :compact, false)::Bool)
print(io::IO, f::Function) = show_function(io, f, true)

function show(io::IO, f::Core.IntrinsicFunction)
if !get(io, :compact, false)
if !(get(io, :compact, false)::Bool)
print(io, "Core.Intrinsics.")
end
print(io, nameof(f))
Expand Down Expand Up @@ -564,7 +564,7 @@ function show_type_name(io::IO, tn::Core.TypeName)
sym = (globfunc ? globname : tn.name)::Symbol
globfunc && print(io, "typeof(")
quo = false
if !get(io, :compact, false)
if !(get(io, :compact, false)::Bool)
# Print module prefix unless type is visible from module passed to
# IOContext If :module is not set, default to Main. nothing can be used
# to force printing prefix
Expand Down Expand Up @@ -1198,7 +1198,7 @@ function show_import_path(io::IO, ex, quote_level)
if i > 1 && ex.args[i-1] !== :(.)
print(io, '.')
end
show_sym(io, ex.args[i], allow_macroname=(i==length(ex.args)))
show_sym(io, ex.args[i]::Symbol, allow_macroname=(i==length(ex.args)))
end
else
show_unquoted(io, ex, 0, 0, quote_level)
Expand Down Expand Up @@ -2129,7 +2129,7 @@ function alignment(io::IO, x::Pair)
ctx = IOContext(io, :typeinfo => gettypeinfos(io, x)[1])
left = length(sprint(show, x.first, context=ctx, sizehint=0))
left += 2 * !isdelimited(ctx, x.first) # for parens around p.first
left += !get(io, :compact, false) # spaces are added around "=>"
left += !(get(io, :compact, false)::Bool) # spaces are added around "=>"
(left+1, length(s)-left-1) # +1 for the "=" part of "=>"
else
(0, length(s)) # as for x::Any
Expand Down
2 changes: 1 addition & 1 deletion base/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ julia> cmp("b", "β")
function cmp(a::AbstractString, b::AbstractString)
a === b && return 0
a, b = Iterators.Stateful(a), Iterators.Stateful(b)
for (c, d) in zip(a, b)
for (c::AbstractChar, d::AbstractChar) in zip(a, b)
c ≠ d && return ifelse(c < d, -1, 1)
end
isempty(a) && return ifelse(isempty(b), 0, -1)
Expand Down
8 changes: 4 additions & 4 deletions base/views.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ function _views(ex::Expr)
# but still use views for the args of the ref:
lhs = ex.args[1]
Expr(ex.head, Meta.isexpr(lhs, :ref) ?
Expr(:ref, _views.(lhs.args)...) : _views(lhs),
Expr(:ref, mapany(_views, lhs.args)...) : _views(lhs),
_views(ex.args[2]))
elseif ex.head === :ref
Expr(:call, maybeview, _views.(ex.args)...)
Expr(:call, maybeview, mapany(_views, ex.args)...)
else
h = string(ex.head)
# don't use view on the lhs of an op-assignment a[i...] += ...
Expand Down Expand Up @@ -182,9 +182,9 @@ function _views(ex::Expr)
Expr(first(h) == '.' ? :(.=) : :(=), :($a[$(I...)]),
Expr(:call, Symbol(h[1:end-1]),
:($maybeview($a, $(I...))),
_views.(ex.args[2:end])...)))
mapany(_views, ex.args[2:end])...)))
else
Expr(ex.head, _views.(ex.args)...)
Expr(ex.head, mapany(_views, ex.args)...)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Base64/src/decode.jl
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ function Base.readbytes!(pipe::Base64DecodePipe, data::AbstractVector{UInt8}, nb
return filled
end

Base.eof(pipe::Base64DecodePipe) = isempty(pipe.rest) && eof(pipe.io)
Base.eof(pipe::Base64DecodePipe) = isempty(pipe.rest) && eof(pipe.io)::Bool
Base.close(pipe::Base64DecodePipe) = nothing

# Decode data from (b1, b2, b3, b5, buffer, input) into (ptr, rest).
Expand Down
6 changes: 3 additions & 3 deletions stdlib/LibGit2/src/gitcredential.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,11 @@ end

function Base.read!(io::IO, cred::GitCredential)
# https://git-scm.com/docs/git-credential#IOFMT
while !eof(io)
key = readuntil(io, '=')
while !(eof(io)::Bool)
key::AbstractString = readuntil(io, '=')
if key == "password"
value = Base.SecretBuffer()
while !eof(io) && (c = read(io, UInt8)) != UInt8('\n')
while !(eof(io)::Bool) && (c = read(io, UInt8)) != UInt8('\n')
write(value, c)
end
seekstart(value)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Markdown/src/Julia/interp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ end

toexpr(x) = x

toexpr(xs::Vector{Any}) = Expr(:call, GlobalRef(Base,:getindex), Any, map(toexpr, xs)...)
toexpr(xs::Vector{Any}) = Expr(:call, GlobalRef(Base,:getindex), Any, mapany(toexpr, xs)...)

for T in Any[MD, Paragraph, Header, Link, Bold, Italic]
@eval function toexpr(md::$T)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Markdown/src/Markdown.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Tools for working with the Markdown file format. Mainly for documentation.
"""
module Markdown

import Base: show, ==, with_output_color
import Base: show, ==, with_output_color, mapany
using Base64: stringmime

# Margin for printing in terminal.
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Markdown/src/parse/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ const flavors = Dict{Symbol, Config}()

macro flavor(name, features)
quote
const $(esc(name)) = config($(map(esc,features.args)...))
const $(esc(name)) = config($(mapany(esc,features.args)...))
flavors[$(Expr(:quote, name))] = $(esc(name))
end
end
2 changes: 1 addition & 1 deletion stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ StreamREPL(stream::IO) = StreamREPL(stream, Base.text_colors[:green], Base.input
run_repl(stream::IO) = run_repl(StreamREPL(stream))

outstream(s::StreamREPL) = s.stream
hascolor(s::StreamREPL) = get(s.stream, :color, false)
hascolor(s::StreamREPL) = get(s.stream, :color, false)::Bool

answer_color(r::LineEditREPL) = r.envcolors ? Base.answer_color() : r.answer_color
answer_color(r::StreamREPL) = r.answer_color
Expand Down
Loading