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

Fix fromListWithDef divergence #42

Merged
merged 2 commits into from
Apr 12, 2024
Merged

Fix fromListWithDef divergence #42

merged 2 commits into from
Apr 12, 2024

Commits on Apr 12, 2024

  1. Configuration menu
    Copy the full SHA
    113c541 View commit details
    Browse the repository at this point in the history
  2. #39 Fix fromListWithDef divergence

    fromListWithDef diverges when passed an infinite list, for the following
    reasons:
    
    Reason 1:
    
      * fromListWithDef calls Data.Primitive.Array.fromListN (bits + 1).
        fromListN requires that the length of the list that is passed to it
        is exactly bits + 1. To ensure this, it forces the spine of the list
        that is passed to it.
    
      * The list that is passed to fromListN is generated by go0, which
        calls go. When xs is infinite, go k xs will be infinite. Therefore,
        fromListN will throw an error since go0 yields a list longer than
        bits + 1.
    
    Even if we take the first bits + 1 elements of go0 before passing to
    fromListN, there is another problem.
    
    Reason 2:
    
      * As fromListN forces the spine, it will compute go 0 xs0, go 1 xs1,
        ..., go 63 xs63, for some xs0, xs1, ..., xs63.
    
      * This in turn requires computing measureOff (2^0) xs0,
        measureOff (2^1) x1, ..., measureOff (2^63) x63, which is
        essentially divergent.
    
    To avoid these problems, we
    
      * Add a check in go to break recursion and ensure that the list that
        is passed to fromListN has length (bits + 1).
    
      * Rearrange how we compute go, so that measureOff is not forced while
        forcing the spine of go.
    pgujjula committed Apr 12, 2024
    Configuration menu
    Copy the full SHA
    b029c40 View commit details
    Browse the repository at this point in the history