[Issue 5057] std.variant.Algebraic-aware GC

d-bugmail at puremagic.com d-bugmail at puremagic.com
Fri Oct 22 05:12:55 PDT 2010


http://d.puremagic.com/issues/show_bug.cgi?id=5057



--- Comment #4 from nfxjfg at gmail.com 2010-10-22 05:12:09 PDT ---
(In reply to comment #2)
> I don't see how a class may replace an union.

Variant/Algebraic has to store its data somewhere. Currently it uses some
horrible hack to store it inline of the struct. All problems would be solved
immediately by allocating a VariantStorage object on the heap instead to store
the data.

D2 already relies that much on heap allocation that this shouldn't be a
problem. Think of hidden memory allocation of closures, or consider bug 4397.

On the other hand, adding an onScan hook to the current GC would probably be a
big deal. Just think about recursive data structures: you have to honor nested
structs, static arrays, dynamic arrays. How would this be efficiently
implemented?

On the other hand, one could just agree to always store a TypeInfo which each
memory block, and let the compiler generate an optional noScan method.
Depending on the implementation details, this could be reasonably efficient,
but would take its toll on the common case; see discussion in issue 3463.

Anyway, this is probably a non-issue, because nobody would seriously consider
to use "Algebraic" for the same purpose as algebraic types usually are used in
functional programming languages. For that it just sucks too much. It would be
different if D would actually support such data types natively.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list