11const DISTMSG = " Right-hand side of a ~ must be subtype of Distribution or a vector of " *
22 " Distributions."
33
4- const INTERNALNAMES = (:_model , :_sampler , :_context , :_varinfo , :_rng )
4+ const INTERNALNAMES = (:__model__ , :__sampler__ , :__context__ , :__varinfo__ , :__rng__ )
5+ const DEPRECATED_INTERNALNAMES = (:_model , :_sampler , :_context , :_varinfo , :_rng )
56
67"""
78 isassumption(expr)
@@ -24,7 +25,7 @@ function isassumption(expr::Union{Symbol, Expr})
2425 let $ vn = $ (varname (expr))
2526 # This branch should compile nicely in all cases except for partial missing data
2627 # For example, when `expr` is `:(x[i])` and `x isa Vector{Union{Missing, Float64}}`
27- if ! $ (DynamicPPL. inargnames)($ vn, _model ) || $ (DynamicPPL. inmissings)($ vn, _model )
28+ if ! $ (DynamicPPL. inargnames)($ vn, __model__ ) || $ (DynamicPPL. inmissings)($ vn, __model__ )
2829 true
2930 else
3031 # Evaluate the LHS
@@ -167,10 +168,20 @@ generate_mainbody(mod, expr, warn) = generate_mainbody!(mod, Symbol[], expr, war
167168
168169generate_mainbody! (mod, found, x, warn) = x
169170function generate_mainbody! (mod, found, sym:: Symbol , warn)
171+ if sym in DEPRECATED_INTERNALNAMES
172+ newsym = Symbol (:_ , sym, :__ )
173+ Base. depwarn (
174+ " internal variable `$sym ` is deprecated, use `$newsym ` instead." ,
175+ :generate_mainbody! ,
176+ )
177+ return generate_mainbody! (mod, found, newsym, warn)
178+ end
179+
170180 if warn && sym in INTERNALNAMES && sym ∉ found
171- @warn " you are using the internal variable `$( sym) `"
181+ @warn " you are using the internal variable `$sym `"
172182 push! (found, sym)
173183 end
184+
174185 return sym
175186end
176187function generate_mainbody! (mod, found, expr:: Expr , warn)
@@ -228,18 +239,20 @@ function generate_tilde(left, right)
228239 $ isassumption = $ (DynamicPPL. isassumption (left))
229240 if $ isassumption
230241 $ left = $ (DynamicPPL. tilde_assume)(
231- _rng, _context, _sampler, $ tmpright, $ vn, $ inds, _varinfo)
242+ __rng__, __context__, __sampler__, $ tmpright, $ vn, $ inds, __varinfo__
243+ )
232244 else
233245 $ (DynamicPPL. tilde_observe)(
234- _context, _sampler, $ tmpright, $ left, $ vn, $ inds, _varinfo)
246+ __context__, __sampler__, $ tmpright, $ left, $ vn, $ inds, __varinfo__
247+ )
235248 end
236249 end
237250 end
238251
239252 # If the LHS is a literal, it is always an observation
240253 return quote
241254 $ (top... )
242- $ (DynamicPPL. tilde_observe)(_context, _sampler , $ tmpright, $ left, _varinfo )
255+ $ (DynamicPPL. tilde_observe)(__context__, __sampler__ , $ tmpright, $ left, __varinfo__ )
243256 end
244257end
245258
@@ -263,18 +276,20 @@ function generate_dot_tilde(left, right)
263276 $ isassumption = $ (DynamicPPL. isassumption (left)) || $ left === missing
264277 if $ isassumption
265278 $ left .= $ (DynamicPPL. dot_tilde_assume)(
266- _rng, _context, _sampler, $ tmpright, $ left, $ vn, $ inds, _varinfo)
279+ __rng__, __context__, __sampler__, $ tmpright, $ left, $ vn, $ inds, __varinfo__
280+ )
267281 else
268282 $ (DynamicPPL. dot_tilde_observe)(
269- _context, _sampler, $ tmpright, $ left, $ vn, $ inds, _varinfo)
283+ __context__, __sampler__, $ tmpright, $ left, $ vn, $ inds, __varinfo__
284+ )
270285 end
271286 end
272287 end
273288
274289 # If the LHS is a literal, it is always an observation
275290 return quote
276291 $ (top... )
277- $ (DynamicPPL. dot_tilde_observe)(_context, _sampler , $ tmpright, $ left, _varinfo )
292+ $ (DynamicPPL. dot_tilde_observe)(__context__, __sampler__ , $ tmpright, $ left, __varinfo__ )
278293 end
279294end
280295
@@ -298,11 +313,11 @@ function build_output(modelinfo, linenumbernode)
298313 # Add the internal arguments to the user-specified arguments (positional + keywords).
299314 evaluatordef[:args ] = vcat (
300315 [
301- :(_rng :: $ (Random. AbstractRNG)),
302- :(_model :: $ (DynamicPPL. Model)),
303- :(_varinfo :: $ (DynamicPPL. AbstractVarInfo)),
304- :(_sampler :: $ (DynamicPPL. AbstractSampler)),
305- :(_context :: $ (DynamicPPL. AbstractContext)),
316+ :(__rng__ :: $ (Random. AbstractRNG)),
317+ :(__model__ :: $ (DynamicPPL. Model)),
318+ :(__varinfo__ :: $ (DynamicPPL. AbstractVarInfo)),
319+ :(__sampler__ :: $ (DynamicPPL. AbstractSampler)),
320+ :(__context__ :: $ (DynamicPPL. AbstractContext)),
306321 ],
307322 modelinfo[:allargs_exprs ],
308323 )
0 commit comments