Skip to content

Commit 54404d9

Browse files
timholysimeonschaub
authored andcommitted
Fix some invalidations during Julia's bootstrap (JuliaLang#36427)
Also add nospecialize to with_output_color
1 parent 906a050 commit 54404d9

File tree

13 files changed

+28
-17
lines changed

13 files changed

+28
-17
lines changed

base/Base.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ include("abstractarraymath.jl")
129129
include("arraymath.jl")
130130

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

base/abstractarray.jl

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,9 @@ function getindex(A::AbstractArray, I...)
10601060
error_if_canonical_getindex(IndexStyle(A), A, I...)
10611061
_getindex(IndexStyle(A), A, to_indices(A, I)...)
10621062
end
1063+
# To avoid invalidations from multidimensional.jl: getindex(A::Array, i1::Union{Integer, CartesianIndex}, I::Union{Integer, CartesianIndex}...)
1064+
getindex(A::Array, i1::Integer, I::Integer...) = A[to_indices(A, (i1, I...))...]
1065+
10631066
function unsafe_getindex(A::AbstractArray, I...)
10641067
@_inline_meta
10651068
@inbounds r = getindex(A, I...)
@@ -2163,7 +2166,7 @@ end
21632166
# map on collections
21642167
map(f, A::AbstractArray) = collect_similar(A, Generator(f,A))
21652168

2166-
mapany(f, itr) = map!(f, Vector{Any}(undef, length(itr)), itr) # convenient for Expr.args
2169+
mapany(f, itr) = map!(f, Vector{Any}(undef, length(itr)::Int), itr) # convenient for Expr.args
21672170

21682171
# default to returning an Array for `map` on general iterators
21692172
"""

base/docs/Docs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function signature!(tv, expr::Expr)
9696
push!(sig.args[end].args, argtype(arg))
9797
end
9898
if isexpr(expr.args[1], :curly) && isempty(tv)
99-
append!(tv, mapany(tvar, expr.args[1].args[2:end]))
99+
append!(tv, mapany(tvar, (expr.args[1]::Expr).args[2:end]))
100100
end
101101
for i = length(tv):-1:1
102102
push!(sig.args, :(Tuple{$(tv[i].args[1])}))

base/essentials.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ convert(::Type{T}, x::T) where {T} = x
172172
convert(::Type{Type}, x::Type) = x # the ssair optimizer is strongly dependent on this method existing to avoid over-specialization
173173
# in the absence of inlining-enabled
174174
# (due to fields typed as `Type`, which is generally a bad idea)
175+
# These end up being called during bootstrap and then would be invalidated if not for the following:
176+
convert(::Type{String}, x::String) = x
175177

176178
"""
177179
@eval [mod,] ex

base/indices.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,10 @@ not all index types are guaranteed to propagate to `Base.to_index`.
320320
"""
321321
to_indices(A, I::Tuple) = (@_inline_meta; to_indices(A, axes(A), I))
322322
to_indices(A, I::Tuple{Any}) = (@_inline_meta; to_indices(A, (eachindex(IndexLinear(), A),), I))
323+
# In simple cases, we know that we don't need to use axes(A), optimize those.
324+
# Having this here avoids invalidations from multidimensional.jl: to_indices(A, I::Tuple{Vararg{Union{Integer, CartesianIndex}}})
325+
to_indices(A, I::Tuple{}) = ()
326+
to_indices(A, I::Tuple{Vararg{Integer}}) = (@_inline_meta; to_indices(A, (), I))
323327
to_indices(A, inds, ::Tuple{}) = ()
324328
to_indices(A, inds, I::Tuple{Any, Vararg{Any}}) =
325329
(@_inline_meta; (to_index(A, I[1]), to_indices(A, _maybetail(inds), tail(I))...))

base/initdefs.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,9 @@ function active_project(search_load_path::Bool=true)
266266
project == "@" && continue
267267
project = load_path_expand(project)
268268
project === nothing && continue
269+
# while this seems well-inferred, nevertheless without the type annotation below
270+
# there are backedges here from abspath(::AbstractString, ::String)
271+
project = project::String
269272
if !isfile_casesensitive(project) && basename(project) project_names
270273
project = abspath(project, "Project.toml")
271274
end

base/meta.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ function _parse_string(text::AbstractString, filename::AbstractString,
155155
if index < 1 || index > ncodeunits(text) + 1
156156
throw(BoundsError(text, index))
157157
end
158-
ex, offset = Core._parse(text, filename, index-1, options)
158+
ex, offset::Int = Core._parse(text, filename, index-1, options)
159159
ex, offset+1
160160
end
161161

base/multidimensional.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -701,7 +701,6 @@ ensure_indexable(I::Tuple{}) = ()
701701

702702
# In simple cases, we know that we don't need to use axes(A). Optimize those
703703
# until Julia gets smart enough to elide the call on its own:
704-
to_indices(A, I::Tuple{}) = ()
705704
@inline to_indices(A, I::Tuple{Vararg{Union{Integer, CartesianIndex}}}) = to_indices(A, (), I)
706705
# But some index types require more context spanning multiple indices
707706
# CartesianIndexes are simple; they just splat out

base/shell.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717

1818
function shell_parse(str::AbstractString, interpolate::Bool=true;
1919
special::AbstractString="")
20-
s::SubString = SubString(str, firstindex(str))
20+
s = SubString(str, firstindex(str))
2121
s = rstrip_shell(lstrip(s))
2222

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

5050
for (j, c) in st
5151
if !in_single_quotes && !in_double_quotes && isspace(c)
52-
consume_upto(j)
52+
i = consume_upto(s, i, j)
5353
append_arg()
5454
while !isempty(st)
5555
# We've made sure above that we don't end in whitespace,
@@ -59,7 +59,7 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
5959
popfirst!(st)
6060
end
6161
elseif interpolate && !in_single_quotes && c == '$'
62-
consume_upto(j)
62+
i = consume_upto(s, i, j)
6363
isempty(st) && error("\$ right before end of command")
6464
stpos, c = popfirst!(st)
6565
isspace(c) && error("space not allowed right after \$")
@@ -79,21 +79,21 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
7979
else
8080
if !in_double_quotes && c == '\''
8181
in_single_quotes = !in_single_quotes
82-
consume_upto(j)
82+
i = consume_upto(s, i, j)
8383
elseif !in_single_quotes && c == '"'
8484
in_double_quotes = !in_double_quotes
85-
consume_upto(j)
85+
i = consume_upto(s, i, j)
8686
elseif c == '\\'
8787
if in_double_quotes
8888
isempty(st) && error("unterminated double quote")
8989
k, c′ = peek(st)
9090
if c′ == '"' || c′ == '$' || c′ == '\\'
91-
consume_upto(j)
91+
i = consume_upto(s, i, j)
9292
_ = popfirst!(st)
9393
end
9494
elseif !in_single_quotes
9595
isempty(st) && error("dangling backslash")
96-
consume_upto(j)
96+
i = consume_upto(s, i, j)
9797
_ = popfirst!(st)
9898
end
9999
elseif !in_single_quotes && !in_double_quotes && c in special

base/simdloop.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function check_body!(x::Expr)
2626
if x.head === :break || x.head === :continue
2727
throw(SimdError("$(x.head) is not allowed inside a @simd loop body"))
2828
elseif x.head === :macrocall && x.args[1] === Symbol("@goto")
29-
throw(SimdError("$(x.args[1]) is not allowed inside a @simd loop body"))
29+
throw(SimdError("@goto is not allowed inside a @simd loop body"))
3030
end
3131
for arg in x.args
3232
check_body!(arg)

0 commit comments

Comments
 (0)