profile
viewpoint
If you are wondering where the data of this site comes from, please visit https://api.github.com/users/xclerc/events. GitMemory does not store any data, but only uses NGINX to cache data for a period of time. The idea behind GitMemory is simply to give users a better reading experience.

ocaml/dune 1135

A composable build system for OCaml.

ocsigen/js_of_ocaml 690

Compiler from OCaml to Javascript.

thierry-martinez/pyml 107

OCaml bindings for Python

janestreet/pythonlib 54

A library to help writing wrappers around ocaml code for python

ocaml-ppx/ppx 53

The future of ppx https://discuss.ocaml.org/t/the-future-of-ppx/

ocaml-ppx/cinaps 40

Trivial Metaprogramming tool using the OCaml toplevel

janestreet/ppx_yojson_conv 23

[@@deriving] plugin to generate Yojson conversion functions

janestreet/ppx_python 19

[@@deriving] plugin to generate Python conversion functions

janestreet/async_websocket 10

A library that implements the websocket protocol on top of Async

PullRequestReviewEvent

pull request commentocaml-flambda/flambda-backend

Add precomputed cfg fields

I read it, and it looks fine.

gretay-js

comment created time in 4 hours

PullRequestReviewEvent
PullRequestReviewEvent
PullRequestReviewEvent
PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentocaml-flambda/flambda-backend

Dump location mappings between intermediate representations (cmm, lambda...) and source code.

 let rec expr ppf = function         el in       fprintf ppf "@[<1>[%a]@]" tuple el   | Cop(op, el, dbg) ->+      with_location_mapping ~label:"Cop" ~dbg ppf (fun () ->       fprintf ppf "@[<2>(%s" (operation dbg op);       List.iter (fun e -> fprintf ppf "@ %a" expr e) el;       begin match op with       | Capply mty -> fprintf ppf "@ %a" machtype mty-      | Cextcall { ret; ty_args; alloc = _; name = _; } -> +      | Cextcall { ret; ty_args; alloc = _; name = _; } ->         fprintf ppf "@ %a" extcall_signature (ret, ty_args)       | _ -> ()       end;-      fprintf ppf ")@]"+      fprintf ppf ")@]")   | Csequence(e1, e2) ->       fprintf ppf "@[<2>(seq@ %a@ %a)@]" sequence e1 sequence e2-  | Cifthenelse(e1, _e2_dbg, e2, _e3_dbg, e3, _dbg) ->-      fprintf ppf "@[<2>(if@ %a@ %a@ %a)@]" expr e1 expr e2 expr e3-  | Cswitch(e1, index, cases, _dbg) ->+  | Cifthenelse(e1, e2_dbg, e2, e3_dbg, e3, dbg) ->+      with_location_mapping ~label:"Cifthenelse-e1" ~dbg ppf (fun () ->+      fprintf ppf "@[<2>(if@ %a@ " expr e1;+      with_location_mapping ~label:"Cifthenelse-e2" ~dbg:e2_dbg ppf (fun () ->+      fprintf ppf "%a@ " expr e2);+      with_location_mapping ~label:"Cifthenelse-e3" ~dbg:e3_dbg ppf (fun () ->+      fprintf ppf "%a" expr e3);+      fprintf ppf ")@]")

(Feel free to resolve.)

poechsel

comment created time in 9 hours

PullRequestReviewEvent

Pull request review commentocaml-flambda/flambda-backend

Dump location mappings between intermediate representations (cmm, lambda...) and source code.

