• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MinaProtocol / mina / 2863

05 Nov 2024 06:20PM UTC coverage: 30.754% (-16.6%) from 47.311%
2863

push

buildkite

web-flow
Merge pull request #16296 from MinaProtocol/dkijania/more_multi_jobs

more multi jobs in CI

20276 of 65930 relevant lines covered (30.75%)

8631.7 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

60.0
/src/lib/unsigned_extended/unsigned_extended.ml
1
(* unsigned_extended.ml *)
2

9✔
3
open Core_kernel
4
include Intf
5
open Snark_params
6
open Tick
7

8
module type Unsigned_intf = Unsigned.S
9

10
module Extend
11
    (Unsigned : Unsigned.S) (M : sig
12
      val length : int
13
    end) : S with type t = Unsigned.t = struct
14
  assert (M.length < Field.size_in_bits - 3)
18✔
15

16
  let length_in_bits = M.length
17

18
  module T = struct
19
    include Sexpable.Of_stringable (Unsigned)
20

21
    type t = Unsigned.t
22

23
    let compare = Unsigned.compare
24

25
    let hash_fold_t s t = Int64.hash_fold_t s (Unsigned.to_int64 t)
5,040✔
26

27
    let hash t = Int64.hash (Unsigned.to_int64 t)
×
28

29
    let to_bigint t =
30
      let i64 = Unsigned.to_int64 t in
60,997✔
31
      if Int64.(i64 >= 0L) then Bignum_bigint.of_int64 i64
60,997✔
32
      else
33
        Bignum_bigint.(
×
34
          of_int64 i64 - of_int64 Int64.min_value + of_int64 Int64.max_value
×
35
          + one)
36
  end
37

38
  include T
39
  include Hashable.Make (T)
40

41
  include (Unsigned : Unsigned_intf with type t := t)
42

43
  (* serializes to and from json as strings since bit lengths > 32 cannot be represented in json *)
44
  let to_yojson n = `String (to_string n)
2,776✔
45

46
  let of_yojson = function
47
    | `String s ->
×
48
        Ok (of_string s)
×
49
    | _ ->
×
50
        Error "expected string"
51

52
  let ( < ) x y = compare x y < 0
1,788✔
53

54
  let ( > ) x y = compare x y > 0
812✔
55

56
  let ( = ) x y = compare x y = 0
4,025,185✔
57

58
  let ( <= ) x y = compare x y <= 0
×
59

60
  let ( >= ) x y = compare x y >= 0
×
61
end
62

63
module UInt64 = struct
64
  module M =
65
    Extend
66
      (Unsigned.UInt64)
67
      (struct
68
        let length = 64
69
      end)
70

71
  (* this module allows use to generate With_all_version_tags from the
72
     Binable.Of_binable functor below, needed to decode transaction ids
73
     for V1 signed commands; it does not add any tags
74
  *)
75
  module Int64_for_version_tags = struct
76
    [%%versioned
77
    module Stable = struct
78
      [@@@no_toplevel_latest_type]
79

80
      module V1 = struct
81
        type t = (Int64.t[@version_asserted])
9✔
82

83
        let to_latest = Fn.id
84

85
        module With_all_version_tags = struct
86
          type typ = t [@@deriving bin_io_unversioned]
9✔
87

88
          type t = typ [@@deriving bin_io_unversioned]
9✔
89
        end
90
      end
91
    end]
92
  end
93

94
  [%%versioned_binable
95
  module Stable = struct
×
96
    [@@@no_toplevel_latest_type]
97

98
    module V1 = struct
99
      [@@@with_all_version_tags]
100

101
      type t = Unsigned.UInt64.t
18✔
102

103
      let to_latest = Fn.id
104

105
      (* these are defined in the Extend functor, rather than derived, so import them *)
106
      [%%define_locally
107
      M.
108
        ( equal
109
        , compare
110
        , hash
111
        , hash_fold_t
112
        , sexp_of_t
113
        , t_of_sexp
114
        , to_yojson
115
        , of_yojson )]
116

117
      module M = struct
118
        type t = Unsigned.UInt64.t
119

120
        let to_binable = Unsigned.UInt64.to_int64
121

122
        let of_binable = Unsigned.UInt64.of_int64
123
      end
124

125
      include Binable.Of_binable (Int64_for_version_tags.Stable.V1) (M)
126
    end
127
  end]
×
128

129
  include M
130

131
  let to_uint64 : t -> uint64 = Fn.id
132

133
  let of_uint64 : uint64 -> t = Fn.id
134
end
135

136
module UInt32 = struct
137
  module M =
138
    Extend
139
      (Unsigned.UInt32)
140
      (struct
141
        let length = 32
142
      end)
143

144
  (* this module allows use to generate With_all_version_tags from the
145
     Binable.Of_binable functor below, needed to decode transaction ids
146
     for V1 signed commands; it does not add any tags
147
  *)
148
  module Int32_for_version_tags = struct
149
    [%%versioned
150
    module Stable = struct
151
      [@@@no_toplevel_latest_type]
152

153
      module V1 = struct
154
        type t = (Int32.t[@version_asserted])
9✔
155

156
        let to_latest = Fn.id
157

158
        module With_all_version_tags = struct
159
          type typ = t [@@deriving bin_io_unversioned]
9✔
160

161
          type t = typ [@@deriving bin_io_unversioned]
9✔
162
        end
163
      end
164
    end]
165
  end
166

167
  [%%versioned_binable
168
  module Stable = struct
×
169
    [@@@no_toplevel_latest_type]
170

171
    module V1 = struct
172
      [@@@with_all_version_tags]
173

174
      type t = Unsigned.UInt32.t
18✔
175

176
      let to_latest = Fn.id
177

178
      (* these are defined in the Extend functor, rather than derived, so import them *)
179
      [%%define_locally
180
      M.
181
        ( equal
182
        , compare
183
        , hash
184
        , hash_fold_t
185
        , sexp_of_t
186
        , t_of_sexp
187
        , to_yojson
188
        , of_yojson )]
189

190
      module M = struct
191
        type t = Unsigned.UInt32.t
192

193
        let to_binable = Unsigned.UInt32.to_int32
194

195
        let of_binable = Unsigned.UInt32.of_int32
196
      end
197

198
      include Binable.Of_binable (Int32_for_version_tags.Stable.V1) (M)
199
    end
200
  end]
×
201

202
  include M
203

204
  let to_uint32 : t -> uint32 = Fn.id
205

206
  let of_uint32 : uint32 -> t = Fn.id
207
end
9✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc