Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Type checker can loop infinitly and consumes all computer memory #7747
Original bug ID: 7747
I allready mentioned the problem in the discussion about MPR #7739 issue, but I think it deserves its own independant report.
Normally cycles in types defintion are disallowed by the type checker, as in this example:
module rec M : sig type t = N.t end = struct type t end
But with GADT we can hide this cycle and reveal it only when inspecting an equality witness value. In some cases this can put the type checker in an infinite loop and memory consumption increases drastically (around 1 GB per 10 seconds on my computer).
The reproduction case (below) is pretty pathological and a corner case, but I don't know if such situation can appear in a more realistic code wich combines GADT and private types.
Steps to reproduce
type (,) eq = Refl : ('a,'a) eq
module M = struct type t end
let f x = match N.eq with Refl -> (x : N.t :> M.t)
let f x = match N.eq with Refl -> (x : M.t :> N.t)
let f x = match N.eq with Refl -> (x : N.t :> int)