JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.54k stars 5.47k forks source link

Bounds error in compiler #48631

Closed maleadt closed 1 year ago

maleadt commented 1 year ago

As seen on PkgEval testing CFITSIO.jl: https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_date/2023-02/08/CFITSIO.primary.log

Internal error: encountered unexpected error in runtime:
BoundsError(a=svec(), i=0)
ijl_bounds_error_int at /cache/build/default-amdci4-1/julialang/julia-master/src/rtutils.c:180
jl_f__svec_ref at /cache/build/default-amdci4-1/julialang/julia-master/src/builtins.c:1633
getindex at ./essentials.jl:704 [inlined]
type_more_complex at ./compiler/typelimits.jl:264
type_more_complex at ./compiler/typelimits.jl:288
type_more_complex at ./compiler/typelimits.jl:288
type_more_complex at ./compiler/typelimits.jl:288
limit_type_size at ./compiler/typelimits.jl:20

Bisected to #48421 (cc @Keno @aviatesk)

maleadt commented 1 year ago

MWE:

function fits_create_img() where N
    naxesr = Ref(convert0)
    ccall(0, Cint, (Cvoid, Cint, Cint, Ptr{NTuple{N,Int64}}, Cint),
          fptr, bitpix_from_type0, N, naxesr, status)
end
mktemp() do _, io
    for fname in []
        for a in fits_create_img()
        end
    end
end
N5N3 commented 1 year ago

The unreachable reached error should also comes from the apply_type_tfunc change MWE

julia> a = Array{Int}[[1;]]
1-element Vector{Array{Int64}}:
 [1]

julia> f(a) = Array{typeof(a[1])}
f (generic function with 1 method)

julia> @code_warntype f(a)
MethodInstance for f(::Vector{Array{Int64}})
  from f(a) @ Main REPL[56]:1
Arguments
  #self#::Core.Const(f)
  a::Vector{Array{Int64}}
Body::Type{Array{Array{Int64, N}, N} where N}
1 ─ %1 = Main.Array::Core.Const(Array)
│   %2 = Base.getindex(a, 1)::Array{Int64}
│   %3 = Main.typeof(%2)::Type{Array{Int64, N}} where N
│   %4 = Core.apply_type(%1, %3)::Type{Array{Array{Int64, N}, N} where N}  # obviously wrong
└──      return %4
ufechner7 commented 1 year ago

I cannot reproduce this on current master:

ufechner@ufryzen:~/repos/julia$ ./julia
               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.10.0-DEV.1292 (2023-05-14)
 _/ |\__'_|_|_|\__'_|  |  Commit 4ed419555a (0 days old master)
|__/                   |

julia> function fits_create_img() where N
           naxesr = Ref(convert0)
           ccall(0, Cint, (Cvoid, Cint, Cint, Ptr{NTuple{N,Int64}}, Cint),
                 fptr, bitpix_from_type0, N, naxesr, status)
       end
WARNING: method definition for fits_create_img at REPL[1]:1 declares type variable N but does not use it.
fits_create_img (generic function with 1 method)

julia> mktemp() do _, io
           for fname in []
               for a in fits_create_img()
               end
           end
       end

Can this issue be closed?