Skip to content

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

@alex-lew

Description

@alex-lew

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    regressionRegression in behavior compared to a previous version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions