Skip to content

Commit

Permalink
Fix some invalidations during Julia's bootstrap (#36427)
Browse files Browse the repository at this point in the history
Also add nospecialize to with_output_color
  • Loading branch information
timholy authored Jun 29, 2020
1 parent 4cf7267 commit cd13404
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 17 deletions.
1 change: 1 addition & 0 deletions base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ include("abstractarraymath.jl")
include("arraymath.jl")

# SIMD loops
@pure sizeof(s::String) = Core.sizeof(s) # needed by gensym as called from simdloop
include("simdloop.jl")
using .SimdLoop

Expand Down
5 changes: 4 additions & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,9 @@ function getindex(A::AbstractArray, I...)
error_if_canonical_getindex(IndexStyle(A), A, I...)
_getindex(IndexStyle(A), A, to_indices(A, I)...)
end
# To avoid invalidations from multidimensional.jl: getindex(A::Array, i1::Union{Integer, CartesianIndex}, I::Union{Integer, CartesianIndex}...)
getindex(A::Array, i1::Integer, I::Integer...) = A[to_indices(A, (i1, I...))...]

function unsafe_getindex(A::AbstractArray, I...)
@_inline_meta
@inbounds r = getindex(A, I...)
Expand Down Expand Up @@ -2163,7 +2166,7 @@ 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
mapany(f, itr) = map!(f, Vector{Any}(undef, length(itr)::Int), itr) # convenient for Expr.args

