Skip to content

Add Lev_module_definition debugging event#857

Merged
mshinwell merged 9 commits intoocaml:trunkfrom
mshinwell:modpath
May 31, 2017
Merged

Add Lev_module_definition debugging event#857
mshinwell merged 9 commits intoocaml:trunkfrom
mshinwell:modpath

Conversation

@mshinwell
Copy link
Contributor

This pull request provides a means of communicating, at the top of a let-binding corresponding to the result of compiling some module, the module path of that module to the middle-end. This is needed so that various identifier names can be correctly prefixed with their path prior to DWARF emission.

Could an expert please advise how to fix the commented "None" case properly?

At present this is only implemented for the Flambda path (which is also used by bytecode). (This is also the same for the "phantom let" support and so forth.) It isn't clear to me that it is worth spending time to implement this various support on the Closure path, given the efforts that are happening to try to make Flambda fast enough in -Oclassic mode. However opinions are welcome...

| Some path -> path
(* CR mshinwell: work out what this should say *)
| None ->
match rootpath with
Copy link
Contributor

@alainfrisch alainfrisch Oct 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If rootpath_inside_module = None, then necessarily rootpath = None: you don't need this pattern matching.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, indeed

@alainfrisch
Copy link
Contributor

I'm not sure about how this will be used, but don't you want to keep more information also for recursive modules, for functor's body, for local modules, etc?

| None ->
match rootpath with
| Some path -> path
| None -> Pident (Ident.create_persistent "Unknown")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't you want to keep at least the module name in that case?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's mb.mb_id, right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.

@mshinwell
Copy link
Contributor Author

mshinwell commented Oct 13, 2016

@alainfrisch Yes, we should do all of those indeed. (I will try to add this)

@mshinwell
Copy link
Contributor Author

As for how this is used: it's used for prefixing variable and function names so that in the debugger full paths appear correctly. For example, a toplevel value named "bar" in module "Foo" will be available in the debugger as "Foo.bar" (even though Flambda may have lifted the definition to a symbol). Function names are also prefixed.

An extended notion of path is actually used in the debugger to allow the identification of subfunctions, though that isn't relevant to this patch. For example the function "baz" whose static scope is "Foo.bar" will be identified as "Foo.bar.baz". Locations are used instead of names if the function is anonymous.

@alainfrisch
Copy link
Contributor

It isn't clear to me that it is worth spending time to implement this various support on the Closure path, given the efforts that are happening to try to make Flambda fast enough in -Oclassic mode.

The decision to drop the Closure path does not really depend on the amount of efforts put into improving the speed of -Oclassic, but rather on the outcome of these efforts, which -- I guess -- are hard to predict. And even if good compilation-time can be achieved, flambda is still evolving quite fast and has not been fully battle-tested yet, so I would argue to keep Closure for some time anyway.

That said, it seems perfectly fine to declare that the advanced debugging experience will only be available to those deciding to switch to flambda.

@mshinwell
Copy link
Contributor Author

@alainfrisch I've addressed your comments together with the addition of support for local and recursive modules. Could you please look this over again? As an example:

module Normal = struct
  type t = int

  let f (t : t) = t

  module Submodule = struct
    let f2 (t : t) = t
  end
end

module Functor (X : sig type t end) = struct
  type z = X.t

  let g (x : z) = x
end

let toplevel_fn () =
  let module M = struct
    let in_local_module x = x + 42
  end in
  M.in_local_module 3

module rec Rec1 : sig
  val in_rec1 : int -> int
end = struct
  let in_rec1 x = x + 1
end and Rec2 : sig
  val in_rec2 : int -> int
end = struct
  let in_rec2 x = x + 2
end

produces:

