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

BoundsError in type inference when abstract-evaluating OpaqueClosure #54236

Open
topolarity opened this issue Apr 24, 2024 · 1 comment
Open
Labels
bug Indicates an unexpected problem or unintended behavior inference Type inference

Comments

@topolarity
Copy link
Member

julia> struct Printable
            self::Any
            show::Core.OpaqueClosure{Tuple{Base.TTY, Any}, Nothing}

            Printable(self::T) where T = new(self,
                #= show =# Base.Experimental.@opaque (io::Base.TTY, @nospecialize(self::Any))->show(io, self::T)::Nothing
            )
       end

julia> Printable(1)
Internal error: during type inference of
(::Type{Main.Printable})(Int64)
Encountered unexpected error in runtime:
BoundsError(a=Array{Core.Compiler.VarState, 1}(dims=(0,), mem=Memory{Core.Compiler.VarState}(0, 0x7f2d2f80df70)[]), i=(1,))
throw_boundserror at ./essentials.jl:14
getindex at ./essentials.jl:891 [inlined]
stmt_effect_flags at ./compiler/optimize.jl:312
recompute_effects_flags at ./compiler/optimize.jl:381 [inlined]
add_inst_flag! at ./compiler/ssair/inlining.jl:1216 [inlined]
add_inst_flag! at ./compiler/ssair/inlining.jl:1213 [inlined]
process_simple! at ./compiler/ssair/inlining.jl:1243
assemble_inline_todo! at ./compiler/ssair/inlining.jl:1614
ssa_inlining_pass! at ./compiler/ssair/inlining.jl:80 [inlined]
run_passes_ipo_safe at ./compiler/optimize.jl:968
run_passes_ipo_safe at ./compiler/optimize.jl:983 [inlined]
optimize at ./compiler/optimize.jl:957
jfptr_optimize_40222.1 at /home/topolarity/dist/julia-cedar/vanilla/latest/lib/julia/sys.so (unknown line)
_jl_invoke at /build/julia/src/gf.c:2994 [inlined]
ijl_apply_generic at /build/julia/src/gf.c:3171
_typeinf at ./compiler/typeinfer.jl:253
typeinf at ./compiler/typeinfer.jl:215
jfptr_typeinf_37232.1 at /home/topolarity/dist/julia-cedar/vanilla/latest/lib/julia/sys.so (unknown line)
typeinf_edge at ./compiler/typeinfer.jl:863
abstract_call_method at ./compiler/abstractinterpretation.jl:655
abstract_call_opaque_closure at ./compiler/abstractinterpretation.jl:2217
abstract_eval_statement_expr at ./compiler/abstractinterpretation.jl:2575
abstract_eval_statement at ./compiler/abstractinterpretation.jl:2775
abstract_eval_basic_statement at ./compiler/abstractinterpretation.jl:3062
typeinf_local at ./compiler/abstractinterpretation.jl:3340
typeinf_nocycle at ./compiler/abstractinterpretation.jl:3422
_typeinf at ./compiler/typeinfer.jl:235
typeinf at ./compiler/typeinfer.jl:215
typeinf_ext at ./compiler/typeinfer.jl:1121
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1179 [inlined]
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1177
jfptr_typeinf_ext_toplevel_37476.1 at /home/topolarity/dist/julia-cedar/vanilla/latest/lib/julia/sys.so (unknown line)
_jl_invoke at /build/julia/src/gf.c:2994 [inlined]
ijl_apply_generic at /build/julia/src/gf.c:3171
jl_apply at /build/julia/src/julia.h:2185 [inlined]
jl_type_infer at /build/julia/src/gf.c:393
jl_compile_method_internal at /build/julia/src/gf.c:2559
_jl_invoke at /build/julia/src/gf.c:2986 [inlined]
ijl_apply_generic at /build/julia/src/gf.c:3171
jl_apply at /build/julia/src/julia.h:2185 [inlined]
do_call at /build/julia/src/interpreter.c:126
eval_value at /build/julia/src/interpreter.c:223
eval_stmt_value at /build/julia/src/interpreter.c:174 [inlined]
eval_body at /build/julia/src/interpreter.c:659
jl_interpret_toplevel_thunk at /build/julia/src/interpreter.c:829
top-level scope at REPL[2]:1
jl_toplevel_eval_flex at /build/julia/src/toplevel.c:953
__repl_entry_eval_expanded_with_loc at /home/topolarity/dist/julia-cedar/vanilla/latest/share/julia/stdlib/v1.12/REPL/src/REPL.jl:220
toplevel_eval_with_hooks at /home/topolarity/dist/julia-cedar/vanilla/latest/share/julia/stdlib/v1.12/REPL/src/REPL.jl:227
toplevel_eval_with_hooks at /home/topolarity/dist/julia-cedar/vanilla/latest/share/julia/stdlib/v1.12/REPL/src/REPL.jl:231
toplevel_eval_with_hooks at /home/topolarity/dist/julia-cedar/vanilla/latest/share/julia/stdlib/v1.12/REPL/src/REPL.jl:224 [inlined]
eval_user_input at /home/topolarity/dist/julia-cedar/vanilla/latest/share/julia/stdlib/v1.12/REPL/src/REPL.jl:249
repl_backend_loop at /home/topolarity/dist/julia-cedar/vanilla/latest/share/julia/stdlib/v1.12/REPL/src/REPL.jl:358
#start_repl_backend#59 at /home/topolarity/dist/julia-cedar/vanilla/latest/share/julia/stdlib/v1.12/REPL/src/REPL.jl:343
start_repl_backend at /home/topolarity/dist/julia-cedar/vanilla/latest/share/julia/stdlib/v1.12/REPL/src/REPL.jl:340
_jl_invoke at /build/julia/src/gf.c:2994 [inlined]
ijl_apply_generic at /build/julia/src/gf.c:3171
#run_repl#72 at /home/topolarity/dist/julia-cedar/vanilla/latest/share/julia/stdlib/v1.12/REPL/src/REPL.jl:499
run_repl at /home/topolarity/dist/julia-cedar/vanilla/latest/share/julia/stdlib/v1.12/REPL/src/REPL.jl:485
unknown function (ip: 0x7f2d4cf05cd6)
_jl_invoke at /build/julia/src/gf.c:2994 [inlined]
ijl_apply_generic at /build/julia/src/gf.c:3171
#1159 at ./client.jl:448
jfptr_YY.1159_16939 at /home/topolarity/.julia/compiled/v1.12/REPL/u0gqU_rt7eL.so (unknown line)
_jl_invoke at /build/julia/src/gf.c:2994 [inlined]
ijl_apply_generic at /build/julia/src/gf.c:3171
jl_apply at /build/julia/src/julia.h:2185 [inlined]
jl_f__call_latest at /build/julia/src/builtins.c:875
#invokelatest#2 at ./essentials.jl:1030 [inlined]
invokelatest at ./essentials.jl:1027 [inlined]
run_main_repl at ./client.jl:432
repl_main at ./client.jl:569 [inlined]
_start at ./client.jl:543
jfptr__start_69785.1 at /home/topolarity/dist/julia-cedar/vanilla/latest/lib/julia/sys.so (unknown line)
_jl_invoke at /build/julia/src/gf.c:2994 [inlined]
ijl_apply_generic at /build/julia/src/gf.c:3171
jl_apply at /build/julia/src/julia.h:2185 [inlined]
true_main at /build/julia/src/jlapi.c:900
jl_repl_entrypoint at /build/julia/src/jlapi.c:1059
main at /build/julia/cli/loader_exe.c:58
unknown function (ip: 0x7f2d5861cd8f)
__libc_start_main at /lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x4010b8)

Seems to occur on 1.10, 1.11, and latest nightly

@topolarity topolarity added bug Indicates an unexpected problem or unintended behavior inference Type inference labels Apr 24, 2024
@topolarity
Copy link
Member Author

Seems related to the usage of where T

This variant works fine:

julia> struct Printable
           self::Any
           show::Core.OpaqueClosure{Tuple{Base.TTY, Any}, Nothing}

           function Printable(self)
               T = typeof(self)
               return new(self,
                   #= show =# Base.Experimental.@opaque (io::Base.TTY, @nospecialize(self::Any))->show(io, self::T)::Nothing
                )
            end
       end

julia> Printable(1)
Printable(1, (::Base.TTY, ::Any)::Nothing->◌)

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 inference Type inference
Projects
None yet
Development

No branches or pull requests

1 participant