From 2d051411de79a024c15f650505e4694111dada8c Mon Sep 17 00:00:00 2001 From: Markus Hauru Date: Fri, 7 Nov 2025 10:28:09 +0000 Subject: [PATCH 1/3] Attempt to fix #207 --- src/copyable_task.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/copyable_task.jl b/src/copyable_task.jl index 675749c1..9f0b29c2 100644 --- a/src/copyable_task.jl +++ b/src/copyable_task.jl @@ -1226,8 +1226,8 @@ end # Helper used in `derive_copyable_task_ir`. @inline function deref_phi(refs::R, n::TupleRef, ::Type{T}) where {R<:Tuple,T} - ref = refs[n.n]::Base.RefValue{T} - return ref[] + ref = refs[n.n] + return ref[]::T end @inline deref_phi(::R, x, t::Type) where {R<:Tuple} = x From 6a568079a05096cda0056d6343e257e9fdf52bae Mon Sep 17 00:00:00 2001 From: Markus Hauru Date: Fri, 7 Nov 2025 11:30:39 +0000 Subject: [PATCH 2/3] Add a test --- test/copyable_task.jl | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/copyable_task.jl b/test/copyable_task.jl index 9ae5377e..9a8383f2 100644 --- a/test/copyable_task.jl +++ b/test/copyable_task.jl @@ -300,4 +300,31 @@ @test Libtask.consume(tt) === 10 @test Libtask.consume(tt) === nothing end + + # Regression test against https://github.com/TuringLang/Libtask.jl/issues/207 + @testset "Union deferencing" begin + function g(i::Int) + produce(1) + return i + end + function g(s::String) + produce(2) + return s + end + Libtask.@might_produce g + + h(i::Int)::Int = i + h(s::String)::Int = length(s) + + function f(x, g) + i_or_s = x > 0 ? 3 : "libtask" + gres = g(i_or_s) + return h(gres) + end + + t = TapedTask(nothing, f, 1, g) + consume(t) + # This used to error + @test (consume(t); true) + end end From b55ad6bea06c18abd1431b5725856be9075ac483 Mon Sep 17 00:00:00 2001 From: Markus Hauru Date: Fri, 7 Nov 2025 11:31:52 +0000 Subject: [PATCH 3/3] Bump patch version to 0.9.10 --- HISTORY.md | 4 ++++ Project.toml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/HISTORY.md b/HISTORY.md index 1ce7744b..9bf6274b 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,7 @@ +# 0.9.10 + +Fix a bug introduced in 0.9.9 that made certain phi nodes with Union types fail a type assertion. + # 0.9.9 Remove manual opaque closure optimisation functions in favour of setting the world age and letting the compiler do more work for us, and providing it with some more type information. This changes no functionality, and shouldn't change performance either, but simplifies code. diff --git a/Project.toml b/Project.toml index 222e4886..9435c87c 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.9.9" +version = "0.9.10" [deps] MistyClosures = "dbe65cb8-6be2-42dd-bbc5-4196aaced4f4"