Skip to content

Commit 55a30d5

Browse files
jishnubKristofferC
authored and
KristofferC
committed
LazyString in interpolated error messages involving types (#54737)
These are often badly inferred, e.g. in: ```julia julia> @report_opt 2//2 ┌ Warning: skipping (::Base.var"#show_bound#661")(io::IO, b) @ Base show.jl:2777 to avoid parsing too much code └ @ Revise ~/.julia/packages/Revise/bAgL0/src/packagedef.jl:1092 ┌ Warning: skipping (::Base.var"#show_bound#661")(io::IO, b) @ Base show.jl:2777 to avoid parsing too much code └ @ Revise ~/.julia/packages/Revise/bAgL0/src/packagedef.jl:1092 ═════ 32 possible errors found ═════ ┌ //(n::Int64, d::Int64) @ Base ./rational.jl:84 │┌ Rational(n::Int64, d::Int64) @ Base ./rational.jl:48 ││┌ Rational{Int64}(num::Int64, den::Int64) @ Base ./rational.jl:32 │││┌ __throw_rational_argerror_zero(T::Type{Int64}) @ Base ./rational.jl:30 ││││┌ string(::String, ::Type{Int64}, ::String, ::Type{Int64}, ::String) @ Base ./strings/io.jl:189 │││││┌ print_to_string(::String, ::Type{Int64}, ::String, ::Type{Int64}, ::String) @ Base ./strings/io.jl:148 ││││││┌ print(io::IOBuffer, x::DataType) @ Base ./strings/io.jl:35 │││││││┌ show(io::IOBuffer, x::DataType) @ Base ./show.jl:970 ││││││││┌ _show_type(io::IOBuffer, x::Type) @ Base ./show.jl:975 │││││││││┌ show_typealias(io::IOBuffer, x::Type) @ Base ./show.jl:810 ││││││││││┌ make_typealias(x::Type) @ Base ./show.jl:620 │││││││││││┌ modulesof!(s::Set{Module}, x::Type) @ Base ./show.jl:595 ││││││││││││ runtime dispatch detected: Base.modulesof!(s::Set{Module}, %20::Any)::Any │││││││││││└──────────────────── │││││││││││┌ modulesof!(s::Set{Module}, x::Type) @ Base ./show.jl:596 ││││││││││││ runtime dispatch detected: Base.modulesof!(s::Set{Module}, %34::Any)::Any │││││││││││└──────────────────── │││││││││││┌ modulesof!(s::Set{Module}, x::TypeVar) @ Base ./show.jl:589 ││││││││││││ runtime dispatch detected: Base.modulesof!(s::Set{Module}, %1::Any)::Set{Module} │││││││││││└──────────────────── │││││││││┌ show_typealias(io::IOBuffer, x::Type) @ Base ./show.jl:813 ││││││││││┌ show_typealias(io::IOBuffer, name::GlobalRef, x::Type, env::Core.SimpleVector, wheres::Vector{TypeVar}) @ Base ./show.jl:760 │││││││││││┌ show_typeparams(io::IOContext{IOBuffer}, env::Core.SimpleVector, orig::Core.SimpleVector, wheres::Vector{TypeVar}) @ Base ./show.jl:724 ││││││││││││┌ show(io::IOContext{IOBuffer}, tv::TypeVar) @ Base ./show.jl:2788 │││││││││││││┌ (::Base.var"#show_bound#661")(io::IOContext{IOBuffer}, b::Any) @ Base ./show.jl:2780 ││││││││││││││ runtime dispatch detected: show(io::IOContext{IOBuffer}, b::Any)::Any │││││││││││││└──────────────────── │││││││││││┌ show_typeparams(io::IOContext{IOBuffer}, env::Core.SimpleVector, orig::Core.SimpleVector, wheres::Vector{TypeVar}) @ Base ./show.jl:719 ││││││││││││ runtime dispatch detected: show(io::IOContext{IOBuffer}, %252::Any)::Any │││││││││││└──────────────────── │││││││││││┌ show_typeparams(io::IOContext{IOBuffer}, env::Core.SimpleVector, orig::Core.SimpleVector, wheres::Vector{TypeVar}) @ Base ./show.jl:722 ││││││││││││ runtime dispatch detected: show(io::IOContext{IOBuffer}, %313::Any)::Any │││││││││││└──────────────────── │││││││││││┌ show_typeparams(io::IOContext{IOBuffer}, env::Core.SimpleVector, orig::Core.SimpleVector, wheres::Vector{TypeVar}) @ Base ./show.jl:727 ││││││││││││ runtime dispatch detected: show(io::IOContext{IOBuffer}, %191::Any)::Any │││││││││││└──────────────────── ││││││││┌ _show_type(io::IOBuffer, x::Type) @ Base ./show.jl:978 │││││││││┌ show_datatype(io::IOBuffer, x::DataType) @ Base ./show.jl:1094 ││││││││││┌ show_datatype(io::IOBuffer, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1097 │││││││││││┌ maybe_kws_nt(x::DataType) @ Base ./show.jl:1085 ││││││││││││ runtime dispatch detected: eltype(%76::DataType)::Any │││││││││││└──────────────────── ││││││││││┌ show_datatype(io::IOBuffer, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1186 │││││││││││┌ show_typeparams(io::IOBuffer, env::Core.SimpleVector, orig::Core.SimpleVector, wheres::Vector{TypeVar}) @ Base ./show.jl:724 ││││││││││││┌ show(io::IOBuffer, tv::TypeVar) @ Base ./show.jl:2788 │││││││││││││┌ (::Base.var"#show_bound#661")(io::IOBuffer, b::Any) @ Base ./show.jl:2780 ││││││││││││││ runtime dispatch detected: show(io::IOBuffer, b::Any)::Any │││││││││││││└──────────────────── │││││││││││┌ show_typeparams(io::IOBuffer, env::Core.SimpleVector, orig::Core.SimpleVector, wheres::Vector{TypeVar}) @ Base ./show.jl:719 ││││││││││││ runtime dispatch detected: show(io::IOBuffer, %250::Any)::Any │││││││││││└──────────────────── │││││││││││┌ show_typeparams(io::IOBuffer, env::Core.SimpleVector, orig::Core.SimpleVector, wheres::Vector{TypeVar}) @ Base ./show.jl:722 ││││││││││││ runtime dispatch detected: show(io::IOBuffer, %310::Any)::Any │││││││││││└──────────────────── │││││││││││┌ show_typeparams(io::IOBuffer, env::Core.SimpleVector, orig::Core.SimpleVector, wheres::Vector{TypeVar}) @ Base ./show.jl:727 ││││││││││││ runtime dispatch detected: show(io::IOBuffer, %190::Any)::Any │││││││││││└──────────────────── ││││││││││┌ show_datatype(io::IOBuffer, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1157 │││││││││││ runtime dispatch detected: show(io::IOBuffer, %224::Any)::Any ││││││││││└──────────────────── ││││││││││┌ show_datatype(io::IOBuffer, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1162 │││││││││││ runtime dispatch detected: show(io::IOBuffer, %54::Any)::Any ││││││││││└──────────────────── ││││││││││┌ show_datatype(io::IOBuffer, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1148 │││││││││││ runtime dispatch detected: show(io::IOBuffer, %57::Any)::Any ││││││││││└──────────────────── ││││││││││┌ show_datatype(io::IOBuffer, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1150 │││││││││││ runtime dispatch detected: show(io::IOBuffer, %54::Any)::Any ││││││││││└──────────────────── ││││││││││┌ show_datatype(io::IOBuffer, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1172 │││││││││││ runtime dispatch detected: Base.show_at_namedtuple(io::IOBuffer, %329::Tuple, %328::DataType)::Any ││││││││││└──────────────────── ││││││││┌ _show_type(io::IOBuffer, x::Type) @ Base ./show.jl:981 │││││││││┌ show_unionaliases(io::IOBuffer, x::Union) @ Base ./show.jl:901 ││││││││││┌ make_typealiases(x::Union) @ Base ./show.jl:822 │││││││││││┌ modulesof!(s::Set{Module}, x::Union) @ Base ./show.jl:595 ││││││││││││ runtime dispatch detected: Base.modulesof!(s::Set{Module}, %3::Any)::Any │││││││││││└──────────────────── │││││││││││┌ modulesof!(s::Set{Module}, x::Union) @ Base ./show.jl:596 ││││││││││││ runtime dispatch detected: Base.modulesof!(s::Set{Module}, %17::Any)::Any │││││││││││└──────────────────── │││││││││┌ show_unionaliases(io::IOBuffer, x::Union) @ Base ./show.jl:914 ││││││││││ runtime dispatch detected: show(io::IOBuffer, %89::Any)::Any │││││││││└──────────────────── │││││││││┌ show_unionaliases(io::IOBuffer, x::Union) @ Base ./show.jl:920 ││││││││││ runtime dispatch detected: Base.show_typealias(io::IOBuffer, %206::Any, x::Union, %204::Core.SimpleVector, %205::Vector{TypeVar})::Any │││││││││└──────────────────── │││││││││┌ show_unionaliases(io::IOBuffer, x::Union) @ Base ./show.jl:928 ││││││││││ runtime dispatch detected: Base.show_typealias(io::IOBuffer, %269::Any, x::Union, %267::Core.SimpleVector, %268::Vector{TypeVar})::Any │││││││││└──────────────────── ││││││││┌ _show_type(io::IOBuffer, x::Type) @ Base ./show.jl:985 │││││││││┌ show_delim_array(io::IOBuffer, itr::Vector{Any}, op::Char, delim::Char, cl::Char, delim_one::Bool) @ Base ./show.jl:1392 ││││││││││┌ show_delim_array(io::IOBuffer, itr::Vector{Any}, op::Char, delim::Char, cl::Char, delim_one::Bool, i1::Int64, l::Int64) @ Base ./show.jl:1403 │││││││││││ runtime dispatch detected: show(%3::IOContext{IOBuffer}, %52::Any)::Any ││││││││││└──────────────────── ││││││││┌ _show_type(io::IOBuffer, x::Type) @ Base ./show.jl:1012 │││││││││┌ show_datatype(io::IOContext{IOBuffer}, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1185 ││││││││││┌ show_type_name(io::IOContext{IOBuffer}, tn::Core.TypeName) @ Base ./show.jl:1059 │││││││││││ runtime dispatch detected: Base.isvisible(%29::Symbol, %86::Module, %80::Any)::Bool ││││││││││└──────────────────── │││││││││┌ show_datatype(io::IOContext{IOBuffer}, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1157 ││││││││││ runtime dispatch detected: show(io::IOContext{IOBuffer}, %227::Any)::Any │││││││││└──────────────────── │││││││││┌ show_datatype(io::IOContext{IOBuffer}, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1162 ││││││││││ runtime dispatch detected: show(io::IOContext{IOBuffer}, %55::Any)::Any │││││││││└──────────────────── │││││││││┌ show_datatype(io::IOContext{IOBuffer}, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1148 ││││││││││ runtime dispatch detected: show(io::IOContext{IOBuffer}, %58::Any)::Any │││││││││└──────────────────── │││││││││┌ show_datatype(io::IOContext{IOBuffer}, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1150 ││││││││││ runtime dispatch detected: show(io::IOContext{IOBuffer}, %55::Any)::Any │││││││││└──────────────────── │││││││││┌ show_datatype(io::IOContext{IOBuffer}, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1172 ││││││││││ runtime dispatch detected: Base.show_at_namedtuple(io::IOContext{IOBuffer}, %338::Tuple, %337::DataType)::Any │││││││││└──────────────────── │││││││││┌ show_datatype(io::IOContext{IOBuffer}, x::DataType, wheres::Vector{TypeVar}) @ Base ./show.jl:1180 ││││││││││ runtime dispatch detected: Base.show_at_namedtuple(io::IOContext{IOBuffer}, %387::Tuple, %391::DataType)::Any │││││││││└──────────────────── ││││││││┌ _show_type(io::IOBuffer, x::Type) @ Base ./show.jl:1014 │││││││││ runtime dispatch detected: show(%98::IOContext{IOBuffer}, %99::Any)::Any ││││││││└──────────────────── │││││││┌ show(io::IOBuffer, x::DataType) @ Base ./show.jl:970 ││││││││ runtime dispatch detected: Base._show_type(io::IOBuffer, %1::Any)::Nothing │││││││└──────────────────── ``` I haven't looked through all instances thoroughly, just a quick `grep`. However, this PR should address several common cases. (cherry picked from commit 2230f79)
1 parent cecd5f2 commit 55a30d5

13 files changed

+37
-34
lines changed

base/Enums.jl

+11-10
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ end
9090
# give Enum types scalar behavior in broadcasting
9191
Base.broadcastable(x::Enum) = Ref(x)
9292

93-
@noinline enum_argument_error(typename, x) = throw(ArgumentError(string("invalid value for Enum $(typename): $x")))
93+
@noinline enum_argument_error(typename, x) = throw(ArgumentError(LazyString("invalid value for Enum ", typename, ": ", x)))
9494

9595
"""
9696
@enum EnumName[::BaseType] value1[=x] value2[=y]
@@ -143,18 +143,19 @@ julia> Symbol(apple)
143143
"""
144144
macro enum(T::Union{Symbol,Expr}, syms...)
145145
if isempty(syms)
146-
throw(ArgumentError("no arguments given for Enum $T"))
146+
throw(ArgumentError(LazyString("no arguments given for Enum ", T)))
147147
end
148148
basetype = Int32
149149
typename = T
150150
if isa(T, Expr) && T.head === :(::) && length(T.args) == 2 && isa(T.args[1], Symbol)
151151
typename = T.args[1]
152152
basetype = Core.eval(__module__, T.args[2])
153153
if !isa(basetype, DataType) || !(basetype <: Integer) || !isbitstype(basetype)
154-
throw(ArgumentError("invalid base type for Enum $typename, $T=::$basetype; base type must be an integer primitive type"))
154+
throw(ArgumentError(
155+
LazyString("invalid base type for Enum ", typename, ", ", T, "=::", basetype, "; base type must be an integer primitive type")))
155156
end
156157
elseif !isa(T, Symbol)
157-
throw(ArgumentError("invalid type expression for enum $T"))
158+
throw(ArgumentError(LazyString("invalid type expression for enum ", T)))
158159
end
159160
values = Vector{basetype}()
160161
seen = Set{Symbol}()
@@ -169,32 +170,32 @@ macro enum(T::Union{Symbol,Expr}, syms...)
169170
s isa LineNumberNode && continue
170171
if isa(s, Symbol)
171172
if i == typemin(basetype) && !isempty(values)
172-
throw(ArgumentError("overflow in value \"$s\" of Enum $typename"))
173+
throw(ArgumentError(LazyString("overflow in value \"", s, "\" of Enum ", typename)))
173174
end
174175
elseif isa(s, Expr) &&
175176
(s.head === :(=) || s.head === :kw) &&
176177
length(s.args) == 2 && isa(s.args[1], Symbol)
177178
i = Core.eval(__module__, s.args[2]) # allow exprs, e.g. uint128"1"
178179
if !isa(i, Integer)
179-
throw(ArgumentError("invalid value for Enum $typename, $s; values must be integers"))
180+
throw(ArgumentError(LazyString("invalid value for Enum ", typename, ", ", s, "; values must be integers")))
180181
end
181182
i = convert(basetype, i)
182183
s = s.args[1]
183184
hasexpr = true
184185
else
185-
throw(ArgumentError(string("invalid argument for Enum ", typename, ": ", s)))
186+
throw(ArgumentError(LazyString("invalid argument for Enum ", typename, ": ", s)))
186187
end
187188
s = s::Symbol
188189
if !Base.isidentifier(s)
189-
throw(ArgumentError("invalid name for Enum $typename; \"$s\" is not a valid identifier"))
190+
throw(ArgumentError(LazyString("invalid name for Enum ", typename, "; \"", s, "\" is not a valid identifier")))
190191
end
191192
if hasexpr && haskey(namemap, i)
192-
throw(ArgumentError("both $s and $(namemap[i]) have value $i in Enum $typename; values must be unique"))
193+
throw(ArgumentError(LazyString("both ", s, " and ", namemap[i], " have value ", i, " in Enum ", typename, "; values must be unique")))
193194
end
194195
namemap[i] = s
195196
push!(values, i)
196197
if s in seen
197-
throw(ArgumentError("name \"$s\" in Enum $typename is not unique"))
198+
throw(ArgumentError(LazyString("name \"", s, "\" in Enum ", typename, " is not unique")))
198199
end
199200
push!(seen, s)
200201
if length(values) == 1

base/abstractarray.jl

+9-8
Original file line numberDiff line numberDiff line change
@@ -756,8 +756,7 @@ julia> checkindex(Bool, 1:20, 21)
756756
false
757757
```
758758
"""
759-
checkindex(::Type{Bool}, inds::AbstractUnitRange, i) =
760-
throw(ArgumentError("unable to check bounds for indices of type $(typeof(i))"))
759+
checkindex(::Type{Bool}, inds::AbstractUnitRange, i) = throw(ArgumentError(LazyString("unable to check bounds for indices of type ", typeof(i))))
761760
checkindex(::Type{Bool}, inds::AbstractUnitRange, i::Real) = (first(inds) <= i) & (i <= last(inds))
762761
checkindex(::Type{Bool}, inds::IdentityUnitRange, i::Real) = checkindex(Bool, inds.indices, i)
763762
checkindex(::Type{Bool}, inds::OneTo{T}, i::T) where {T<:BitInteger} = unsigned(i - one(i)) < unsigned(last(inds))
@@ -1497,12 +1496,14 @@ much more common case where aliasing does not occur. By default,
14971496
unaliascopy(A::Array) = copy(A)
14981497
unaliascopy(A::AbstractArray)::typeof(A) = (@noinline; _unaliascopy(A, copy(A)))
14991498
_unaliascopy(A::T, C::T) where {T} = C
1500-
_unaliascopy(A, C) = throw(ArgumentError("""
1501-
an array of type `$(typename(typeof(A)).wrapper)` shares memory with another argument
1502-
and must make a preventative copy of itself in order to maintain consistent semantics,
1503-
but `copy(::$(typeof(A)))` returns a new array of type `$(typeof(C))`.
1504-
To fix, implement:
1505-
`Base.unaliascopy(A::$(typename(typeof(A)).wrapper))::typeof(A)`"""))
1499+
function _unaliascopy(A, C)
1500+
Aw = typename(typeof(A)).wrapper
1501+
throw(ArgumentError(LazyString("an array of type `", Aw, "` shares memory with another argument ",
1502+
"and must make a preventative copy of itself in order to maintain consistent semantics, ",
1503+
"but `copy(::", typeof(A), ")` returns a new array of type `", typeof(C), "`.\n",
1504+
"""To fix, implement:
1505+
`Base.unaliascopy(A::""", Aw, ")::typeof(A)`")))
1506+
end
15061507
unaliascopy(A) = A
15071508

15081509
"""

base/c.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ function ccall_macro_lower(convention, func, rettype, types, args, nreq)
650650
check = quote
651651
if !isa(func, Ptr{Cvoid})
652652
name = $name
653-
throw(ArgumentError("interpolated function `$name` was not a Ptr{Cvoid}, but $(typeof(func))"))
653+
throw(ArgumentError(LazyString("interpolated function `", name, "` was not a Ptr{Cvoid}, but ", typeof(func))))
654654
end
655655
end
656656
push!(statements, check)

base/indices.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -295,9 +295,9 @@ to_index(I::AbstractArray{Bool}) = LogicalIndex(I)
295295
to_index(I::AbstractArray) = I
296296
to_index(I::AbstractArray{Union{}}) = I
297297
to_index(I::AbstractArray{<:Union{AbstractArray, Colon}}) =
298-
throw(ArgumentError("invalid index: $(limitrepr(I)) of type $(typeof(I))"))
298+
throw(ArgumentError(LazyString("invalid index: ", limitrepr(I), " of type ", typeof(I))))
299299
to_index(::Colon) = throw(ArgumentError("colons must be converted by to_indices(...)"))
300-
to_index(i) = throw(ArgumentError("invalid index: $(limitrepr(i)) of type $(typeof(i))"))
300+
to_index(i) = throw(ArgumentError(LazyString("invalid index: ", limitrepr(i), " of type ", typeof(i))))
301301

302302
# The general to_indices is mostly defined in multidimensional.jl, but this
303303
# definition is required for bootstrap:

base/intfuncs.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ julia> bitstring(2.2)
916916
```
917917
"""
918918
function bitstring(x::T) where {T}
919-
isprimitivetype(T) || throw(ArgumentError("$T not a primitive type"))
919+
isprimitivetype(T) || throw(ArgumentError(LazyString(T, " not a primitive type")))
920920
sz = sizeof(T) * 8
921921
str = StringVector(sz)
922922
i = sz
@@ -1016,7 +1016,7 @@ julia> digits!([2, 2, 2, 2, 2, 2], 10, base = 2)
10161016
function digits!(a::AbstractVector{T}, n::Integer; base::Integer = 10) where T<:Integer
10171017
2 <= abs(base) || throw(DomainError(base, "base must be ≥ 2 or ≤ -2"))
10181018
hastypemax(T) && abs(base) - 1 > typemax(T) &&
1019-
throw(ArgumentError("type $T too small for base $base"))
1019+
throw(ArgumentError(LazyString("type ", T, " too small for base ", base)))
10201020
isempty(a) && return a
10211021

10221022
if base > 0

base/io.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ previously marked position. Throw an error if the stream is not marked.
12631263
See also [`mark`](@ref), [`unmark`](@ref), [`ismarked`](@ref).
12641264
"""
12651265
function reset(io::T) where T<:IO
1266-
ismarked(io) || throw(ArgumentError("$T not marked"))
1266+
ismarked(io) || throw(ArgumentError(LazyString(T, " not marked")))
12671267
m = io.mark
12681268
seek(io, m)
12691269
io.mark = -1 # must be after seek, or seek may fail

base/iterators.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ using .Base:
1515
AbstractRange, AbstractUnitRange, UnitRange, LinearIndices, TupleOrBottom,
1616
(:), |, +, -, *, !==, !, ==, !=, <=, <, >, >=, missing,
1717
any, _counttuple, eachindex, ntuple, zero, prod, reduce, in, firstindex, lastindex,
18-
tail, fieldtypes, min, max, minimum, zero, oneunit, promote, promote_shape
18+
tail, fieldtypes, min, max, minimum, zero, oneunit, promote, promote_shape, LazyString
1919
using Core: @doc
2020

2121
if Base !== Core.Compiler
@@ -1048,15 +1048,15 @@ _prod_size(t::Tuple) = (_prod_size1(t[1], IteratorSize(t[1]))..., _prod_size(tai
10481048
_prod_size1(a, ::HasShape) = size(a)
10491049
_prod_size1(a, ::HasLength) = (length(a),)
10501050
_prod_size1(a, A) =
1051-
throw(ArgumentError("Cannot compute size for object of type $(typeof(a))"))
1051+
throw(ArgumentError(LazyString("Cannot compute size for object of type ", typeof(a))))
10521052

10531053
axes(P::ProductIterator) = _prod_indices(P.iterators)
10541054
_prod_indices(::Tuple{}) = ()
10551055
_prod_indices(t::Tuple) = (_prod_axes1(t[1], IteratorSize(t[1]))..., _prod_indices(tail(t))...)
10561056
_prod_axes1(a, ::HasShape) = axes(a)
10571057
_prod_axes1(a, ::HasLength) = (OneTo(length(a)),)
10581058
_prod_axes1(a, A) =
1059-
throw(ArgumentError("Cannot compute indices for object of type $(typeof(a))"))
1059+
throw(ArgumentError(LazyString("Cannot compute indices for object of type ", typeof(a))))
10601060

10611061
ndims(p::ProductIterator) = length(axes(p))
10621062
length(P::ProductIterator) = reduce(checked_mul, size(P); init=1)

base/multidimensional.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ module IteratorsMD
583583
else
584584
# Given the fact that StepRange 1:2:4 === 1:2:3, we lost the original size information
585585
# and thus cannot calculate the correct linear indices when the steps are not 1.
586-
throw(ArgumentError("LinearIndices for $(typeof(inds)) with non-1 step size is not yet supported."))
586+
throw(ArgumentError(LazyString("LinearIndices for ", typeof(inds), " with non-1 step size is not yet supported.")))
587587
end
588588
end
589589

base/parse.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ function tryparse_internal(::Type{T}, s::AbstractString, raise::Bool; kwargs...)
385385
return result
386386
end
387387
@noinline _parse_failure(T, s::AbstractString, startpos = firstindex(s), endpos = lastindex(s)) =
388-
throw(ArgumentError("cannot parse $(repr(s[startpos:endpos])) as $T"))
388+
throw(ArgumentError(LazyString("cannot parse ", repr(s[startpos:endpos]), " as ", T)))
389389

390390
tryparse_internal(::Type{T}, s::AbstractString, startpos::Int, endpos::Int, raise::Bool) where T<:Integer =
391391
tryparse_internal(T, s, startpos, endpos, 10, raise)

base/rational.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ end
2929
checked_den(num::T, den::T) where T<:Integer = checked_den(T, num, den)
3030
checked_den(num::Integer, den::Integer) = checked_den(promote(num, den)...)
3131

32-
@noinline __throw_rational_argerror_zero(T) = throw(ArgumentError("invalid rational: zero($T)//zero($T)"))
32+
@noinline __throw_rational_argerror_zero(T) = throw(ArgumentError(LazyString("invalid rational: zero(", T, ")//zero(", T, ")")))
3333
function Rational{T}(num::Integer, den::Integer) where T<:Integer
3434
iszero(den) && iszero(num) && __throw_rational_argerror_zero(T)
3535
num, den = divgcd(num, den)

base/sort.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -2217,7 +2217,7 @@ function _sort!(v::AbstractVector, a::Algorithm, o::Ordering, kw)
22172217
@getkw lo hi scratch legacy_dispatch_entry
22182218
if legacy_dispatch_entry === a
22192219
# This error prevents infinite recursion for unknown algorithms
2220-
throw(ArgumentError("Base.Sort._sort!(::$(typeof(v)), ::$(typeof(a)), ::$(typeof(o)), ::Any) is not defined"))
2220+
throw(ArgumentError(LazyString("Base.Sort._sort!(::", typeof(v), ", ::", typeof(a), ", ::", typeof(o), ", ::Any) is not defined")))
22212221
else
22222222
sort!(v, lo, hi, a, o)
22232223
scratch

base/subarray.jl

+3-2
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ substrides(strds::Tuple{}, ::Tuple{}) = ()
398398
substrides(strds::NTuple{N,Int}, I::Tuple{ScalarIndex, Vararg{Any}}) where N = (substrides(tail(strds), tail(I))...,)
399399
substrides(strds::NTuple{N,Int}, I::Tuple{Slice, Vararg{Any}}) where N = (first(strds), substrides(tail(strds), tail(I))...)
400400
substrides(strds::NTuple{N,Int}, I::Tuple{AbstractRange, Vararg{Any}}) where N = (first(strds)*step(I[1]), substrides(tail(strds), tail(I))...)
401-
substrides(strds, I::Tuple{Any, Vararg{Any}}) = throw(ArgumentError("strides is invalid for SubArrays with indices of type $(typeof(I[1]))"))
401+
substrides(strds, I::Tuple{Any, Vararg{Any}}) = throw(ArgumentError(
402+
LazyString("strides is invalid for SubArrays with indices of type ", typeof(I[1]))))
402403

403404
stride(V::SubArray, d::Integer) = d <= ndims(V) ? strides(V)[d] : strides(V)[end] * size(V)[end]
404405

@@ -410,7 +411,7 @@ compute_stride1(s, inds, I::Tuple{ScalarIndex, Vararg{Any}}) =
410411
(@inline; compute_stride1(s*length(inds[1]), tail(inds), tail(I)))
411412
compute_stride1(s, inds, I::Tuple{AbstractRange, Vararg{Any}}) = s*step(I[1])
412413
compute_stride1(s, inds, I::Tuple{Slice, Vararg{Any}}) = s
413-
compute_stride1(s, inds, I::Tuple{Any, Vararg{Any}}) = throw(ArgumentError("invalid strided index type $(typeof(I[1]))"))
414+
compute_stride1(s, inds, I::Tuple{Any, Vararg{Any}}) = throw(ArgumentError(LazyString("invalid strided index type ", typeof(I[1]))))
414415

415416
elsize(::Type{<:SubArray{<:Any,<:Any,P}}) where {P} = elsize(P)
416417

base/tuple.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ _totuple(::Type{Tuple{}}, itr, s...) = ()
394394

395395
function _totuple_err(@nospecialize T)
396396
@noinline
397-
throw(ArgumentError("too few elements for tuple type $T"))
397+
throw(ArgumentError(LazyString("too few elements for tuple type ", T)))
398398
end
399399

400400
function _totuple(::Type{T}, itr, s::Vararg{Any,N}) where {T,N}

0 commit comments

Comments
 (0)