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

Internal error when interpolating function calls w/ type inference in debug strings #47435

Closed
kleinschmidt opened this issue Nov 2, 2022 · 4 comments · Fixed by #47438
Closed
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior regression Regression in behavior compared to a previous version

Comments

@kleinschmidt
Copy link
Contributor

I came across this on 1.8.2, demonstrated by the following MWE:

               _
   _       _ _(_)_     |  Documentation: https://docs.julialang.org
  (_)     | (_) (_)    |
   _ _   _| |_  __ _   |  Type "?" for help, "]?" for Pkg help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 1.8.2 (2022-09-29)
 _/ |\__'_|_|_|\__'_|  |  Official https://julialang.org/ release
|__/                   |

julia> is_closed_ex(e::InvalidStateException) = true
is_closed_ex (generic function with 1 method)

julia> is_closed_ex(e) = false
is_closed_ex (generic function with 2 methods)

julia> function f()
           try
           catch e
               @debug "caught $e.  Checking whether `is_closed_ex(e)`: $(is_closed_ex(e))"
           end
       end
f (generic function with 1 method)

julia> f()
Internal error: encountered unexpected error in runtime:
BoundsError(a=Array{Any, (2,)}[
  Core.Const(val=Base.string),
  Core.PartialStruct(typ=Tuple{String, Any, String, Bool}, fields=Array{Any, (4,)}[
  Core.Const(val="caught "),
  Any,
  Core.Const(val=".  Checking whether `is_closed_ex(e)`: "),
  Bool])], i=(5,))
ijl_bounds_error_ints at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
getindex at ./array.jl:924 [inlined]
matching_cache_argtypes at ./compiler/inferenceresult.jl:75
InferenceResult at ./compiler/types.jl:205 [inlined]
abstract_call_method_with_const_args at ./compiler/abstractinterpretation.jl:860
abstract_call_method_with_const_args at ./compiler/abstractinterpretation.jl:835
abstract_call_gf_by_type at ./compiler/abstractinterpretation.jl:148
abstract_call_known at ./compiler/abstractinterpretation.jl:1716
abstract_call at ./compiler/abstractinterpretation.jl:1786
abstract_call at ./compiler/abstractinterpretation.jl:1753
abstract_eval_statement at ./compiler/abstractinterpretation.jl:1910
typeinf_local at ./compiler/abstractinterpretation.jl:2360
typeinf_nocycle at ./compiler/abstractinterpretation.jl:2482
_typeinf at ./compiler/typeinfer.jl:230
typeinf at ./compiler/typeinfer.jl:213
typeinf_ext at ./compiler/typeinfer.jl:967
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1000
typeinf_ext_toplevel at ./compiler/typeinfer.jl:996
jfptr_typeinf_ext_toplevel_13385 at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_type_infer at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_generate_fptr_impl at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-codegen.1.8.dylib (unknown line)
jl_compile_method_internal at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
ijl_apply_generic at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
do_call at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
eval_body at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_interpret_toplevel_thunk at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
top-level scope at REPL[4]:1
jl_toplevel_eval_flex at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_toplevel_eval_flex at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_toplevel_eval_flex at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
ijl_toplevel_eval_in at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
eval at ./boot.jl:368 [inlined]
eval_user_input at /Users/administrator/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-aarch64-1.0/build/default-macmini-aarch64-1-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:151
repl_backend_loop at /Users/administrator/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-aarch64-1.0/build/default-macmini-aarch64-1-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:247
start_repl_backend at /Users/administrator/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-aarch64-1.0/build/default-macmini-aarch64-1-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:232
#run_repl#47 at /Users/administrator/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-aarch64-1.0/build/default-macmini-aarch64-1-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:369
run_repl at /Users/administrator/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-macmini-aarch64-1.0/build/default-macmini-aarch64-1-0/julialang/julia-release-1-dot-8/usr/share/julia/stdlib/v1.8/REPL/src/REPL.jl:355
jfptr_run_repl_65176 at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
#967 at ./client.jl:419
jfptr_YY.967_28708 at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_f__call_latest at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
#invokelatest#2 at ./essentials.jl:729 [inlined]
invokelatest at ./essentials.jl:726 [inlined]
run_main_repl at ./client.jl:404
exec_options at ./client.jl:318
_start at ./client.jl:522
jfptr__start_30903 at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/sys.dylib (unknown line)
ijl_apply_generic at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
true_main at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)
jl_repl_entrypoint at /Users/dkleinschmidt/.julia/juliaup/julia-1.8.2+0.aarch64/lib/julia/libjulia-internal.1.8.dylib (unknown line)

apologies if this has been reported elsewhere but my issue search fu failed to turn up anything that seemed related!

@kleinschmidt
Copy link
Contributor Author

The important thing is that this method needs to be defined

julia> is_closed_ex(e::InvalidStateException) = true

without that, no error.

@vtjnash
Copy link
Member

vtjnash commented Nov 2, 2022

still fails on master (b9da8a9):

julia> f()
Internal error: encountered unexpected error in runtime:
BoundsError(a=Array{Any, (2,)}[
  Core.Const(val=Base.string),
  Core.PartialStruct(typ=Tuple{String, Any, String, Bool}, fields=Array{Any, (4,)}[
  Core.Const(val="caught "),
  Any,
  Core.Const(val=".  Checking whether `is_closed_ex(e)`: "),
  Bool])], i=(5,))
ijl_bounds_error_ints at /data/vtjnash/julia1/src/rtutils.c:194
getindex at ./essentials.jl:13
jfptr_getindex_17288 at /data/vtjnash/julia1/usr/lib/julia/sys.so (unknown line)
_jl_invoke at /data/vtjnash/julia1/src/gf.c:2431 [inlined]
ijl_apply_generic at /data/vtjnash/julia1/src/gf.c:2632
va_process_argtypes at ./compiler/inferenceresult.jl:40
matching_cache_argtypes at ./compiler/inferenceresult.jl:90
_InferenceResult at ./compiler/types.jl:54 [inlined]
InferenceResult at ./compiler/inferencestate.jl:234 [inlined]

@ararslan
Copy link
Member

ararslan commented Nov 2, 2022

Some further notes from playing around with this briefly in case it's helpful to anyone:

  • The error occurs with any interpolation; it's not limited to @debug other logging macros
  • Both the exception and the function call must be interpolated for this to be hit. Either on their own works fine.
  • The interpolation can't be the first thing in the string. For example, " $e will trigger the error but "$e will not.

@ararslan ararslan added bug Indicates an unexpected problem or unintended behavior regression Regression in behavior compared to a previous version labels Nov 2, 2022
@vtjnash
Copy link
Member

vtjnash commented Nov 3, 2022

It appears to be a misordering of the handling of converting trailing arguments into a single Vararg and the discarding of unusable Conditional information on some of those arguments. @aviatesk might be familiar with that code already to provide a fix?

@aviatesk aviatesk self-assigned this Nov 3, 2022
aviatesk added a commit that referenced this issue Nov 3, 2022
If `Conditional` is imposed on argument that is squashed to vararg-tuple
then we don't need to `widenconditional` on `isva_given_argtypes`
(because `Conditional`-information is already widened during the
conversion to that vararg-tuple type -- since `PartialStruct` now never
wraps slot wrappers with the explicit check within its constructor).

Fixes #47435.
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 Regression in behavior compared to a previous version
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants