Opened 10 years ago

Last modified 3 years ago

#2207 new feature request

Load the interface details for GHC.* even without -O

Reported by: simonpj Owned by:
Priority: normal Milestone:
Component: Compiler Version: 6.8.2
Keywords: Cc:
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: None/Unknown Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Neil says: I just tried compiling the following program:

foo = (1 :: Int) == (2 :: Int)

with ghc --ddump-simpl, and no optimisation flags, in GHC 6.6.1

The resultant code is:

Test.foo =
  case GHC.Base.$f2 of tpl_X8 { GHC.Base.:DEq tpl1_B2 tpl2_B3 ->
  tpl1_B2 (GHC.Base.I# 1) (GHC.Base.I# 2)
  }

GHC has introduced dictionaries in this example. In comparison, Yhc and nhc wouldn't introduce dictionaries here, as the type class desugaring knows the type of the item is fixed, and makes a direct call to the appropriate function.

If the desugaring was changed, it would make programs in GHCi run faster, would reduce the size of programs, and would speed up the optimiser, as it would have less to do. I am not sure how much additional work this would require in the simplifier, but if it was minimal, the gains would probably be worth it.

The reason nothing happens is that without -0 GHC does not load the unfoldings for anything from interface files, including GHC.Base. Idea: even without -O, load the unfoldings from GHC.* modules. That would pick up a lot of very fundamental stuff, and might, as Neil says, make compilation faster.

Relatively easy to try. But would need a good nofib run to test the effects. Any takers? I'd point you at what to change.

Simon

Attachments (1)

Tick2207.hs (64 bytes) - added by morabbin 5 years ago.
Exhibits problems described in #2207

Download all attachments as: .zip

Change History (15)

comment:1 Changed 9 years ago by igloo

Milestone: 6.10 branch

comment:2 Changed 9 years ago by simonmar

Architecture: UnknownUnknown/Multiple

comment:3 Changed 9 years ago by simonmar

Operating System: UnknownUnknown/Multiple

comment:4 Changed 9 years ago by igloo

Milestone: 6.10 branch6.12 branch

comment:5 Changed 7 years ago by igloo

Milestone: 6.12 branch6.12.3

comment:6 Changed 7 years ago by igloo

Milestone: 6.12.36.14.1
Priority: normallow

comment:7 Changed 7 years ago by igloo

Milestone: 7.0.17.0.2

comment:8 Changed 7 years ago by igloo

Milestone: 7.0.27.2.1

comment:9 Changed 6 years ago by igloo

Milestone: 7.2.17.4.1

comment:10 Changed 6 years ago by igloo

Milestone: 7.4.17.6.1
Priority: lowlowest

comment:11 Changed 5 years ago by igloo

Milestone: 7.6.17.6.2

Changed 5 years ago by morabbin

Attachment: Tick2207.hs added

Exhibits problems described in #2207

comment:12 Changed 5 years ago by morabbin

Type of failure: None/Unknown

With ghc 7.6.1 and the attached file:

Orac:~/work/ghc $ ghc -ddump-simpl Tick2207.hs
[1 of 1] Compiling Main             ( Tick2207.hs, Tick2207.o )
...
Main.foo :: GHC.Types.Bool
[GblId]
Main.foo =
  GHC.Classes.==
    @ GHC.Types.Int
    GHC.Classes.$fEqInt
    (GHC.Types.I# 1)
    (GHC.Types.I# 2)
...

Output is much prettier, but still exhibits OP's issue.

comment:13 Changed 5 years ago by igloo

Milestone: 7.6.2_|_
Priority: lowestnormal

comment:14 Changed 3 years ago by rodlogic

For what is worth, this is in 7.8.3:

❯❯❯ ghc -ddump-simpl a.hs
[1 of 1] Compiling Main             ( a.hs, a.o )

==================== Tidy Core ====================
Result size of Tidy Core = {terms: 13, types: 7, coercions: 0}

Main.main :: GHC.Types.IO ()
[GblId, Str=DmdType]
Main.main =
  System.IO.putStrLn
    (GHC.Show.show
       @ GHC.Types.Bool
       GHC.Show.$fShowBool
       (GHC.Classes.==
          @ GHC.Types.Int
          GHC.Classes.$fEqInt
          (GHC.Types.I# 1)
          (GHC.Types.I# 2)))

:Main.main :: GHC.Types.IO ()
[GblId, Str=DmdType]
:Main.main = GHC.TopHandler.runMainIO @ () Main.main

For:

main = putStrLn $ show foo
foo = (1 :: Int) == (2 :: Int)
Note: See TracTickets for help on using tickets.