Opened 3 years ago

Closed 2 years ago

#11407 closed bug (fixed)

-XTypeInType uses up all memory when used in data family instance

Reported by: RyanGlScott Owned by: goldfire
Priority: highest Milestone: 8.0.1
Component: Compiler (Type checker) Version: 8.0.1-rc1
Keywords: TypeInType, TypeFamilies Cc: goldfire
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Compile-time performance bug Test Case: dependent/should_fail/T11407
Blocked By: Blocking:
Related Tickets: Differential Rev(s):
Wiki Page:

Description

Compiling this code with GHC 8.1 causes all my memory to be used very quickly:

{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeInType #-}
module TypeInTypeEatsAllMemory where

import Data.Kind

type Const a b = a

data family UhOh (f :: k1) (a :: k2) (b :: k3)
data instance UhOh (f :: * -> * -> *) (a :: forall a) (b :: Const * a) = UhOh

On the other hand, this code compiles without issue:

{-# LANGUAGE TypeInType #-}
module TypeInTypeEatsAllMemory where

import Data.Kind

type Const a b = a

data UhOh (f :: * -> * -> *) (a :: forall a) (b :: Const * a) = UhOh

Change History (8)

comment:1 Changed 3 years ago by bgamari

Milestone: 8.0.1
Version: 8.18.0.1-rc1

Uh oh.

Note that the version in question here is 8.0.1, not 8.1.

comment:2 Changed 3 years ago by bgamari

Priority: highhighest

comment:3 Changed 2 years ago by thomie

Keywords: TypeFamilies added

comment:4 Changed 2 years ago by simonpj

Owner: set to goldfire

comment:5 Changed 2 years ago by bgamari

Hmm, on master this merely results in a stack overflow, not that this is much of an improvement.

comment:6 Changed 2 years ago by Richard Eisenberg <eir@…>

In e9bf7bb5/ghc:

Fix #11407.

This removes the `defer_me` check that was in checkTauTvUpdate
and uses only a type family check instead. The old defer_me check
repeated work done by fast_check in occurCheckExpand.

There is also some error message improvement, necessitated by
the terrible error message that the test case produced, even when
it didn't consume all of memory.

test case: dependent/should_fail/T11407

[skip ci]

comment:7 Changed 2 years ago by goldfire

Status: newmerge
Test Case: dependent/should_fail/T11407

comment:8 Changed 2 years ago by bgamari

Resolution: fixed
Status: mergeclosed
Note: See TracTickets for help on using tickets.