package incremental

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file import.ml

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
[%%import "debug.mlh"]

open Core

(* All [assert]s and other checks throughout the code are guarded by [if debug].  The
   DEBUG variable is set in the lib [incremental] and unset in the lib
   [incremental_debug], but apart from that they are identical.  Tests are run with both
   the production and debug lib, and users can choose to build with the debug library, if
   they suspect they found a bug in incremental. *)

[%%if JSC_DEBUG]

let debug = true

[%%else]

let debug = false

[%%endif]

let concat = String.concat
let tag name a sexp_of_a = (name, a) |> [%sexp_of: string * a]

module Step_function = Incremental_step_function

module Time_ns = struct
  include Time_ns

  let sexp_of_t = Time_ns.Alternate_sexp.sexp_of_t
end

module Array = struct
  include Array

  (* Not defining aliases in production mode, since they break type specialization of
     array accesses. *)
  [%%if JSC_DEBUG]

  let unsafe_get = get
  let unsafe_set = set

  [%%endif]

  (* Requires [len >= length t]. *)
  let realloc t ~len a =
    let new_t = create ~len a in
    Array.blit ~src:t ~src_pos:0 ~dst:new_t ~dst_pos:0 ~len:(length t);
    new_t
  ;;
end

module Uopt = struct
  include Uopt

  let unsafe_value = if debug then value_exn else unsafe_value
end

module Uniform_array = struct
  include Uniform_array

  [%%if JSC_DEBUG]

  let unsafe_get = get
  let unsafe_set = set_with_caml_modify

  [%%else]

  (* Uniform_array is being "smart" by checking if elements are integers, but Uopt.t
     almost never contain integers, so the extra check to make generated code harder to
     read and potentially slower. *)
  let unsafe_set = unsafe_set_with_caml_modify
  let set = set_with_caml_modify

  [%%endif]

  (* Requires [len >= length t]. *)
  let realloc t ~len =
    let new_t = create ~len Uopt.none in
    blit ~src:t ~src_pos:0 ~dst:new_t ~dst_pos:0 ~len:(length t);
    new_t
  ;;
end

module Alarm_precision = Timing_wheel.Alarm_precision