Giter Site home page Giter Site logo

Comments (11)

gasche avatar gasche commented on June 16, 2024 1

@Octachron and myself have now fixed this issue -- the uncaught exception. The fix will be included in next release of 4.14, and in OCaml 5.2 and later releases. We found some independent issues with the same or related test cases, that have yet to be fixed.

from ocaml.

Vanille-N avatar Vanille-N commented on June 16, 2024

trace.txt

from ocaml.

gasche avatar gasche commented on June 16, 2024

Nice find!

This is related to the handling of the (equi)-recursive types built by this incorrect program. The failure is reproducible starting with OCaml 4.13, but 4.12 and 4.11 (older versions don't have Seq) fail with a proper error:

File "test.ml", lines 4-5, characters 2-22:
4 | ..let T x = xt in
5 |   Seq.cons Seq.empty x
Error: This expression has type
         ('a Seq.t as 'a) Seq.t Seq.t = unit -> 'a Seq.t Seq.node
       but an expression was expected of type 'b
       Type 'c is not compatible with type 'a = unit -> 'c Seq.node 
       The type variable 'c occurs inside 'a

The program also gets accepted when -rectypes is used, including on recent versions.

val to_seq : ('a Seq.t as 'a) Seq.t t -> 'a Seq.t Seq.t

from ocaml.

gasche avatar gasche commented on June 16, 2024

Testing indicates that this failure was introduced by #10170 .

from ocaml.

gasche avatar gasche commented on June 16, 2024

Minimal repro case (does not rely on an external module):

type 'a t = T of 'a

module Seq : sig
  type 'a t = unit -> 'a node
  and 'a node
  
  val empty : 'a t
  val cons : 'a -> 'a t -> 'a t
end = struct
  type 'a t = unit -> 'a node
  and 'a node = unit
  
  let empty () = ()
  let cons x xs () = ()
end 

let to_seq (xt : 'a t) : 'a Seq.t =
  let T x = xt in
  Seq.cons Seq.empty x

from ocaml.

gasche avatar gasche commented on June 16, 2024

I proposed a one-line fix in #10170 (comment) . But in fact, it looks like this error cannot be reproduced in trunk and in the 5.2 release branch, thanks to another change in 52 ( #12691 ). So in a sense it is "already fixed", even though we may still want to apply the proper one-line fix.

from ocaml.

Octachron avatar Octachron commented on June 16, 2024

I think I might prefer to backport the expand_gen_abbrev cleanup from #12691 to 4.14 (to have the same behavior on 4.14.2+ and 5.2+).

from ocaml.

gasche avatar gasche commented on June 16, 2024

My impression is that the one-line change makes the code more consistent. I don't understand if the expand_gen_abbrev change makes all of that code inconsistent again (maybe there is no need to use the _safe variant anymore in most cases?), but I would be inclined to make all callsites look the same independently of that change -- which we could also backtrack to 4.14, even if it is noticeably more invasive.

from ocaml.

gasche avatar gasche commented on June 16, 2024

I proposed my one-liner with the repro case as a PR in #12974.

from ocaml.

Octachron avatar Octachron commented on June 16, 2024

Further testing indicates that the rectype bug is quite old:

(* core.mli *)
type 'a pre = Nil | Cons of 'a * 'a pre
type 'a t = unit -> 'a pre
val cons: 'a -> 'a t -> 'a t
val empty: 'a t
(* main.ml *)
let cons_empty (x : 'a) : 'a Core.t = Core.(cons empty x)

has been broken since 4.01 .

from ocaml.

gasche avatar gasche commented on June 16, 2024

Thanks for the report!

from ocaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.