Skip to content

Commit 7308651

Browse files
v0.18~preview.130.36+188
1 parent 26c2f4d commit 7308651

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+2823
-2030
lines changed

shadow-stdlib/gen/mapper.mll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ let module_replacement = function
274274
| "Gc" -> Some No_equivalent
275275
| "Printexc" -> Some (Repl_text "Use [Exn] or [Backtrace] instead")
276276
| "Seq" -> Some (Approx "Sequence")
277+
| "Atomic" ->
278+
Some (Repl_text "\
279+
Use [Atomic] from [Portable] (or [Core], which reexports it from\n\
280+
[Portable]) instead")
277281
| _ -> None
278282

279283
let replace ~is_exn id replacement =

src/array.ml

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
open! Import
22
include Array_intf.Definitions
3-
include Array0
3+
module Array = Array0
4+
include Array
45

56
type ('a : any_non_null) t = 'a array
67

@@ -567,7 +568,7 @@ let filter_map t ~f = filter_mapi t ~f:(fun _i a -> f a) [@nontail]
567568
let filter_opt t = filter_map t ~f:Fn.id
568569

569570
let raise_length_mismatch name n1 n2 =
570-
invalid_argf "length mismatch in %s: %d <> %d" name n1 n2 ()
571+
Printf.invalid_argf "length mismatch in %s: %d <> %d" name n1 n2 ()
571572
[@@cold]
572573
;;
573574

@@ -916,7 +917,16 @@ let transpose_exn tt =
916917
| Some tt' -> tt'
917918
;;
918919

919-
let map t ~f = map t ~f
920+
[@@@warning "-incompatible-with-upstream"]
921+
922+
let%template[@kind
923+
ki = (value, float64, bits32, bits64, word, immediate, immediate64)
924+
, ko = (value, float64, bits32, bits64, word, immediate, immediate64)] map
925+
t
926+
~f
927+
=
928+
(map [@kind ki ko]) t ~f
929+
;;
920930

921931
include%template Binary_searchable.Make1 [@modality portable] (struct
922932
type nonrec 'a t = 'a t

src/array0.ml

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,18 @@ let fill (local_ a) ~pos ~len v =
137137
else unsafe_fill a pos len v
138138
;;
139139

140-
let init len ~(local_ f : _ -> _) =
140+
let%template[@alloc a = (heap, stack)] init len ~(local_ f : _ -> _) =
141141
if len = 0
142142
then [||]
143143
else if len < 0
144144
then invalid_arg "Array.init"
145145
else (
146-
let res = create ~len (f 0) in
147-
for i = 1 to Int0.pred len do
148-
unsafe_set res i (f i)
149-
done;
150-
res)
146+
(let res = (create [@alloc a]) ~len (f 0) in
147+
for i = 1 to Int0.pred len do
148+
unsafe_set res i (f i)
149+
done;
150+
res)
151+
[@exclave_if_stack a])
151152
;;
152153

153154
let make_matrix = Stdlib.Array.make_matrix
@@ -190,7 +191,35 @@ let iteri t ~(local_ f : _ -> _ -> _) =
190191
done
191192
;;
192193

193-
let map (local_ t) ~(local_ f : _ -> _) =
194+
[@@@warning "-incompatible-with-upstream"]
195+
196+
let%template[@kind
197+
ki = (value, immediate, immediate64, float64, bits32, bits64, word)
198+
, ko = (float64, bits32, bits64, word)] map
199+
(type (a : ki) (b : ko))
200+
(local_ (t : a array))
201+
~(local_ f : _ -> _)
202+
: b array
203+
=
204+
let len = length t in
205+
if len = 0
206+
then [||]
207+
else (
208+
let r = magic_create_uninitialized ~len in
209+
for i = 0 to len - 1 do
210+
unsafe_set r i (f (unsafe_get t i))
211+
done;
212+
r)
213+
;;
214+
215+
let%template[@kind
216+
ki = (value, immediate, immediate64, float64, bits32, bits64, word)
217+
, ko = (value, immediate, immediate64)] map
218+
(type (a : ki) (b : ko))
219+
(local_ (t : a array))
220+
~(local_ f : _ -> _)
221+
: b array
222+
=
194223
let len = length t in
195224
if len = 0
196225
then [||]

src/array0.mli

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
@@ portable
2+
3+
[%%template:
4+
external create
5+
: ('a : any_non_null).
6+
len:int -> 'a -> 'a array @ m
7+
= "%makearray_dynamic"
8+
[@@alloc __ @ m = (heap_global, stack_local)] [@@layout_poly]]
9+
10+
external create_local
11+
: ('a : any_non_null).
12+
len:int -> 'a -> local_ 'a array
13+
= "%makearray_dynamic"
14+
[@@layout_poly]
15+
16+
external magic_create_uninitialized
17+
: ('a : any_non_null).
18+
len:int -> ('a array[@local_opt])
19+
= "%makearray_dynamic_uninit"
20+
[@@layout_poly]
21+
22+
external%template get
23+
: ('a : any_non_null).
24+
('a array[@local_opt]) @ m -> (int[@local_opt]) -> 'a @ m
25+
= "%array_safe_get"
26+
[@@layout_poly] [@@mode m = (uncontended, shared)]
27+
28+
external length
29+
: ('a : any_non_null).
30+
('a array[@local_opt]) @ contended -> int
31+
= "%array_length"
32+
[@@layout_poly]
33+
34+
external set
35+
: ('a : any_non_null).
36+
('a array[@local_opt]) -> (int[@local_opt]) -> 'a -> unit
37+
= "%array_safe_set"
38+
[@@layout_poly]
39+
40+
external%template unsafe_get
41+
: ('a : any_non_null).
42+
('a array[@local_opt]) @ m -> (int[@local_opt]) -> 'a @ m
43+
= "%array_unsafe_get"
44+
[@@mode m = (uncontended, shared)] [@@layout_poly]
45+
46+
external unsafe_set
47+
: ('a : any_non_null).
48+
('a array[@local_opt]) -> (int[@local_opt]) -> 'a -> unit
49+
= "%array_unsafe_set"
50+
[@@layout_poly]
51+
52+
external unsafe_blit
53+
: src:('a array[@local_opt])
54+
-> src_pos:int
55+
-> dst:('a array[@local_opt])
56+
-> dst_pos:int
57+
-> len:int
58+
-> unit
59+
= "caml_array_blit"
60+
61+
external unsafe_fill : local_ 'a array -> int -> int -> 'a -> unit = "caml_array_fill"
62+
external unsafe_sub : local_ 'a array -> int -> int -> 'a array = "caml_array_sub"
63+
external concat : local_ 'a array list -> 'a array = "caml_array_concat"
64+
val max_length : int
65+
val create_float_uninitialized : len:int -> float array
66+
val append : 'a array -> 'a array -> 'a array
67+
68+
val blit
69+
: src:'a array @ local
70+
-> src_pos:int
71+
-> dst:'a array @ local
72+
-> dst_pos:int
73+
-> len:int
74+
-> unit
75+
76+
val fill : 'a array @ local -> pos:int -> len:int -> 'a -> unit
77+
78+
val%template init : int -> f:(int -> 'a) @ local -> 'a array @ m
79+
[@@alloc __ @ m = (heap_global, stack_local)]
80+
81+
val make_matrix : dimx:int -> dimy:int -> 'a -> 'a array array
82+
val of_list : 'a list -> 'a array
83+
val sub : 'a array @ local -> pos:int -> len:int -> 'a array
84+
val to_list : 'a array -> 'a list
85+
val fold : 'a array -> init:'b -> f:('b -> 'a -> 'b) @ local -> 'b
86+
87+
val%template fold_right : 'a array @ m -> f:('a @ m -> 'b -> 'b) @ local -> init:'b -> 'b
88+
[@@mode m = (uncontended, shared)]
89+
90+
val iter : 'a array -> f:('a -> unit) @ local -> unit
91+
val iteri : 'a array -> f:(int -> 'a -> unit) @ local -> unit
92+
93+
[@@@warning "-incompatible-with-upstream"]
94+
95+
val%template map
96+
: ('a : ki) ('b : ko).
97+
'a array @ local -> f:('a -> 'b) @ local -> 'b array
98+
[@@kind
99+
ki = (value, immediate, immediate64, float64, bits32, bits64, word)
100+
, ko = (value, immediate, immediate64, float64, bits32, bits64, word)]
101+
102+
val mapi : 'a array -> f:(int -> 'a -> 'b) @ local -> 'b array
103+
val stable_sort : 'a array -> compare:('a -> 'a -> int) -> unit
104+
val swap : 'a array @ local -> int -> int -> unit

src/array_intf.ml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ module Definitions = struct
1717
include Indexed_container.S1_with_creators with type 'a t := 'a t
1818
include Invariant.S1 with type 'a t := 'a t
1919

20+
val%template map : ('a : ki) ('b : ko). 'a t -> f:local_ ('a -> 'b) -> 'b t
21+
[@@kind
22+
ki = (value, float64, bits32, bits64, word, immediate, immediate64)
23+
, ko = (value, float64, bits32, bits64, word, immediate, immediate64)]
24+
2025
(** Maximum length of a normal array. The maximum length of a float array is
2126
[max_length/2] on 32-bit machines and [max_length] on 64-bit machines. *)
2227
val max_length : int
@@ -117,6 +122,10 @@ module Definitions = struct
117122
float array representations are enabled. *)
118123
val create_float_uninitialized : len:int -> float t
119124

125+
(** [init n ~f] creates an array of length [n] with index [i] set to [f i]. *)
126+
val%template init : int -> f:(int -> 'a) @ local -> 'a array @ m
127+
[@@alloc __ @ m = (heap_global, stack_local)]
128+
120129
(** [Array.make_matrix dimx dimy e] returns a two-dimensional array (an array of
121130
arrays) with first dimension [dimx] and second dimension [dimy]. All the elements
122131
of this new matrix are initially physically equal to [e]. The element ([x,y]) of a

src/array_permute.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@@ portable
2+
3+
val permute
4+
: ?random_state:Random.State.t
5+
-> ?pos:int
6+
-> ?len:int
7+
-> 'a array @ local
8+
-> unit

src/base.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ include (
3838
end
3939
(* Modules defined in Base *)
4040
with module Array := Shadow_stdlib.Array
41-
with module Atomic := Shadow_stdlib.Atomic
4241
with module Bool := Shadow_stdlib.Bool
4342
with module Buffer := Shadow_stdlib.Buffer
4443
with module Bytes := Shadow_stdlib.Bytes
@@ -187,10 +186,8 @@ end
187186
(**/**)
188187

189188
module Exported_for_specific_uses = struct
190-
module Fieldslib = Fieldslib
191189
module Globalize = Globalize
192190
module Obj_array = Obj_array
193-
module Variantslib = Variantslib
194191

195192
let am_testing = am_testing
196193
end

src/blit.ml

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,23 @@ include Blit_intf.Definitions
33

44
[@@@warning "-incompatible-with-upstream"]
55

6-
module%template.portable Make1_phantom_distinct
6+
module%template.portable Make1_phantom2_distinct
77
(Src : sig
8-
type ('elt : k, 'phantom) t
8+
type ('elt : k, 'p1, 'p2) t
99

10-
val length : local_ (_, _) t -> int
10+
val length : local_ (_, _, _) t -> int
1111
end)
1212
(Dst : sig
13-
type ('elt : k, 'phantom) t
13+
type ('elt : k, 'p1, 'p2) t
1414

15-
val length : local_ (_, _) t -> int
16-
val create_like : len:int -> local_ ('elt, _) Src.t -> ('elt, _) t
17-
val unsafe_blit : (('elt, _) Src.t, ('elt, _) t) blit
15+
val length : local_ (_, _, _) t -> int
16+
val create_like : len:int -> local_ ('elt, _, _) Src.t -> ('elt, _, _) t
17+
val unsafe_blit : (('elt, _, _) Src.t, ('elt, _, _) t) blit
1818
end) :
19-
S1_phantom_distinct
19+
S1_phantom2_distinct
2020
[@kind k]
21-
with type ('elt, 'phantom) src := ('elt, 'phantom) Src.t
22-
with type ('elt, 'phantom) dst := ('elt, 'phantom) Dst.t = struct
21+
with type ('elt, 'p1, 'p2) src := ('elt, 'p1, 'p2) Src.t
22+
with type ('elt, 'p1, 'p2) dst := ('elt, 'p1, 'p2) Dst.t = struct
2323
let unsafe_blit = Dst.unsafe_blit
2424

2525
let blit ~src ~src_pos ~dst ~dst_pos ~len =
@@ -71,10 +71,10 @@ module%template.portable [@modality p] Make1 (Sequence : Sequence1 [@kind k]) =
7171
module Seq = struct
7272
include Sequence
7373

74-
type ('a : k, _) t = 'a Sequence.t
74+
type ('a : k, _, _) t = 'a Sequence.t
7575
end
7676

77-
include Make1_phantom_distinct [@kind k] [@modality p] (Seq) (Seq)
77+
include Make1_phantom2_distinct [@kind k] [@modality p] (Seq) (Seq)
7878
end
7979
[@@kind k = (value, immediate, immediate64)]
8080

@@ -87,7 +87,7 @@ module%template.portable
8787
end) =
8888
struct
8989
module Sequence = struct
90-
type (_, _) t = Sequence.t
90+
type (_, _, _) t = Sequence.t
9191

9292
open Sequence
9393

@@ -96,7 +96,7 @@ struct
9696
let unsafe_blit = unsafe_blit
9797
end
9898

99-
include Make1_phantom_distinct [@modality p] (Sequence) (Sequence)
99+
include Make1_phantom2_distinct [@modality p] (Sequence) (Sequence)
100100
end
101101

102102
module%template.portable
@@ -108,16 +108,16 @@ module%template.portable
108108
val create : len:int -> t
109109
val unsafe_blit : (Src.t, t) blit
110110
end) =
111-
Make1_phantom_distinct [@modality p]
111+
Make1_phantom2_distinct [@modality p]
112112
(struct
113-
type (_, _) t = Src.t
113+
type (_, _, _) t = Src.t
114114

115115
open Src
116116

117117
let length = length
118118
end)
119119
(struct
120-
type (_, _) t = Dst.t
120+
type (_, _, _) t = Dst.t
121121

122122
open Dst
123123

0 commit comments

Comments
 (0)