Skip to content

Commit 6866f05

Browse files
authored
Add jit macro for simplified testing (#194)
1 parent 1dd24b8 commit 6866f05

File tree

2 files changed

+26
-2
lines changed

2 files changed

+26
-2
lines changed

src/Compiler.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,30 @@ macro compile(options, maybe_call=nothing)
421421
end
422422
end
423423

424+
"""
425+
@jit f(args...)
426+
427+
Run @compile f(args..) then immediately execute it
428+
"""
429+
macro jit(options, maybe_call=nothing)
430+
call = something(maybe_call, options)
431+
options = isnothing(maybe_call) ? :(optimize = true) : options
432+
Meta.isexpr(call, :call) || error("@compile: expected call, got $call")
433+
if !Meta.isexpr(options, :(=)) || options.args[1] != :optimize
434+
error("@compile: expected options in format optimize=value, got $options")
435+
end
436+
437+
options = Expr(:tuple, Expr(:parameters, Expr(:kw, options.args...)))
438+
439+
quote
440+
options = $(esc(options))
441+
f = $(esc(call.args[1]))
442+
args = $(esc(Expr(:tuple, call.args[2:end]...)))
443+
fn = compile(f, args; options.optimize)
444+
fn(args...)
445+
end
446+
end
447+
424448
"""
425449
codegen_flatten!
426450

src/Reactant.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ const TracedType = Union{TracedRArray,TracedRNumber}
9393
include("Tracing.jl")
9494
include("Compiler.jl")
9595

96-
using .Compiler: @compile, @code_hlo, traced_getfield, create_result, compile
97-
export ConcreteRArray, @compile, @code_hlo
96+
using .Compiler: @compile, @code_hlo, @jit, traced_getfield, create_result, compile
97+
export ConcreteRArray, @compile, @code_hlo, @jit
9898

9999
const registry = Ref{MLIR.IR.DialectRegistry}()
100100
function __init__()

0 commit comments

Comments
 (0)