caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* inspecting abstract values in the debugger
       [not found] <A6296BA9-6068-4445-8CD6-94BF835F2814@cs.uni-sb.de>
@ 2007-02-20  9:43 ` Christian Lindig
  2007-03-07  8:33   ` [Caml-list] " Hendrik Tews
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Lindig @ 2007-02-20  9:43 UTC (permalink / raw)
  To: Caml List

[-- Attachment #1: Type: text/plain, Size: 1734 bytes --]


In the debugger, abstract values cannot be inspected. This can be  
annoying since it gets in the way of understanding why something  
doesn't work. At least for debugging we would like all types to be  
fully declared such that we can inspect their values in the debugger.

A quick fix is to remove all .cmi and .mli files and to compile a  
project again. Then at least all top-level types would be manifest  
and the debugger could print them. It would still not work for sub  
structures since they could be still constraint by interfaces.  
Another problem is that removing .cmi and .mli files temporarily for  
debugging does not work too well with Makefiles.

Therefore I'd like to discuss a feature wish: a compiler flag that  
makes all type declarations manifest. When compiling a signature  
ascription - whether per explicit ":" operator or implicitly per .mli  
file - the compiler would automatically refine the signature to make  
all types manifest. In the case of .mli's this might require  
replacing an existing .cmi file.

As a crude first approximation I am supplying a patch below that  
introduces such a flag. The -ignore-cmi flag makes the ocamlc  
compiler behave as if no .cmi/.mli file exists, hence it creates a  
new one that hides nothing. As explained above, this only works on  
the outermost level and therefore is not ideal. I'd expect that the  
correct solution is not too hard to implement for somebody who  
understands the type checker.

Beware: sometimes the type annotations provided by an .mli file are  
necessary and compiling with -ignore-cmi might not work. In this case  
either compile the one file without -ignore-cmi, or supply the type  
annotation in the .ml file.

-- Christian


[-- Attachment #2: ocaml-3.09.3.patch --]
[-- Type: application/octet-stream, Size: 4574 bytes --]

diff -c -r -x '*.cmo' -x '*.cmi' -x '*.[oa]' ocaml-3.09.3/driver/main.ml ocaml-3.09.3-patched/driver/main.ml
*** ocaml-3.09.3/driver/main.ml	Mon May  9 15:39:17 2005
--- ocaml-3.09.3-patched/driver/main.ml	Sat Feb 17 22:15:03 2007
***************
*** 134,139 ****
--- 134,140 ----
    let _drawlambda = set dump_rawlambda
    let _dlambda = set dump_lambda
    let _dinstr = set dump_instr
+   let _ignore_cmi = set ignore_cmi
    let anonymous = anonymous
  end)
  
diff -c -r -x '*.cmo' -x '*.cmi' -x '*.[oa]' ocaml-3.09.3/driver/main_args.ml ocaml-3.09.3-patched/driver/main_args.ml
*** ocaml-3.09.3/driver/main_args.ml	Wed Dec 28 18:27:03 2005
--- ocaml-3.09.3-patched/driver/main_args.ml	Sat Feb 17 22:18:10 2007
***************
*** 60,65 ****
--- 60,66 ----
       val _drawlambda : unit -> unit
       val _dlambda : unit -> unit
       val _dinstr : unit -> unit
+      val _ignore_cmi : unit -> unit
       val anonymous : string -> unit
     end) =
  struct
***************
*** 158,164 ****
      "-dlambda", Arg.Unit F._dlambda, " (undocumented)";
      "-dinstr", Arg.Unit F._dinstr, " (undocumented)";
      "-use-prims", Arg.String F._use_prims, "<file>  (undocumented)";
! 
      "-", Arg.String F.anonymous,
             "<file>  Treat <file> as a file name (even if it starts with `-')";
    ]
--- 159,165 ----
      "-dlambda", Arg.Unit F._dlambda, " (undocumented)";
      "-dinstr", Arg.Unit F._dinstr, " (undocumented)";
      "-use-prims", Arg.String F._use_prims, "<file>  (undocumented)";
!     "-ignore-cmi", Arg.Unit F._ignore_cmi, " ignore own cmi/mli file";
      "-", Arg.String F.anonymous,
             "<file>  Treat <file> as a file name (even if it starts with `-')";
    ]
diff -c -r -x '*.cmo' -x '*.cmi' -x '*.[oa]' ocaml-3.09.3/driver/main_args.mli ocaml-3.09.3-patched/driver/main_args.mli
*** ocaml-3.09.3/driver/main_args.mli	Mon May  9 15:39:17 2005
--- ocaml-3.09.3-patched/driver/main_args.mli	Sat Feb 17 22:13:39 2007
***************
*** 60,65 ****
--- 60,66 ----
        val _drawlambda : unit -> unit
        val _dlambda : unit -> unit
        val _dinstr : unit -> unit
+       val _ignore_cmi: unit -> unit
        val anonymous : string -> unit
      end) :
    sig
