Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007787OCamlmiddle end (typedtree to clambda)public2018-04-27 12:592018-05-01 10:47
Reportershinwell 
Assigned Totrefis 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version4.07.0+dev/beta2 
Target Version4.07.0+dev/beta2Fixed in Version 
Summary0007787: "module type of" + recursive modules + functors segfault in bytecode interpreter (4.07 regression)
DescriptionIn 4.07 the following code causes a segfault in the bytecode interpreter, trying to read a field of the unit value, unless the "remove_aliases" attribute is added. This appears to work with 4.06.

Thanks to hheuzard and xclerc for help investigating this.

module O (T : sig
  module N : sig
    val foo : int -> int
  end
end) = struct
  open T

  let go () =
    N.foo 42 (* finding N (from T) goes wrong *)
end

module T = struct
  module N = struct
    let foo x = x + 3
  end
end;;

(* Incidentally, M isn't used in T2, but it doesn't seem to fail if
   it's just "module M" and "module T2" separately *)
module rec M : sig
  val go : unit -> int
end = O (T2)
and T2 : sig
  include module type of struct include T end (* [@remove_aliases] *)
end = struct
  include T
end;;

let _ = ignore (M.go ())
Steps To ReproduceCompile the above program with ocamlc and run it.
TagsNo tags attached.
Attached Files? file icon remove-aliases.lambda [^] (1,290 bytes) 2018-04-27 14:44
? file icon broken-dont-remove-aliases.lambda [^] (1,272 bytes) 2018-04-27 14:45

- Relationships

-  Notes
(0019069)
shinwell (developer)
2018-04-27 13:28

The lambda code (for the version without the attribute) is:

(setglobal Test!
  (let
    (O/1002 =
       (module-defn(O/1002) test.ml(1):0-157
         (function T/1054 is_a_functor
           (let
             (go/1006 =
                (function param/1008 (apply (field 0 (field 0 T/1054)) 42)))
             (makeblock 0 go/1006))))
     T/1009 =
       (module-defn(T/1009) test.ml(12):159-228
         (let
           (N/1010 =
              (module-defn(N/1010) test.ml(13):179-224
                (let (foo/1011 = (function x/1012 (+ x/1012 3)))
                  (makeblock 0 foo/1011))))
           (makeblock 0 N/1010)))
     M/1013 =
       (apply (field 0 (global CamlinternalMod!)) [0: "test.ml" 22 6]
         [0: [0: 0]])
     T2/1014 =
       (apply (field 0 (global CamlinternalMod!)) [0: "test.ml" 25 6]
         [0: [0: [1: 0]]]))
    (seq
      (apply (field 1 (global CamlinternalMod!)) [0: [0: 0]] M/1013
        (module-defn(M/1013) test.ml(20):354-408 (apply O/1002 T2/1014)))
      (apply (field 1 (global CamlinternalMod!)) [0: [0: [1: 0]]] T2/1014
        (module-defn(T2/1014) test.ml(23):409-520
          (makeblock 0 (field 0 T/1009))))
      (ignore (apply (field 0 M/1013) 0))
      (makeblock 0 O/1002 T/1009 M/1013 T2/1014))))
(0019070)
shinwell (developer)
2018-04-27 13:29

trefis confirms this segfaults with ocamlopt too.
(0019071)
gasche (developer)
2018-04-27 13:54

This looks like a bug for Leo, related to https://github.com/ocaml/ocaml/pull/1652 [^]
(0019072)
trefis (manager)
2018-04-27 14:31

I'm wondering if https://github.com/ocaml/ocaml/pull/1610 [^] might not have a positive impact here.
I'm currently in the middle of rebasing it and I'll report back once I have tried it out.
(0019073)
trefis (manager)
2018-04-27 14:38
edited on: 2018-04-27 14:38

Confirmed: https://github.com/ocaml/ocaml/pull/1610 [^] fixes the issue.

(0019074)
gasche (developer)
2018-04-27 14:42

trefis: given that GPR#1610 has a large conflict with the current trunk, maybe it would be useful to push your rebase somewhere for easier testing? (Maybe we could open another PR, or maybe you can get Leo to update his.)
(0019075)
trefis (manager)
2018-04-27 14:44

I pushed the rebased patch here: https://github.com/trefis/ocaml/commit/5f1036f57af0cfad7bac69692e4673525265c224 [^] (I'll let Leo do a proper rebase)

For the record, I'm attaching the -dlambda output ocamlc without 1652 nor 1610 (that's remove-aliases.lambda), with only 1652 (broken-dont-remove-aliases) and with both (fixed-dont-remove-aliases).
The first and last one are the same, only the second one differs.
(0019076)
shinwell (developer)
2018-04-27 15:24

Let's add this example to the testsuite in GPR#1610 too...
(0019077)
trefis (manager)
2018-04-27 16:15
edited on: 2018-04-27 16:17

Spoke too quickly, I had tested the rebase of gpr1610 with the [@remove_aliases] uncommented.

If I remove it the example is still broken; gpr1610 actually has no impact.

Sorry.

(0019078)
trefis (manager)
2018-04-27 17:30

I think I've got a fix for this, I'll create a GPR shortly.
(0019079)
trefis (manager)
2018-04-27 17:55

https://github.com/ocaml/ocaml/pull/1743 [^]
(0019083)
trefis (manager)
2018-05-01 10:46

GPR#1743 has been merged into trunk and cherry-picked to 4.07.

- Issue History
Date Modified Username Field Change
2018-04-27 12:59 shinwell New Issue
2018-04-27 13:00 shinwell Status new => confirmed
2018-04-27 13:28 shinwell Note Added: 0019069
2018-04-27 13:29 shinwell Note Added: 0019070
2018-04-27 13:54 gasche Note Added: 0019071
2018-04-27 14:31 trefis Note Added: 0019072
2018-04-27 14:38 trefis Note Added: 0019073
2018-04-27 14:38 trefis Note Edited: 0019073 View Revisions
2018-04-27 14:42 gasche Note Added: 0019074
2018-04-27 14:44 trefis Note Added: 0019075
2018-04-27 14:44 trefis File Added: remove-aliases.lambda
2018-04-27 14:45 trefis File Added: broken-dont-remove-aliases.lambda
2018-04-27 14:45 trefis File Added: fixed-dont-remove-aliases.lambda
2018-04-27 15:24 shinwell Note Added: 0019076
2018-04-27 16:15 trefis Note Added: 0019077
2018-04-27 16:15 trefis File Deleted: fixed-dont-remove-aliases.lambda
2018-04-27 16:17 trefis Note Edited: 0019077 View Revisions
2018-04-27 17:30 trefis Note Added: 0019078
2018-04-27 17:55 trefis Note Added: 0019079
2018-05-01 10:46 trefis Note Added: 0019083
2018-05-01 10:47 trefis Assigned To => trefis
2018-05-01 10:47 trefis Status confirmed => assigned
2018-05-01 10:47 trefis Status assigned => resolved
2018-05-01 10:47 trefis Resolution open => fixed


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker