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

DEC: support functions with more then 62 arguments (copy #1727) #1730

Merged
merged 5 commits into from
Mar 27, 2021

Commits on Mar 27, 2021

  1. clash-dev: enable DEBUG flag

    (cherry picked from commit f7a4325)
    leonschoorl authored and mergify-bot committed Mar 27, 2021
    Configuration menu
    Copy the full SHA
    ede1e7e View commit details
    Browse the repository at this point in the history
  2. DEC: Don't generates pointless cases for shared global arguments

    Given
        topEntity :: Bool -> Bool -> Bool
        topEntity b x = case b of
            False -> f x False
            True  -> f x True
    
        f :: Eq a => a -> a -> Bool
        f = ...
    
    DEC would do:
        Changes when applying rewrite to:
        case b[LocalId] of
          False  ->
            f[GlobalId] @Bool $fEqBool[GlobalId] x[LocalId]
              False
          True  ->
            f[GlobalId] @Bool $fEqBool[GlobalId] x[LocalId]
              True
        Result:
        letrec
          c$fOut :: Bool
          = f[GlobalId] @Bool
              (case b[LocalId] of
                 False  ->
                   $fEqBool[GlobalId]
                 True  ->
                   $fEqBool[GlobalId])
              x[LocalId]
              (case b[LocalId] of
                 False  ->
                   False
                 True  ->
                   True)
        in case b[LocalId] of
             False  ->
               c$fOut[LocalId]
             True  ->
               c$fOut[LocalId]
    
    Because both f's gets the same x argument, in the result the single f
    gets the x directly.
    But this sharing only worked for LocalId's, for GlobalId's like the
    $fEqBool(Eq class dictionary), but clash generates as argument to the
    new f:
              (case b[LocalId] of
                 False  ->
                   $fEqBool[GlobalId]
                 True  ->
                   $fEqBool[GlobalId])
    
    With this patch we now generate:
        letrec
          c$fOut :: Bool
          = f[GlobalId] @Bool $fEqBool[GlobalId]
              x[LocalId]
              (case b[LocalId] of
                 False  ->
                   False
                 True  ->
                   True)
        in case b[LocalId] of
             False  ->
               c$fOut[LocalId]
             True  ->
               c$fOut[LocalId]
    
    (cherry picked from commit c5be58b)
    leonschoorl authored and mergify-bot committed Mar 27, 2021
    Configuration menu
    Copy the full SHA
    9776326 View commit details
    Browse the repository at this point in the history
  3. Don't hardcode the max tuple size

    GHC's max tuple size has been 62 for a long time, but on master it is now increased to 64.
    
    https://gitlab.haskell.org/ghc/ghc/-/commit/6e5a83bb6052f9e251a54026294c87a5bd650c93?merge_request_iid=4146
    (cherry picked from commit 2c88533)
    leonschoorl authored and mergify-bot committed Mar 27, 2021
    Configuration menu
    Copy the full SHA
    e5c9066 View commit details
    Browse the repository at this point in the history
  4. DEC: Split out mkTup, mkTupTy and mkTupSelector

    So in the next commit we can easily make wrappers around them for big tuples (>62 elements).
    
    (cherry picked from commit d2df1b2)
    leonschoorl authored and mergify-bot committed Mar 27, 2021
    Configuration menu
    Copy the full SHA
    5abd68a View commit details
    Browse the repository at this point in the history
  5. DEC: support functions with more then 62 arguments

    All (non-shared) arguments to DEC'ed functions are combined into tuples,
    so they can all be defined via a single case expression.
    But because GHC's tuples are limited to 62 elements, this fails for functions with many arguments.
    
    This patch uses GHC's mkChunkified to create (2-levels of) nested tuples for a maximum of 62^2=3844 arguments.
    
    Fixes #1669
    
    (cherry picked from commit 28b9a57)
    leonschoorl authored and mergify-bot committed Mar 27, 2021
    Configuration menu
    Copy the full SHA
    7690def View commit details
    Browse the repository at this point in the history