caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Christian Lindig <lindig@cs.uni-sb.de>
To: Caml List <caml-list@inria.fr>
Subject: inspecting abstract values in the debugger
Date: Tue, 20 Feb 2007 10:43:39 +0100	[thread overview]
Message-ID: <0FF9569C-EDF8-4D11-AC9C-B50CAEFE1D7E@cs.uni-sb.de> (raw)
In-Reply-To: <A6296BA9-6068-4445-8CD6-94BF835F2814@cs.uni-sb.de>

[-- 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 --]




       reply	other threads:[~2007-02-20  9:45 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <A6296BA9-6068-4445-8CD6-94BF835F2814@cs.uni-sb.de>
2007-02-20  9:43 ` Christian Lindig [this message]
2007-03-07  8:33   ` [Caml-list] " Hendrik Tews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0FF9569C-EDF8-4D11-AC9C-B50CAEFE1D7E@cs.uni-sb.de \
    --to=lindig@cs.uni-sb.de \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).