(let
  (Normal/1204 =
     (under-module-path(Testmod.Normal) testmod.ml(1):0-120
       (let
         (f/1206 = (function t/1207 t/1207)
          Submodule/1208 =
            (under-module-path(Testmod.Normal.Submodule) testmod.ml(6):62-116
              (let (f2/1209 = (function t/1210 t/1210))
                (makeblock 0 f2/1209))))
         (makeblock 0 f/1206 Submodule/1208)))
   Functor/1211 =
     (under-module-path(Testmod.Functor) testmod.ml(11):122-206
       (function X/1213 is_a_functor
         (let (g/1215 = (function x/1216 x/1216)) (makeblock 0 g/1215))))
   toplevel_fn/1217 =
     (function param/1221
       (let
         (M/1220 =
            (in-local-module(M/1220) testmod.ml(18):242-243
              (let (in_local_module/1218 = (function x/1219 (+ x/1219 42)))
                (makeblock 0 in_local_module/1218))))
         (apply (field 0 M/1220) 3)))
   Rec1/1222 =
     (apply (field 0 (global CamlinternalMod!)) [0: "testmod.ml" 25 6]
       [0: [0: 0a]])
   Rec2/1223 =
     (apply (field 0 (global CamlinternalMod!)) [0: "testmod.ml" 29 6]
       [0: [0: 0a]]))
  (seq
    (apply (field 1 (global CamlinternalMod!)) [0: [0: 0a]] Rec1/1222
      (under-module-path(Testmod.Rec1) testmod.ml(23):320-409
        (let (in_rec1/1230 = (function x/1231 (+ x/1231 1)))
          (makeblock 0 in_rec1/1230))))
    (apply (field 1 (global CamlinternalMod!)) [0: [0: 0a]] Rec2/1223
      (under-module-path(Testmod.Rec2) testmod.ml(27):410-492
        (let (in_rec2/1232 = (function x/1233 (+ x/1233 2)))
          (makeblock 0 in_rec2/1232))))
    (makeblock 0 Normal/1204 Functor/1211 toplevel_fn/1217 Rec1/1222
      Rec2/1223)))

It looks like the character positions may be too large for recursive modules, but that can be fixed separately.

The intention is that local modules will have their path completed upon entry to Flambda. That process will take the current module and function path (e.g. Foo.f) and prepend it to the local module path from the event to form the new current module path (e.g. Foo.f.M). This will be dealt with in a subsequent patch.

@alainfrisch
Copy link
Contributor

Could you please look this over again?

I'm really not familiar with debugging events and how they are used, so it would be better if someone more familiar with these topics can have a look.

