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

Conversation

mergify[bot]
Copy link

@mergify mergify bot commented Mar 27, 2021

This is an automatic copy of pull request #1727 done by Mergify.


Mergify commands and options

More conditions and actions can be found in the documentation.

You can also trigger Mergify actions by commenting on this pull request:

  • @Mergifyio refresh will re-evaluate the rules
  • @Mergifyio rebase will rebase this PR on its base branch
  • @Mergifyio update will merge the base branch into this PR
  • @Mergifyio backport <destination> will backport this PR on <destination> branch

Additionally, on Mergify dashboard you can:

  • look at your merge queues
  • generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.io/

(cherry picked from commit f7a4325)
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)
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)
So in the next commit we can easily make wrappers around them for big tuples (>62 elements).

(cherry picked from commit d2df1b2)
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)
@christiaanb christiaanb merged commit efb815b into 1.4 Mar 27, 2021
@christiaanb christiaanb deleted the mergify/copy/1.4/pr-1727 branch March 27, 2021 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants