Skip to content

Translate new construction of NamedTuple #156

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

Merged
merged 3 commits into from
Aug 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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.8.1"
version = "0.8.2"

[deps]
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"
Expand Down
11 changes: 10 additions & 1 deletion src/tapedfunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,15 @@ function translate!!(var::IRVar, line::Core.SlotNumber,
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
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::Core.TypedSlot,
bindings::Bindings, isconst::Bool, ir)
input_box = bind_var!(Core.SlotNumber(line.id), bindings, ir)
Expand Down Expand Up @@ -437,7 +446,7 @@ function translate!!(var::IRVar, line::Expr,
end
end

function translate!!(var, line, bindings, ir)
function translate!!(var, line, bindings, isconst, ir)
@error "Unknown IR code: " typeof(var) var typeof(line) line
throw(ErrorException("Unknown IR code"))
end
Expand Down
11 changes: 11 additions & 0 deletions test/issues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,15 @@
ttask = TapedTask(f, 2)
@test consume(ttask) == 1
end

@testset "Issue-Turing-1873, NamedTuple syntax" begin
function g(x, y)
c = x + y
return (; c, x, y)
end

tf = Libtask.TapedFunction(g, 1, 2)
r = tf(1, 2)
@test r == (c=3, x=1, y=2)
end
end