File: deriving_inline.ml

package info (click to toggle)
ppx-fields-conv 0.17.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 276 kB
  • sloc: ml: 2,177; sh: 37; makefile: 14
file content (178 lines) | stat: -rw-r--r-- 4,663 bytes parent folder | download
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
module One_thing = struct
  type t =
    { x : int
    ; mutable y : bool
    }
  [@@deriving_inline fields ~setters]

  let _ = fun (_ : t) -> ()
  let set_y _r__ v__ = _r__.y <- v__
  let _ = set_y

  [@@@end]
end

module Everything = struct
  type t =
    { x : int
    ; mutable y : bool
    }
  [@@deriving_inline
    fields
      ~getters
      ~setters
      ~names
      ~fields
      ~iterators:
        ( create
        , make_creator
        , exists
        , fold
        , fold_right
        , for_all
        , iter
        , map
        , to_list
        , map_poly )
      ~direct_iterators:
        (exists, fold, fold_right, for_all, iter, map, to_list, set_all_mutable_fields)]

  include struct
    [@@@ocaml.warning "-60"]

    let _ = fun (_ : t) -> ()
    let y _r__ = _r__.y
    let _ = y
    let set_y _r__ v__ = _r__.y <- v__
    let _ = set_y
    let x _r__ = _r__.x
    let _ = x

    module Fields = struct
      let names = [ "x"; "y" ]
      let _ = names

      let y =
        (Fieldslib.Field.Field
           { Fieldslib.Field.For_generated_code.force_variance =
               (fun (_ : [< `Read | `Set_and_create ]) -> ())
           ; name = "y"
           ; getter = y
           ; setter = Some set_y
           ; fset = (fun _r__ v__ -> { _r__ with y = v__ })
           }
          : ([< `Read | `Set_and_create ], _, bool) Fieldslib.Field.t_with_perm)
      ;;

      let _ = y

      let x =
        (Fieldslib.Field.Field
           { Fieldslib.Field.For_generated_code.force_variance =
               (fun (_ : [< `Read | `Set_and_create ]) -> ())
           ; name = "x"
           ; getter = x
           ; setter = None
           ; fset = (fun _r__ v__ -> { _r__ with x = v__ })
           }
          : ([< `Read | `Set_and_create ], _, int) Fieldslib.Field.t_with_perm)
      ;;

      let _ = x

      let make_creator ~x:x_fun__ ~y:y_fun__ compile_acc__ =
        let x_gen__, compile_acc__ = x_fun__ x compile_acc__ in
        let y_gen__, compile_acc__ = y_fun__ y compile_acc__ in
        ( (fun acc__ ->
            let x = x_gen__ acc__ in
            let y = y_gen__ acc__ in
            { x; y })
        , compile_acc__ )
      ;;

      let _ = make_creator
      let create ~x ~y = { x; y }
      let _ = create
      let map ~x:x_fun__ ~y:y_fun__ = { x = x_fun__ x; y = y_fun__ y }
      let _ = map

      let iter ~x:x_fun__ ~y:y_fun__ =
        (x_fun__ x : unit);
        (y_fun__ y : unit)
      ;;

      let _ = iter
      let fold ~init:init__ ~x:x_fun__ ~y:y_fun__ = y_fun__ (x_fun__ init__ x) y
      let _ = fold

      let map_poly record__ =
        [ record__.Fieldslib.Field.f x; record__.Fieldslib.Field.f y ]
      ;;

      let _ = map_poly
      let for_all ~x:x_fun__ ~y:y_fun__ = (true && x_fun__ x) && y_fun__ y
      let _ = for_all
      let exists ~x:x_fun__ ~y:y_fun__ = (false || x_fun__ x) || y_fun__ y
      let _ = exists
      let to_list ~x:x_fun__ ~y:y_fun__ = [ x_fun__ x; y_fun__ y ]
      let _ = to_list
      let fold_right ~x:x_fun__ ~y:y_fun__ ~init:init__ = x_fun__ x (y_fun__ y init__)
      let _ = fold_right

      module Direct = struct
        let iter record__ ~x:x_fun__ ~y:y_fun__ =
          x_fun__ x record__ record__.x;
          y_fun__ y record__ record__.y
        ;;

        let _ = iter

        let fold record__ ~init:init__ ~x:x_fun__ ~y:y_fun__ =
          y_fun__ (x_fun__ init__ x record__ record__.x) y record__ record__.y
        ;;

        let _ = fold

        let for_all record__ ~x:x_fun__ ~y:y_fun__ =
          (true && x_fun__ x record__ record__.x) && y_fun__ y record__ record__.y
        ;;

        let _ = for_all

        let exists record__ ~x:x_fun__ ~y:y_fun__ =
          (false || x_fun__ x record__ record__.x) || y_fun__ y record__ record__.y
        ;;

        let _ = exists

        let to_list record__ ~x:x_fun__ ~y:y_fun__ =
          [ x_fun__ x record__ record__.x; y_fun__ y record__ record__.y ]
        ;;

        let _ = to_list

        let fold_right record__ ~x:x_fun__ ~y:y_fun__ ~init:init__ =
          x_fun__ x record__ record__.x (y_fun__ y record__ record__.y init__)
        ;;

        let _ = fold_right

        let map record__ ~x:x_fun__ ~y:y_fun__ =
          { x = x_fun__ x record__ record__.x; y = y_fun__ y record__ record__.y }
        ;;

        let _ = map

        let set_all_mutable_fields _record__ ~y =
          let _record__ = Fieldslib.Field.For_generated_code.opaque_identity _record__ in
          _record__.y <- y
          [@@inline always]
        ;;

        let _ = set_all_mutable_fields
      end
    end
  end [@@ocaml.doc "@inline"]

  [@@@end]
end