Closed
Description
I have encountered segmentation faults in Julia 1.9 in the following specific test case: a module MWE2
makes a call to a macro that's defined in another module, MWE1
, where the macro features a construct of the form map(zip(a, b)) do (a, b)
.
Interestingly, the same construct works as expected when wrapped as a function (defined in MWE1
) or when the exact same macro, but defined in MWE2
, is called. It also works fine in Julia 1.8; or if you disable precompilation in 1.9 using __precompile__(false)
.
Minimal Reproducible Example
module MWE1
macro map_test()
quote
map(zip(1:2, 1:2)) do (x1, x2)
x1*x2
end
end
end
function map_test()
map(zip(1:2, 1:2)) do (x1, x2)
x1*x2
end
end
end
module MWE2
using MWE1
x1 = MWE1.@map_test # seg fault
x2 = MWE1.map_test() # fine
macro map_test_internal()
quote
map(zip(1:2, 1:2)) do (x1, x2)
x1*x2
end
end
end
x3 = @map_test_internal # fine
end
Version
It fails in Julia 1.9, but works in Julia 1.8.
Julia Version 1.9.2
Commit e4ee485e909 (2023-07-05 09:39 UTC)
Platform Info:
OS: macOS (arm64-apple-darwin22.4.0)
CPU: 10 × Apple M1 Pro
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-14.0.6 (ORCJIT, apple-m1)
Threads: 1 on 8 virtual cores
Julia Version 1.8.5
Commit 17cfb8e65ea (2023-01-08 06:45 UTC)
Platform Info:
OS: macOS (arm64-apple-darwin21.5.0)
CPU: 10 × Apple M1 Pro
WORD_SIZE: 64
LIBM: libopenlibm
LLVM: libLLVM-13.0.1 (ORCJIT, apple-m1)
Threads: 1 on 8 virtual cores
Modules Setup
For local setup of the module structure, you may use the following convenience script:
import Pkg
Pkg.generate("MWE1")
write("MWE1/src/MWE1.jl",
"""
module MWE1
macro map_test()
quote
map(zip(1:2, 1:2)) do (x1, x2)
x1*x2
end
end
end
function map_test()
map(zip(1:2, 1:2)) do (x1, x2)
x1*x2
end
end
end""")
Pkg.generate("MWE2")
write("MWE2/src/MWE2.jl",
"""
module MWE2
using MWE1
x1 = MWE1.@map_test # seg fault
x2 = MWE1.map_test() # fine
macro map_test_internal()
quote
map(zip(1:2, 1:2)) do (x1, x2)
x1*x2
end
end
end
x3 = @map_test_internal # fine
end""")
Pkg.activate("MWE2")
Pkg.develop(path="MWE1")
using MWE2