# default to returning an Array for `map` on general iterators
"""
Expand Down
2 changes: 1 addition & 1 deletion base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -96,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, mapany(tvar, expr.args[1].args[2:end]))
append!(tv, mapany(tvar, (expr.args[1]::Expr).args[2:end]))
end
for i = length(tv):-1:1
push!(sig.args, :(Tuple{$(tv[i].args[1])}))
Expand Down
2 changes: 2 additions & 0 deletions base/essentials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ convert(::Type{T}, x::T) where {T} = x
convert(::Type{Type}, x::Type) = x # the ssair optimizer is strongly dependent on this method existing to avoid over-specialization
# in the absence of inlining-enabled
# (due to fields typed as `Type`, which is generally a bad idea)
# These end up being called during bootstrap and then would be invalidated if not for the following:
convert(::Type{String}, x::String) = x

"""
@eval [mod,] ex
Expand Down
4 changes: 4 additions & 0 deletions base/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ not all index types are guaranteed to propagate to `Base.to_index`.
"""
to_indices(A, I::Tuple) = (@_inline_meta; to_indices(A, axes(A), I))
to_indices(A, I::Tuple{Any}) = (@_inline_meta; to_indices(A, (eachindex(IndexLinear(), A),), I))
# In simple cases, we know that we don't need to use axes(A), optimize those.
# Having this here avoids invalidations from multidimensional.jl: to_indices(A, I::Tuple{Vararg{Union{Integer, CartesianIndex}}})
to_indices(A, I::Tuple{}) = ()
to_indices(A, I::Tuple{Vararg{Integer}}) = (@_inline_meta; to_indices(A, (), I))
to_indices(A, inds, ::Tuple{}) = ()
to_indices(A, inds, I::Tuple{Any, Vararg{Any}}) =
(@_inline_meta; (to_index(A, I[1]), to_indices(A, _maybetail(inds), tail(I))...))
Expand Down
3 changes: 3 additions & 0 deletions base/initdefs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,9 @@ function active_project(search_load_path::Bool=true)
project == "@" && continue
project = load_path_expand(project)
project === nothing && continue
# while this seems well-inferred, nevertheless without the type annotation below
# there are backedges here from abspath(::AbstractString, ::String)
project = project::String
if !isfile_casesensitive(project) && basename(project) project_names
project = abspath(project, "Project.toml")
end
Expand Down
2 changes: 1 addition & 1 deletion base/meta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ function _parse_string(text::AbstractString, filename::AbstractString,
if index < 1 || index > ncodeunits(text) + 1
throw(BoundsError(text, index))
end
ex, offset = Core._parse(text, filename, index-1, options)
ex, offset::Int = Core._parse(text, filename, index-1, options)
ex, offset+1
end

Expand Down
1 change: 0 additions & 1 deletion base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,6 @@ ensure_indexable(I::Tuple{}) = ()

# In simple cases, we know that we don't need to use axes(A). Optimize those
# until Julia gets smart enough to elide the call on its own:
to_indices(A, I::Tuple{}) = ()
@inline to_indices(A, I::Tuple{Vararg{Union{Integer, CartesianIndex}}}) = to_indices(A, (), I)
# But some index types require more context spanning multiple indices
# CartesianIndexes are simple; they just splat out
Expand Down
18 changes: 9 additions & 9 deletions base/shell.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ end

function shell_parse(str::AbstractString, interpolate::Bool=true;
special::AbstractString="")
s::SubString = SubString(str, firstindex(str))
s = SubString(str, firstindex(str))
s = rstrip_shell(lstrip(s))

# N.B.: This is used by REPLCompletions
Expand All @@ -37,9 +37,9 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
push!(arg, x)
end
end
function consume_upto(j)
function consume_upto(s, i, j)
update_arg(s[i:prevind(s, j)])
i = something(peek(st), (lastindex(s)+1,'\0'))[1]
something(peek(st), (lastindex(s)+1,'\0'))[1]
end
function append_arg()
if isempty(arg); arg = Any["",]; end
Expand All @@ -49,7 +49,7 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;

for (j, c) in st
if !in_single_quotes && !in_double_quotes && isspace(c)
consume_upto(j)
i = consume_upto(s, i, j)
append_arg()
while !isempty(st)
# We've made sure above that we don't end in whitespace,
Expand All @@ -59,7 +59,7 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
popfirst!(st)
end
elseif interpolate && !in_single_quotes && c == '$'
consume_upto(j)
i = consume_upto(s, i, j)
isempty(st) && error("\$ right before end of command")
stpos, c = popfirst!(st)
isspace(c) && error("space not allowed right after \$")
Expand All @@ -79,21 +79,21 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
else
if !in_double_quotes && c == '\''
in_single_quotes = !in_single_quotes
consume_upto(j)
i = consume_upto(s, i, j)
elseif !in_single_quotes && c == '"'
in_double_quotes = !in_double_quotes
consume_upto(j)
i = consume_upto(s, i, j)
elseif c == '\\'
if in_double_quotes
isempty(st) && error("unterminated double quote")
k, c′ = peek(st)
if c′ == '"' || c′ == '$' || c′ == '\\'
consume_upto(j)
i = consume_upto(s, i, j)
_ = popfirst!(st)
end
elseif !in_single_quotes
isempty(st) && error("dangling backslash")
consume_upto(j)
i = consume_upto(s, i, j)
_ = popfirst!(st)
end
elseif !in_single_quotes && !in_double_quotes && c in special
Expand Down
2 changes: 1 addition & 1 deletion base/simdloop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function check_body!(x::Expr)
if x.head === :break || x.head === :continue
throw(SimdError("$(x.head) is not allowed inside a @simd loop body"))
elseif x.head === :macrocall && x.args[1] === Symbol("@goto")
throw(SimdError("$(x.args[1]) is not allowed inside a @simd loop body"))
throw(SimdError("@goto is not allowed inside a @simd loop body"))
end
for arg in x.args
check_body!(arg)
Expand Down
1 change: 0 additions & 1 deletion base/strings/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ pointer(s::String) = unsafe_convert(Ptr{UInt8}, s)
pointer(s::String, i::Integer) = pointer(s)+(i-1)

@pure ncodeunits(s::String) = Core.sizeof(s)
@pure sizeof(s::String) = Core.sizeof(s)
codeunit(s::String) = UInt8

@inline function codeunit(s::String, i::Integer)
Expand Down
2 changes: 1 addition & 1 deletion base/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ julia> lstrip(a)
"""
function lstrip(f, s::AbstractString)
e = lastindex(s)
for (i, c) in pairs(s)
for (i::Int, c::AbstractChar) in pairs(s)
!f(c) && return @inbounds SubString(s, i, e)
end
SubString(s, e+1, e)
Expand Down
2 changes: 1 addition & 1 deletion base/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Printing with the color `:nothing` will print the string without modifications.
"""
text_colors

function with_output_color(f::Function, color::Union{Int, Symbol}, io::IO, args...; bold::Bool = false)
function with_output_color(@nospecialize(f::Function), color::Union{Int, Symbol}, io::IO, args...; bold::Bool = false)
buf = IOBuffer()
iscolor = get(io, :color, false)::Bool
try f(IOContext(buf, io), args...)
Expand Down

0 comments on commit cd13404

Please sign in to comment.