Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong Lazy assumption #7068

Closed
vicuna opened this issue Nov 30, 2015 · 3 comments
Closed

Wrong Lazy assumption #7068

vicuna opened this issue Nov 30, 2015 · 3 comments
Labels
Milestone

Comments

@vicuna
Copy link

vicuna commented Nov 30, 2015

Original bug ID: 7068
Reporter: lavi
Status: closed (set by @xavierleroy on 2017-02-16T14:18:22Z)
Resolution: not a bug
Priority: normal
Severity: major
Version: 4.02.3
Target version: 4.03.0+dev / +beta1
Category: ~DO NOT USE (was: OCaml general)
Monitored by: @gasche

Bug description

Manual http://caml.inria.fr/pub/docs/manual-ocaml-4.02/libref/Lazy.html says:

Note: if the program is compiled with the -rectypes option, ill-founded recursive definitions of the form let rec x = lazy x or let rec x = lazy(lazy(...(lazy x))) are accepted by the type-checker and lead, when forced, to ill-formed values that trigger infinite loops in the garbage collector and other parts of the run-time system. Without the -rectypes option, such ill-founded recursive definitions are rejected by the type-checker.

The last sentence is over optimistic:

module rec A : sig
type t = B.t Lazy.t
val x : t
end = struct
type t = B.t Lazy.t
let x = lazy B.x
end and B : sig
type t
val x : t
end = struct
type t = A.t
let x = A.x
end

let y = Lazy.force A.x

@vicuna
Copy link
Author

vicuna commented Dec 5, 2015

Comment author: @xavierleroy

These recursive definitions lead to cyclic values with tag 250 (Forward_tag), that's right. But I would not call these values "ill formed".

Do you have a repro case for an infinite loop in the GC caused by such values? I could not reproduce this so far.

@vicuna
Copy link
Author

vicuna commented Dec 7, 2015

Comment author: lavi

I personnaly do not have, but I would say the same with -rectypes. My point is only that using recursive modules allows to build the same values (with inner abstract type) than with -rectypes.

@vicuna
Copy link
Author

vicuna commented Dec 9, 2015

Comment author: @xavierleroy

My point is only that using recursive modules allows to build the same values with inner abstract type) than with -rectypes.

This is correct, but rather harmless in my opinion. The purpose of -rectypes is not so much to restrict cyclic data structures (you can always do "let rec x = 1 :: x") but to prohibit cyclic types, which can lead to extremely mysterious inferred types and type errors.

I'm closing this PR as requiring no immediate action.

@vicuna vicuna closed this as completed Feb 16, 2017
@vicuna vicuna added this to the 4.03.0 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant