Skip to content

Commit 0f2e114

Browse files
committed
Get rid of gensym type tags and variable assignment
1 parent 8987b55 commit 0f2e114

File tree

1 file changed

+13
-19
lines changed

1 file changed

+13
-19
lines changed

src/compiler.jl

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,6 @@ function build_model_info(input_expr)
173173

174174
model_info = Dict(
175175
:name => modeldef[:name],
176-
:model_tag => gensym(modeldef[:name]),
177176
:main_body => modeldef[:body],
178177
:arg_syms => arg_syms,
179178
:args_nt => args_nt,
@@ -431,8 +430,6 @@ function build_output(model_info)
431430
whereparams = model_info[:whereparams]
432431
# Model generator name
433432
model_gen = model_info[:name]
434-
# Tag used for the model type
435-
model_tag = model_info[:model_tag]
436433
# Main body of the model
437434
main_body = model_info[:main_body]
438435

@@ -454,13 +451,22 @@ function build_output(model_info)
454451
end)
455452
end
456453

457-
model_type = :(DynamicPPL.Model{$(QuoteNode(model_tag))})
458-
kw_form = isempty(args) ? () : (:($model_type(;$(args...)) = $model_type($(arg_syms...))),)
454+
kw_form = isempty(args) ? () : (:($model_gen(;$(args...)) = $model_gen($(arg_syms...))),)
459455
missings = gensym(:missings)
460456
args_tuple = gensym(:args_tuple)
461457

462458
ex = quote
463-
function ($model::$model_type)(
459+
function $model_gen($(args...))
460+
$args_tuple = $args_nt
461+
$missings = DynamicPPL.getmissing($args_tuple)
462+
return DynamicPPL.Model{typeof($model_gen),
463+
typeof($args_tuple),
464+
typeof($missings)}($args_tuple, $missings)
465+
end
466+
467+
$(kw_form...)
468+
469+
function ($model::DynamicPPL.Model{typeof($model_gen)})(
464470
$vi::DynamicPPL.VarInfo,
465471
$sampler::DynamicPPL.AbstractSampler,
466472
$ctx::DynamicPPL.AbstractContext,
@@ -469,20 +475,8 @@ function build_output(model_info)
469475
DynamicPPL.resetlogp!($vi)
470476
$main_body
471477
end
472-
473-
DynamicPPL.getdefaults(::Type{$model_type}) = $defaults_nt
474478

475-
function $model_type($(args...))
476-
$args_tuple = $args_nt
477-
$missings = DynamicPPL.getmissing($args_tuple)
478-
return DynamicPPL.Model{$(QuoteNode(model_tag)),
479-
typeof($args_tuple),
480-
typeof($missings)}($args_tuple, $missings)
481-
end
482-
483-
$(kw_form...)
484-
485-
$model_gen = $model_type
479+
DynamicPPL.getdefaults(::typeof($model_gen)) = $defaults_nt
486480
end
487481

488482
return esc(ex)

0 commit comments

Comments
 (0)