Opened 7 years ago

Last modified 23 months ago

#5224 new bug

Improve consistency checking for family instances

Reported by: simonpj Owned by: simonpj
Priority: low Milestone:
Component: Compiler Version: 7.0.3
Keywords: TypeFamilies Cc: chak@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time performance bug Test Case:
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Several compiler-performance tests got worse when I added the new generic default methods (with Pedro):

  • T3064: peak_megabytes_allocated 24 is more than maximum allowed 16
  • IndTypesPerf: needs more than the 20M heap it is given
  • T4801: max_bytes_used 31.4M is more than maximum allowed 30M

For the first two of these we know exactly why: the (necessarily) eager overlap check is reading interface files that are otherwise not read, becuase of the new Rep type family instances in Data.Maybe and so on. Both these tests use type families.

For T4801 it's more mysterious. The test does not use type families, and no new interface files are read, but residency increases. So the cause may be different.

I'm pretty sure we can improve matters by propagating a bit more info; specifically, rather than a module simply saying "I have some type familily instances" it can say "I have type family instances for F, G, H".

I have marked the three tests as expect-broken for now, with the ticket to remind me to get back to it.

Change History (15)

comment:1 Changed 7 years ago by simonmar

Priority: normalhighest
Type of failure: None/UnknownCompile-time performance bug

Regression - bumping prio.

comment:2 Changed 7 years ago by daniel.is.fischer

Didn't find this soon enough: as reported in #5232, T3064 and T4801 now use less than the minimum allowed, additionally, I got an unexpected pass for IndTypesPerf. So the issue might be fixed already. Definitely worth a check, IMO.

comment:3 in reply to:  2 Changed 7 years ago by simonmar

Replying to daniel.is.fischer:

Didn't find this soon enough: as reported in #5232, T3064 and T4801 now use less than the minimum allowed, additionally, I got an unexpected pass for IndTypesPerf. So the issue might be fixed already. Definitely worth a check, IMO.

There is a temporary workaround in place, Igloo removed the deriving Generics from Data.Tuple due to #5227. This accounts for some unexpected passes and/or failures, some of which I just fixed.

comment:4 Changed 7 years ago by simonpj

The problem here is the the (necessary) eager check for type-function overlap. This is causing interface files to be read (ones that contain type instance declarations) that would not previously have been read.

I have two ideas. First, many type function instances have the form

module X where
import M(F)
data T a = ...
type instance F (T a) = ...

Can another instance of F overlap with this? Yes in principle:

type instance F a = ...

But suppose we don't allow type variables in (all) the index positions of a type function. After all, such a type instance would make the family degenerate to a synonym, and you could never declare any other instances!

With that restriction we know that you can only overlap the type instance if you import (transitively) M, so you have access to T. So for instances of this form we don't need to treat M as an orphan module.

I think this is a wildly common case, and in particular hits the examples in the Prelude.

Second idea: export a bit more info about the family instance modules, namely which type functions they have instances for. No need to check for overlap between M.hi which defines instancs for F and N.hi which defines instances for G.

comment:5 Changed 7 years ago by simonpj

Cc: chak@… added

comment:6 Changed 7 years ago by igloo

Owner: set to simonpj
Priority: highestnormal

I don't think this is critical for 7.2.1, after we removed most of the generic tuple instances. T3064 and T4801 are now failing because ghc doesn't allocate as much as expected, and IndTypesPerf is passing.

comment:7 Changed 6 years ago by daniel.is.fischer

On my 32-bit linux box, T3064 now allocates a bit too much, 63817792 bytes, maximum allowed is 63000000. I suggest increasing the limit for now.

comment:8 Changed 6 years ago by simonpj

Milestone: 7.2.17.4.1

OK I've bumped that limit a bit.

Meanwhile I think it's not really urgent to improve the eager family-instance checking. I'll re-milestone for 7.4.

Simon

comment:9 Changed 6 years ago by igloo

Milestone: 7.4.17.6.1
Priority: normallow

comment:10 Changed 5 years ago by igloo

Milestone: 7.6.17.6.2

comment:11 Changed 3 years ago by thoughtpolice

Milestone: 7.6.27.10.1

Moving to 7.10.1.

comment:12 Changed 3 years ago by thoughtpolice

Milestone: 7.10.17.12.1

Moving to 7.12.1 milestone; if you feel this is an error and should be addressed sooner, please move it back to the 7.10.1 milestone.

comment:13 Changed 2 years ago by thoughtpolice

Milestone: 7.12.18.0.1

Milestone renamed

comment:14 Changed 23 months ago by thomie

Keywords: TypeFamilies added

comment:15 Changed 23 months ago by thomie

Milestone: 8.0.1
Note: See TracTickets for help on using tickets.