Redefining structure (again).. what' the current situation and what to expect?

Recently there have been a lot of discussions about the possibility and the implementations allowing Struct redefinition (1, 2, 3, …) and some related pull requests/issues have been closed (1,2,…)

So, which is the situation now? Struct redefinition with Revise will just work ( :rofl: )? Will I need Julia 1.12 for it to work, or will I still need another package to add some temporary macro ?

1 Like

TLDR: Fix struct/const revision by timholy · Pull Request #894 · timholy/Revise.jl · GitHub

For a long while there have been ways to “fake” struct revision by putting things into temporary modules. Pluto.jl can do that for instance and there are other helper packages for stuff like that.

A few months ago, Keno implemented the necessary tracking capabilities in core julia (up until then only method redefinition was tracking in core julia). Support in Revise.jl is trailing a bit, given that this is a big undertaking.

5 Likes

Example of it working, just not automated with Revise yet:

❯ julia +1.11 # installed with juliaup

julia> struct A a::Int end

julia> struct A a::Float64 end
ERROR: invalid redefinition of type A
Stacktrace:
 [1] top-level scope
   @ REPL[2]:1
❯ julia +beta # installed with juliaup

julia> struct A a::Int end

julia> struct A a::Float64 end

5 Likes

Would love if a blogpost can be written about the history of this.

3 Likes

The thing I love the most about this is that Julia simultaneously became more dynamic and more static. Within a given world age, you no longer need to worry about constants changing behind your back. But then there’s a very well-defined dynamic behavior — invalidation & recompilation — when you do change them. Even better, the printing of objects makes it evident:

julia> struct A a::Float64 end

julia> const foo = A(2.3)
A(2.3)

julia> struct A a::Int end

julia> foo
@world(A, 40778:40781)(2.3)

julia> const foo = A(4)
A(4)

julia> dump(@world(A, 40781))
struct @world(A, 40778:40781) <: Any
  a::Float64

julia> dump(@world(A, 40782))
struct A <: Any
  a::Int64

julia> foo
A(4)

julia> @world(foo, 40781)
@world(A, 40778:40781)(2.3)
18 Likes

Is this in 1.12 beta1 ? I can’t see anything related in the news

1 Like