diff --git a/HISTORY.md b/HISTORY.md index fd3e1c106..2b2ca2c35 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,9 @@ # DynamicPPL Changelog +## 0.38.7 + +Made a small tweak to DynamicPPL's compiler output to avoid potential undefined variables when resuming model functions midway through (e.g. with Libtask in Turing's SMC/PG samplers). + ## 0.38.6 Renamed keyword argument `only_ddpl` to `only_dppl` for `Experimental.is_suitable_varinfo`. diff --git a/Project.toml b/Project.toml index 8ced1d425..9d013d287 100644 --- a/Project.toml +++ b/Project.toml @@ -1,6 +1,6 @@ name = "DynamicPPL" uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8" -version = "0.38.6" +version = "0.38.7" [deps] ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b" diff --git a/src/compiler.jl b/src/compiler.jl index 6384eaa7c..badba9f9d 100644 --- a/src/compiler.jl +++ b/src/compiler.jl @@ -461,9 +461,16 @@ function generate_tilde(left, right) elseif $isassumption $(generate_tilde_assume(left, dist, vn)) else - # If `vn` is not in `argnames`, we need to make sure that the variable is defined. - if !$(DynamicPPL.inargnames)($vn, __model__) - $left = $(DynamicPPL.getconditioned_nested)( + # If `vn` is not in `argnames`, then it's definitely been conditioned on (if + # it's not in `argnames` and wasn't conditioned on, then `isassumption` would + # be true). + $left = if $(DynamicPPL.inargnames)($vn, __model__) + # This is a no-op and looks redundant, but defining the compiler output this + # way ensures that the variable `$left` is always defined. See + # https://github.com/TuringLang/DynamicPPL.jl/pull/1110. + $left + else + $(DynamicPPL.getconditioned_nested)( __model__.context, $(DynamicPPL.prefix)(__model__.context, $vn) ) end