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

serialize doesn't preserve identity of Expr.args #15881

Open
tmptrash opened this issue Apr 15, 2016 · 6 comments
Open

serialize doesn't preserve identity of Expr.args #15881

tmptrash opened this issue Apr 15, 2016 · 6 comments
Labels
io Involving the I/O subsystem: libuv, read, write, etc.

Comments

@tmptrash
Copy link

It looks like julia doesn't store references correctly. For example, in this snippet, T.a is a reference to block/quote of a function. So, after deserializing, this reference will be broken. Look at the example:

type T
    e::Expr
    a::Array{Any,1}
end

ex = :(function f() return true end)
t  = T(ex, ex.args[2].args) # a refers to function's block
io = open("file.dat", "w")
serialize(io, t)
close(io)

io = open("file.dat")
t1 = deserialize(io)
t1.e.args[2].args === t1.a # false, but should be true, no?
close(io)

This issue is related to this one.

@yuyichao
Copy link
Contributor

I don't think it is possible to do this. In fact deserialize shouldn't create any aliasing with the original input.

@JeffBezanson
Copy link
Member

No, this is about shared references within an object. We can handle this in some cases, but not all. For efficiency, we don't track the args array of an Expr separately. @tmptrash how did this come up? I don't think it should be necessary to persist an Expr and its args array and then mutate them. That seems very strange to me.

@yuyichao
Copy link
Contributor

Ahh, I didn't realize the RHS of the === is using t1 and not t.

@yuyichao yuyichao reopened this Apr 15, 2016
@tmptrash
Copy link
Author

tmptrash commented Apr 15, 2016

It comes from my backup mechanism. I have to save application state in a file from time to time, because of these crashes. So, after crash it may recover itself from last backup and continue working. I use special tree-like structures (types) for storing all the references inside my AST. This is something like AST meta data (where all variables are, where all functions are and so on).

P.S. For now, i'm thinking about rewriting my code and this meta data types especially, to support numeric indexes instead of references.

@JeffBezanson
Copy link
Member

Shared references to Exprs should work. Is it possible to avoid separately referencing the Expr args arrays?

@tmptrash
Copy link
Author

As i understand, I may serialize ex.args[x] instead of ex.args[x].args. Is it correct? If yes, then it's possible to rewrite my code in this way, thanks.

@JeffBezanson JeffBezanson changed the title serialize()/deserialize() references problem serialize doesn't preserve identity of Expr.args Apr 17, 2016
@kshyatt kshyatt added the io Involving the I/O subsystem: libuv, read, write, etc. label Jan 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
io Involving the I/O subsystem: libuv, read, write, etc.
Projects
None yet
Development

No branches or pull requests

4 participants