Skip to content
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

Runtime crash with unreachable reached #55206

Closed
AaronGhost opened this issue Jul 22, 2024 · 4 comments · Fixed by #55299
Closed

Runtime crash with unreachable reached #55206

AaronGhost opened this issue Jul 22, 2024 · 4 comments · Fixed by #55299
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior regression 1.10 Regression in the 1.10 release regression 1.11 Regression in the 1.11 release regression 1.12 Regression in the 1.12 release types and dispatch Types, subtyping and method dispatch

Comments

@AaronGhost
Copy link

Hi, thanks for developing Julia!

I encountered a runtime crash on 1.10.4 while including the script below. The runtime crash still exists in 1.11.0rc1 and nightly. I tried to reduce it to the best of my ability:

  • A StructB contains a StructA and an additional array
  • Both StructA and StructB have a "parameter" version (AParams and BParams)
  • a StructA/B can be with buildA/B and A/BParams
  • Calling buildB triggers a crash, only when using a boolean array (which does not depend on T).
abstract type AbstractA{T <: AbstractFloat} end
const UnionT{T, N} = Union{Array{T, N}, Array{Bool, N}}

struct StructA{T} <: AbstractA{T}
    x::T
end

struct AParams
    x
end

function buildA(params::AParams)
    return StructA(params.x)
end

struct StructB{T, DIM, S <: AbstractA{T}, SMT<: UnionT{T, DIM}}
    StructB(::S, arr::SMT) where {T, DIM, S <: AbstractA{T}, SMT <: UnionT{T, DIM}} = new{T, DIM, S, SMT}()
end

struct BParams{T}
    arr::UnionT{T}
    op::AParams
end

function buildB(objparams::BParams)
    op = buildA(objparams.op)
    return StructB(op, objparams.arr)
end

opparams = AParams(1.0f0)
objparams = BParams(ones(Bool, (10,10)), opparams)
obj = buildB(objparams)
Please find below the crash log

Unreachable reached at 0000023570eb17ff

Please submit a bug report with steps to reproduce this fault, and any error messages that follow (in their entirety). Thanks.
Exception: EXCEPTION_ILLEGAL_INSTRUCTION at 0x23570eb17ff -- buildB at D:\Documents\Julia\reproduceissue.jl:27
in expression starting at D:\Documents\Julia\reproduceissue.jl:32
buildB at D:\Documents\Julia\reproduceissue.jl:27
unknown function (ip: 0000023570eb183b)
jl_apply at C:/workdir/src\julia.h:1982 [inlined]
do_call at C:/workdir/src\interpreter.c:126
eval_value at C:/workdir/src\interpreter.c:223
eval_stmt_value at C:/workdir/src\interpreter.c:174 [inlined]
eval_body at C:/workdir/src\interpreter.c:635
jl_interpret_toplevel_thunk at C:/workdir/src\interpreter.c:775
jl_toplevel_eval_flex at C:/workdir/src\toplevel.c:934
jl_toplevel_eval_flex at C:/workdir/src\toplevel.c:877
ijl_toplevel_eval at C:/workdir/src\toplevel.c:943 [inlined]
ijl_toplevel_eval_in at C:/workdir/src\toplevel.c:985
eval at .\boot.jl:385 [inlined]
include_string at .\loading.jl:2076
_include at .\loading.jl:2136
include at .\client.jl:489
unknown function (ip: 0000023570eb052b)
jl_apply at C:/workdir/src\julia.h:1982 [inlined]
do_call at C:/workdir/src\interpreter.c:126
eval_value at C:/workdir/src\interpreter.c:223
eval_stmt_value at C:/workdir/src\interpreter.c:174 [inlined]
eval_body at C:/workdir/src\interpreter.c:635
jl_interpret_toplevel_thunk at C:/workdir/src\interpreter.c:775
jl_toplevel_eval_flex at C:/workdir/src\toplevel.c:934
jl_toplevel_eval_flex at C:/workdir/src\toplevel.c:877
ijl_toplevel_eval at C:/workdir/src\toplevel.c:943 [inlined]
ijl_toplevel_eval_in at C:/workdir/src\toplevel.c:985
eval at .\boot.jl:385 [inlined]
eval_user_input at C:\workdir\usr\share\julia\stdlib\v1.10\REPL\src\REPL.jl:150
repl_backend_loop at C:\workdir\usr\share\julia\stdlib\v1.10\REPL\src\REPL.jl:246
#start_repl_backend#46 at C:\workdir\usr\share\julia\stdlib\v1.10\REPL\src\REPL.jl:231
#run_repl#59 at C:\workdir\usr\share\julia\stdlib\v1.10\REPL\src\REPL.jl:389
jfptr_run_repl_95791.1 at C:\Users\anon\AppData\Local\Programs\Julia-1.10.4\lib\julia\sys.dll (unknown line)
#1013 at .\client.jl:432
jfptr_YY.1013_86566.1 at C:\Users\anon\AppData\Local\Programs\Julia-1.10.4\lib\julia\sys.dll (unknown line)
jl_apply at C:/workdir/src\julia.h:1982 [inlined]
jl_f__call_latest at C:/workdir/src\builtins.c:812
#invokelatest#2 at .\essentials.jl:892 [inlined]
invokelatest at .\essentials.jl:889 [inlined]
run_main_repl at .\client.jl:416
exec_options at .\client.jl:333
_start at .\client.jl:552
jfptr__start_86591.1 at C:\Users\anon\AppData\Local\Programs\Julia-1.10.4\lib\julia\sys.dll (unknown line)
jl_apply at C:/workdir/src\julia.h:1982 [inlined]
true_main at C:/workdir/src\jlapi.c:582
jl_repl_entrypoint at C:/workdir/src\jlapi.c:731
mainCRTStartup at C:/workdir/cli\loader_exe.c:58
BaseThreadInitThunk at C:\Windows\System32\KERNEL32.DLL (unknown line)
RtlUserThreadStart at C:\Windows\SYSTEM32\ntdll.dll (unknown line)
Allocations: 2908 (Pool: 2900; Big: 8); GC: 0

Output from versioninfo:

Julia Version 1.10.4
Commit 48d4fd4843 (2024-06-04 10:41 UTC)
Build Info:
  Official https://julialang.org/ release
Platform Info:
  OS: Windows (x86_64-w64-mingw32)
  CPU: 16 × 11th Gen Intel(R) Core(TM) i9-11900K @ 3.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-15.0.7 (ORCJIT, rocketlake)
Threads: 1 default, 0 interactive, 1 GC (on 16 virtual cores)
@nsajko nsajko added bug Indicates an unexpected problem or unintended behavior regression 1.10 Regression in the 1.10 release regression 1.11 Regression in the 1.11 release regression 1.12 Regression in the 1.12 release labels Jul 22, 2024
@vtjnash
Copy link
Member

vtjnash commented Jul 22, 2024

Looks like this is assumed to be un-constructible

│   %6 = Core.apply_type(%1, %2, %3, %4, %5)::Type{StructB{_A, _B, S, SMT}} where {_A, _B, S<:StructA, SMT<:(Array{Bool})}
│        %new(%6)::Union{}

due to this incorrect type intersection result

julia> typeintersect(StructB, StructB{_A, _B, S, SMT} where {_A, _B, S<:StructA, SMT<:(Array{Bool})})
Union{}

This appears to occur due to an incorrect assignment of T = Bool terminating the algorithm, which is not instead correctly propagating the constraint from AbstractA against the Union to instead derive the correct assignment of T = _A

@vtjnash vtjnash added the types and dispatch Types, subtyping and method dispatch label Jul 22, 2024
@JeffBezanson
Copy link
Member

JeffBezanson commented Jul 24, 2024

@AaronGhost Thanks for the useful report. A good workaround in a case like this is to remove or simplify the constraints on struct type parameters.

bisect points to 51e3bc3, but I guess that only exposed this intersection problem. I will try to separately bisect the intersection bug.

@JeffBezanson
Copy link
Member

Bisect points to 748149e @N5N3

It looks like this commit was a precision improvement and not a correctness fix, so it should be ok to revert it?

@N5N3
Copy link
Member

N5N3 commented Jul 26, 2024

Ah, yes. That commit brings about more correctness issues. Reverting seems the best choice here.

@N5N3 N5N3 self-assigned this Jul 26, 2024
N5N3 added a commit to N5N3/julia that referenced this issue Jul 29, 2024
revert 748149e
as that commit makes no sense especially when typevar occurs both inside and outside the inner intersection.
close JuliaLang#55206
vtjnash pushed a commit that referenced this issue Jul 30, 2024
This PR reverts the optimization from
748149e (part of #48167), while
keeping the fix for merging occurs_inv/occurs_cov, as that optimzation
makes no sense especially when typevar occurs both inside and outside
the inner intersection.

Close #55206
KristofferC pushed a commit that referenced this issue Aug 2, 2024
This PR reverts the optimization from
748149e (part of #48167), while
keeping the fix for merging occurs_inv/occurs_cov, as that optimzation
makes no sense especially when typevar occurs both inside and outside
the inner intersection.

Close #55206

(cherry picked from commit fb6b790)
lazarusA pushed a commit to lazarusA/julia that referenced this issue Aug 17, 2024
…Lang#55299)

This PR reverts the optimization from
748149e (part of JuliaLang#48167), while
keeping the fix for merging occurs_inv/occurs_cov, as that optimzation
makes no sense especially when typevar occurs both inside and outside
the inner intersection.

Close JuliaLang#55206
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior regression 1.10 Regression in the 1.10 release regression 1.11 Regression in the 1.11 release regression 1.12 Regression in the 1.12 release types and dispatch Types, subtyping and method dispatch
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants