Skip to content

Commit 0bb2504

Browse files
committed
Hotfixes after #309 (#351)
#309 was merged a bit too soon, for example `bors` was never run on the final version due to some issues. Before we make a release, we should make sure that it all works properly.
1 parent 1744ba7 commit 0bb2504

File tree

6 files changed

+29
-6
lines changed

6 files changed

+29
-6
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ jobs:
1616
strategy:
1717
matrix:
1818
version:
19-
# - '1.3' # minimum supported version
19+
- '1.3' # minimum supported version
2020
- '1' # current stable version
2121
os:
2222
- ubuntu-latest

docs/make.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ makedocs(;
1818
r"(Array{.+,\s?1}|Vector{.+})",
1919
# Older versions will show "Array{...,2}" instead of "Matrix{...}".
2020
r"(Array{.+,\s?2}|Matrix{.+})",
21+
# Errors from macros sometimes result in `LoadError: LoadError:`
22+
# rather than `LoadError:`, depending on Julia version.
23+
r"ERROR: (LoadError:\s)+",
2124
],
2225
)
2326

src/submodel_macro.jl

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -212,17 +212,23 @@ function submodel(prefix_expr, expr, ctx=esc(:__context__))
212212
if prefix_left !== :prefix
213213
error("$(prefix_left) is not a valid kwarg")
214214
end
215+
216+
# The user expects `@submodel ...` to return the
217+
# return-value of the `...`, hence we need to capture
218+
# the return-value and handle it correctly.
219+
@gensym retval
220+
215221
# `prefix=false` => don't prefix, i.e. do nothing to `ctx`.
216222
# `prefix=true` => automatically determine prefix.
217223
# `prefix=...` => use it.
218224
args_assign = getargs_assignment(expr)
219225
return if args_assign === nothing
220226
ctx = prefix_submodel_context(prefix, ctx)
221-
# In this case we only want to get the `__varinfo__`.
222227
quote
223-
$(esc(:__varinfo__)) = last(
224-
$(DynamicPPL._evaluate!!)($(esc(expr)), $(esc(:__varinfo__)), $(ctx))
228+
$retval, $(esc(:__varinfo__)) = $(DynamicPPL._evaluate!!)(
229+
$(esc(expr)), $(esc(:__varinfo__)), $(ctx)
225230
)
231+
$retval
226232
end
227233
else
228234
L, R = args_assign
@@ -235,9 +241,10 @@ function submodel(prefix_expr, expr, ctx=esc(:__context__))
235241
)
236242
end
237243
quote
238-
$(esc(L)), $(esc(:__varinfo__)) = $(DynamicPPL._evaluate!!)(
244+
$retval, $(esc(:__varinfo__)) = $(DynamicPPL._evaluate!!)(
239245
$(esc(R)), $(esc(:__varinfo__)), $(ctx)
240246
)
247+
$(esc(L)) = $retval
241248
end
242249
end
243250
end

test/compiler.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,5 +570,15 @@ end
570570

571571
@model demo() = x ~ Normal()
572572
retval, svi = DynamicPPL.evaluate!!(demo(), SimpleVarInfo(), SamplingContext())
573+
574+
# Return-value when using `@submodel`
575+
@model inner() = x ~ Normal()
576+
# Without assignment.
577+
@model outer() = @submodel inner()
578+
@test outer()() isa Real
579+
580+
# With assignment.
581+
@model outer() = @submodel x = inner()
582+
@test outer()() isa Real
573583
end
574584
end

test/runtests.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ include("test_util.jl")
6666
r"(Array{.+,\s?1}|Vector{.+})",
6767
# Older versions will show "Array{...,2}" instead of "Matrix{...}".
6868
r"(Array{.+,\s?2}|Matrix{.+})",
69+
# Errors from macros sometimes result in `LoadError: LoadError:`
70+
# rather than `LoadError:`, depending on Julia version.
71+
r"ERROR: (LoadError:\s)+",
6972
]
7073
doctest(DynamicPPL; manual=false, doctestfilters=doctestfilters)
7174
end

test/turing/Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,6 @@ Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
55
Turing = "fce5fe82-541a-59a6-adf8-730c64b5f9a0"
66

77
[compat]
8-
DynamicPPL = "0.16"
8+
DynamicPPL = "0.17"
99
Turing = "0.18, 0.19"
1010
julia = "1.3"

0 commit comments

Comments
 (0)