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

Uncaught exception when a public library has a virtual module #10635

Open
gadmm opened this issue Jun 10, 2024 · 0 comments
Open

Uncaught exception when a public library has a virtual module #10635

gadmm opened this issue Jun 10, 2024 · 0 comments

Comments

@gadmm
Copy link

gadmm commented Jun 10, 2024

I set out to use virtual modules to present my library as a virtual library with two implementations:

  • one library destined to be used in programs that use the Thread module (named memprof-limits.threads);
  • one for programs that need to avoid linking with the Thread module (named memprof-limits.nothreads).

The current state of my implementation is available here (branch virtual_lib): https://gitlab.com/gadmm/memprof-limits/-/tree/virtual_lib?ref_type=heads, more precisely the following commit introduces the virtual modules: https://gitlab.com/gadmm/memprof-limits/-/commit/fc96f08aa54c87e5897e72b5a92104be02e0c143

As a control, I created a version that uses virtual modules but does not declare public names for the libraries (branch virtual_lib.nocrash): https://gitlab.com/gadmm/memprof-limits/-/tree/virtual_lib.nocrash?ref_type=heads, more precisely the following commit: https://gitlab.com/gadmm/memprof-limits/-/commit/751890860b8e6107bc9afc9029c30fc2a2a902f2

I also found the manual unclear about virtual libraries; it claims to do what I want (example of libraries clock.unix and clock.win) but the example is not detailed and it took several days of failed attempts to get to something that might work (though it shows the bug below). I wonder if I am doing things correctly and, if not, what is the intended use.

Expected Behavior

dune build and dune test successfully complete in the same way with both branches when using ocaml 4 (e.g. 4.14).

Actual Behavior

dune build and dune test succeed with the branch virtual_lib.nocrash. However, for the branch virtual_lib (adding public_names), dune outputs the following message:

Internal error, please report upstream including the contents of _build/log.
Description:
  ("External.cm_dir",
  { t =
      { public_dir = In_build_dir "default/src/nothreads"
      ; private_dir = None
      ; public_cmi_ocaml_dir = None
      ; melange_dir = In_build_dir "default/src/nothreads/melange"
      ; public_cmi_melange_dir = None
      }
  })
Raised at Stdune__Code_error.raise in file
  "otherlibs/stdune/src/code_error.ml", line 10, characters 30-62
Called from
  Dune_rules__Install_rules.Stanzas_to_entries.lib_install_files.(fun) in
  file "src/dune_rules/install_rules.ml", line 253, characters 21-71
Called from
  Dune_rules__Install_rules.Stanzas_to_entries.lib_install_files.set_dir.(fun)
  in file "src/dune_rules/install_rules.ml", line 285, characters 59-75
Called from Stdlib__List.rev_map.rmap_f in file "list.ml", line 103,
  characters 22-25
Called from Stdune__List.rev_concat_map.aux in file
  "otherlibs/stdune/src/list.ml", line 54, characters 15-18
Called from Dune_rules__Install_rules.Stanzas_to_entries.lib_install_files in
  file "src/dune_rules/install_rules.ml", line 304, characters 8-138
Called from Fiber__Core.O.(>>|).(fun) in file "vendor/fiber/src/core.ml",
  line 253, characters 36-41
Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml",
  line 76, characters 8-11
-> required by ("stanzas-to-entries", "default")
-> required by ("symlinked_entries", ("default", "memprof-limits"))
-> required by ("Rule.make", ())
-> required by ("execute-rule", { id = 2; info = Internal })
-> required by ("<unnamed>", ())
-> required by ("build-file", In_build_dir "default/memprof-limits.install")
-> required by
   ("build_file_selector",
   { dir = In_build_dir "default"
   ; predicate = True
   ; only_generated_files = false
   })
-> required by ("<unnamed>", ())
-> required by
   ("build-alias", { dir = In_build_dir "default"; name = "all" })
-> required by ("<unnamed>", ())
-> required by
   ("build-alias", { dir = In_build_dir "default"; name = "default" })
-> required by ("toplevel", ())

I must not crash.  Uncertainty is the mind-killer. Exceptions are the
little-death that brings total obliteration.  I will fully express my cases. 
Execution will pass over me and through me.  And when it has gone past, I
will unwind the stack along its path.  Where the cases are handled there will
be nothing.  Only I will remain.
Internal error, please report upstream including the contents of _build/log.
Description:
  ("External.cm_dir",
  { t =
      { public_dir = In_build_dir "default/src/threads"
      ; private_dir = None
      ; public_cmi_ocaml_dir = None
      ; melange_dir = In_build_dir "default/src/threads/melange"
      ; public_cmi_melange_dir = None
      }
  })
Raised at Stdune__Code_error.raise in file
  "otherlibs/stdune/src/code_error.ml", line 10, characters 30-62
Called from
  Dune_rules__Install_rules.Stanzas_to_entries.lib_install_files.(fun) in
  file "src/dune_rules/install_rules.ml", line 253, characters 21-71
Called from
  Dune_rules__Install_rules.Stanzas_to_entries.lib_install_files.set_dir.(fun)
  in file "src/dune_rules/install_rules.ml", line 285, characters 59-75
Called from Stdlib__List.rev_map.rmap_f in file "list.ml", line 103,
  characters 22-25
Called from Stdune__List.rev_concat_map.aux in file
  "otherlibs/stdune/src/list.ml", line 54, characters 15-18
Called from Dune_rules__Install_rules.Stanzas_to_entries.lib_install_files in
  file "src/dune_rules/install_rules.ml", line 304, characters 8-138
Called from Fiber__Core.O.(>>|).(fun) in file "vendor/fiber/src/core.ml",
  line 253, characters 36-41
Called from Fiber__Scheduler.exec in file "vendor/fiber/src/scheduler.ml",
  line 76, characters 8-11
-> required by ("stanzas-to-entries", "default")
-> required by ("symlinked_entries", ("default", "memprof-limits"))
-> required by ("Rule.make", ())
-> required by ("execute-rule", { id = 2; info = Internal })
-> required by ("<unnamed>", ())
-> required by ("build-file", In_build_dir "default/memprof-limits.install")
-> required by
   ("build_file_selector",
   { dir = In_build_dir "default"
   ; predicate = True
   ; only_generated_files = false
   })
-> required by ("<unnamed>", ())
-> required by
   ("build-alias", { dir = In_build_dir "default"; name = "all" })
-> required by ("<unnamed>", ())
-> required by
   ("build-alias", { dir = In_build_dir "default"; name = "default" })
-> required by ("toplevel", ())

Nevertheless the library appears to compile and the tests do succeed after this initial error message.

Please find attached _build/log.

Reproduction

  1. Have 4.12 ≤ ocaml < 5.0 as your current opam switch.
  2. git clone -b virtual_lib --single-branch https://gitlab.com/gadmm/memprof-limits.git
  3. cd memprof-limits
  4. dune build or dune test

Specifications

  • Version of dune (output of dune --version): 3.15.3
  • Version of ocaml (output of ocamlc --version): 4.14.0
  • Operating system (distribution and version): Ubuntu 23.04

Additional information

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants