WeakMaps question ?

Mark S. Miller erights at google.com
Sat Nov 12 05:52:14 PST 2011


On Fri, Nov 11, 2011 at 3:55 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:
[...]

> Yes, but this isn't just an implementation decision. The primitive values
> have existential identify (my term,  philosophers may mean something else).
>  All such values conceptually exist for all time, regardless of whether or
> not an instance of a particular value is actually instantiated an any
> particular point in time.


I agree, but I would explain the distinction differently. In a memory safe
object language such as JS with GC and without destructors or finalizers, I
would say that all values, both primitives and objects, "conceptually exist
for all time, regardless of whether or not an instance of a particular
value is actually instantiated an any particular point in time." However,
some values may no longer be reachable from live computation -- which is
why the garbage collector can deallocate these unobservably (modulo
resource usage and limits).

Rather, I would divide up values into those which
1) have an *unforgeable* unique identity associated with a unique act of
creation. Direct access to these are "access limited" rather than
"knowledge limited" -- you only obtain direct access if something that
already has direct access to it (and to you) gives it to you.
2) are *synthesizable* from the identical ingredients. Access to a
synthesizable object is "knowledge limited" rather than "access limited" --
given its ingredients (which may themselves be unforgeable), you can obtain
access to a synthesizable object if you know or can guess how these
ingredients are arranged.

In JS today, this distinction is even clearer because all synthesizable
values are fully synthesizable all the way down -- they contain no
unforgeable ingredients. I refer to fully synthesizable values as "data".
By contrast, given unforgeable x and y, in HOBD, #[x, y] would be a
synthesizable pair of x and y, which is synthesizable by anyone with direct
access to x and y and the knowledge to arrange them again in this manner.
This pair is synthesizable but not fully synthesizable.

A WeakMap preserves this unobservability by only collecting associations
whose keys can no longer be reached from live computation. The garbage
collector cannot feasibly determine that a fully synthesizable value will
not be re-synthesized, and so could never collect these. Since the
*purpose* of a WeakMap is to avoid unbounded leakage, were it to accept
fully synthesizable keys, it would need to retain those associations
forever, creating a hard to debug infinite memory leak. Better to reject
quickly, to give an informative diagnostic early.

An open question is whether WeakMaps should accept synthesizable containers
of unforgeable ingredients, such as the above #[x, y], since it knows that,
for example, once x is no longer reachable, then it is no longer possible
to re-synthesize #[x, y]. Once x has been collected, this pair has also
become unreachable. We'll cross that bridge when we come to HOBD.

-- 
    Cheers,
    --MarkM
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111112/9b2fa4e7/attachment-0001.html>


More information about the es-discuss mailing list