| ... |
... |
@@ -42,7 +42,7 @@ import GHC.Core.Utils |
|
42
|
42
|
import GHC.Core.DataCon
|
|
43
|
43
|
import GHC.Core.Type
|
|
44
|
44
|
import GHC.Core.Class( Class )
|
|
45
|
|
-import GHC.Core.Predicate( isUnaryClass )
|
|
|
45
|
+import GHC.Core.Predicate( isUnaryClass, isDictId )
|
|
46
|
46
|
|
|
47
|
47
|
import GHC.Types.Id
|
|
48
|
48
|
import GHC.Types.Literal
|
| ... |
... |
@@ -782,7 +782,7 @@ classOpSize :: UnfoldingOpts -> Class -> [Id] -> [CoreExpr] -> ExprSize |
|
782
|
782
|
classOpSize _opts _cls _top_args []
|
|
783
|
783
|
= sizeZero -- A non-applied classop
|
|
784
|
784
|
classOpSize opts cls top_args (dict_arg:other_val_args)
|
|
785
|
|
- = SizeIs size (dict_arg_discount dict_arg) 0
|
|
|
785
|
+ = SizeIs size dict_arg_discount 0
|
|
786
|
786
|
where
|
|
787
|
787
|
-- See (UCM4) in Note [Unary class magic] in GHC.Core.TyCon
|
|
788
|
788
|
op_app_size = if isUnaryClass cls then 0 else 20
|
| ... |
... |
@@ -797,8 +797,8 @@ classOpSize opts cls top_args (dict_arg:other_val_args) |
|
797
|
797
|
-- give it a discount, to encourage the inlining of this function
|
|
798
|
798
|
dict_arg_discount = case getIdFromTrivialExpr_maybe dict_arg of
|
|
799
|
799
|
Nothing -> emptyBag
|
|
800
|
|
- Just var
|
|
801
|
|
- | var `elem` top_args = unitBag (dict, dict_discount)
|
|
|
800
|
+ Just dict
|
|
|
801
|
+ | dict `elem` top_args -> unitBag (dict, dict_discount)
|
|
802
|
802
|
| otherwise -> emptyBag
|
|
803
|
803
|
|
|
804
|
804
|
-- If we have (class-op d arg1 .. argn) then it's super-good to inline
|
| ... |
... |
@@ -808,7 +808,15 @@ classOpSize opts cls top_args (dict_arg:other_val_args) |
|
808
|
808
|
-- See the discussion on #26831, esp "Delicate inlining".
|
|
809
|
809
|
dict_discount
|
|
810
|
810
|
| null other_val_args = unfoldingDictDiscount opts
|
|
811
|
|
- | otherwise = unfoldingDictDiscount opts + unfoldingFunAppDiscount opts
|
|
|
811
|
+ | otherwise = unfoldingDictDiscount opts + unfoldingFunAppDiscount opts +
|
|
|
812
|
+ -- Just trying things.
|
|
|
813
|
+ 5 * numTopDictArgs
|
|
|
814
|
+ numTopDictArgs = (count (isTopArgDict) other_val_args)
|
|
|
815
|
+ isTopArgDict expr
|
|
|
816
|
+ | Just v <- getIdFromTrivialExpr_maybe expr
|
|
|
817
|
+ , v `elem` top_args
|
|
|
818
|
+ = isDictId v
|
|
|
819
|
+ | otherwise = False
|
|
812
|
820
|
|
|
813
|
821
|
-- | The size of a function call
|
|
814
|
822
|
callSize
|