cscherrer / Soss.jl

Probabilistic programming via source rewriting
https://cscherrer.github.io/Soss.jl/stable/
MIT License
412 stars 30 forks source link

Can't use M as variable name #331

Open marius311 opened 2 years ago

marius311 commented 2 years ago

Random thing I unearthed w/ Soss v0.20.9 and GeneralizedGenerated v0.3.3, not sure if it belongs here or there but I only know how to trigger it from here:

model = @model () begin
    M ~ Normal()
end
rand(model) # invalid let syntax
cscherrer commented 2 years ago

Sorry for the delay on this. I've just released a new version that works with the latest MeasureTheory, so I think we can address this in a minor release.

The problem comes from this:

@gg function _rand(M::Type{<:TypeLevel}, _m::Model, _args)
    body = type2model(_m) |> sourceRand() |> loadvals(_args, NamedTuple())
    @under_global from_type(_unwrap_type(M)) @q let M
        $body
    end
end

@thautwarm I don't understand what this let M without a binding is doing. I think it would be ok to change all M references to _M, but even better would be to gensym the name. Do you see a way for that to work? Or if not we can just use _M or some more complicated version.

thautwarm commented 2 years ago

I just played with Soss and this example, it seems that JuliaVariables.jl gets broken in 1.7 Will investigate this tonight.

thautwarm commented 2 years ago

Hope I can give some results tomorrow. Debugging GG functions is hard, and I should make it support viewing the generated code with InteractiveUtils.less.

cscherrer commented 2 years ago

Sounds good. Thanks for digging into this!