Skip to content

Conversation

@mofeing
Copy link
Collaborator

@mofeing mofeing commented Dec 30, 2025

closes #319

changes

  • Context now records ownership and calls mlirContextDestroy on finalization if owner == true
  • context methods on AffineExpr, AffineMap, Attribute, Dialect, Identifier, IntegerSet, Location, Module, Operation and Type now return a non-owned Context
  • removed activate!, deactivate! in favor of with_context, to avoid leakage
  • replaced the task-local storage of the Context stack with a ScopedValue
  • fix Module leak by adding a fake dependency
  • fix dangling Operation leak

@mofeing mofeing added the MLIR.jl backport Should be backported to upstream MLIR.jl label Dec 30, 2025
@mofeing
Copy link
Collaborator Author

mofeing commented Dec 31, 2025

currently erroring on Operation finalization but the erroring test changes... most probably because the GC schedules finalizers non-deterministically and it errors when it runs first the finalizer of the parent Context before the Operation.

[18553] signal 11 (2): Segmentation fault: 11
in expression starting at /Users/mofeing/Developer/Reactant.jl/test/basic.jl:167
_ZN4mlir9OperationD2Ev at /Users/mofeing/.julia/artifacts/8958638f89ffec8644d228ff1cfb35b993cb2d39/lib/libReactantExtra.dylib (unknown line)
_ZN4mlir9Operation5eraseEv at /Users/mofeing/.julia/artifacts/8958638f89ffec8644d228ff1cfb35b993cb2d39/lib/libReactantExtra.dylib (unknown line)
mlirOperationDestroy at /Users/mofeing/Developer/Reactant.jl/src/mlir/libMLIR_h.jl:1292 [inlined]
#64 at /Users/mofeing/Developer/Reactant.jl/src/mlir/IR/Operation.jl:9
jfptr_YY.64_10447 at /Users/mofeing/.julia/compiled/v1.12/Reactant/p9PzF_fQeTA.dylib (unknown line)
run_finalizer at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/gc-common.c:180
jl_gc_run_finalizers_in_list at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/gc-common.c:270
run_finalizers at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/gc-common.c:316
finish_nocycle at ./../usr/share/julia/Compiler/src/typeinfer.jl:210
jfptr_finish_nocycle_82210.1 at /Users/mofeing/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/lib/julia/sys.dylib (unknown line)
typeinf at ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:4508
typeinf_ext at ./../usr/share/julia/Compiler/src/typeinfer.jl:1252
typeinf_ext_toplevel at ./../usr/share/julia/Compiler/src/typeinfer.jl:1435 [inlined]
typeinf_ext_toplevel at ./../usr/share/julia/Compiler/src/typeinfer.jl:1444
jfptr_typeinf_ext_toplevel_82882.1 at /Users/mofeing/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/./julia.h:2391 [inlined]
jl_type_infer at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/gf.c:462
jl_compile_method_internal at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/gf.c:3512
_jl_invoke at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/gf.c:4002 [inlined]
ijl_apply_generic at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/gf.c:4210
#61 at /Users/mofeing/Developer/Reactant.jl/src/Compiler.jl:3633
with at ./scopedvalues.jl:269
unknown function (ip: 0x165c0026b) at (unknown file)
with_context at /Users/mofeing/Developer/Reactant.jl/src/mlir/IR/Context.jl:76
#compile_xla#59 at /Users/mofeing/Developer/Reactant.jl/src/Compiler.jl:3628
compile_xla at /Users/mofeing/Developer/Reactant.jl/src/Compiler.jl:3606 [inlined]
#compile#63 at /Users/mofeing/Developer/Reactant.jl/src/Compiler.jl:3707
compile at /Users/mofeing/Developer/Reactant.jl/src/Compiler.jl:3704
unknown function (ip: 0x165f4415b) at (unknown file)
jl_apply at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/./julia.h:2391 [inlined]
do_call at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:123
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:581
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:558
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:558
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:558
jl_interpret_toplevel_thunk at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:898
jl_toplevel_eval_flex at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1035
jl_toplevel_eval_flex at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:975
ijl_toplevel_eval at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1047 [inlined]
ijl_toplevel_eval_in at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1092
eval at ./boot.jl:489
include_string at ./loading.jl:2870
_include at ./loading.jl:2930
include at ./Base.jl:307
IncludeInto at ./Base.jl:308
jfptr_IncludeInto_64112.1 at /Users/mofeing/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/./julia.h:2391 [inlined]
do_call at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:123
eval_stmt_value at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:194
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:689
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:558
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:558
jl_interpret_toplevel_thunk at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:898
jl_toplevel_eval_flex at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1035
jl_eval_module_expr at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:197 [inlined]
jl_toplevel_eval_flex at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:814
ijl_toplevel_eval at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1047 [inlined]
ijl_toplevel_eval_in at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1092
eval at ./boot.jl:489
jfptr_eval_8419.1 at /Users/mofeing/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/./julia.h:2391 [inlined]
do_call at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:123
eval_stmt_value at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:194
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:689
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:558
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:558
jl_interpret_toplevel_thunk at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:898
jl_toplevel_eval_flex at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1035
jl_toplevel_eval_flex at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:975
ijl_toplevel_eval at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1047 [inlined]
ijl_toplevel_eval_in at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1092
eval at ./boot.jl:489
include_string at ./loading.jl:2870
_include at ./loading.jl:2930
include at ./Base.jl:307
IncludeInto at ./Base.jl:308
jfptr_IncludeInto_64112.1 at /Users/mofeing/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/./julia.h:2391 [inlined]
do_call at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:123
eval_stmt_value at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:194
eval_body at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:689
jl_interpret_toplevel_thunk at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/interpreter.c:898
jl_toplevel_eval_flex at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1035
jl_toplevel_eval_flex at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:975
ijl_toplevel_eval at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1047 [inlined]
ijl_toplevel_eval_in at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/toplevel.c:1092
jlplt_ijl_toplevel_eval_in_8421.1 at /Users/mofeing/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/lib/julia/sys.dylib (unknown line)
eval at ./boot.jl:489
exec_options at ./client.jl:283
_start at ./client.jl:550
jfptr__start_38197.1 at /Users/mofeing/.julia/juliaup/julia-1.12.3+0.aarch64.apple.darwin14/lib/julia/sys.dylib (unknown line)
jl_apply at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/./julia.h:2391 [inlined]
true_main at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/jlapi.c:971
jl_repl_entrypoint at /Users/julia/.julia/scratchspaces/a66863c6-20e8-4ff4-8a62-49f30b1f605e/agent-cache/default-honeycrisp-R17H3W25T9.0/build/default-honeycrisp-R17H3W25T9-0/julialang/julia-release-1-dot-12/src/jlapi.c:1139
Allocations: 240203939 (Pool: 240200179; Big: 3760); GC: 93