diff -c -r -x '*.cmo' -x '*.cmi' -x '*.[oa]' ocaml-3.09.3/tools/ocamlcp.ml ocaml-3.09.3-patched/tools/ocamlcp.ml
*** ocaml-3.09.3/tools/ocamlcp.ml	Mon May  9 15:39:17 2005
--- ocaml-3.09.3-patched/tools/ocamlcp.ml	Sat Feb 17 22:20:10 2007
***************
*** 87,92 ****
--- 87,93 ----
    let _drawlambda = option "-drawlambda"
    let _dlambda = option "-dlambda"
    let _dinstr = option "-dinstr"
+   let _ignore_cmi = option "-ignore_cmi"
    let anonymous = process_file
  end);;
  
diff -c -r -x '*.cmo' -x '*.cmi' -x '*.[oa]' ocaml-3.09.3/typing/typemod.ml ocaml-3.09.3-patched/typing/typemod.ml
*** ocaml-3.09.3/typing/typemod.ml	Fri Apr 21 08:18:51 2006
--- ocaml-3.09.3-patched/typing/typemod.ml	Sun Feb 18 08:00:53 2007
***************
*** 793,799 ****
      let coercion =
        let sourceintf =
          Misc.chop_extension_if_any sourcefile ^ !Config.interface_suffix in
!       if Sys.file_exists sourceintf then begin
          let intf_file =
            try
              find_in_path_uncap !Config.load_path (modulename ^ ".cmi")
--- 793,799 ----
      let coercion =
        let sourceintf =
          Misc.chop_extension_if_any sourcefile ^ !Config.interface_suffix in
!       if Sys.file_exists sourceintf && not !Clflags.ignore_cmi then begin
          let intf_file =
            try
              find_in_path_uncap !Config.load_path (modulename ^ ".cmi")
diff -c -r -x '*.cmo' -x '*.cmi' -x '*.[oa]' ocaml-3.09.3/utils/clflags.ml ocaml-3.09.3-patched/utils/clflags.ml
*** ocaml-3.09.3/utils/clflags.ml	Mon Aug  1 17:51:09 2005
--- ocaml-3.09.3-patched/utils/clflags.ml	Sat Feb 17 22:16:22 2007
***************
*** 77,82 ****
--- 77,83 ----
  
  let native_code = ref false             (* set to true under ocamlopt *)
  let inline_threshold = ref 10
+ let ignore_cmi = ref false              (* -ignore_cmi *)
  
  let dont_write_files = ref false        (* set to true under ocamldoc *)
  
diff -c -r -x '*.cmo' -x '*.cmi' -x '*.[oa]' ocaml-3.09.3/utils/clflags.mli ocaml-3.09.3-patched/utils/clflags.mli
*** ocaml-3.09.3/utils/clflags.mli	Wed Oct 26 15:23:27 2005
--- ocaml-3.09.3-patched/utils/clflags.mli	Sat Feb 17 22:15:48 2007
***************
*** 73,75 ****
--- 73,76 ----
  val dont_write_files : bool ref
  val std_include_flag : string -> string
  val std_include_dir : unit -> string list
+ val ignore_cmi : bool ref

[-- Attachment #3: Type: text/plain, Size: 2 bytes --]




^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] inspecting abstract values in the debugger
  2007-02-20  9:43 ` inspecting abstract values in the debugger Christian Lindig
@ 2007-03-07  8:33   ` Hendrik Tews
  0 siblings, 0 replies; 3+ messages in thread
From: Hendrik Tews @ 2007-03-07  8:33 UTC (permalink / raw)
  To: Caml List

Christian Lindig <lindig@cs.uni-sb.de> writes:

   In the debugger, abstract values cannot be inspected. This can be

Yes, and the same applies for values inside polymorphic
functions. For instance, inside a List.iter you cannot inspect
the list.

   Therefore I'd like to discuss a feature wish: a compiler flag that
   makes all type declarations manifest. When compiling a signature

This doesn't solve the problem with polymorphic functions.

I would rather like to see a debugger feature "print value with
this type", where it is the responsibility of the user to supply
the right type. For instance, inside List.iter, you could do

  print a : int option

to see the current element of an int option list.

Bye,

Hendrik


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Caml-list] inspecting abstract values in the debugger
       [not found] <20070220094543.EE684BC76@yquem.inria.fr>
@ 2007-02-20 10:04 ` David Allsopp
  0 siblings, 0 replies; 3+ messages in thread
From: David Allsopp @ 2007-02-20 10:04 UTC (permalink / raw)
  To: caml-list

Christian Lindig wrote:
> In the debugger, abstract values cannot be inspected.

I can't experiment in the debugger as I develop under native Windows and so
use the toplevel for debugging, but won't inserting temporary Obj.magic
calls into your code to "cast" abstract values to their actual
representations help as it does in the toplevel?

e.g.

*S.mli*
type t
val make : int -> int -> t

*S.ml*
type t = int * int
let make x y = (x, y)

*Toplevel*
#load "t.cmo";;
let (t : int * int) = Obj.magic (T.make 1 2);;


David


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2007-03-07  8:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <A6296BA9-6068-4445-8CD6-94BF835F2814@cs.uni-sb.de>
2007-02-20  9:43 ` inspecting abstract values in the debugger Christian Lindig
2007-03-07  8:33   ` [Caml-list] " Hendrik Tews
     [not found] <20070220094543.EE684BC76@yquem.inria.fr>
2007-02-20 10:04 ` David Allsopp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).