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

Bug with first-class modules and includes #6262

Closed
vicuna opened this issue Dec 5, 2013 · 4 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Dec 5, 2013

Original bug ID: 6262
Reporter: @lpw25
Assigned to: @alainfrisch
Status: closed (set by @xavierleroy on 2015-12-11T18:25:26Z)
Resolution: fixed
Priority: normal
Severity: minor
Category: typing
Monitored by: @hcarty

Bug description

There is a bug in the interaction between first-class modules and includes:

        OCaml version 4.02.0+dev2-2013-09-12
 
# module X : sig 
    module type S
    type t = Foo of (module S)
  end = struct
    module type S = sig end
    type t = Foo of (module S)
  end;;
            module X : sig module type S type t = Foo of (module S) end
# module Y = struct
    include X
  end;;
    module Y : sig module type S = X.S type t = X.t = Foo of (module S) end

This says that Y.t is equal to X.t, however the representations of these types are not equivalent because (module X.S) is not equal to (module Y.S).

File attachments

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 5, 2013

Comment author: @lpw25

This bug may seem harmless, but it causes a soundness bug in 4.01.0:

        OCaml version 4.01.0
 
# type ('a, 'b) eq = Refl : ('a, 'a) eq;;
type ('a, 'b) eq = Refl : ('a, 'a) eq
# module X : sig 
    module type S
    type 'a t = Foo of ('a ,(module S)) eq
  end = struct
    module type S = sig end
    type 'a t = Foo of ('a ,(module S)) eq
  end;;
            module X : sig module type S type 'a t = Foo of ('a, (module S)) eq end
# module Y = struct
    include X
  end;;
    module Y :
  sig module type S = X.S type 'a t = 'a X.t = Foo of ('a, (module S)) eq end
# let Y.Foo x_eq_y  = X.Foo Refl;;
val x_eq_y : ((module X.S), (module Y.S)) eq = Refl
# type 'a t = 
    X : int -> (module X.S) t
  | Y : string -> (module Y.S) t;;
    type 'a t = X : int -> (module X.S) t | Y : string -> (module Y.S) t
# let coerce (type a) (type b) (eq : (a, b) eq) (x : a t) : b t = 
    match eq with
      Refl -> x;;
    val coerce : ('a, 'b) eq -> 'a t -> 'b t = <fun>
# let y_of_x x = coerce x_eq_y x;;
val y_of_x : (module X.S) t -> (module Y.S) t = <fun>
# let f (y : (module Y.S) t) = 
    match y with
      Y s -> s;;
    val f : (module Y.S) t -> string = <fun>
# f (y_of_x (X 10));;
 
Process ocaml-toplevel segmentation fault

Since r14305 this soundness bug no longer exists because the exhaustivity checker now seems to always assumes that package types may be compatible, so the bug is probably "harmless" again.

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 5, 2013

Comment author: @lpw25

In general, first-class modules do not interact well with module inclusion because they ignore module type aliases.

Assuming that making first-class modules work based on the structures of modules rather than their paths is too much work, I think that the best solution to this problem is to make first-class modules take module type aliases into account.

So given:

module type T
module type S = T

(module S) and (module T) would be considered equivalent.

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 5, 2013

Comment author: @alainfrisch

I agree with your latest note and I attach a patch attempting to take module type aliases into account for the equality of package types.

@vicuna

This comment has been minimized.

Copy link
Author

commented Dec 5, 2013

Comment author: @alainfrisch

Commit to trunk, rev 14342. Thanks!

@vicuna vicuna closed this Dec 11, 2015

@vicuna vicuna added the typing label 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
You can’t perform that action at this time.