diff --git a/Project.toml b/Project.toml index 4ea2e86c..a1db18f3 100644 --- a/Project.toml +++ b/Project.toml @@ -3,7 +3,7 @@ uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f" license = "MIT" desc = "Tape based task copying in Turing" repo = "https://github.com/TuringLang/Libtask.jl.git" -version = "0.6.8" +version = "0.6.9" [deps] IRTools = "7869d1d1-7146-5819-86e3-90919afe41df" diff --git a/src/tapedfunction.jl b/src/tapedfunction.jl index ea5ea13c..b6c22e71 100644 --- a/src/tapedfunction.jl +++ b/src/tapedfunction.jl @@ -173,12 +173,25 @@ function (instr::Instruction{F})() where F end end +""" + __new__(T, args) + +Return a new instance of `T` with `args` even when there is no inner constructor for these args. +Source: https://discourse.julialang.org/t/create-a-struct-with-uninitialized-fields/6967/5 +""" +@generated function __new__(T, args) + return Expr(:splatnew, :T, :args) +end + function _new end function (instr::Instruction{typeof(_new)})() # catch run-time exceptions / errors. try - expr = Expr(:new, map(val, instr.input)...) - output = eval(expr) + input = map(val, instr.input) + T = input[1] + args = input[2:end] + output = __new__(T, args) + instr.output.val = output instr.tape.counter += 1 catch e