Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006262OCamlOCaml typingpublic2013-12-05 14:132013-12-05 15:57
Reporterlpw25 
Assigned Tofrisch 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0006262: Bug with first-class modules and includes
DescriptionThere 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)`.
TagsNo tags attached.
Attached Filesdiff file icon alias_modtype.diff [^] (2,579 bytes) 2013-12-05 15:32 [Show Content]

- Relationships

-  Notes
(0010694)
lpw25 (developer)
2013-12-05 14:16
edited on: 2013-12-05 14:19

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.

(0010695)
lpw25 (developer)
2013-12-05 14:22

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.
(0010696)
frisch (developer)
2013-12-05 15:33

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.
(0010697)
frisch (developer)
2013-12-05 15:57

Commit to trunk, rev 14342. Thanks!

- Issue History
Date Modified Username Field Change
2013-12-05 14:13 lpw25 New Issue
2013-12-05 14:16 lpw25 Note Added: 0010694
2013-12-05 14:19 lpw25 Note Edited: 0010694 View Revisions
2013-12-05 14:22 lpw25 Note Added: 0010695
2013-12-05 15:23 doligez Status new => acknowledged
2013-12-05 15:32 frisch File Added: alias_modtype.diff
2013-12-05 15:33 frisch Note Added: 0010696
2013-12-05 15:38 frisch Assigned To => frisch
2013-12-05 15:38 frisch Status acknowledged => assigned
2013-12-05 15:57 frisch Note Added: 0010697
2013-12-05 15:57 frisch Status assigned => resolved
2013-12-05 15:57 frisch Resolution open => fixed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker