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

Unsafe operations for array uninitialization and raw arrays #207

Merged
merged 27 commits into from
Oct 21, 2017

Commits on Oct 7, 2017

  1. Configuration menu
    Copy the full SHA
    612eede View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    898d3a6 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    8663034 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    eec191d View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    ee9d072 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    884d7ef View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    1c0b24e View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    5e4b00d View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    37c73d7 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    2ab5d9e View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    52d266c View commit details
    Browse the repository at this point in the history
  12. Configuration menu
    Copy the full SHA
    d3569db View commit details
    Browse the repository at this point in the history

Commits on Oct 10, 2017

  1. Add Array_uninit: 'a array * SeqInt.int -> unit primitive

    The Array_uninit primitive sets all objptrs in the element at the
    given index to a bogus non-objptr value (0wx1).  One motivation for
    this primitive is to support space-efficient polymorphic resizeable
    arrays.  When shrinking a resizeable array, we would like to "NULL"
    out the elements that are no longer part of the logical array, in
    order to avoid a (logical) space leak.
    MatthewFluet committed Oct 10, 2017
    Configuration menu
    Copy the full SHA
    946385f View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    1672c55 View commit details
    Browse the repository at this point in the history

Commits on Oct 11, 2017

  1. Configuration menu
    Copy the full SHA
    1b87b4b View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    098d606 View commit details
    Browse the repository at this point in the history

Commits on Oct 12, 2017

  1. Configuration menu
    Copy the full SHA
    51fc022 View commit details
    Browse the repository at this point in the history

Commits on Oct 16, 2017

  1. Update Useless optimization to handle Array_uninit primitive

    It is correct to not special case the Array_uninit primitive, but
    doing so inhibits the Useless optimization.
    MatthewFluet committed Oct 16, 2017
    Configuration menu
    Copy the full SHA
    295f9cd View commit details
    Browse the repository at this point in the history
  2. Add Array_uninitIsNop: 'a array -> bool primitive

    The Array_uninitIsNop primitive answers if the Array_uninit primitive
    applied to the same array would be a nop (i.e., if the array has no
    objptrs in the elements).  This can be used to skip a
    bulk-Array_uninit loop when it is known that the Array_uninit
    operations would be nops.
    
    The primitive is translated to a constant by toRssa.
    
    It would be possible to introduce SSA and SSA2 optimizations that
    simplified Array_uninitIsNop and Array_uninit when it is clear that
    the array will never have objptrs in the elements.  In particular,
    while an `(int64 * int64) array` (in SSA) might become an `int64
    array` (due to Useless), the reverse can never happen.  Similarly,
    while an `((int64 * int64)) array` (in SSA2) might become an `(int64 *
    int64) array` (due to DeepFlatten), the reverse can never happen.
    
    Also, RSSA shrink does not seem to simplify the
    
        switch {test = 0x0: Word32, default = None, cases = ((0x0, L_1277), (0x1, L_1276))}
    
    that results from replacing Array_uninitIsNop with a constant.
    MatthewFluet committed Oct 16, 2017
    Configuration menu
    Copy the full SHA
    426baa1 View commit details
    Browse the repository at this point in the history
  3. Fix code formatting

    MatthewFluet committed Oct 16, 2017
    Configuration menu
    Copy the full SHA
    af42741 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    1f08772 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    9853172 View commit details
    Browse the repository at this point in the history
  6. Add Array_allocRaw: SeqIndex.int -> 'a array primitive

    The `Array_allocRaw` primitive allocates an array, but with a header
    that indicates that the array has no objptrs.  A related
    `Array_toArray` primitive updates the header of an `Array_allocRaw`
    primitive to reveal the objptrs.  Between the allocation and the cast,
    all elements of the array must be uninitialized (setting all objptrs
    in elements to a bogus non-objptr value (0wx1)).
    
    One motiviation for this primitive is that, in a parallel setting, the
    uninitialization of an array can be a sequential bottleneck.  The
    `Array_allocRaw` is a constant time operation and the subsequent
    `Array_uninit` operations can be performed in parallel.
    
    Note that it is not safe to write non-bogus objptrs into a raw array.
    Because the raw array's header indicates that the array has no
    objptrs, non-bogus objptrs written to the array will not be traced or
    updated during a garbage collection.
    
    In the future, we may consider eliminating `Array_alloc` (the non-raw
    array allocation) and moving the uninitialization loop from the
    runtime to SML.  To do so, though, we should ensure that arrays that
    do not need uninitialization are optimized early in the optimization
    pipeline.
    MatthewFluet committed Oct 16, 2017
    Configuration menu
    Copy the full SHA
    580da00 View commit details
    Browse the repository at this point in the history

Commits on Oct 20, 2017

  1. Configuration menu
    Copy the full SHA
    e5206bb View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    81bb827 View commit details
    Browse the repository at this point in the history

Commits on Oct 21, 2017

  1. Fix latent bugs in ConstantProgagation with Array_allocRaw

    Currently, no arrays are globalized; see MLton#206.
    
    However, if "small" arrays were globalized, then an
    `Array_allocRaw[t] (l)` would be globalized as `Array_alloc[t] (l)`
    and the `Array_toArray` (that casts the raw array to a normal array)
    would be dropped.
    
    Now, the `Array` abstract value tracks whether the array is raw or
    normal, which is used to generate either `Array_allocRaw` or
    `Array_alloc` if the array is globalized.
    
    Also, `Array_toArray` creates the destination `Array` abstract value
    with `Birth.unknown()`, which prohibits globalization.
    MatthewFluet committed Oct 21, 2017
    Configuration menu
    Copy the full SHA
    5c747df View commit details
    Browse the repository at this point in the history
  2. Merge branch 'master' of github.com:MLton/mlton into array-uninit

    ShareZeroVec only optimizes
    
        val a: t array = Array_alloc[t] (l)
        ...
        val v: t vector = Array_toVector[t] (a)
    
    not
    
        val r: t array = Array_allocRaw[t] (l)
        ...
        val a: t vector = Array_toArray[t] (r)
        ...
        val v: t vector = Array_toVector[t] (a)
    
    The latter is possibly, just requires a more sophisticated analysis to
    connect Array_alloc/Array_allocRaw with Array_toVector.
    MatthewFluet committed Oct 21, 2017
    Configuration menu
    Copy the full SHA
    c8c4ef6 View commit details
    Browse the repository at this point in the history