@@ -60,11 +60,14 @@ evaluates to a `VarName`, and this will be used in the subsequent checks.
6060If `vn` is not specified, `AbstractPPL.varname(expr, need_concretize(expr))` will be 
6161used in its place. 
6262""" 
63- function  isassumption (expr:: Union{Expr,Symbol} , vn= make_varname_expression (expr))
63+ function  isassumption (expr:: Union{Expr,Symbol} , left_vn= make_varname_expression (expr))
64+     @gensym  vn
6465    return  quote 
65-         if  $ (DynamicPPL. contextual_isassumption)(
66-             __model__. context, $ (DynamicPPL. prefix)(__model__. context, $ vn)
67-         )
66+         #  TODO (penelopeysm): This re-prefixing seems a bit wasteful. I'd really like
67+         #  the whole `isassumption` thing to be simplified, though, so I'll
68+         #  leave it till later.
69+         $ vn =  $ (DynamicPPL. maybe_prefix)($ left_vn, __model__. prefix)
70+         if  $ (DynamicPPL. contextual_isassumption)(__model__. context, $ vn)
6871            #  Considered an assumption by `__model__.context` which means either:
6972            #  1. We hit the default implementation, e.g. using `DefaultContext`,
7073            #     which in turn means that we haven't considered if it's one of
@@ -78,8 +81,8 @@ function isassumption(expr::Union{Expr,Symbol}, vn=make_varname_expression(expr)
7881            #     TODO : Support by adding context to model, and use `model.args`
7982            #     as the default conditioning. Then we no longer need to check `inargnames`
8083            #     since it will all be handled by `contextual_isassumption`.
81-             if  ! ($ (DynamicPPL. inargnames)($ vn , __model__)) || 
82-                 $ (DynamicPPL. inmissings)($ vn , __model__)
84+             if  ! ($ (DynamicPPL. inargnames)($ left_vn , __model__)) || 
85+                 $ (DynamicPPL. inmissings)($ left_vn , __model__)
8386                true 
8487            else 
8588                $ (maybe_view (expr)) ===  missing 
@@ -99,7 +102,7 @@ isassumption(expr) = :(false)
99102
100103Return `true` if `vn` is considered an assumption by `context`. 
101104""" 
102- function  contextual_isassumption (context:: AbstractContext , vn)
105+ function  contextual_isassumption (context:: AbstractContext , vn:: VarName )
103106    if  hasconditioned_nested (context, vn)
104107        val =  getconditioned_nested (context, vn)
105108        #  TODO : Do we even need the `>: Missing`, i.e. does it even help the compiler?
115118
116119isfixed (expr, vn) =  false 
117120function  isfixed (:: Union{Symbol,Expr} , vn)
118-     return  :($ (DynamicPPL. contextual_isfixed)(
119-         __model__. context, $ (DynamicPPL. prefix)(__model__. context, $ vn)
120-     ))
121+     return  :($ (DynamicPPL. contextual_isfixed)(__model__. context, $ vn))
121122end 
122123
123124""" 
@@ -413,7 +414,9 @@ function generate_assign(left, right)
413414    return  quote 
414415        $ right_val =  $ right
415416        if  $ (DynamicPPL. is_extracting_values)(__varinfo__)
416-             $ vn =  $ (DynamicPPL. prefix)(__model__. context, $ (make_varname_expression (left)))
417+             $ vn =  $ (DynamicPPL. maybe_prefix)(
418+                 $ (make_varname_expression (left)), __model__. prefix
419+             )
417420            __varinfo__ =  $ (map_accumulator!!)(
418421                $ acc ->  push! ($ acc, $ vn, $ right_val), __varinfo__, Val (:ValuesAsInModel )
419422            )
@@ -448,24 +451,23 @@ function generate_tilde(left, right)
448451
449452    #  Otherwise it is determined by the model or its value,
450453    #  if the LHS represents an observation
451-     @gensym  vn isassumption value dist
454+     @gensym  left_vn  vn isassumption value dist
452455
453456    return  quote 
454457        $ dist =  $ right
455-         $ vn =  $ (DynamicPPL. resolve_varnames)($ (make_varname_expression (left)), $ dist)
456-         $ isassumption =  $ (DynamicPPL. isassumption (left, vn))
458+         $ left_vn =  $ (DynamicPPL. resolve_varnames)($ (make_varname_expression (left)), $ dist)
459+         $ vn =  $ (DynamicPPL. maybe_prefix)($ left_vn, __model__. prefix)
460+         $ isassumption =  $ (DynamicPPL. isassumption (left, left_vn))
457461        if  $ (DynamicPPL. isfixed (left, vn))
458-             $ left =  $ (DynamicPPL. getfixed_nested)(
459-                 __model__. context, $ (DynamicPPL. prefix)(__model__. context, $ vn)
460-             )
462+             $ left =  $ (DynamicPPL. getfixed_nested)(__model__. context, $ vn)
461463        elseif  $ isassumption
462464            $ (generate_tilde_assume (left, dist, vn))
463465        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)( 
467-                     __model__ . context,  $ (DynamicPPL. prefix)(__model__ . context,  $ vn )
468-                 )
466+             #  If `left_vn ` is not in `argnames`, we need to make sure that the variable is defined.
467+             #  (Note: we use the unprefixed `left_vn` here rather than `vn` which will have had 
468+             #  prefixes applied!) 
469+             if   ! $ (DynamicPPL. inargnames)( $ left_vn, __model__ )
470+                 $ left  =   $ (DynamicPPL . getconditioned_nested)(__model__ . context,  $ vn )
469471            end 
470472
471473            $ value, __varinfo__ =  $ (DynamicPPL. tilde_observe!!)(
@@ -495,6 +497,7 @@ function generate_tilde_assume(left, right, vn)
495497    return  quote 
496498        $ value, __varinfo__ =  $ (DynamicPPL. tilde_assume!!)(
497499            __model__. context,
500+             __model__. prefix,
498501            $ (DynamicPPL. unwrap_right_vn)($ (DynamicPPL. check_tilde_rhs)($ right), $ vn). .. ,
499502            __varinfo__,
500503        )
0 commit comments