Skip to content

Commit ab6f38a

Browse files
authored
Fix potential undefined variable in model compiler output (#1110)
1 parent d9af270 commit ab6f38a

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

HISTORY.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# DynamicPPL Changelog
22

3+
## 0.38.7
4+
5+
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).
6+
37
## 0.38.6
48

59
Renamed keyword argument `only_ddpl` to `only_dppl` for `Experimental.is_suitable_varinfo`.

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DynamicPPL"
22
uuid = "366bfd00-2699-11ea-058f-f148b4cae6d8"
3-
version = "0.38.6"
3+
version = "0.38.7"
44

55
[deps]
66
ADTypes = "47edcb42-4c32-4615-8424-f2b9edc5f35b"

src/compiler.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -461,9 +461,16 @@ function generate_tilde(left, right)
461461
elseif $isassumption
462462
$(generate_tilde_assume(left, dist, vn))
463463
else
464-
# If `vn` is not in `argnames`, we need to make sure that the variable is defined.
465-
if !$(DynamicPPL.inargnames)($vn, __model__)
466-
$left = $(DynamicPPL.getconditioned_nested)(
464+
# If `vn` is not in `argnames`, then it's definitely been conditioned on (if
465+
# it's not in `argnames` and wasn't conditioned on, then `isassumption` would
466+
# be true).
467+
$left = if $(DynamicPPL.inargnames)($vn, __model__)
468+
# This is a no-op and looks redundant, but defining the compiler output this
469+
# way ensures that the variable `$left` is always defined. See
470+
# https://github.com/TuringLang/DynamicPPL.jl/pull/1110.
471+
$left
472+
else
473+
$(DynamicPPL.getconditioned_nested)(
467474
__model__.context, $(DynamicPPL.prefix)(__model__.context, $vn)
468475
)
469476
end

0 commit comments

Comments
 (0)