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

fix tracking of serialization state for Function types and Expr #13134

Merged
merged 3 commits into from
Sep 17, 2015

Conversation

amitmurthy
Copy link
Contributor

While serialize_cycle was being called for all Function types, deserialize_cycle was not. This causes a mismatch in deserializing state.

Closes #12848

@JeffBezanson - I am not really familiar with the ser/deser codebase. Can you review this?

deserialize_cycle(s, f)
f.env = deserialize(s)
Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be after deserialize_cycle to handle possible cycles through f.env.

@JeffBezanson
Copy link
Sponsor Member

Thanks, great catch.

@tkelman
Copy link
Contributor

tkelman commented Sep 16, 2015

This could really use a test if at all possible.

end
linfo = deserialize(s)
f = ccall(:jl_new_closure, Any, (Ptr{Void}, Ptr{Void}, Any), C_NULL, C_NULL, linfo)::Function

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whitespace

@amitmurthy
Copy link
Contributor Author

Adding tests was a good suggestion. Threw up errors that @JeffBezanson / others are probably in a better position to fix.

@tkelman
Copy link
Contributor

tkelman commented Sep 16, 2015

why ci skip, are they still broken?

@test b[10]("foobar") == "foobar"

@test b[end] == 5
@test length(b) == length(A)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the patch stands, deserialized A is

1 ====> 1
2 ====> 2
3 ====> Any[1,2,#= circular reference =#,abs,abs,(anonymous function),AST(:($(Expr(:lambda, Any[:(x::Any)], Any[Any[Any[:x,:Any,0]],Any[],0,Any[]], :(begin  # none, line 1:
        return x
    end))))),echo,:(begin  # none, line 1:
        return x
    end),CycleFoo.echo,:(return x),4,5]
4 ====> abs
5 ====> abs
6 ====> (anonymous function)
7 ====> AST(:($(Expr(:lambda, Any[:(x::Any)], Any[Any[Any[:x,:Any,0]],Any[],0,Any[]], :(begin  # none, line 1:
        return x
    end)))))
8 ====> echo
9 ====> begin  # none, line 1:
    return x
end
10 ====> CycleFoo.echo
11 ====> return x
12 ====> 4
13 ====> 5

indexexes 6,7 should be the same. As also index pairs (8,9) and (10,11)

@amitmurthy
Copy link
Contributor Author

Yup. The fix may be a little more involved.

@tkelman tkelman changed the title fix tracking of serialization state for Function types WIP: fix tracking of serialization state for Function types Sep 16, 2015
elseif b==3
env = deserialize(s)
return ccall(:jl_new_gf_internal, Any, (Any,), env)::Function
f = ccall(:jl_new_gf_internal, Any, (Any,), env)::Function
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can anyone give an example of this type of function? Needs to be added to the tests.

Copy link
Sponsor Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe it is for inner generic functions. You can also generate a function that references itself using

function foo()
    f = x->f(x)
end

@amitmurthy
Copy link
Contributor Author

A short term workaround could be to remove cyclic handling for Function types.

@JeffBezanson
Copy link
Sponsor Member

Ok I think I have this working now. Will push to this branch.

@JeffBezanson JeffBezanson changed the title WIP: fix tracking of serialization state for Function types fix tracking of serialization state for Function types and Expr Sep 16, 2015
JeffBezanson added a commit that referenced this pull request Sep 17, 2015
fix tracking of serialization state for Function types and Expr
@JeffBezanson JeffBezanson merged commit afaa4de into master Sep 17, 2015
@amitmurthy amitmurthy deleted the amitm/12848 branch September 17, 2015 02:56
amitmurthy added a commit that referenced this pull request Sep 17, 2015
@tkelman
Copy link
Contributor

tkelman commented Sep 18, 2015

backported in #13182

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

Successfully merging this pull request may close these issues.

3 participants