JuliaInterop / libcxxwrap-julia

C++ library for backing CxxWrap.jl
Other
85 stars 43 forks source link

"invalid subtyping" for C++ type `std::array<double, 7>` #90

Closed eschnett closed 2 years ago

eschnett commented 3 years ago

When I precompile the openPMD package with Julia 1.7, I encounter this error:

julia> using openPMD
[ Info: Precompiling openPMD [e4c73209-6c8c-4213-807b-38d671e094ab]
C++ exception while wrapping module openPMD: invalid subtyping in definition of array_double_7 with supertype Any

signal (11): Segmentation fault: 11

This works fine with Julia 1.6.

The type array_double_7 is defined by

template <typename T, std::size_t N>
void add_array_type(jlcxx::Module &mod, const std::string &name) {
  mod.add_type<std::array<T, N>>(name)
      .template constructor<>()
      .template constructor<const std::array<T, N> &>()
      .method("size1", &std::array<T, N>::size)
      .method("getindex1",
              [](const std::array<T, N> &a, std::size_t n) { return a[n]; });
  jlcxx::stl::apply_stl<std::array<T, N>>(mod);
}

with the call

  add_array_type<double, 7>(mod, "array_double_7");

See https://github.com/eschnett/openPMD-api/blob/1f6559bd7891fa1bbd0313c84137289dc8cc6757/src/binding/julia/openPMD.cpp#L10 and https://github.com/eschnett/openPMD-api/blob/1f6559bd7891fa1bbd0313c84137289dc8cc6757/src/binding/julia/defs.hpp#L157 .

This is with Julia 1.7

julia> versioninfo()
Julia Version 1.7.0-beta3.0
Commit e76c9dad42 (2021-07-07 08:12 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin20.5.0)
  CPU: Intel(R) Core(TM) i7-8850H CPU @ 2.60GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-12.0.0 (ORCJIT, skylake)

I don't understand what is going on here. I'd be happy to dig into the code of libcxxwrap, but I don't know where to start, or what changed (in Julia, presumably) for version 1.7.

eschnett commented 3 years ago

This issue prevents me from using Julia 1.7 with libcxxwrap. Am I the only one experiencing this? Or is there maybe a simple work-around to avoid this?

fingolfin commented 2 years ago

I can reproduce this. I was going to suggest that the JLL needs to be rebuilt, but I just see that you did this in https://github.com/JuliaPackaging/Yggdrasil/pull/4120. But that update never got into the registry: https://github.com/JuliaRegistries/General/pull/51404. This is because the JLL didn't change its version...

eschnett commented 2 years ago

As discussed in https://github.com/JuliaPackaging/Yggdrasil/pull/4120, I can make this problem go away by using a different julia_version for libcxxwrap-julia, following the changes recently make to build_tarballs.jl for libcxxwrap-julia.

fingolfin commented 2 years ago

... where "recently" means "in July, long before 1.7 was released" ;-).

Anyway, excellent news!