-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Illegal instruction in collect #25907
Comments
As a datapoint, this works: |
Is crashing caused by type inference stuffs? julia> @code_warntype f()
Variables:
Body:
begin
# meta: location REPL[15] f 2
# meta: location strings/unicode.jl isxdigit 561
goto 4
4:
5:
goto 7
7:
goto 9
9:
10:
goto 12
12:
goto 14
14:
# meta: pop location
goto 17
17:
# meta: pop location
return 0
end::Int64
julia> function f(c = Char(1))
isxdigit(c) ? tryparse(UInt, "0x$c") : 0
end |
That looks ok, it's the result of constant-propagating the |
No idea why (I just randomly comment out something), but this patch solves this issue. diff --git a/base/array.jl b/base/array.jl
index 3dbaa5957e..6b0da32d1b 100644
--- a/base/array.jl
+++ b/base/array.jl
@@ -575,7 +575,7 @@ function collect_to!(dest::AbstractArray{T}, itr, offs, st) where T
el, st = next(itr, st)
S = typeof(el)
if S === T || S <: T
- @inbounds dest[i] = el::T
+ @inbounds dest[i] = el
i += 1
else
R = promote_typejoin(T, S) |
FWIW, #25828 doesn't make the crash disappear either (too bad!). |
@nalimilan I applied your patch from #25828 diff --git a/base/array.jl b/base/array.jl
index 3dbaa5957e..93111a0c61 100644
--- a/base/array.jl
+++ b/base/array.jl
@@ -574,12 +574,13 @@ function collect_to!(dest::AbstractArray{T}, itr, offs, st) where T
while !done(itr, st)
el, st = next(itr, st)
S = typeof(el)
- if S === T || S <: T
- @inbounds dest[i] = el::T
+ if el isa T || typeof(el) === T
+ @inbounds dest[i] = el
i += 1
else
R = promote_typejoin(T, S) |
I meant that #25828 on its own doesn't make any difference if you don't remove |
I guess this should be all that's needed: if el isa T
@inbounds dest[i] = el I think inference should be able to figure out that But the code as it is now also should not crash. So might be worthwhile figuring out what's wrong there. |
See #25828 (comment). But we should probably remove the |
I tested |
That's interesting. But most probably unrelated. Meanwhile I've managed to come up with a fairly minimal reproducer for this issue's underlying bug: julia> @noinline f() = let c=rand(1:2); c == 1 ? 0 : c == 2 ? UInt(0) : nothing; end # @noinline for uncluttered code_warntype output
f (generic function with 1 method)
julia> function foo!(dest::AbstractArray{Integer})
el = f()
dest[1] = el::Integer
return dest
end
foo! (generic function with 1 method)
julia> @code_warntype foo!(Vector{Integer}(uninitialized, 1))
Variables:
dest::Array{Integer,1}
el::Union{Nothing, Int64, UInt64}
Body:
begin
el::Union{Nothing, Int64, UInt64} = $(Expr(:invoke, MethodInstance for f(), :(Main.f)))::Union{Nothing, Int64, UInt64}
#= line 3 =#
Core.SSAValue(0) = (Core.typeassert)(el::Union{Nothing, Int64, UInt64}, Main.Integer)::Integer
# meta: location array.jl setindex! 689
(Base.arrayset)(true, dest::Array{Integer,1}, Core.SSAValue(0), 1)::Array{Integer,1}
# meta: pop location
#= line 4 =#
return dest::Array{Integer,1}
end::Array{Integer,1}
julia> foo!(Vector{Integer}(uninitialized, 1))
Unreachable reached at 0x7f2d95930f91
signal (4): Illegal instruction
in expression starting at no file:0
foo! at ./REPL[2]:3
jl_call_fptr_internal at /home/hol/Projects/julia-master/src/julia_internal.h:383 [inlined]
jl_call_method_internal at /home/hol/Projects/julia-master/src/julia_internal.h:402 [inlined]
jl_apply_generic at /home/hol/Projects/julia-master/src/gf.c:2089
do_call at /home/hol/Projects/julia-master/src/interpreter.c:323
# ... Changing |
Addition: Not restricted to arrays; this crashes, too: mutable struct Foo; x::Integer; end
@noinline f() = let c=rand(1:2); c == 1 ? 0 : c == 2 ? UInt(0) : nothing; end # @noinline for uncluttered code_warntype output
function foo!(dest)
el = f()
dest.x = el::Integer
end
foo!(Foo(1)) |
Even shorter:
|
edit: same for |
A couple of observations:
|
The text was updated successfully, but these errors were encountered: