Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diffractor forgets contents of structure? #40

Closed
DavidKoplow opened this issue Aug 25, 2021 · 2 comments
Closed

Diffractor forgets contents of structure? #40

DavidKoplow opened this issue Aug 25, 2021 · 2 comments

Comments

@DavidKoplow
Copy link

DavidKoplow commented Aug 25, 2021

I've been having an issue with Diffractor with TransformVariables.jl.
I have isolated the issue to this function. Diffractor it seems to forget the contents of the structure. Any idea what might be going wrong?

using Diffractor
@inline UNPACK(x, ::Val{f}) where {f} = getproperty(x, f)
@inline UNPACK(x::AbstractDict{Symbol}, ::Val{k}) where {k} = x[k]
@inline UNPACK(x::AbstractDict{<:AbstractString}, ::Val{k}) where {k} = x[string(k)]

macro UNPACK(args)
    args.head!=:(=) && error("Expression needs to be of form `a, b = c`")
    items, suitecase = args.args
    items = isa(items, Symbol) ? [items] : items.args
    suitecase_instance = gensym()
    kd = [:( $key = $UNPACK($suitecase_instance, Val{$(Expr(:quote, key))}()) ) for key in items]
    kdblock = Expr(:block, kd...)
    expr = quote
        local $suitecase_instance = $suitecase # handles if suitecase is not a variable but an expression
        $kdblock
        $suitecase_instance # return RHS of `=` as standard in Julia
    end
    esc(expr)
end

function er(tranforms)
    @UNPACK transformations = tranforms
    transformations
end
struct tr
    transformations
end
er(tr(1)) #Works
Diffractor.∂⃖recurse{1}()(er,tr(1)) #Doesn't Work
@Keno Keno closed this as completed in 7696e8a Aug 26, 2021
@Keno
Copy link
Collaborator

Keno commented Aug 26, 2021

Fixed! For future reference, it's helpful to include the actual error message in the issue, just so I can be sure I see the same issue as you.

@DavidKoplow
Copy link
Author

Amazing. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants