Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

static_parameter expr #175

Merged
merged 12 commits into from
Oct 22, 2024
3 changes: 2 additions & 1 deletion perf/benchmark.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ println("======= breakdown benchmark =======")
x = rand(100000)
tf = Libtask.TapedFunction(ackley, x, nothing)
tf(x, nothing);
ins = tf.tape[45]
idx = findlast((x)->isa(x, Libtask.Instruction), tf.tape)
ins = tf.tape[idx]
b = ins.input[1]

@show ins.input |> length
Expand Down
1 change: 1 addition & 0 deletions src/Libtask.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export TArray, tzeros, tfill, TRef # legacy types back compat

@static if isdefined(Core, :TypedSlot) || isdefined(Core.Compiler, :TypedSlot)
# Julia v1.10 removed Core.TypedSlot
# Julia v1.11 removed Core.Compiler.TypedSlot
const TypedSlot = @static if isdefined(Core, :TypedSlot)
Core.TypedSlot
else
Expand Down
11 changes: 11 additions & 0 deletions src/tapedfunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,14 @@ function translate!!(var::IRVar, line::Core.SlotNumber,
return Instruction(func, input, output)
end

function translate!!(var::IRVar, line::Number, # literal vars
bindings::Bindings, isconst::Bool, ir)
func = identity
input = (bind_var!(line, bindings, ir),)
output = bind_var!(var, bindings, ir)
return Instruction(func, input, output)
end

function translate!!(var::IRVar, line::NTuple{N, Symbol},
bindings::Bindings, isconst::Bool, ir) where {N}
# for syntax (; x, y, z), see Turing.jl#1873
Expand Down Expand Up @@ -439,6 +447,9 @@ function translate!!(var::IRVar, line::Expr,
end
return Instruction(identity, (_bind_fn(rhs),), _bind_fn(lhs))
end
elseif head === :static_parameter
v = ir.parent.sparam_vals[line.args[1]]
return Instruction(identity, (_bind_fn(v),), _bind_fn(var))
else
@error "Unknown Expression: " typeof(var) var typeof(line) line
throw(ErrorException("Unknown Expression"))
Expand Down
Loading