Being able to give a nice name, including for local modules, is a very good direction, but it would be nice it this could also be used for synthesizing the internal name attached to exception/extension constructors. Do you think your current approach would help for this goal as well? (I'm a bit concerned about the fact that support for local module is related to flambda, for instance.)

@damiendoligez damiendoligez modified the milestone: 4.05-or-later Feb 15, 2017
@chambart
Copy link
Contributor

It seems safe. I think it can be merged after rebasing.

@mshinwell
Copy link
Contributor Author

@alainfrisch I'm not sure about exception/extension constructor names; I will have to leave that for someone else to investigate. We need to make progress with merging these patches for the native debugging work...

@mshinwell
Copy link
Contributor Author

I've made a few simplifications (there was some potential confusion between absolute and relative module paths before). We may need to tweak this some more once all of the debugging work has been merged, but I think this is ok for now.

@mshinwell mshinwell merged commit a01ca47 into ocaml:trunk May 31, 2017
stedolan added a commit to stedolan/ocaml that referenced this pull request Oct 25, 2022
* Use relative paths instead of project_root/ocaml

* Simplify ocaml/tools/dune

  - Remove an flambda-backend specific build hack that is no longer needed
  - Restore rules for ocaml/tools/objinfo by renaming tools/objinfo

* Move parts of the Makefile useful for building ocaml/ to that subdir.

Refactors the Makefile to remove flambda-backend dependencies.

* Move dune environments to ocaml/dune
sadiqj pushed a commit to sadiqj/ocaml that referenced this pull request Feb 21, 2023
* Use relative paths instead of project_root/ocaml

* Simplify ocaml/tools/dune

  - Remove an flambda-backend specific build hack that is no longer needed
  - Restore rules for ocaml/tools/objinfo by renaming tools/objinfo

* Move parts of the Makefile useful for building ocaml/ to that subdir.

Refactors the Makefile to remove flambda-backend dependencies.

* Move dune environments to ocaml/dune
stedolan pushed a commit to stedolan/ocaml that referenced this pull request Mar 21, 2023
25188da flambda-backend: Missed comment from PR802 (ocaml#887)
9469765 flambda-backend: Improve the semantics of asynchronous exceptions (new simpler version) (ocaml#802)
d9e4dd0 flambda-backend: Fix `make runtest` on NixOS (ocaml#874)
4bbde7a flambda-backend: Simpler symbols (ocaml#753)
ef37262 flambda-backend: Add opaqueness to Obj.magic under Flambda 2 (ocaml#862)
a9616e9 flambda-backend: Add build system hooks for ocaml-jst (ocaml#869)
045ef67 flambda-backend: Allow the compiler to build with stock Dune (ocaml#868)
3cac5be flambda-backend: Simplify Makefile logic for natdynlinkops (ocaml#866)
c5b12bf flambda-backend: Remove unnecessary install lines (ocaml#860)
ff12bbe flambda-backend: Fix unused variable warning in st_stubs.c (ocaml#861)
c84976c flambda-backend: Static check for noalloc: attributes (ocaml#825)
ca56052 flambda-backend: Build system refactoring for ocaml-jst (ocaml#857)
39eb7f9 flambda-backend: Remove integer comparison involving nonconstant polymorphic variants (ocaml#854)
c102688 flambda-backend: Fix soundness bug by using currying information from typing (ocaml#850)
6a96b61 flambda-backend: Add a primitive to enable/disable the tick thread (ocaml#852)
f64370b flambda-backend: Make Obj.dup use a new primitive, %obj_dup (ocaml#843)
9b78eb2 flambda-backend: Add test for ocaml#820 (include functor soundness bug) (ocaml#841)
8f24346 flambda-backend: Add `-dtimings-precision` flag (ocaml#833)
65c2f22 flambda-backend: Add test for ocaml#829 (ocaml#831)
7b27a49 flambda-backend: Follow-up PR#829 (comballoc fixes for locals) (ocaml#830)
ad7ec10 flambda-backend: Use a custom condition variable implementation (ocaml#787)
3ee650c flambda-backend: Fix soundness bug in include functor (ocaml#820)
2f57378 flambda-backend: Static check noalloc (ocaml#778)
aaad625 flambda-backend: Emit begin/end region only when stack allocation is enabled (ocaml#812)
17c7173 flambda-backend: Fix .cmt for included signatures (ocaml#803)
e119669 flambda-backend: Increase delays in tests/lib-threads/beat.ml (ocaml#800)
ccc356d flambda-backend: Prevent dynamic loading of the same .cmxs twice in private mode, etc. (ocaml#784)
14eb572 flambda-backend: Make local extension point equivalent to local_ expression (ocaml#790)
487d11b flambda-backend: Fix tast_iterator and tast_mapper for include functor. (ocaml#795)
a50a818 flambda-backend: Reduce closure allocation in List (ocaml#792)
96c9c60 flambda-backend: Merge ocaml-jst
a775b88 flambda-backend: Fix ocaml/otherlibs/unix 32-bit build (ocaml#767)
f7c2679 flambda-backend: Create object files internally to avoid invoking GAS (ocaml#757)
c7a46bb flambda-backend: Bugfix for Cmmgen.expr_size with locals (ocaml#756)
b337cb6 flambda-backend: Fix build_upstream for PR749 (ocaml#750)
8e7e81c flambda-backend: Differentiate is_int primitive between generic and variant-only versions (ocaml#749)

git-subtree-dir: ocaml
git-subtree-split: 25188da
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants