Skip to content

Commit bafaa1f

Browse files
KDr2yebai
andauthored
Translate new construction of NamedTuple (#156)
* translate new construction of NamedTuple * Update src/tapedfunction.jl * Update Project.toml Co-authored-by: Hong Ge <[email protected]>
1 parent 22d0d46 commit bafaa1f

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Diff for: Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ uuid = "6f1fad26-d15e-5dc8-ae53-837a1d7b8c9f"
33
license = "MIT"
44
desc = "Tape based task copying in Turing"
55
repo = "https://github.com/TuringLang/Libtask.jl.git"
6-
version = "0.8.1"
6+
version = "0.8.2"
77

88
[deps]
99
FunctionWrappers = "069b7b12-0de2-55c6-9aab-29f3d0a68a2e"

Diff for: src/tapedfunction.jl

+10-1
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,15 @@ function translate!!(var::IRVar, line::Core.SlotNumber,
369369
return Instruction(func, input, output)
370370
end
371371

372+
function translate!!(var::IRVar, line::NTuple{N, Symbol},
373+
bindings::Bindings, isconst::Bool, ir) where {N}
374+
# for syntax (; x, y, z), see Turing.jl#1873
375+
func = identity
376+
input = (bind_var!(line, bindings, ir),)
377+
output = bind_var!(var, bindings, ir)
378+
return Instruction(func, input, output)
379+
end
380+
372381
function translate!!(var::IRVar, line::Core.TypedSlot,
373382
bindings::Bindings, isconst::Bool, ir)
374383
input_box = bind_var!(Core.SlotNumber(line.id), bindings, ir)
@@ -437,7 +446,7 @@ function translate!!(var::IRVar, line::Expr,
437446
end
438447
end
439448

440-
function translate!!(var, line, bindings, ir)
449+
function translate!!(var, line, bindings, isconst, ir)
441450
@error "Unknown IR code: " typeof(var) var typeof(line) line
442451
throw(ErrorException("Unknown IR code"))
443452
end

Diff for: test/issues.jl

+11
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,15 @@
4848
ttask = TapedTask(f, 2)
4949
@test consume(ttask) == 1
5050
end
51+
52+
@testset "Issue-Turing-1873, NamedTuple syntax" begin
53+
function g(x, y)
54+
c = x + y
55+
return (; c, x, y)
56+
end
57+
58+
tf = Libtask.TapedFunction(g, 1, 2)
59+
r = tf(1, 2)
60+
@test r == (c=3, x=1, y=2)
61+
end
5162
end

0 commit comments

Comments
 (0)