Skip to content

DEC transformation creates bad case-expressions for sum-types #2770

Open
@christiaanb

Description

@christiaanb

Seen in the wild:

DEC {97}
Changes when applying rewrite to:
case ds8[7566047373982590768][LocalId] of
  Data.Either.Left[3891110078048108619]
    (k1[7566047373982590771] :: Punctuate.Punctuate[8214565720323801001]
                                  3
                                  "
                                  "
                                  (Punctuate.Punctuate[8214565720323801001]
                                     3
                                     " "
                                     (Punctuate.Punctuate[8214565720323801001]
                                        3
                                        " "
                                        (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                           1)))) ->
    case k1[7566047373982590771][LocalId] of
      GHC.Tuple.(,)[3963167672086036486]
        (x2[6341068275337658382] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                      3)
          (wild4[6341068275337658383] :: Data.Either.Either[3674937295934324904]
                                           (Punctuate.Punctuate[8214565720323801001]
                                              3
                                              " "
                                              (Punctuate.Punctuate[8214565720323801001]
                                                 3
                                                 " "
                                                 (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                    1)))
                                           (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                              (Punctuate.SymbolLength'[8214565720323801006]
                                                 (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                    "
                                                    ")))) ->
        case wild4[6341068275337658383][LocalId] of
          Data.Either.Left[3891110078048108619]
            (ds3[6341068275337658385] :: Punctuate.Punctuate[8214565720323801001]
                                           3
                                           " "
                                           (Punctuate.Punctuate[8214565720323801001]
                                              3
                                              " "
                                              (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                 1))) ->
            case ds3[6341068275337658385][LocalId] of
              GHC.Tuple.(,)[3963167672086036486]
                (x2[6341068275337658387] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                              3)
                  (wild4[6341068275337658388] :: Data.Either.Either[3674937295934324904]
                                                   (Punctuate.Punctuate[8214565720323801001]
                                                      3
                                                      " "
                                                      (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                         1))
                                                   (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                      (Punctuate.SymbolLength'[8214565720323801006]
                                                         (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                            " ")))) ->
                case wild4[6341068275337658388][LocalId] of
                  Data.Either.Left[3891110078048108619]
                    (ds4[6341068275337658390] :: Punctuate.Punctuate[8214565720323801001]
                                                   3
                                                   " "
                                                   (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                      1)) ->
                    case ds4[6341068275337658390][LocalId] of
                      GHC.Tuple.(,)[3963167672086036486]
                        (wild5[6341068275337658392] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                         3)
                          (ds5[6341068275337658393] :: Data.Either.Either[3674937295934324904]
                                                         (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                            1)
                                                         (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                            (Punctuate.SymbolLength'[8214565720323801006]
                                                               (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                                  " ")))) ->
                        case ds5[6341068275337658393][LocalId] of
                          Data.Either.Left[3891110078048108619]
                            (wild2[6341068275337658395] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                             1) ->
                            GHC.Maybe.Nothing[3891110078048108565]
                              @GHC.Types.Char[3674937295934324752]
                          Data.Either.Right[3891110078048108622]
                            (i[7566047373982590773] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                         (Punctuate.SymbolLength'[8214565720323801006]
                                                            (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                               " "))) ->
                            GHC.Maybe.Just[3891110078048108568]
                              @GHC.Types.Char[3674937295934324752]
                              (Sudoku.$s$fSymbolLength_'Just_$csymbolAt[8214565720323943138][GlobalId]
                                 @(Data.Proxy.Proxy[8214565720323786477]
                                     (GHC.Maybe.Maybe[3674937295934324792]
                                        (GHC.Types.Char[3674937295934324752],
                                        GHC.Types.Symbol[3674937295934325536])))
                                 (Data.Proxy.Proxy[8214565720323788813]
                                    @(GHC.Maybe.Maybe[3674937295934324792]
                                        (GHC.Types.Char[3674937295934324752],
                                        GHC.Types.Symbol[3674937295934325536]))
                                    @(GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                        " "))
                                 i[7566047373982590773][LocalId])
                  Data.Either.Right[3891110078048108622]
                    (i[7566047373982590773] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                 (Punctuate.SymbolLength'[8214565720323801006]
                                                    (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                       " "))) ->
                    GHC.Maybe.Just[3891110078048108568]
                      @GHC.Types.Char[3674937295934324752]
                      (Sudoku.$s$fSymbolLength_'Just_$csymbolAt[8214565720323943138][GlobalId]
                         @(Data.Proxy.Proxy[8214565720323786477]
                             (GHC.Maybe.Maybe[3674937295934324792]
                                (GHC.Types.Char[3674937295934324752],
                                GHC.Types.Symbol[3674937295934325536])))
                         (Data.Proxy.Proxy[8214565720323788813]
                            @(GHC.Maybe.Maybe[3674937295934324792]
                                (GHC.Types.Char[3674937295934324752],
                                GHC.Types.Symbol[3674937295934325536]))
                            @(GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                " "))
                         i[7566047373982590773][LocalId])
          Data.Either.Right[3891110078048108622]
            (i[7566047373982590773] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                         (Punctuate.SymbolLength'[8214565720323801006]
                                            (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                               "
                                               "))) ->
            GHC.Maybe.Just[3891110078048108568]
              @GHC.Types.Char[3674937295934324752]
              (Sudoku.$s$fSymbolLength_'Just_$csymbolAt5[8214565720323943144][GlobalId]
                 @(Data.Proxy.Proxy[8214565720323786477]
                     (GHC.Maybe.Maybe[3674937295934324792]
                        (GHC.Types.Char[3674937295934324752],
                        GHC.Types.Symbol[3674937295934325536])))
                 (Data.Proxy.Proxy[8214565720323788813]
                    @(GHC.Maybe.Maybe[3674937295934324792]
                        (GHC.Types.Char[3674937295934324752],
                        GHC.Types.Symbol[3674937295934325536]))
                    @(GHC.TypeLits.UnconsSymbol[3674937295934325564]
                        "
                        "))
                 i[7566047373982590773][LocalId])
  Data.Either.Right[3891110078048108622]
    (i[7566047373982590773] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                 (Punctuate.SymbolLength'[8214565720323801006]
                                    (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                       "
                                       "))) ->
    GHC.Maybe.Just[3891110078048108568]
      @GHC.Types.Char[3674937295934324752]
      (Sudoku.$s$fSymbolLength_'Just_$csymbolAt5[8214565720323943144][GlobalId]
         @(Data.Proxy.Proxy[8214565720323786477]
             (GHC.Maybe.Maybe[3674937295934324792]
                (GHC.Types.Char[3674937295934324752],
                GHC.Types.Symbol[3674937295934325536])))
         (Data.Proxy.Proxy[8214565720323788813]
            @(GHC.Maybe.Maybe[3674937295934324792]
                (GHC.Types.Char[3674937295934324752],
                GHC.Types.Symbol[3674937295934325536]))
            @(GHC.TypeLits.UnconsSymbol[3674937295934325564]
                "
                "))
         i[7566047373982590773][LocalId])
Result:
letrec
  c$$s$fSymbolLength_'Just_$csymbolAt5Out[5056] :: GHC.Types.Char[3674937295934324752]
  = Sudoku.$s$fSymbolLength_'Just_$csymbolAt5[8214565720323943144][GlobalId]
      @(Data.Proxy.Proxy[8214565720323786477]
          (GHC.Maybe.Maybe[3674937295934324792]
             (GHC.Types.Char[3674937295934324752],
             GHC.Types.Symbol[3674937295934325536])))
      (Data.Proxy.Proxy[8214565720323788813]
         @(GHC.Maybe.Maybe[3674937295934324792]
             (GHC.Types.Char[3674937295934324752],
             GHC.Types.Symbol[3674937295934325536]))
         @(GHC.TypeLits.UnconsSymbol[3674937295934325564]
             "
             "))
      (case ds8[7566047373982590768][LocalId] of
         Data.Either.Left[3891110078048108619]
           (k1[7566047373982590771] :: Punctuate.Punctuate[8214565720323801001]
                                         3
                                         "
                                         "
                                         (Punctuate.Punctuate[8214565720323801001]
                                            3
                                            " "
                                            (Punctuate.Punctuate[8214565720323801001]
                                               3
                                               " "
                                               (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                  1)))) ->
           case k1[7566047373982590771][LocalId] of
             GHC.Tuple.(,)[3963167672086036486]
               (x2[6341068275337658382] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                             3)
                 (wild4[6341068275337658383] :: Data.Either.Either[3674937295934324904]
                                                  (Punctuate.Punctuate[8214565720323801001]
                                                     3
                                                     " "
                                                     (Punctuate.Punctuate[8214565720323801001]
                                                        3
                                                        " "
                                                        (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                           1)))
                                                  (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                     (Punctuate.SymbolLength'[8214565720323801006]
                                                        (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                           "
                                                           ")))) ->
               case wild4[6341068275337658383][LocalId] of
                 Data.Either.Right[3891110078048108622]
                   (i[7566047373982590773] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                (Punctuate.SymbolLength'[8214565720323801006]
                                                   (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                      "
                                                      "))) ->
                   i[7566047373982590773][LocalId]
         Data.Either.Right[3891110078048108622]
           (i[7566047373982590773] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                        (Punctuate.SymbolLength'[8214565720323801006]
                                           (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                              "
                                              "))) ->
           i[7566047373982590773][LocalId])
in case ds8[7566047373982590768][LocalId] of
     Data.Either.Left[3891110078048108619]
       (k1[7566047373982590771] :: Punctuate.Punctuate[8214565720323801001]
                                     3
                                     "
                                     "
                                     (Punctuate.Punctuate[8214565720323801001]
                                        3
                                        " "
                                        (Punctuate.Punctuate[8214565720323801001]
                                           3
                                           " "
                                           (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                              1)))) ->
       case k1[7566047373982590771][LocalId] of
         GHC.Tuple.(,)[3963167672086036486]
           (x2[6341068275337658382] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                         3)
             (wild4[6341068275337658383] :: Data.Either.Either[3674937295934324904]
                                              (Punctuate.Punctuate[8214565720323801001]
                                                 3
                                                 " "
                                                 (Punctuate.Punctuate[8214565720323801001]
                                                    3
                                                    " "
                                                    (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                       1)))
                                              (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                 (Punctuate.SymbolLength'[8214565720323801006]
                                                    (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                       "
                                                       ")))) ->
           case wild4[6341068275337658383][LocalId] of
             Data.Either.Left[3891110078048108619]
               (ds3[6341068275337658385] :: Punctuate.Punctuate[8214565720323801001]
                                              3
                                              " "
                                              (Punctuate.Punctuate[8214565720323801001]
                                                 3
                                                 " "
                                                 (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                    1))) ->
               case ds3[6341068275337658385][LocalId] of
                 GHC.Tuple.(,)[3963167672086036486]
                   (x2[6341068275337658387] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                 3)
                     (wild4[6341068275337658388] :: Data.Either.Either[3674937295934324904]
                                                      (Punctuate.Punctuate[8214565720323801001]
                                                         3
                                                         " "
                                                         (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                            1))
                                                      (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                         (Punctuate.SymbolLength'[8214565720323801006]
                                                            (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                               " ")))) ->
                   case wild4[6341068275337658388][LocalId] of
                     Data.Either.Left[3891110078048108619]
                       (ds4[6341068275337658390] :: Punctuate.Punctuate[8214565720323801001]
                                                      3
                                                      " "
                                                      (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                         1)) ->
                       case ds4[6341068275337658390][LocalId] of
                         GHC.Tuple.(,)[3963167672086036486]
                           (wild5[6341068275337658392] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                            3)
                             (ds5[6341068275337658393] :: Data.Either.Either[3674937295934324904]
                                                            (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                               1)
                                                            (Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                               (Punctuate.SymbolLength'[8214565720323801006]
                                                                  (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                                     " ")))) ->
                           case ds5[6341068275337658393][LocalId] of
                             Data.Either.Left[3891110078048108619]
                               (wild2[6341068275337658395] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                                1) ->
                               GHC.Maybe.Nothing[3891110078048108565]
                                 @GHC.Types.Char[3674937295934324752]
                             Data.Either.Right[3891110078048108622]
                               (i[7566047373982590773] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                            (Punctuate.SymbolLength'[8214565720323801006]
                                                               (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                                  " "))) ->
                               GHC.Maybe.Just[3891110078048108568]
                                 @GHC.Types.Char[3674937295934324752]
                                 (Sudoku.$s$fSymbolLength_'Just_$csymbolAt[8214565720323943138][GlobalId]
                                    @(Data.Proxy.Proxy[8214565720323786477]
                                        (GHC.Maybe.Maybe[3674937295934324792]
                                           (GHC.Types.Char[3674937295934324752],
                                           GHC.Types.Symbol[3674937295934325536])))
                                    (Data.Proxy.Proxy[8214565720323788813]
                                       @(GHC.Maybe.Maybe[3674937295934324792]
                                           (GHC.Types.Char[3674937295934324752],
                                           GHC.Types.Symbol[3674937295934325536]))
                                       @(GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                           " "))
                                    i[7566047373982590773][LocalId])
                     Data.Either.Right[3891110078048108622]
                       (i[7566047373982590773] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                                    (Punctuate.SymbolLength'[8214565720323801006]
                                                       (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                          " "))) ->
                       GHC.Maybe.Just[3891110078048108568]
                         @GHC.Types.Char[3674937295934324752]
                         (Sudoku.$s$fSymbolLength_'Just_$csymbolAt[8214565720323943138][GlobalId]
                            @(Data.Proxy.Proxy[8214565720323786477]
                                (GHC.Maybe.Maybe[3674937295934324792]
                                   (GHC.Types.Char[3674937295934324752],
                                   GHC.Types.Symbol[3674937295934325536])))
                            (Data.Proxy.Proxy[8214565720323788813]
                               @(GHC.Maybe.Maybe[3674937295934324792]
                                   (GHC.Types.Char[3674937295934324752],
                                   GHC.Types.Symbol[3674937295934325536]))
                               @(GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                   " "))
                            i[7566047373982590773][LocalId])
             Data.Either.Right[3891110078048108622]
               (i[7566047373982590773] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                            (Punctuate.SymbolLength'[8214565720323801006]
                                               (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                                  "
                                                  "))) ->
               GHC.Maybe.Just[3891110078048108568]
                 @GHC.Types.Char[3674937295934324752]
                 c$$s$fSymbolLength_'Just_$csymbolAt5Out[5056][LocalId]
     Data.Either.Right[3891110078048108622]
       (i[7566047373982590773] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                    (Punctuate.SymbolLength'[8214565720323801006]
                                       (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                          "
                                          "))) ->
       GHC.Maybe.Just[3891110078048108568]
         @GHC.Types.Char[3674937295934324752]
         c$$s$fSymbolLength_'Just_$csymbolAt5Out[5056][LocalId]

which later leads to:

<no location info>: error:
    Clash error call:
    scrutinise: case Data.Either.Left[3891110078048108619]
           @(Punctuate.Punctuate[8214565720323801001]
               3
               " "
               (Punctuate.Punctuate[8214565720323801001]
                  3
                  " "
                  (Clash.Sized.Internal.Index.Index[8214565720323788476]
                     1)))
           @(Clash.Sized.Internal.Index.Index[8214565720323788476]
               2)
           (GHC.Tuple.(,)[3963167672086036486]
              @(Clash.Sized.Internal.Index.Index[8214565720323788476]
                  3)
              @(Data.Either.Either[3674937295934324904]
                  (Punctuate.Punctuate[8214565720323801001]
                     3
                     " "
                     (Clash.Sized.Internal.Index.Index[8214565720323788476]
                        1))
                  (Clash.Sized.Internal.Index.Index[8214565720323788476]
                     1))
              (Clash.Sized.Internal.Index.fromInteger# @3
                 (GHC.Num.Natural.NS 3##)
                 (GHC.Num.Integer.IS 0#))
              (Data.Either.Left[3891110078048108619]
                 @(Punctuate.Punctuate[8214565720323801001]
                     3
                     " "
                     (Clash.Sized.Internal.Index.Index[8214565720323788476]
                        1))
                 @(Clash.Sized.Internal.Index.Index[8214565720323788476]
                     1)
                 (GHC.Tuple.(,)[3963167672086036486]
                    @(Clash.Sized.Internal.Index.Index[8214565720323788476]
                        3)
                    @(Data.Either.Either[3674937295934324904]
                        (Clash.Sized.Internal.Index.Index[8214565720323788476]
                           1)
                        (Clash.Sized.Internal.Index.Index[8214565720323788476]
                           1))
                    (Clash.Sized.Internal.Index.fromInteger# @3
                       (GHC.Num.Natural.NS 3##)
                       (GHC.Num.Integer.IS 0#))
                    (Data.Either.Left[3891110078048108619]
                       @(Clash.Sized.Internal.Index.Index[8214565720323788476]
                           1)
                       @(Clash.Sized.Internal.Index.Index[8214565720323788476]
                           1)
                       (Clash.Sized.Internal.Index.fromInteger# @1
                          (GHC.Num.Natural.NS 1##)
                          (GHC.Num.Integer.IS 0#)))))) of
      Data.Either.Right[3891110078048108622]
        (i[7566047373982590773] :: Clash.Sized.Internal.Index.Index[8214565720323788476]
                                     (Punctuate.SymbolLength'[8214565720323801006]
                                        (GHC.TypeLits.UnconsSymbol[3674937295934325564]
                                           "
                                           "))) ->
        i[7566047373982590773][LocalId]
    CallStack (from HasCallStack):
      error, called at src-ghc/Clash/GHC/Evaluator.hs:469:3 in clash-ghc-1.8.1-1880DmzRExrBY11Ge7sKQs:Clash.GHC.Evaluator

The DEC transformation should add a default case alternative for alternatives in which the lifted out function is not used.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions