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

union*: More unboxing #376

Merged
merged 4 commits into from
Mar 15, 2022
Merged

union*: More unboxing #376

merged 4 commits into from
Mar 15, 2022

Conversation

sjakobi
Copy link
Member

@sjakobi sjakobi commented Mar 12, 2022

Two nice bits extracted from #230.

Core diff for unionArrayBy:

--- RHS size: {terms: 570, types: 298, coercions: 0, joins: 5/7}
+-- RHS size: {terms: 180, types: 121, coercions: 0, joins: 2/4}
 unionArrayBy [InlPrag=INLINE (sat-args=5)]
   :: forall a.
      (a -> a -> a) -> Bitmap -> Bitmap -> Array a -> Array a -> Array a
 [GblId,
  Arity=5,
- Str=<LCL(C1(L))><1P(L)><1P(L)><LP(L)><LP(L)>,
+ Str=<LCL(C1(L))><1P(L)><1P(L)><1P(L)><1P(L)>,
  Cpr=1,
  Unf=Unf{Src=InlineStable, TopLvl=True, Value=True, ConLike=True,
          WorkFree=True, Expandable=True,
@@ -8123,31 +8123,33 @@ unionArrayBy
       (b2 :: Bitmap)
       (ary1 :: Array a)
       (ary2 :: Array a) ->
+      case b1 of { W# ipv ->
+      case b2 of { W# ipv1 ->
+      case ary1 of { Array ipv2 ->
+      case ary2 of { Array ipv3 ->
       runRW#
         @LiftedRep
         @(Array a)
         (\ (s [OS=OneShot] :: State# RealWorld) ->
-           case b1 of { W# x# ->
-           case b2 of { W# y# ->
            let {
-             x#1 :: Word#
+             b' :: Word#
              [LclId]
-             x#1 = or# x# y# } in
+             b' = or# ipv ipv1 } in
            case newSmallArray#
-                  @a @RealWorld (word2Int# (popCnt# x#1)) (undefinedElem @a) s
+                  @a @RealWorld (word2Int# (popCnt# b')) (undefinedElem @a) s
            of
-           { (# ipv, ipv1 #) ->
+           { (# ipv4, ipv5 #) ->
            let {
              ba :: Word#
              [LclId]
-             ba = and# x# y# } in
+             ba = and# ipv ipv1 } in
            join {
              exit [Dmd=SCS(L)] :: State# RealWorld -> Array a
              [LclId[JoinId(1)], Arity=1, Str=<L>]
              exit (w [OS=OneShot] :: State# RealWorld)
-               = case unsafeFreezeSmallArray# @RealWorld @a ipv1 w of
-                 { (# ipv2, ipv3 #) ->
-                 Array @a ipv3
+               = case unsafeFreezeSmallArray# @RealWorld @a ipv5 w of
+                 { (# ipv6, ipv7 #) ->
+                 Array @a ipv7
                  } } in
            joinrec {
              $wgo1 [InlPrag=[2], Occ=LoopBreaker, Dmd=SCS(C1(C1(C1(C1(L)))))]
@@ -8158,268 +8160,37 @@ unionArrayBy
                    (ww2 :: Int#)
                    (ww3 :: Word#)
                    (w :: State# RealWorld)
-               = case gtWord# ww3 x#1 of {
+               = case gtWord# ww3 b' of {
                    __DEFAULT ->
-                     case and# x#1 ww3 of {
+                     case and# b' ww3 of {
                        __DEFAULT ->
                          case and# ba ww3 of {
                            __DEFAULT ->
-                             case ary1 of { Array ds1 ->
-                             case indexSmallArray# @a ds1 ww1 of { (# ipv2 #) ->
-                             case ary2 of { Array ds3 ->
-                             case indexSmallArray# @a ds3 ww2 of { (# ipv3 #) ->
-                             case f ipv2 ipv3 of vx { __DEFAULT ->
-                             case writeSmallArray# @RealWorld @a ipv1 ww vx w of s'
+                             case indexSmallArray# @a ipv2 ww1 of { (# ipv6 #) ->
+                             case indexSmallArray# @a ipv3 ww2 of { (# ipv7 #) ->
+                             case f ipv6 ipv7 of vx { __DEFAULT ->
+                             case writeSmallArray# @RealWorld @a ipv5 ww vx w of s'
                              { __DEFAULT ->
-                             joinrec {
-                               $wgo2 [InlPrag=[2], Occ=LoopBreaker, Dmd=SCS(C1(C1(C1(C1(L)))))]
-                                 :: Int# -> Int# -> Int# -> Word# -> State# RealWorld -> Array a
-                               [LclId[JoinId(5)], Arity=5, Str=<L><L><L><L><L>, Unf=OtherCon []]
-                               $wgo2 (ww4 :: Int#)
-                                     (ww5 :: Int#)
-                                     (ww6 :: Int#)
-                                     (ww7 :: Word#)
-                                     (w1 :: State# RealWorld)
-                                 = case gtWord# ww7 x#1 of {
-                                     __DEFAULT ->
-                                       case and# x#1 ww7 of {
-                                         __DEFAULT ->
-                                           case and# ba ww7 of {
-                                             __DEFAULT ->
-                                               case indexSmallArray# @a ds1 ww5 of { (# ipv4 #) ->
-                                               case indexSmallArray# @a ds3 ww6 of { (# ipv5 #) ->
-                                               case f ipv4 ipv5 of vx1 { __DEFAULT ->
-                                               case writeSmallArray# @RealWorld @a ipv1 ww4 vx1 w1
-                                               of s'1
-                                               { __DEFAULT ->
-                                               jump $wgo2
-                                                 (+# ww4 1#)
-                                                 (+# ww5 1#)
-                                                 (+# ww6 1#)
-                                                 (uncheckedShiftL# ww7 1#)
-                                                 s'1
-                                               }
-                                               }
-                                               }
-                                               };
-                                             0## ->
-                                               case and# x# ww7 of {
-                                                 __DEFAULT ->
-                                                   case indexSmallArray# @a ds1 ww5 of
-                                                   { (# ipv4 #) ->
-                                                   case writeSmallArray#
-                                                          @RealWorld @a ipv1 ww4 ipv4 w1
-                                                   of s'1
-                                                   { __DEFAULT ->
-                                                   jump $wgo2
-                                                     (+# ww4 1#)
-                                                     (+# ww5 1#)
-                                                     ww6
-                                                     (uncheckedShiftL# ww7 1#)
-                                                     s'1
-                                                   }
-                                                   };
-                                                 0## ->
-                                                   case indexSmallArray# @a ds3 ww6 of
-                                                   { (# ipv4 #) ->
-                                                   case writeSmallArray#
-                                                          @RealWorld @a ipv1 ww4 ipv4 w1
-                                                   of s'1
-                                                   { __DEFAULT ->
-                                                   jump $wgo2
-                                                     (+# ww4 1#)
-                                                     ww5
-                                                     (+# ww6 1#)
-                                                     (uncheckedShiftL# ww7 1#)
-                                                     s'1
-                                                   }
-                                                   }
-                                               }
-                                           };
-                                         0## -> jump $wgo2 ww4 ww5 ww6 (uncheckedShiftL# ww7 1#) w1
-                                       };
-                                     1# -> jump exit w1
-                                   }; } in
-                             jump $wgo2
+                             jump $wgo1
                                (+# ww 1#) (+# ww1 1#) (+# ww2 1#) (uncheckedShiftL# ww3 1#) s'
                              }
                              }
                              }
-                             }
-                             }
                              };
                            0## ->
-                             case and# x# ww3 of {
+                             case and# ipv ww3 of {
                                __DEFAULT ->
-                                 case ary1 of { Array ds1 ->
-                                 case indexSmallArray# @a ds1 ww1 of { (# ipv2 #) ->
-                                 case writeSmallArray# @RealWorld @a ipv1 ww ipv2 w of s'
+                                 case indexSmallArray# @a ipv2 ww1 of { (# ipv6 #) ->
+                                 case writeSmallArray# @RealWorld @a ipv5 ww ipv6 w of s'
                                  { __DEFAULT ->
-                                 joinrec {
-                                   $wgo2 [InlPrag=[2], Occ=LoopBreaker, Dmd=SCS(C1(C1(C1(C1(L)))))]
-                                     :: Int# -> Int# -> Int# -> Word# -> State# RealWorld -> Array a
-                                   [LclId[JoinId(5)], Arity=5, Str=<L><L><L><L><L>, Unf=OtherCon []]
-                                   $wgo2 (ww4 :: Int#)
-                                         (ww5 :: Int#)
-                                         (ww6 :: Int#)
-                                         (ww7 :: Word#)
-                                         (w1 :: State# RealWorld)
-                                     = case gtWord# ww7 x#1 of {
-                                         __DEFAULT ->
-                                           case and# x#1 ww7 of {
-                                             __DEFAULT ->
-                                               case and# ba ww7 of {
-                                                 __DEFAULT ->
-                                                   case indexSmallArray# @a ds1 ww5 of
-                                                   { (# ipv3 #) ->
-                                                   case ary2 of { Array ds4 ->
-                                                   case indexSmallArray# @a ds4 ww6 of
-                                                   { (# ipv4 #) ->
-                                                   case f ipv3 ipv4 of vx { __DEFAULT ->
-                                                   case writeSmallArray#
-                                                          @RealWorld @a ipv1 ww4 vx w1
-                                                   of s'1
-                                                   { __DEFAULT ->
-                                                   jump $wgo2
-                                                     (+# ww4 1#)
-                                                     (+# ww5 1#)
-                                                     (+# ww6 1#)
-                                                     (uncheckedShiftL# ww7 1#)
-                                                     s'1
-                                                   }
-                                                   }
-                                                   }
-                                                   }
-                                                   };
-                                                 0## ->
-                                                   case and# x# ww7 of {
-                                                     __DEFAULT ->
-                                                       case indexSmallArray# @a ds1 ww5 of
-                                                       { (# ipv3 #) ->
-                                                       case writeSmallArray#
-                                                              @RealWorld @a ipv1 ww4 ipv3 w1
-                                                       of s'1
-                                                       { __DEFAULT ->
-                                                       jump $wgo2
-                                                         (+# ww4 1#)
-                                                         (+# ww5 1#)
-                                                         ww6
-                                                         (uncheckedShiftL# ww7 1#)
-                                                         s'1
-                                                       }
-                                                       };
-                                                     0## ->
-                                                       case ary2 of { Array ds3 ->
-                                                       case indexSmallArray# @a ds3 ww6 of
-                                                       { (# ipv3 #) ->
-                                                       case writeSmallArray#
-                                                              @RealWorld @a ipv1 ww4 ipv3 w1
-                                                       of s'1
-                                                       { __DEFAULT ->
-                                                       jump $wgo2
-                                                         (+# ww4 1#)
-                                                         ww5
-                                                         (+# ww6 1#)
-                                                         (uncheckedShiftL# ww7 1#)
-                                                         s'1
-                                                       }
-                                                       }
-                                                       }
-                                                   }
-                                               };
-                                             0## ->
-                                               jump $wgo2 ww4 ww5 ww6 (uncheckedShiftL# ww7 1#) w1
-                                           };
-                                         1# -> jump exit w1
-                                       }; } in
-                                 jump $wgo2 (+# ww 1#) (+# ww1 1#) ww2 (uncheckedShiftL# ww3 1#) s'
-                                 }
+                                 jump $wgo1 (+# ww 1#) (+# ww1 1#) ww2 (uncheckedShiftL# ww3 1#) s'
                                  }
                                  };
                                0## ->
-                                 case ary2 of { Array ds1 ->
-                                 case indexSmallArray# @a ds1 ww2 of { (# ipv2 #) ->
-                                 case writeSmallArray# @RealWorld @a ipv1 ww ipv2 w of s'
+                                 case indexSmallArray# @a ipv3 ww2 of { (# ipv6 #) ->
+                                 case writeSmallArray# @RealWorld @a ipv5 ww ipv6 w of s'
                                  { __DEFAULT ->
-                                 joinrec {
-                                   $wgo2 [InlPrag=[2], Occ=LoopBreaker, Dmd=SCS(C1(C1(C1(C1(L)))))]
-                                     :: Int# -> Int# -> Int# -> Word# -> State# RealWorld -> Array a
-                                   [LclId[JoinId(5)], Arity=5, Str=<L><L><L><L><L>, Unf=OtherCon []]
-                                   $wgo2 (ww4 :: Int#)
-                                         (ww5 :: Int#)
-                                         (ww6 :: Int#)
-                                         (ww7 :: Word#)
-                                         (w1 :: State# RealWorld)
-                                     = case gtWord# ww7 x#1 of {
-                                         __DEFAULT ->
-                                           case and# x#1 ww7 of {
-                                             __DEFAULT ->
-                                               case and# ba ww7 of {
-                                                 __DEFAULT ->
-                                                   case ary1 of { Array ds3 ->
-                                                   case indexSmallArray# @a ds3 ww5 of
-                                                   { (# ipv3 #) ->
-                                                   case indexSmallArray# @a ds1 ww6 of
-                                                   { (# ipv4 #) ->
-                                                   case f ipv3 ipv4 of vx { __DEFAULT ->
-                                                   case writeSmallArray#
-                                                          @RealWorld @a ipv1 ww4 vx w1
-                                                   of s'1
-                                                   { __DEFAULT ->
-                                                   jump $wgo2
-                                                     (+# ww4 1#)
-                                                     (+# ww5 1#)
-                                                     (+# ww6 1#)
-                                                     (uncheckedShiftL# ww7 1#)
-                                                     s'1
-                                                   }
-                                                   }
-                                                   }
-                                                   }
-                                                   };
-                                                 0## ->
-                                                   case and# x# ww7 of {
-                                                     __DEFAULT ->
-                                                       case ary1 of { Array ds3 ->
-                                                       case indexSmallArray# @a ds3 ww5 of
-                                                       { (# ipv3 #) ->
-                                                       case writeSmallArray#
-                                                              @RealWorld @a ipv1 ww4 ipv3 w1
-                                                       of s'1
-                                                       { __DEFAULT ->
-                                                       jump $wgo2
-                                                         (+# ww4 1#)
-                                                         (+# ww5 1#)
-                                                         ww6
-                                                         (uncheckedShiftL# ww7 1#)
-                                                         s'1
-                                                       }
-                                                       }
-                                                       };
-                                                     0## ->
-                                                       case indexSmallArray# @a ds1 ww6 of
-                                                       { (# ipv3 #) ->
-                                                       case writeSmallArray#
-                                                              @RealWorld @a ipv1 ww4 ipv3 w1
-                                                       of s'1
-                                                       { __DEFAULT ->
-                                                       jump $wgo2
-                                                         (+# ww4 1#)
-                                                         ww5
-                                                         (+# ww6 1#)
-                                                         (uncheckedShiftL# ww7 1#)
-                                                         s'1
-                                                       }
-                                                       }
-                                                   }
-                                               };
-                                             0## ->
-                                               jump $wgo2 ww4 ww5 ww6 (uncheckedShiftL# ww7 1#) w1
-                                           };
-                                         1# -> jump exit w1
-                                       }; } in
-                                 jump $wgo2 (+# ww 1#) ww1 (+# ww2 1#) (uncheckedShiftL# ww3 1#) s'
-                                 }
+                                 jump $wgo1 (+# ww 1#) ww1 (+# ww2 1#) (uncheckedShiftL# ww3 1#) s'
                                  }
                                  }
                              }
@@ -8429,10 +8200,12 @@ unionArrayBy
                    1# -> jump exit w
                  }; } in
            jump $wgo1
-             0# 0# 0# (and# x#1 (int2Word# (negateInt# (word2Int# x#1)))) ipv
-           }
-           }
+             0# 0# 0# (and# b' (int2Word# (negateInt# (word2Int# b')))) ipv4
            })
+      }
+      }
+      }
+      }

Core diff for unionWithKey:

--- RHS size: {terms: 2,313,
-              types: 2,817,
+-- RHS size: {terms: 2,214,
+              types: 2,681,
               coercions: 12,
-              joins: 11/63}
+              joins: 11/59}
 unionWithKey [InlPrag=INLINE (sat-args=1)]
   :: forall k v.
      (Eq k, Hashable k) =>
@@ -11048,94 +10822,40 @@ unionWithKey
                       }
                       };
                     0## ->
-                      case or# dt y# of wild2 {
-                        __DEFAULT ->
-                          runRW#
-                            @LiftedRep
-                            @(HashMap k v)
-                            (\ (s [OS=OneShot] :: State# RealWorld) ->
-                               let {
-                                 ipv :: Int#
-                                 [LclId]
-                                 ipv = sizeofSmallArray# @(HashMap k v) dt1 } in
-                               case newSmallArray#
-                                      @(HashMap k v)
-                                      @RealWorld
-                                      (+# ipv 1#)
-                                      (Leaf @k @v sc sc1 sc2)
-                                      s
-                               of
-                               { (# ipv1, ipv2 #) ->
-                               let {
-                                 n# :: Int#
-                                 [LclId]
-                                 n# = word2Int# (popCnt# (and# dt (minusWord# y# 1##))) } in
-                               case copySmallArray#
-                                      @(HashMap k v) @RealWorld dt1 0# ipv2 0# n# ipv1
-                               of s2
-                               { __DEFAULT ->
-                               case copySmallArray#
-                                      @(HashMap k v)
-                                      @RealWorld
-                                      dt1
-                                      n#
-                                      ipv2
-                                      (+# n# 1#)
-                                      (-# ipv n#)
-                                      s2
-                               of s1
-                               { __DEFAULT ->
-                               case unsafeFreezeSmallArray# @RealWorld @(HashMap k v) ipv2 s1 of
-                               { (# ipv3, ipv4 #) ->
-                               BitmapIndexed @k @v wild2 ipv4
-                               }
-                               }
-                               }
-                               });
-                        4294967295## ->
-                          runRW#
-                            @LiftedRep
-                            @(HashMap k v)
-                            (\ (s [OS=OneShot] :: State# RealWorld) ->
-                               let {
-                                 ipv :: Int#
-                                 [LclId]
-                                 ipv = sizeofSmallArray# @(HashMap k v) dt1 } in
-                               case newSmallArray#
-                                      @(HashMap k v)
-                                      @RealWorld
-                                      (+# ipv 1#)
-                                      (Leaf @k @v sc sc1 sc2)
-                                      s
-                               of
-                               { (# ipv1, ipv2 #) ->
-                               let {
-                                 n# :: Int#
-                                 [LclId]
-                                 n# = word2Int# (popCnt# (and# dt (minusWord# y# 1##))) } in
-                               case copySmallArray#
-                                      @(HashMap k v) @RealWorld dt1 0# ipv2 0# n# ipv1
-                               of s2
-                               { __DEFAULT ->
-                               case copySmallArray#
-                                      @(HashMap k v)
-                                      @RealWorld
-                                      dt1
-                                      n#
-                                      ipv2
-                                      (+# n# 1#)
-                                      (-# ipv n#)
-                                      s2
-                               of s1
-                               { __DEFAULT ->
-                               case unsafeFreezeSmallArray# @RealWorld @(HashMap k v) ipv2 s1 of
-                               { (# ipv3, ipv4 #) ->
-                               Full @k @v ipv4
-                               }
-                               }
-                               }
-                               })
-                      }
+                      runRW#
+                        @LiftedRep
+                        @(HashMap k v)
+                        (\ (s [OS=OneShot] :: State# RealWorld) ->
+                           let {
+                             ipv :: Int#
+                             [LclId]
+                             ipv = sizeofSmallArray# @(HashMap k v) dt1 } in
+                           case newSmallArray#
+                                  @(HashMap k v) @RealWorld (+# ipv 1#) (Leaf @k @v sc sc1 sc2) s
+                           of
+                           { (# ipv1, ipv2 #) ->
+                           let {
+                             n# :: Int#
+                             [LclId]
+                             n# = word2Int# (popCnt# (and# dt (minusWord# y# 1##))) } in
+                           case copySmallArray#
+                                  @(HashMap k v) @RealWorld dt1 0# ipv2 0# n# ipv1
+                           of s2
+                           { __DEFAULT ->
+                           case copySmallArray#
+                                  @(HashMap k v) @RealWorld dt1 n# ipv2 (+# n# 1#) (-# ipv n#) s2
+                           of s1
+                           { __DEFAULT ->
+                           case unsafeFreezeSmallArray# @RealWorld @(HashMap k v) ipv2 s1 of
+                           { (# ipv3, ipv4 #) ->
+                           case or# dt y# of wild2 {
+                             __DEFAULT -> BitmapIndexed @k @v wild2 ipv4;
+                             4294967295## -> Full @k @v ipv4
+                           }
+                           }
+                           }
+                           }
+                           })
                   };
                 Leaf dt dt1 dt2 ->
                   case eqWord# dt sc of {
@@ -11822,94 +11542,51 @@ unionWithKey
                                     }
                                     };
                                   0## ->
-                                    case or# dt y# of wild4 {
-                                      __DEFAULT ->
-                                        runRW#
-                                          @LiftedRep
-                                          @(HashMap k v)
-                                          (\ (s [OS=OneShot] :: State# RealWorld) ->
-                                             let {
-                                               ipv :: Int#
-                                               [LclId]
-                                               ipv = sizeofSmallArray# @(HashMap k v) dt1 } in
-                                             case newSmallArray#
-                                                    @(HashMap k v) @RealWorld (+# ipv 1#) wild2 s
-                                             of
-                                             { (# ipv1, ipv2 #) ->
-                                             let {
-                                               n# :: Int#
-                                               [LclId]
-                                               n#
-                                                 = word2Int#
-                                                     (popCnt# (and# dt (minusWord# y# 1##))) } in
-                                             case copySmallArray#
-                                                    @(HashMap k v) @RealWorld dt1 0# ipv2 0# n# ipv1
-                                             of s2
-                                             { __DEFAULT ->
-                                             case copySmallArray#
-                                                    @(HashMap k v)
-                                                    @RealWorld
-                                                    dt1
-                                                    n#
-                                                    ipv2
-                                                    (+# n# 1#)
-                                                    (-# ipv n#)
-                                                    s2
-                                             of s1
-                                             { __DEFAULT ->
-                                             case unsafeFreezeSmallArray#
-                                                    @RealWorld @(HashMap k v) ipv2 s1
-                                             of
-                                             { (# ipv3, ipv4 #) ->
-                                             BitmapIndexed @k @v wild4 ipv4
-                                             }
-                                             }
-                                             }
-                                             });
-                                      4294967295## ->
-                                        runRW#
-                                          @LiftedRep
-                                          @(HashMap k v)
-                                          (\ (s [OS=OneShot] :: State# RealWorld) ->
-                                             let {
-                                               ipv :: Int#
-                                               [LclId]
-                                               ipv = sizeofSmallArray# @(HashMap k v) dt1 } in
-                                             case newSmallArray#
-                                                    @(HashMap k v) @RealWorld (+# ipv 1#) wild2 s
-                                             of
-                                             { (# ipv1, ipv2 #) ->
-                                             let {
-                                               n# :: Int#
-                                               [LclId]
-                                               n#
-                                                 = word2Int#
-                                                     (popCnt# (and# dt (minusWord# y# 1##))) } in
-                                             case copySmallArray#
-                                                    @(HashMap k v) @RealWorld dt1 0# ipv2 0# n# ipv1
-                                             of s2
-                                             { __DEFAULT ->
-                                             case copySmallArray#
-                                                    @(HashMap k v)
-                                                    @RealWorld
-                                                    dt1
-                                                    n#
-                                                    ipv2
-                                                    (+# n# 1#)
-                                                    (-# ipv n#)
-                                                    s2
-                                             of s1
-                                             { __DEFAULT ->
-                                             case unsafeFreezeSmallArray#
-                                                    @RealWorld @(HashMap k v) ipv2 s1
-                                             of
-                                             { (# ipv3, ipv4 #) ->
-                                             Full @k @v ipv4
-                                             }
-                                             }
-                                             }
-                                             })
-                                    }
+                                    runRW#
+                                      @LiftedRep
+                                      @(HashMap k v)
+                                      (\ (s [OS=OneShot] :: State# RealWorld) ->
+                                         let {
+                                           ipv :: Int#
+                                           [LclId]
+                                           ipv = sizeofSmallArray# @(HashMap k v) dt1 } in
+                                         case newSmallArray#
+                                                @(HashMap k v) @RealWorld (+# ipv 1#) wild2 s
+                                         of
+                                         { (# ipv1, ipv2 #) ->
+                                         let {
+                                           n# :: Int#
+                                           [LclId]
+                                           n#
+                                             = word2Int#
+                                                 (popCnt# (and# dt (minusWord# y# 1##))) } in
+                                         case copySmallArray#
+                                                @(HashMap k v) @RealWorld dt1 0# ipv2 0# n# ipv1
+                                         of s2
+                                         { __DEFAULT ->
+                                         case copySmallArray#
+                                                @(HashMap k v)
+                                                @RealWorld
+                                                dt1
+                                                n#
+                                                ipv2
+                                                (+# n# 1#)
+                                                (-# ipv n#)
+                                                s2
+                                         of s1
+                                         { __DEFAULT ->
+                                         case unsafeFreezeSmallArray#
+                                                @RealWorld @(HashMap k v) ipv2 s1
+                                         of
+                                         { (# ipv3, ipv4 #) ->
+                                         case or# dt y# of wild4 {
+                                           __DEFAULT -> BitmapIndexed @k @v wild4 ipv4;
+                                           4294967295## -> Full @k @v ipv4
+                                         }
+                                         }
+                                         }
+                                         }
+                                         })
                                 } } in
                           case wild2 of {
                             Leaf dt2 dt3 dt4 ->
@@ -11947,9 +11624,9 @@ unionWithKey
                                  [LclId]
                                  ba = and# dt dt2 } in
                                join {
-                                 exit [Dmd=SCS(L)] :: State# RealWorld -> HashMap k v
+                                 $w$j [InlPrag=[2], Dmd=SCS(L)] :: State# RealWorld -> HashMap k v
                                  [LclId[JoinId(1)], Arity=1, Str=<L>]
-                                 exit (w2 [OS=OneShot] :: State# RealWorld)
+                                 $w$j (w2 [OS=OneShot] :: State# RealWorld)
                                    = case unsafeFreezeSmallArray# @RealWorld @(HashMap k v) ipv1 w2
                                      of
                                      { (# ipv2, ipv3 #) ->
@@ -12040,7 +11717,7 @@ unionWithKey
                                            0## ->
                                              jump $wgo2 ww1 ww2 ww3 (uncheckedShiftL# ww4 1#) w2
                                          };
-                                       1# -> jump exit w2
+                                       1# -> jump $w$j w2
                                      }; } in
                                jump $wgo2
                                  0# 0# 0# (and# b' (int2Word# (negateInt# (word2Int# b')))) ipv
@@ -12444,10 +12121,10 @@ unionWithKey
               }; } in
       \ (w :: HashMap k v) (w1 :: HashMap k v) -> $wgo1 0# w w1

TODO:

  • Documentation / comments

@sjakobi sjakobi marked this pull request as ready for review March 12, 2022 11:04
@sjakobi
Copy link
Member Author

sjakobi commented Mar 12, 2022

I can't find a significant speedup in the union benchmark, but that may be because the noise level is too high. The Core looks good anyway so I'm inclined to merge this.

This helps reduce the Core size of the `union*` variants.
This prevents reboxing of arrays in the union variants.
@sjakobi sjakobi force-pushed the sjakobi/unbox-arrays-1-union branch from 29351ea to c126bb0 Compare March 14, 2022 22:22
@sjakobi sjakobi merged commit f1ea9a4 into master Mar 15, 2022
@sjakobi sjakobi deleted the sjakobi/unbox-arrays-1-union branch March 15, 2022 20:30
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.

1 participant