Skip to content

Commit 248d382

Browse files
authored
Merge pull request #469 from maleadt/tb/tsmod_ret
Support returning values from thread-safe module callbacks.
2 parents 362500d + ffb42b9 commit 248d382

File tree

3 files changed

+11
-8
lines changed

3 files changed

+11
-8
lines changed

.github/workflows/enzyme.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,11 @@ jobs:
5353
using Pkg
5454
try
5555
# force it to use this PR's version of the package
56-
Pkg.develop(PackageSpec(path=".")) # resolver may fail with main deps
56+
## resolver may fail with main deps
57+
Pkg.develop(PackageSpec(path="."))
5758
Pkg.update()
58-
Pkg.test(coverage=true) # resolver may fail with test time deps
59+
## # resolver may fail with test time deps
60+
Pkg.test(; coverage=true, julia_args=`--depwarn=no`)
5961
catch err
6062
err isa Pkg.Resolve.ResolverError || rethrow()
6163
# If we can't resolve that means this is incompatible by SemVer and this is fine

src/executionengine/ts_module.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ function dispose(mod::ThreadSafeModule)
5858
end
5959

6060
mutable struct ThreadSafeModuleCallback
61+
ret::Ref{Any}
6162
callback
63+
64+
ThreadSafeModuleCallback(callback) = new(Ref{Any}(), callback)
6265
end
6366

6467
function tsm_callback(data::Ptr{Cvoid}, ref::API.LLVMModuleRef)
@@ -67,7 +70,7 @@ function tsm_callback(data::Ptr{Cvoid}, ref::API.LLVMModuleRef)
6770
ctx = context(mod)
6871
activate(ctx)
6972
try
70-
cb.callback(Module(ref))
73+
cb.ret = cb.callback(Module(ref))
7174
catch err
7275
msg = sprint(Base.display_error, err, Base.catch_backtrace())
7376
return API.LLVMCreateStringError(msg)
@@ -91,5 +94,5 @@ function (mod::ThreadSafeModule)(f)
9194
@cfunction(tsm_callback, API.LLVMErrorRef, (Ptr{Cvoid}, API.LLVMModuleRef)),
9295
Base.pointer_from_objref(cb))
9396
end
94-
return mod
97+
cb.ret[]
9598
end

test/orc_tests.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,9 @@ end
2020
@test_throws LLVMException ts_mod() do mod
2121
error("Error")
2222
end
23-
run = Ref{Bool}(false)
24-
ts_mod() do mod
25-
run[] = true
23+
@test ts_mod() do mod
24+
true
2625
end
27-
@test run[]
2826
end
2927
end
3028

0 commit comments

Comments
 (0)