Skip to content

Segmentation fault with recursive first class modules #12592

@lthls

Description

@lthls

Hopefully the last report of a bug with recursive values, as I'm reaching the end of my work on rewriting the compilation of recursive values in a more obviously correct way.
Here is an example:

module type N = sig val n : int end
module type T = functor (N : N) -> N
module N0 = struct let n = 0 end
let n =
  let rec (module M : T) =
    let module F (N : N) : N = struct
      module N2 = M(N)
      let n = N2.n
    end in
    let (module F : T) = if true then (module F) else (module F) in
    (module F : T)
  in
  let module N1 = M(N0) in
  N1.n

The issue is the same as usual: Rec_check thinks that first-class modules are Static, but that's not always the case: not only can they be non-recursive but without a known size (e.g. let rec (module M) = (module N)), they can also, in some tricky cases, be actually recursive but without a known size.

I think I could refine the current classification to only return Static when we actually have an expression with statically-known size, however I would like to be able to actually compute this size (for the rewritten compilation) and I'm a bit stuck. Does anyone known of a good way to compute a size from an arbitrary module expression (of type Typedtree.module_expr) ? Translmod.transl_module is the only one I could find, and it's not easily lifted out. There are also ways to compute sizes from the module types, but I couldn't find it a convenient function for that and it's not my preferred choice anyway (it would allow more recursive definitions than we have now, which is not the direction I want).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions