How does `Base.ImmutableDict` work internally?

I just discovered Base.ImmutableDict, and it appears to be a very strange type. I get the core concept of a linked list of key-value pairs. But the reference to the next node is of type Base.ImmutableDict{K, V}. How can an immutable struct contain another instance of itself?

I tried defining a similar struct in the REPL, and to my shock, it was allowed. But I still can’t figure out how to construct an instance of it. The sizeof() my struct implies that the self-referential field is 8 bytes, which might mean that it’s stored as a pointer.

Can self-referential immutable structs actually be utilized in normal Julia code, or is there some compiler magic involved with this type?

https://docs.julialang.org/en/v1/manual/constructors/#Incomplete-Initialization

2 Likes