Skip to content

Commit 7100c36

Browse files
committed
Fix some invalidations that occur during bootstrap
1 parent 6cd329c commit 7100c36

File tree

11 files changed

+31
-18
lines changed

11 files changed

+31
-18
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
@@ -1047,6 +1047,9 @@ function getindex(A::AbstractArray, I...)
10471047
error_if_canonical_getindex(IndexStyle(A), A, I...)
10481048
_getindex(IndexStyle(A), A, to_indices(A, I)...)
10491049
end
1050+
# To avoid invalidations from multidimensional.jl: getindex(A::Array, i1::Union{Integer, CartesianIndex}, I::Union{Integer, CartesianIndex}...)
1051+
getindex(A::Array, i1::Integer, I::Integer...) = A[to_indices(A, (i1, I...))...]
1052+
10501053
function unsafe_getindex(A::AbstractArray, I...)
10511054
@_inline_meta
10521055
@inbounds r = getindex(A, I...)
@@ -2150,7 +2153,7 @@ end
21502153
# map on collections
21512154
map(f, A::AbstractArray) = collect_similar(A, Generator(f,A))
21522155

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

21552158
# default to returning an Array for `map` on general iterators
21562159
"""

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/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: 14 additions & 12 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
@@ -33,23 +33,25 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
3333
st = Iterators.Stateful(pairs(s))
3434

3535
function update_arg(x)
36-
if !isa(x,AbstractString) || !isempty(x)
37-
push!(arg, x)
36+
let arg = arg
37+
if !isa(x,AbstractString) || !isempty(x)
38+
push!(arg, x)
39+
end
3840
end
3941
end
40-
function consume_upto(j)
42+
function consume_upto(s, i, j)
4143
update_arg(s[i:prevind(s, j)])
42-
i = something(peek(st), (lastindex(s)+1,'\0'))[1]
44+
something(peek(st), (lastindex(s)+1,'\0'))[1]
4345
end
4446
function append_arg()
4547
if isempty(arg); arg = Any["",]; end
4648
push!(args, arg)
4749
arg = []
4850
end
4951

50-
for (j, c) in st
52+
for (j::Int, c) in st
5153
if !in_single_quotes && !in_double_quotes && isspace(c)
52-
consume_upto(j)
54+
i = consume_upto(s, i, j)
5355
append_arg()
5456
while !isempty(st)
5557
# We've made sure above that we don't end in whitespace,
@@ -59,7 +61,7 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
5961
popfirst!(st)
6062
end
6163
elseif interpolate && !in_single_quotes && c == '$'
62-
consume_upto(j)
64+
i = consume_upto(s, i, j)
6365
isempty(st) && error("\$ right before end of command")
6466
stpos, c = popfirst!(st)
6567
isspace(c) && error("space not allowed right after \$")
@@ -79,21 +81,21 @@ function shell_parse(str::AbstractString, interpolate::Bool=true;
7981
else
8082
if !in_double_quotes && c == '\''
8183
in_single_quotes = !in_single_quotes
82-
consume_upto(j)
84+
i = consume_upto(s, i, j)
8385
elseif !in_single_quotes && c == '"'
8486
in_double_quotes = !in_double_quotes
85-
consume_upto(j)
87+
i = consume_upto(s, i, j)
8688
elseif c == '\\'
8789
if in_double_quotes
8890
isempty(st) && error("unterminated double quote")
8991
k, c′ = peek(st)
9092
if c′ == '"' || c′ == '$' || c′ == '\\'
91-
consume_upto(j)
93+
i = consume_upto(s, i, j)
9294
_ = popfirst!(st)
9395
end
9496
elseif !in_single_quotes
9597
isempty(st) && error("dangling backslash")
96-
consume_upto(j)
98+
i = consume_upto(s, i, j)
9799
_ = popfirst!(st)
98100
end
99101
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)

base/strings/string.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ pointer(s::String) = unsafe_convert(Ptr{UInt8}, s)
9595
pointer(s::String, i::Integer) = pointer(s)+(i-1)
9696

9797
@pure ncodeunits(s::String) = Core.sizeof(s)
98-
@pure sizeof(s::String) = Core.sizeof(s)
9998
codeunit(s::String) = UInt8
10099

101100
@inline function codeunit(s::String, i::Integer)

0 commit comments

Comments
 (0)