@mofeing mofeing marked this pull request as draft December 31, 2025 00:37
@mofeing
Copy link
Collaborator Author

mofeing commented Jan 5, 2026

a stacktrace with debug symbols shows new info: it seems like the error triggers on the finalizer of Module (mlirModuleDestroy gets called)

[1836500] signal 11 (2): Segmentation fault
in expression starting at /mnt2/mofeing/Reactant.jl/test/basic.jl:1125
_ZN4llvm33LazyMachineBlockFrequencyInfoPass2IDE at /mnt2/mofeing/.julia/juliaup/julia-1.12.3+0.x64.linux.gnu/bin/../lib/julia/libLLVM.so.18.1jl (unknown line)
destroy at /proc/self/cwd/external/llvm-project/mlir/lib/IR/Operation.cpp:213 [inlined]
deleteNode at /proc/self/cwd/external/llvm-project/mlir/lib/IR/Operation.cpp:487
erase at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:205 [inlined]
pop_back at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:257 [inlined]
clear at /proc/self/cwd/external/llvm-project/mlir/include/mlir/IR/Block.h:45
~Block at /proc/self/cwd/external/llvm-project/mlir/lib/IR/Block.cpp:22
deleteNode at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:42 [inlined]
erase at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:205 [inlined]
erase at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:242 [inlined]
clear at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:246 [inlined]
~iplist_impl at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:147 [inlined]
~Region at /proc/self/cwd/external/llvm-project/mlir/lib/IR/Region.cpp:20
~Operation at /proc/self/cwd/external/llvm-project/mlir/lib/IR/Operation.cpp:202
destroy at /proc/self/cwd/external/llvm-project/mlir/lib/IR/Operation.cpp:213 [inlined]
deleteNode at /proc/self/cwd/external/llvm-project/mlir/lib/IR/Operation.cpp:487
erase at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:205 [inlined]
pop_back at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:257 [inlined]
clear at /proc/self/cwd/external/llvm-project/mlir/include/mlir/IR/Block.h:45
~Block at /proc/self/cwd/external/llvm-project/mlir/lib/IR/Block.cpp:22
deleteNode at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:42 [inlined]
erase at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:205 [inlined]
erase at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:242 [inlined]
clear at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:246 [inlined]
~iplist_impl at /proc/self/cwd/external/llvm-project/llvm/include/llvm/ADT/ilist.h:147 [inlined]
~Region at /proc/self/cwd/external/llvm-project/mlir/lib/IR/Region.cpp:20
~Operation at /proc/self/cwd/external/llvm-project/mlir/lib/IR/Operation.cpp:202
erase at /proc/self/cwd/external/llvm-project/mlir/lib/IR/Operation.cpp:0
~OwningOpRef at /proc/self/cwd/external/llvm-project/mlir/include/mlir/IR/OwningOpRef.h:39 [inlined]
mlirModuleDestroy at /proc/self/cwd/external/llvm-project/mlir/lib/CAPI/IR/IR.cpp:457
mlirModuleDestroy at /mnt2/mofeing/Reactant.jl/src/mlir/libMLIR_h.jl:978
unknown function (ip: 0x774ac77de9c2) at (unknown file)
run_finalizer at /cache/build/tester-amdci4-9/julialang/julia-release-1-dot-12/src/gc-common.c:180
jl_gc_run_finalizers_in_list at /cache/build/tester-amdci4-9/julialang/julia-release-1-dot-12/src/gc-common.c:270
run_finalizers at /cache/build/tester-amdci4-9/julialang/julia-release-1-dot-12/src/gc-common.c:316
jl_promote_ci_to_current at /cache/build/tester-amdci4-9/julialang/julia-release-1-dot-12/src/gf.c:1804
finish_nocycle at ./../usr/share/julia/Compiler/src/typeinfer.jl:210
jfptr_finish_nocycle_83308.1 at /mnt2/mofeing/.julia/juliaup/julia-1.12.3+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
typeinf at ./../usr/share/julia/Compiler/src/abstractinterpretation.jl:4508
typeinf_ext at ./../usr/share/julia/Compiler/src/typeinfer.jl:1252
typeinf_ext_toplevel at ./../usr/share/julia/Compiler/src/typeinfer.jl:1435 [inlined]
typeinf_ext_toplevel at ./../usr/share/julia/Compiler/src/typeinfer.jl:1444
jfptr_typeinf_ext_toplevel_80469.1 at /mnt2/mofeing/.julia/juliaup/julia-1.12.3+0.x64.linux.gnu/lib/julia/sys.so (unknown line)
jl_apply at /cache/build/tester-amdci4-9/julialang/julia-release-1-dot-12/src/julia.h:2391 [inlined]
jl_type_infer at /cache/build/tester-amdci4-9/julialang/julia-release-1-dot-12/src/gf.c:462
jl_compile_method_internal at /cache/build/tester-amdci4-9/julialang/julia-release-1-dot-12/src/gf.c:3512
_jl_invoke at /cache/build/tester-amdci4-9/julialang/julia-release-1-dot-12/src/gf.c:4002 [inlined]
ijl_apply_generic at /cache/build/tester-amdci4-9/julialang/julia-release-1-dot-12/src/gf.c:4210
#61 at /mnt2/mofeing/Reactant.jl/src/Compiler.jl:3633
with at ./scopedvalues.jl:269
unknown function (ip: 0x774aa5b94a6f) at (unknown file)
with_context at /mnt2/mofeing/Reactant.jl/src/mlir/IR/Context.jl:76
#compile_xla#59 at /mnt2/mofeing/Reactant.jl/src/Compiler.jl:3628
compile_xla at /mnt2/mofeing/Reactant.jl/src/Compiler.jl:3606 [inlined]
#compile#63 at /mnt2/mofeing/Reactant.jl/src/Compiler.jl:3707
compile at /mnt2/mofeing/Reactant.jl/src/Compiler.jl:3704
unknown function (ip: 0x774aa5b8f4f3) at (unknown file)

UPDATE: this has been fixed by adding a fake dependency between Module and Context

end

# use types from API to avoid interfering with GC
const __context_gc_module = Dict{API.MlirContext, Set{API.MlirModule}}()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[JuliaFormatter] reported by reviewdog 🐶

Suggested change
const __context_gc_module = Dict{API.MlirContext, Set{API.MlirModule}}()
const __context_gc_module = Dict{API.MlirContext,Set{API.MlirModule}}()

@mofeing
Copy link
Collaborator Author

mofeing commented Jan 8, 2026

There are problems with this implementation summarized in #2088

Closed in favor of #2093

@mofeing mofeing closed this Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

MLIR.jl backport Should be backported to upstream MLIR.jl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Allocations and time on compile are ever-increasing

2 participants