title: Improving the lambda-code OCaml generates for assertions
body: <p>I would like to improve the lambda-code generated for the "assert" OCaml 3.12.1 construct. Here is an example:</p>
  
  <pre><code>let f x =
      assert (x = 4);
      assert (2 + x = 6);
      assert (x - x = 0);
      exit x
  </code></pre>
  
  <p>The file longfilename.ml above is representative of large OCaml modules for which I would like lambda-code generation to be improved. It compiles to:</p>
  
  <pre><code>$ ocamlopt -S longfilename.ml
  $ cat longfilename.s
  ...
      .data
      .quad   3072
  _camlLongfilename__2:
      .quad   L100007
      .quad   9
      .quad   9
      .quad   2300
  L100007: .L100007:
      .ascii  "longfilename.ml"
      .byte   0
      .data
      .quad   3072
  _camlLongfilename__3:
      .quad   L100006
      .quad   7
      .quad   9
      .quad   2300
  L100006: .L100006:
      .ascii  "longfilename.ml"
      .byte   0
      .data
      .quad   3072
  _camlLongfilename__4:
      .quad   L100005
      .quad   5
      .quad   9
      .quad   2300
  L100005: .L100005:
      .ascii  "longfilename.ml"
      .byte   0
  ...
  </code></pre>
  
  <p>The above is terribly redundant. The name of the source file each assertion may come from is duplicated. The culprit appears to be bytecomp/translcore.ml:</p>
  
  <pre><code>let assert_failed loc =
    (* [Location.get_pos_info] is too expensive *)
    let fname = match loc.Location.loc_start.Lexing.pos_fname with
                | "" -&gt; !Location.input_name
                | x -&gt; x
    in
    let pos = loc.Location.loc_start in
    let line = pos.Lexing.pos_lnum in
    let char = pos.Lexing.pos_cnum - pos.Lexing.pos_bol in
    Lprim(Praise, [Lprim(Pmakeblock(0, Immutable),
            [transl_path Predef.path_assert_failure;
             Lconst(Const_block(0,
                [Const_base(Const_string fname);
                 Const_base(Const_int line);
                 Const_base(Const_int char)]))])])
  ;;
  </code></pre>
  
  <p>On the face of it, it looks like it would be enough to give a name to
  <code>Const_base(Const_string fname)</code>, and to store and reuse it with
  a compile-time hash-table. For intra-module optimization, 
  the changes just might be manageable
  (as long as the hash-table is reset at each compilation unit).</p>
  
  <p>I am a little out of my depth here, especially the “reset at each compilation
  unit” part. Any hint?</p>