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

Packing an empty NamedTuple into a struct with other elements causes UndefRefError: access to undefined reference (Julia 1.7) #43783

Closed
alex-lew opened this issue Jan 12, 2022 · 3 comments
Labels
regression Regression in behavior compared to a previous version
Milestone

Comments

@alex-lew
Copy link

alex-lew commented Jan 12, 2022

The following code fails with an UndefRefError on Julia 1.7:

struct BadStruct{R,S}
    named_tuple::NamedTuple{R,S}
    n::Int
end

BadStruct(NamedTuple{}(), 0)

It also exits the REPL.

I'm not sure what's going on here, but here are some observations:

  1. I can't reproduce the error with only the named tuple in the struct.
  2. With no type parameters (R, S), there's no crash.
  3. When the Named Tuple is nonempty, there's no crash.
  4. The construction of the struct succeeds, because let x = BadStruct(NamedTuple{}(), 0); x.n end works. But let x = BadStruct(NamedTuple{}(), 0); x.named_tuple end raises the UndefRefError, this time in Base.getproperty. So it seems the struct is being constructed, but the named_tuple field is not getting initialized properly? Note this example gives an error but does not kill the REPL.
  5. This is possibly related to Wrapping NamedTuple in struct is no longer bitstype in 1.7 #43411.

My versioninfo() is

Julia Version 1.7.1
Commit ac5cc99908 (2021-12-22 19:35 UTC)
Platform Info:
  OS: macOS (arm64-apple-darwin21.2.0)
  CPU: Apple M1 Pro
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, cyclone)

but @femtomc has reproduced the error, with

Julia Version 1.7.0
Commit 3bf9d17731 (2021-11-30 12:12 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Xeon(R) Platinum 8259CL CPU @ 2.50GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.1 (ORCJIT, skylake-avx512)
Environment:
  JULIA_VERSION = 1.6.1

This issue came up because Gen.jl's StaticChoiceMap datatype is similar to the BadStruct above, and we noticed crashes when upgrading to Julia 1.7. (https://github.com/probcomp/Gen.jl/blob/44f5f1408caf05ff95932bb58d9f57907c5084e3/src/choice_map.jl#L350).

The code works fine on my machine on Julia 1.6.3.

Thanks!

@alex-lew alex-lew changed the title Packing two NamedTuples into a struct causes UndefRefError: access to undefined reference (Julia 1.7) Packing one empty and one non-empty NamedTuple into a struct causes UndefRefError: access to undefined reference (Julia 1.7) Jan 12, 2022
@alex-lew alex-lew changed the title Packing one empty and one non-empty NamedTuple into a struct causes UndefRefError: access to undefined reference (Julia 1.7) Packing an empty NamedTuple into a struct with other elements causes UndefRefError: access to undefined reference (Julia 1.7) Jan 12, 2022
@femtomc
Copy link
Contributor

femtomc commented Jan 12, 2022

Here's an additional yikes:

julia> struct BadStruct{R,S}
           named_tuple::NamedTuple{R,S}
           n::Int
       end

julia> hasfield(BadStruct(NamedTuple(), 5), :named_tuple)
ERROR:
signal (11): Segmentation fault
in expression starting at none:0
sig_match_simple at /buildworker/worker/package_linux64/build/src/typemap.c:194 [inlined]
jl_typemap_entry_assoc_exact at /buildworker/worker/package_linux64/build/src/typemap.c:959
jl_typemap_assoc_exact at /buildworker/worker/package_linux64/build/src/julia_internal.h:1267 [inlined]
jl_lookup_generic_ at /buildworker/worker/package_linux64/build/src/gf.c:2369 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2425
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
do_apply at /buildworker/worker/package_linux64/build/src/builtins.c:713
showerror at ./errorshow.jl:222
#showerror#813 at ./errorshow.jl:88
showerror##kw at ./errorshow.jl:87
jfptr_showerrorYY.YY.kw_32910.clone_1 at /home/ubuntu/julia-1.7.0/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
show_exception_stack at ./errorshow.jl:866
display_error at ./client.jl:104
jfptr_display_error_34726.clone_1 at /home/ubuntu/julia-1.7.0/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
jl_f__call_latest at /buildworker/worker/package_linux64/build/src/builtins.c:757
#invokelatest#2 at ./essentials.jl:716 [inlined]
invokelatest at ./essentials.jl:714 [inlined]
print_response at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:286
#45 at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:275
jfptr_YY.45_48142.clone_1 at /home/ubuntu/julia-1.7.0/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
with_repl_linfo at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:508
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
print_response at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:273
do_respond at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:844
jfptr_do_respond_46689.clone_1 at /home/ubuntu/julia-1.7.0/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
jl_f__call_latest at /buildworker/worker/package_linux64/build/src/builtins.c:757
#invokelatest#2 at ./essentials.jl:716 [inlined]
invokelatest at ./essentials.jl:714 [inlined]
run_interface at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/LineEdit.jl:2493
jfptr_run_interface_47484.clone_1 at /home/ubuntu/julia-1.7.0/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
run_frontend at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.7/REPL/src/REPL.jl:1230
#49 at ./task.jl:423
jfptr_YY.49_48145.clone_1 at /home/ubuntu/julia-1.7.0/lib/julia/sys.so (unknown line)
_jl_invoke at /buildworker/worker/package_linux64/build/src/gf.c:2247 [inlined]
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2429
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1788 [inlined]
start_task at /buildworker/worker/package_linux64/build/src/task.c:877
Allocations: 2721 (Pool: 2713; Big: 8); GC: 0
[1]    4190442 segmentation fault (core dumped)  julia

@vtjnash vtjnash added this to the 1.8 milestone Jan 12, 2022
@vtjnash vtjnash added the regression Regression in behavior compared to a previous version label Jan 12, 2022
@femtomc
Copy link
Contributor

femtomc commented Jan 13, 2022

Is this #40947 from Tim's comment on #43411 (?)

@JeffBezanson
Copy link
Member

Also fixed by #44311, so yes I think this is a duplicate of #43411.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

4 participants