haskell / play-haskell

Haskell Playground
129 stars 8 forks source link

Button to toggle -ftypeable-binds (which I argue should be off by default) #35

Closed alt-romes closed 1 year ago

alt-romes commented 1 year ago

Feature request

I think the Core and Asm output could be less scary/noisy if we were to hide the typeable binds in the output of Core by default. This can be done by passing the flag -fno-typeable-binds.

I hypothetise that most playground users care more about the generated code directly related to what they wrote than they do about the typeable artifacts. Nonetheless, it might be useful to some to see the full extent of generated code, and in that case it should be possible to toggle it back on. Thought I'm not too sure.

For comparison, consider

module X where
f = map (+1)

The generated code with -fno-typeable-binds:

``` ==================== Tidy Core ==================== 2023-04-29 19:34:20.390731 UTC Result size of Tidy Core = {terms: 12, types: 12, coercions: 0, joins: 0/2} -- RHS size: {terms: 11, types: 8, coercions: 0, joins: 0/2} f :: [Integer] -> [Integer] [GblId] f = map @Integer @Integer (let { v_B1 :: Integer -> Integer -> Integer [LclId] v_B1 = + @Integer GHC.Num.$fNumInteger } in let { v1_B3 :: Integer [LclId, Unf=OtherCon []] v1_B3 = GHC.Num.Integer.IS 1# } in \ (v2_B2 :: Integer) -> v_B1 v2_B2 v1_B3) ```

The generated code without -fno-typeable-binds:

``` ==================== Tidy Core ==================== 2023-04-29 19:36:22.339051 UTC Result size of Tidy Core = {terms: 26, types: 17, coercions: 0, joins: 0/2} -- RHS size: {terms: 11, types: 8, coercions: 0, joins: 0/2} f :: [Integer] -> [Integer] [GblId] f = map @Integer @Integer (let { v_B1 :: Integer -> Integer -> Integer [LclId] v_B1 = + @Integer GHC.Num.$fNumInteger } in let { v1_B3 :: Integer [LclId, Unf=OtherCon []] v1_B3 = GHC.Num.Integer.IS 1# } in \ (v2_B2 :: Integer) -> v_B1 v2_B2 v1_B3) -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} $trModule1_ryq :: GHC.Prim.Addr# [GblId, Unf=OtherCon []] $trModule1_ryq = "main"# -- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} $trModule2_ryr :: GHC.Types.TrName [GblId, Unf=OtherCon []] $trModule2_ryr = GHC.Types.TrNameS $trModule1_ryq -- RHS size: {terms: 1, types: 0, coercions: 0, joins: 0/0} $trModule3_rys :: GHC.Prim.Addr# [GblId, Unf=OtherCon []] $trModule3_rys = "X"# -- RHS size: {terms: 2, types: 0, coercions: 0, joins: 0/0} $trModule4_ryt :: GHC.Types.TrName [GblId, Unf=OtherCon []] $trModule4_ryt = GHC.Types.TrNameS $trModule3_rys -- RHS size: {terms: 3, types: 0, coercions: 0, joins: 0/0} X.$trModule :: GHC.Types.Module [GblId, Unf=OtherCon []] X.$trModule = GHC.Types.Module $trModule2_ryr $trModule4_ryt ```
tomsmeding commented 1 year ago

I agree re the flag (though it's -dno-typeable-binds, not -f :) ).

Sorry for taking so long, I'm quite busy currently and was wanting to find time to add the configurability you mentioned before adding the flag. But it seems I'm not going to find that time any time soon, so I'll just add the flag.

alt-romes commented 1 year ago

Awesome! We can open another issue to track the configuration button, or otherwise wait until someone requests that feature