+(**************************************************************************)+(*                                                                        *)+(*                                 OCaml                                  *)+(*                                                                        *)+(*                  Mark Shinwell, Jane Street Europe                     *)+(*                                                                        *)+(*   Copyright 2018--2019 Jane Street Group LLC                           *)+(*                                                                        *)+(*   All rights reserved.  This file is distributed under the terms of    *)+(*   the GNU Lesser General Public License version 2.1, with the          *)+(*   special exception on linking described in the file LICENSE.          *)+(*                                                                        *)+(**************************************************************************)++[@@@ocaml.warning "+a-4-30-40-41-42"]++let is_activated = ref false++let activate_tracking () = is_activated := true+let deactivate_tracking () = is_activated := false+    let is_tracking () = !is_activated++module Location_in_file = struct+  type t = {+    line : int;+    char : int;+    bol : int;+  }++  let print ppf { line; char; bol } = Format.fprintf ppf "{line=%d; char=%d; bol=%d}" line char bol++  let create ~line ~char ~bol =+    { line; char; bol }++  let line { line; _ } = line+  let char { char; _ } = char+  let bol { bol; _ } = bol+end++module Range = struct+  type t = {+    file : string;+    start : Location_in_file.t;+    end_ : Location_in_file.t;+  }++  let print ppf {file; start; end_} =+    Format.fprintf ppf "{file=%s; start=%a; end=%a}" file Location_in_file.print start Location_in_file.print end_++  let create ~file ~start ~end_ = { file; end_; start }++  let of_location (location : Location.t) =+    let loc_start = location.loc_start in+    let loc_end = location.loc_end in+    { file = loc_start.pos_fname+      ; start = Location_in_file.create ~line:loc_start.pos_lnum+          ~char:loc_start.pos_cnum ~bol:loc_start.pos_bol+     ; end_ = Location_in_file.create ~line:loc_end.pos_lnum+          ~char:loc_end.pos_cnum ~bol:loc_end.pos_bol+    }++  let file { file; _ } = file+  let start { start; _ } = start+  let end_ { end_; _ } = end_+end++type Format.stag += Location_mapping_tag of Range.t * string option++let with_location_mapping ?label ~loc ppf f =+  if is_tracking () then begin+    let range = Range.of_location loc in+    Format.pp_open_stag ppf (Location_mapping_tag (range, label));+    let ret = f () in+    Format.pp_close_stag ppf ();+    ret+  end else f ()++module Mappings = struct+  module Item = struct+    type t = {+      source : Range.t;+      ir : Range.t;+      label : string option;+    }++    let create ~source ~ir ~label = { source; ir; label }+    let source { source; _ } = source+    let ir { ir; _ } = ir+    let label { label; _ } = label+  end+  type t = Item.t list++  let empty = []++  let append mapping t = mapping :: t++  let print ppf t =+    List.iter (fun Item.{source; ir; label} ->+        Format.fprintf ppf "%s: %a -> %a\n"+          (match label with | Some s -> s | None -> "")+          Range.print source+          Range.print ir+      ) t++  let dump ~file t =+    let ch = open_out (file ^ ".map") in+    Marshal.to_channel ch t [];+    close_out ch+end++module Tracking_formatter = struct+  module Pending_mapping = struct+    type t = {+      label : string option;+      source : Range.t;+      start_in_buffer : Location_in_file.t;+    }++    let create ~label ~source ~start_in_buffer =+      { label; source; start_in_buffer }++    let to_mapping ~file ~end_in_buffer { label; source; start_in_buffer } =+      let ir = Range.create ~file ~start:start_in_buffer ~end_:end_in_buffer in+      Mappings.Item.create ~source ~ir ~label+  end++  type t =+    { ppf : Format.formatter+    ; file : string+    ; mutable pending_mappings : Pending_mapping.t list+    ; mutable mappings : Mappings.t+    ; mutable position : Location_in_file.t+    }++  let close t = assert (List.length t.pending_mappings = 0)+  let ppf t = t.ppf++  let track_output_position_of_formatter t =+    let ppf = t.ppf in+    let { Format.out_string; out_flush; out_newline; out_spaces; out_indent } =+      Format.pp_get_formatter_out_functions ppf ()+    in+    let track_newline () =+      (* When a newline is created [line] obviously increases by one, but also+      now both bol and char are the same as the new line is empty. *)+      t.position <-+        { line = t.position.line + 1+        ; bol = t.position.char+        ; char = t.position.char+        }+    in+    let track_new_char () =+      t.position <-+        { t.position with+          char = t.position.char + 1+        }+    in+    let out_string str start_pos num_chars =+      for index = start_pos to start_pos + num_chars - 1 do+        track_new_char ();+        if str.[index] = '\n' then track_newline ()+      done;+      out_string str start_pos num_chars+    in+    let out_functions : Format.formatter_out_functions =+      { out_string+      ; out_flush+      ; (* The default [out_newline] calls [out_string] with a newline+           character, so we don't need to override [out_newline]. A similar+           situation exists for [out_spaces] and [out_indent]. *)+        out_newline+      ; out_spaces+      ; out_indent+      }+    in+    Format.pp_set_formatter_out_functions ppf out_functions+  ;;++  let intercept_location_tags_on_formatter t =+    let ppf = t.ppf in+    let stag_functions = Format.pp_get_formatter_stag_functions ppf () in+    let mark_open_stag = function+      | Location_mapping_tag (source, label) ->+        let pending =+          Pending_mapping.create ~label ~source ~start_in_buffer:t.position+        in+        t.pending_mappings <- pending :: t.pending_mappings;+        ""+      | stag -> stag_functions.mark_open_stag stag+    in+    let mark_close_stag = function+      | Location_mapping_tag _ ->+        (match t.pending_mappings with+         | [] -> failwith "End_pos_tag encountered without matching Start_pos_tag"

Right, failwith and Misc.fatal sound equally right then, and I have no preference. (Feel free to resolve.)

poechsel

comment created time in 9 hours

PullRequestReviewEvent

Pull request review commentocaml-flambda/flambda-backend

Dump location mappings between intermediate representations (cmm, lambda...) and source code.

 let rec expr ppf = function         el in       fprintf ppf "@[<1>[%a]@]" tuple el   | Cop(op, el, dbg) ->+      with_location_mapping ~label:"Cop" ~dbg ppf (fun () ->       fprintf ppf "@[<2>(%s" (operation dbg op);       List.iter (fun e -> fprintf ppf "@ %a" expr e) el;       begin match op with       | Capply mty -> fprintf ppf "@ %a" machtype mty-      | Cextcall { ret; ty_args; alloc = _; name = _; } -> +      | Cextcall { ret; ty_args; alloc = _; name = _; } ->         fprintf ppf "@ %a" extcall_signature (ret, ty_args)       | _ -> ()       end;-      fprintf ppf ")@]"+      fprintf ppf ")@]")   | Csequence(e1, e2) ->       fprintf ppf "@[<2>(seq@ %a@ %a)@]" sequence e1 sequence e2-  | Cifthenelse(e1, _e2_dbg, e2, _e3_dbg, e3, _dbg) ->-      fprintf ppf "@[<2>(if@ %a@ %a@ %a)@]" expr e1 expr e2 expr e3-  | Cswitch(e1, index, cases, _dbg) ->+  | Cifthenelse(e1, e2_dbg, e2, e3_dbg, e3, dbg) ->+      with_location_mapping ~label:"Cifthenelse-e1" ~dbg ppf (fun () ->+      fprintf ppf "@[<2>(if@ %a@ " expr e1;

I am not sure either, but you are probably right.

poechsel

comment created time in 9 hours

PullRequestReviewEvent
PullRequestReviewEvent

Pull request review commentocaml-flambda/flambda-backend

Dump location mappings between intermediate representations (cmm, lambda...) and source code.

+(**************************************************************************)+(*                                                                        *)+(*                                 OCaml                                  *)+(*                                                                        *)+(*                  Mark Shinwell, Jane Street Europe                     *)+(*                                                                        *)+(*   Copyright 2018--2019 Jane Street Group LLC                           *)+(*                                                                        *)+(*   All rights reserved.  This file is distributed under the terms of    *)+(*   the GNU Lesser General Public License version 2.1, with the          *)+(*   special exception on linking described in the file LICENSE.          *)+(*                                                                        *)+(**************************************************************************)++[@@@ocaml.warning "+a-4-30-40-41-42"]++let is_activated = ref false++let activate_tracking () = is_activated := true+let deactivate_tracking () = is_activated := false+    let is_tracking () = !is_activated++module Location_in_file = struct+  type t = {+    line : int;+    char : int;+    bol : int;+  }++  let print ppf { line; char; bol } = Format.fprintf ppf "{line=%d; char=%d; bol=%d}" line char bol++  let create ~line ~char ~bol =+    { line; char; bol }++  let line { line; _ } = line+  let char { char; _ } = char+  let bol { bol; _ } = bol+end++module Range = struct+  type t = {+    file : string;+    start : Location_in_file.t;+    end_ : Location_in_file.t;+  }++  let print ppf {file; start; end_} =+    Format.fprintf ppf "{file=%s; start=%a; end=%a}" file Location_in_file.print start Location_in_file.print end_++  let create ~file ~start ~end_ = { file; end_; start }++  let of_location (location : Location.t) =+    let loc_start = location.loc_start in+    let loc_end = location.loc_end in+    { file = loc_start.pos_fname+      ; start = Location_in_file.create ~line:loc_start.pos_lnum+          ~char:loc_start.pos_cnum ~bol:loc_start.pos_bol+     ; end_ = Location_in_file.create ~line:loc_end.pos_lnum+          ~char:loc_end.pos_cnum ~bol:loc_end.pos_bol+    }++  let file { file; _ } = file+  let start { start; _ } = start+  let end_ { end_; _ } = end_+end++type Format.stag += Location_mapping_tag of Range.t * string option++let with_location_mapping ?label ~loc ppf f =+  if is_tracking () then begin+    let range = Range.of_location loc in+    Format.pp_open_stag ppf (Location_mapping_tag (range, label));+    let ret = f () in+    Format.pp_close_stag ppf ();+    ret+  end else f ()++module Mappings = struct+  module Item = struct+    type t = {+      source : Range.t;+      ir : Range.t;+      label : string option;+    }++    let create ~source ~ir ~label = { source; ir; label }+    let source { source; _ } = source+    let ir { ir; _ } = ir+    let label { label; _ } = label+  end+  type t = Item.t list++  let empty = []++  let append mapping t = mapping :: t++  let print ppf t =+    List.iter (fun Item.{source; ir; label} ->+        Format.fprintf ppf "%s: %a -> %a\n"+          (match label with | Some s -> s | None -> "")+          Range.print source+          Range.print ir+      ) t++  let dump ~file t =+    let ch = open_out (file ^ ".map") in+    Marshal.to_channel ch t [];+    close_out ch+end++module Tracking_formatter = struct+  module Pending_mapping = struct+    type t = {+      label : string option;+      source : Range.t;+      start_in_buffer : Location_in_file.t;+    }++    let create ~label ~source ~start_in_buffer =+      { label; source; start_in_buffer }++    let to_mapping ~file ~end_in_buffer { label; source; start_in_buffer } =+      let ir = Range.create ~file ~start:start_in_buffer ~end_:end_in_buffer in+      Mappings.Item.create ~source ~ir ~label+  end++  type t =+    { ppf : Format.formatter+    ; file : string+    ; mutable pending_mappings : Pending_mapping.t list+    ; mutable mappings : Mappings.t+    ; mutable position : Location_in_file.t+    }++  let close t = assert (List.length t.pending_mappings = 0)+  let ppf t = t.ppf++  let track_output_position_of_formatter t =+    let ppf = t.ppf in+    let { Format.out_string; out_flush; out_newline; out_spaces; out_indent } =+      Format.pp_get_formatter_out_functions ppf ()+    in+    let track_newline () =+      (* When a newline is created [line] obviously increases by one, but also+      now both bol and char are the same as the new line is empty. *)+      t.position <-+        { line = t.position.line + 1+        ; bol = t.position.char+        ; char = t.position.char+        }+    in+    let track_new_char () =+      t.position <-+        { t.position with+          char = t.position.char + 1+        }+    in+    let out_string str start_pos num_chars =+      for index = start_pos to start_pos + num_chars - 1 do+        track_new_char ();+        if str.[index] = '\n' then track_newline ()+      done;+      out_string str start_pos num_chars+    in+    let out_functions : Format.formatter_out_functions =+      { out_string+      ; out_flush+      ; (* The default [out_newline] calls [out_string] with a newline+           character, so we don't need to override [out_newline]. A similar+           situation exists for [out_spaces] and [out_indent]. *)+        out_newline+      ; out_spaces+      ; out_indent+      }+    in+    Format.pp_set_formatter_out_functions ppf out_functions+  ;;++  let intercept_location_tags_on_formatter t =+    let ppf = t.ppf in+    let stag_functions = Format.pp_get_formatter_stag_functions ppf () in+    let mark_open_stag = function+      | Location_mapping_tag (source, label) ->+        let pending =+          Pending_mapping.create ~label ~source ~start_in_buffer:t.position+        in+        t.pending_mappings <- pending :: t.pending_mappings;+        ""+      | stag -> stag_functions.mark_open_stag stag+    in+    let mark_close_stag = function+      | Location_mapping_tag _ ->+        (match t.pending_mappings with+         | [] -> failwith "End_pos_tag encountered without matching Start_pos_tag"

(Will the exception be caught/used by the Format machinery? In other words, should it be a Misc.fatal?)

poechsel

comment created time in 10 hours

PullRequestReviewEvent

Pull request review commentocaml-flambda/flambda-backend

Dump location mappings between intermediate representations (cmm, lambda...) and source code.

+(**************************************************************************)+(*                                                                        *)+(*                                 OCaml                                  *)+(*                                                                        *)+(*                  Mark Shinwell, Jane Street Europe                     *)+(*                                                                        *)+(*   Copyright 2018--2019 Jane Street Group LLC                           *)+(*                                                                        *)+(*   All rights reserved.  This file is distributed under the terms of    *)+(*   the GNU Lesser General Public License version 2.1, with the          *)+(*   special exception on linking described in the file LICENSE.          *)+(*                                                                        *)+(**************************************************************************)++[@@@ocaml.warning "+a-4-30-40-41-42"]++let is_activated = ref false++let activate_tracking () = is_activated := true+let deactivate_tracking () = is_activated := false+    let is_tracking () = !is_activated
let is_tracking () = !is_activated
poechsel

comment created time in 10 hours

Pull request review commentocaml-flambda/flambda-backend

Dump location mappings between intermediate representations (cmm, lambda...) and source code.

 let rec expr ppf = function         el in       fprintf ppf "@[<1>[%a]@]" tuple el   | Cop(op, el, dbg) ->+      with_location_mapping ~label:"Cop" ~dbg ppf (fun () ->       fprintf ppf "@[<2>(%s" (operation dbg op);       List.iter (fun e -> fprintf ppf "@ %a" expr e) el;       begin match op with       | Capply mty -> fprintf ppf "@ %a" machtype mty-      | Cextcall { ret; ty_args; alloc = _; name = _; } -> +      | Cextcall { ret; ty_args; alloc = _; name = _; } ->         fprintf ppf "@ %a" extcall_signature (ret, ty_args)       | _ -> ()       end;-      fprintf ppf ")@]"+      fprintf ppf ")@]")   | Csequence(e1, e2) ->       fprintf ppf "@[<2>(seq@ %a@ %a)@]" sequence e1 sequence e2-  | Cifthenelse(e1, _e2_dbg, e2, _e3_dbg, e3, _dbg) ->-      fprintf ppf "@[<2>(if@ %a@ %a@ %a)@]" expr e1 expr e2 expr e3-  | Cswitch(e1, index, cases, _dbg) ->+  | Cifthenelse(e1, e2_dbg, e2, e3_dbg, e3, dbg) ->+      with_location_mapping ~label:"Cifthenelse-e1" ~dbg ppf (fun () ->+      fprintf ppf "@[<2>(if@ %a@ " expr e1;+      with_location_mapping ~label:"Cifthenelse-e2" ~dbg:e2_dbg ppf (fun () ->+      fprintf ppf "%a@ " expr e2);+      with_location_mapping ~label:"Cifthenelse-e3" ~dbg:e3_dbg ppf (fun () ->+      fprintf ppf "%a" expr e3);+      fprintf ppf ")@]")
      fprintf ppf ")@]"
poechsel

comment created time in 10 hours

Pull request review commentocaml-flambda/flambda-backend

Dump location mappings between intermediate representations (cmm, lambda...) and source code.

+(**************************************************************************)+(*                                                                        *)+(*                                 OCaml                                  *)+(*                                                                        *)+(*                  Mark Shinwell, Jane Street Europe                     *)+(*                                                                        *)+(*   Copyright 2018--2019 Jane Street Group LLC                           *)+(*                                                                        *)+(*   All rights reserved.  This file is distributed under the terms of    *)+(*   the GNU Lesser General Public License version 2.1, with the          *)+(*   special exception on linking described in the file LICENSE.          *)+(*                                                                        *)+(**************************************************************************)++[@@@ocaml.warning "+a-4-30-40-41-42"]++let is_activated = ref false++let activate_tracking () = is_activated := true+let deactivate_tracking () = is_activated := false+    let is_tracking () = !is_activated++module Location_in_file = struct+  type t = {+    line : int;+    char : int;+    bol : int;+  }++  let print ppf { line; char; bol } = Format.fprintf ppf "{line=%d; char=%d; bol=%d}" line char bol++  let create ~line ~char ~bol =+    { line; char; bol }++  let line { line; _ } = line+  let char { char; _ } = char+  let bol { bol; _ } = bol+end++module Range = struct+  type t = {+    file : string;+    start : Location_in_file.t;+    end_ : Location_in_file.t;+  }++  let print ppf {file; start; end_} =+    Format.fprintf ppf "{file=%s; start=%a; end=%a}" file Location_in_file.print start Location_in_file.print end_++  let create ~file ~start ~end_ = { file; end_; start }++  let of_location (location : Location.t) =+    let loc_start = location.loc_start in+    let loc_end = location.loc_end in+    { file = loc_start.pos_fname+      ; start = Location_in_file.create ~line:loc_start.pos_lnum+          ~char:loc_start.pos_cnum ~bol:loc_start.pos_bol+     ; end_ = Location_in_file.create ~line:loc_end.pos_lnum+          ~char:loc_end.pos_cnum ~bol:loc_end.pos_bol+    }++  let file { file; _ } = file+  let start { start; _ } = start+  let end_ { end_; _ } = end_+end++type Format.stag += Location_mapping_tag of Range.t * string option++let with_location_mapping ?label ~loc ppf f =+  if is_tracking () then begin+    let range = Range.of_location loc in+    Format.pp_open_stag ppf (Location_mapping_tag (range, label));+    let ret = f () in+    Format.pp_close_stag ppf ();+    ret+  end else f ()++module Mappings = struct+  module Item = struct+    type t = {+      source : Range.t;+      ir : Range.t;+      label : string option;+    }++    let create ~source ~ir ~label = { source; ir; label }+    let source { source; _ } = source+    let ir { ir; _ } = ir+    let label { label; _ } = label+  end+  type t = Item.t list++  let empty = []++  let append mapping t = mapping :: t++  let print ppf t =+    List.iter (fun Item.{source; ir; label} ->+        Format.fprintf ppf "%s: %a -> %a\n"

(Don't we want the colon to be present iff label matches Some _?)

poechsel

comment created time in 10 hours

Pull request review commentocaml-flambda/flambda-backend

Dump location mappings between intermediate representations (cmm, lambda...) and source code.

 let rec expr ppf = function         el in       fprintf ppf "@[<1>[%a]@]" tuple el   | Cop(op, el, dbg) ->+      with_location_mapping ~label:"Cop" ~dbg ppf (fun () ->       fprintf ppf "@[<2>(%s" (operation dbg op);       List.iter (fun e -> fprintf ppf "@ %a" expr e) el;       begin match op with       | Capply mty -> fprintf ppf "@ %a" machtype mty-      | Cextcall { ret; ty_args; alloc = _; name = _; } -> +      | Cextcall { ret; ty_args; alloc = _; name = _; } ->         fprintf ppf "@ %a" extcall_signature (ret, ty_args)       | _ -> ()       end;-      fprintf ppf ")@]"+      fprintf ppf ")@]")   | Csequence(e1, e2) ->       fprintf ppf "@[<2>(seq@ %a@ %a)@]" sequence e1 sequence e2-  | Cifthenelse(e1, _e2_dbg, e2, _e3_dbg, e3, _dbg) ->-      fprintf ppf "@[<2>(if@ %a@ %a@ %a)@]" expr e1 expr e2 expr e3-  | Cswitch(e1, index, cases, _dbg) ->+  | Cifthenelse(e1, e2_dbg, e2, e3_dbg, e3, dbg) ->+      with_location_mapping ~label:"Cifthenelse-e1" ~dbg ppf (fun () ->+      fprintf ppf "@[<2>(if@ %a@ " expr e1;
      fprintf ppf "@[<2>(if@ %a@ " expr e1);
poechsel

comment created time in 10 hours

PullRequestReviewEvent

Pull request review commentocaml-flambda/flambda-backend

Save cfg to file

+(**************************************************************************)+(*                                                                        *)+(*                                 OCaml                                  *)+(*                                                                        *)+(*             Xavier Leroy, projet Cristal, INRIA Rocquencourt           *)+(*                    Greta Yorsh, Jane Street Europe                     *)+(*                                                                        *)+(*   Copyright 1996 Institut National de Recherche en Informatique et     *)+(*     en Automatique.                                                    *)+(*   Copyright 2019 Jane Street Group LLC                                 *)+(*                                                                        *)+(*   All rights reserved.  This file is distributed under the terms of    *)+(*   the GNU Lesser General Public License version 2.1, with the          *)+(*   special exception on linking described in the file LICENSE.          *)+(*                                                                        *)+(**************************************************************************)++(* Marshal and unmarshal a compilation unit in Cfg format *)+type cfg_item_info =+  | Cfg of Cfg_with_layout.t+  | Data of Cmm.data_item list++type cfg_unit_info =+  {+    mutable unit_name : string;+    mutable items : cfg_item_info list;+    mutable for_pack : string option+  }++type error =+  | Wrong_format of string+  | Wrong_version of string+  | Corrupted of string+  | Marshal_failed of string++exception Error of error++let save filename cfg_unit_info =+  let ch = open_out_bin filename in+  Misc.try_finally (fun () ->+    output_string ch Config.cfg_magic_number;+    output_value ch cfg_unit_info;+    (* Saved because Emit depends on Cmm.label. *)+    output_value ch (Cmm.cur_label ());+    (* Compute digest of the contents and append it to the file. *)+    flush ch;+    let crc = Digest.file filename in+    output_value ch crc+  )+    ~always:(fun () -> close_out ch)+    ~exceptionally:(fun () -> raise (Error (Marshal_failed filename)))++let restore filename =+  let ic = open_in_bin filename in+  Misc.try_finally+    (fun () ->+       let magic = Config.cfg_magic_number in+       let buffer = really_input_string ic (String.length magic) in+       if String.equal buffer magic then begin+         try+           let cfg_unit_info = (input_value ic : cfg_unit_info) in+           let last_label = (input_value ic : Cmm.label) in+           Cmm.reset ();+           Cmm.set_label last_label;+           let crc = (input_value ic : Digest.t) in

(As an echo to another comment, other parts of the compiler use Digest.input.)

gretay-js

comment created time in 12 hours

Pull request review commentocaml-flambda/flambda-backend

Save cfg to file

     (.ocamloptcomp.objs/native/unbox_specialised_args.cmx as compiler-libs/unbox_specialised_args.cmx)     (.ocamloptcomp.objs/native/var_within_closure.cmx as compiler-libs/var_within_closure.cmx)     (.ocamloptcomp.objs/native/variable.cmx as compiler-libs/variable.cmx)+    (cfg_format.mli as compiler-libs/cfg_format.mli)

(This line has a different format, with respect to the surrounding ones - something is probably off.)

gretay-js

comment created time in 12 hours

Pull request review commentocaml-flambda/flambda-backend

Save cfg to file

 and ast_intf_magic_number = "Caml1999N029" and cmxs_magic_number = "Caml1999D029" and cmt_magic_number = "Caml1999T029" and linear_magic_number = "Caml1999L029"+and cfg_magic_number = "Caml1999G029"

(I am wondering whether we should have different magic numbers for the different backends.)

gretay-js

comment created time in 12 hours

Pull request review commentocaml-flambda/flambda-backend

Save cfg to file

+(**************************************************************************)+(*                                                                        *)+(*                                 OCaml                                  *)+(*                                                                        *)+(*             Xavier Leroy, projet Cristal, INRIA Rocquencourt           *)+(*                    Greta Yorsh, Jane Street Europe                     *)+(*                                                                        *)+(*   Copyright 1996 Institut National de Recherche en Informatique et     *)+(*     en Automatique.                                                    *)+(*   Copyright 2019 Jane Street Group LLC                                 *)+(*                                                                        *)+(*   All rights reserved.  This file is distributed under the terms of    *)+(*   the GNU Lesser General Public License version 2.1, with the          *)+(*   special exception on linking described in the file LICENSE.          *)+(*                                                                        *)+(**************************************************************************)++(* Marshal and unmarshal a compilation unit in Cfg format *)+type cfg_item_info =+  | Cfg of Cfg_with_layout.t+  | Data of Cmm.data_item list++type cfg_unit_info =+  {+    mutable unit_name : string;+    mutable items : cfg_item_info list;+    mutable for_pack : string option+  }++type error =+  | Wrong_format of string+  | Wrong_version of string+  | Corrupted of string+  | Marshal_failed of string++exception Error of error++let save filename cfg_unit_info =+  let ch = open_out_bin filename in+  Misc.try_finally (fun () ->+    output_string ch Config.cfg_magic_number;+    output_value ch cfg_unit_info;+    (* Saved because Emit depends on Cmm.label. *)+    output_value ch (Cmm.cur_label ());+    (* Compute digest of the contents and append it to the file. *)+    flush ch;+    let crc = Digest.file filename in+    output_value ch crc

(I think other parts of the compiler use Digest.output.)

gretay-js

comment created time in 12 hours

Pull request review commentocaml-flambda/flambda-backend

Save cfg to file

+(**************************************************************************)+(*                                                                        *)+(*                                 OCaml                                  *)+(*                                                                        *)+(*             Xavier Leroy, projet Cristal, INRIA Rocquencourt           *)+(*                    Greta Yorsh, Jane Street Europe                     *)+(*                                                                        *)+(*   Copyright 1996 Institut National de Recherche en Informatique et     *)+(*     en Automatique.                                                    *)+(*   Copyright 2019 Jane Street Group LLC                                 *)+(*                                                                        *)+(*   All rights reserved.  This file is distributed under the terms of    *)+(*   the GNU Lesser General Public License version 2.1, with the          *)+(*   special exception on linking described in the file LICENSE.          *)+(*                                                                        *)+(**************************************************************************)++(* Marshal and unmarshal a compilation unit in Cfg format *)+type cfg_item_info =+  | Cfg of Cfg_with_layout.t+  | Data of Cmm.data_item list++type cfg_unit_info =+  {+    mutable unit_name : string;+    mutable items : cfg_item_info list;+    mutable for_pack : string option+  }++type error =+  | Wrong_format of string+  | Wrong_version of string+  | Corrupted of string+  | Marshal_failed of string++exception Error of error++let save filename cfg_unit_info =+  let ch = open_out_bin filename in+  Misc.try_finally (fun () ->+    output_string ch Config.cfg_magic_number;+    output_value ch cfg_unit_info;+    (* Saved because Emit depends on Cmm.label. *)+    output_value ch (Cmm.cur_label ());+    (* Compute digest of the contents and append it to the file. *)+    flush ch;+    let crc = Digest.file filename in+    output_value ch crc+  )+    ~always:(fun () -> close_out ch)+    ~exceptionally:(fun () -> raise (Error (Marshal_failed filename)))++let restore filename =+  let ic = open_in_bin filename in+  Misc.try_finally+    (fun () ->+       let magic = Config.cfg_magic_number in+       let buffer = really_input_string ic (String.length magic) in+       if String.equal buffer magic then begin+         try+           let cfg_unit_info = (input_value ic : cfg_unit_info) in+           let last_label = (input_value ic : Cmm.label) in+           Cmm.reset ();+           Cmm.set_label last_label;+           let crc = (input_value ic : Digest.t) in+           cfg_unit_info, crc+         with End_of_file | Failure _ -> raise (Error (Corrupted filename))+            | Error e -> raise (Error e)+       end+       else if String.sub buffer 0 9 = String.sub magic 0 9 then

(String.sub buffer 0 9 may raise.)

gretay-js

comment created time in 12 hours

Pull request review commentocaml-flambda/flambda-backend

Save cfg to file

 let compile_fundecl ~ppf_dump fd_cmm =   ++ Profile.record ~accumulate:true "linearize" Linearize.fundecl   ++ pass_dump_linear_if ppf_dump dump_linear "Linearized code"   ++ (fun (fd : Linear.fundecl) ->-      if !use_ocamlcfg then begin-        let cfg = Linear_to_cfg.run fd ~preserve_orig_labels:true in+    if !use_ocamlcfg then begin+      fd+      ++ Profile.record ~accumulate:true "linear_to_cfg"+           (Linear_to_cfg.run ~preserve_orig_labels:false)

(Not sure it matters, but preserve_orig_labels changed from true to false.)

gretay-js

comment created time in 11 hours

PullRequestReviewEvent
PullRequestReviewEvent
PullRequestReviewEvent