Skip to content

Commit 7e67b26

Browse files
authored
Merge branch 'main' into delete-old-ctypes
2 parents 9086656 + 2de23a6 commit 7e67b26

File tree

10 files changed

+152
-61
lines changed

10 files changed

+152
-61
lines changed

bin/dune_init.ml

+32-31
Original file line numberDiff line numberDiff line change
@@ -265,63 +265,64 @@ module Component = struct
265265
open Dune_lang
266266

267267
module Field = struct
268-
let atoms : Atom.t list -> Dune_lang.t list =
269-
List.map ~f:(fun x -> Atom x)
268+
let inline_tests = Encoder.field_b "inline_tests"
270269

271-
let public_name name = List [ atom "public_name"; Atom name ]
270+
let pps_encoder pps = Encoder.list Encoder.string ("pps" :: pps)
272271

273-
let name name = List [ atom "name"; Atom name ]
274-
275-
let inline_tests = List [ atom "inline_tests" ]
276-
277-
let libraries libs = List (atom "libraries" :: atoms libs)
278-
279-
let pps pps = List [ atom "preprocess"; List (atom "pps" :: atoms pps) ]
280-
281-
let optional_field ~f = function
272+
let preprocess_field = function
282273
| [] -> []
283-
| args -> [ f args ]
274+
| pps -> [ Encoder.field "preprocess" pps_encoder pps ]
284275

285276
let common (options : Options.Common.t) =
286-
name options.name
287-
:: (optional_field ~f:libraries options.libraries
288-
@ optional_field ~f:pps options.pps)
277+
[ Encoder.field "name" Encoder.string (Atom.to_string options.name)
278+
; Encoder.field_l "libraries" Encoder.string
279+
(List.map ~f:Atom.to_string options.libraries)
280+
]
281+
@ preprocess_field (List.map ~f:Atom.to_string options.pps)
289282
end
290283

291284
(* Make CST representation of a stanza for the given `kind` *)
292285
let make kind common_options fields =
293-
(* Form the AST *)
294-
List ((atom kind :: fields) @ Field.common common_options)
286+
Encoder.named_record_fields kind (fields @ Field.common common_options)
295287
(* Convert to a CST *)
296288
|> Dune_lang.Ast.add_loc ~loc:Loc.none
297289
|> Cst.concrete (* Package as a list CSTs *) |> List.singleton
298290

299291
let add_to_list_set elem set =
300292
if List.mem ~equal:Dune_lang.Atom.equal set elem then set else elem :: set
301293

302-
let public_name_field ~default = function
303-
| (None : Options.public_name option) -> []
304-
| Some Use_name -> [ Field.public_name default ]
305-
| Some (Public_name name) -> [ Field.public_name name ]
294+
let public_name_encoder ~default (p : Options.public_name) =
295+
let atom =
296+
match p with
297+
| Use_name -> default
298+
| Public_name x -> x
299+
in
300+
Atom atom
301+
302+
let public_name_field ~default =
303+
Encoder.field_o "public_name" (public_name_encoder ~default)
306304

307305
let executable (common : Options.Common.t) (options : Options.Executable.t)
308306
=
309-
let public_name = public_name_field ~default:common.name options.public in
310-
make "executable" common public_name
307+
make "executable" common
308+
[ public_name_field ~default:common.name options.public ]
311309

312-
let library (common : Options.Common.t) (options : Options.Library.t) =
313-
let common, inline_tests =
314-
if not options.inline_tests then (common, [])
315-
else
310+
let library (common : Options.Common.t)
311+
{ Options.Library.inline_tests; public } =
312+
let common =
313+
if inline_tests then
316314
let pps =
317315
add_to_list_set
318316
(Dune_lang.Atom.of_string "ppx_inline_test")
319317
common.pps
320318
in
321-
({ common with pps }, [ Field.inline_tests ])
319+
{ common with pps }
320+
else common
322321
in
323-
let public_name = public_name_field ~default:common.name options.public in
324-
make "library" common (public_name @ inline_tests)
322+
make "library" common
323+
[ public_name_field ~default:common.name public
324+
; Field.inline_tests inline_tests
325+
]
325326

326327
let test common (() : Options.Test.t) = make "test" common []
327328

otherlibs/stdune/src/option.ml

+35
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,38 @@ let first_some x y =
119119
match x with
120120
| None -> y
121121
| Some _ -> x
122+
123+
module Unboxed = struct
124+
module T : sig
125+
type 'a t
126+
127+
val get_exn : 'a t -> 'a
128+
129+
val some : 'a -> 'a t
130+
131+
val none : 'a t
132+
133+
val is_none : 'a t -> bool
134+
end = struct
135+
type 'a t = 'a
136+
137+
let none : 'a. 'a t = Obj.magic 0
138+
139+
let is_none x = x == none
140+
141+
let get_exn x =
142+
if is_none x then Code_error.raise "Option.Unboxed.get_exn: x is none" [];
143+
x
144+
145+
let some x =
146+
if Obj.is_int (Obj.repr x) then
147+
Code_error.raise "Option.Unboxed.some: x must not be immediate" [];
148+
x
149+
end
150+
151+
include T
152+
153+
let to_dyn f x =
154+
if is_none x then Dyn.variant "None" []
155+
else Dyn.variant "Some" [ f (get_exn x) ]
156+
end

otherlibs/stdune/src/option.mli

+19
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,22 @@ module List : sig
6060
end
6161

6262
val merge : 'a t -> 'a t -> f:('a -> 'a -> 'a) -> 'a t
63+
64+
module Unboxed : sig
65+
(** Poor man's unboxed option types. The value stored must not be immediate. A
66+
consequence of that is that such option types cannot be nested *)
67+
68+
type 'a t
69+
70+
val get_exn : 'a t -> 'a
71+
72+
(** [some a] will construct the present value. If [a] is immediate, this
73+
function will raise *)
74+
val some : 'a -> 'a t
75+
76+
val none : 'a t
77+
78+
val is_none : 'a t -> bool
79+
80+
val to_dyn : ('a -> Dyn.t) -> 'a t -> Dyn.t
81+
end

src/dag/dag.ml

+11-7
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module Make (Value : Value) () : S with type value := Value.t = struct
1818
; mutable level : int
1919
; mutable deps : node list
2020
; mutable rev_deps : node list
21-
; mutable parent : node option
21+
; mutable parent : node Option.Unboxed.t
2222
; value : Value.t
2323
}
2424

@@ -51,12 +51,9 @@ module Make (Value : Value) () : S with type value := Value.t = struct
5151

5252
let get_outgoing _ v = v.deps
5353

54-
let get_parent _ v =
55-
match v.parent with
56-
| None -> assert false
57-
| Some v -> v
54+
let get_parent _ v = Option.Unboxed.get_exn v.parent
5855

59-
let set_parent _ v p = v.parent <- Some p
56+
let set_parent _ v p = v.parent <- Option.Unboxed.some p
6057

6158
let raw_add_edge _ v w = v.deps <- w :: v.deps
6259

@@ -70,7 +67,14 @@ module Make (Value : Value) () : S with type value := Value.t = struct
7067

7168
let create_node value =
7269
let id = Id.gen () in
73-
{ id; mark = -1; level = 1; deps = []; rev_deps = []; parent = None; value }
70+
{ id
71+
; mark = -1
72+
; level = 1
73+
; deps = []
74+
; rev_deps = []
75+
; parent = Option.Unboxed.none
76+
; value
77+
}
7478

7579
let value t = t.value
7680

src/dune_engine/action_runner.ml

100755100644
File mode changed.

src/dune_engine/action_runner.mli

100755100644
File mode changed.

src/fsevents/fsevents_stubs.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#include <AvailabilityMacros.h>
1111
#endif
1212

13-
#if defined(__APPLE__) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 100700
13+
#if defined(__APPLE__) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 101000
1414

1515
#include <CoreFoundation/CoreFoundation.h>
1616
#include <CoreServices/CoreServices.h>

src/memo/memo.ml

+38-22
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,13 @@ module Cache_lookup = struct
314314
outcome would have been [Out_of_date {old_value = None}] instead. *)
315315
module Failure = struct
316316
type 'a t =
317-
| Out_of_date of { old_value : 'a option }
317+
| Out_of_date of
318+
{ (* ['a] is instantiated to ['a Cached_value.t] below but making
319+
this explicit would require us to move this type and [Result]
320+
into the recursive module of [M]. We leave this comment to
321+
explain why using [Option.Unboxed.t] is OK here. *)
322+
old_value : 'a Option.Unboxed.t
323+
}
318324
| Cancelled of { dependency_cycle : Cycle_error.t }
319325
end
320326

@@ -325,9 +331,11 @@ module Cache_lookup = struct
325331

326332
let _to_string_hum = function
327333
| Ok _ -> "Ok"
328-
| Failure (Out_of_date { old_value = None }) -> "Failed (no value)"
329-
| Failure (Out_of_date { old_value = Some _ }) -> "Failed (old value)"
330334
| Failure (Cancelled _) -> "Failed (dependency cycle)"
335+
| Failure (Out_of_date { old_value }) -> (
336+
match Option.Unboxed.is_none old_value with
337+
| true -> "Failed (no value)"
338+
| false -> "Failed (old value)")
331339
end
332340
end
333341

@@ -341,25 +349,26 @@ module Dag : Dag.S with type value := Dep_node_without_state.packed =
341349
(* This is similar to [type t = Dag.node Lazy.t] but avoids creating a closure
342350
with a [dep_node]; the latter is available when we need to [force] a [t]. *)
343351
module Lazy_dag_node = struct
344-
type t = Dag.node option ref
352+
type t = Dag.node Option.Unboxed.t ref
345353

346-
let create () = ref None
354+
let create () = ref Option.Unboxed.none
347355

348356
let force t ~(dep_node : _ Dep_node_without_state.t) =
349-
match !t with
350-
| Some (dag_node : Dag.node) ->
357+
match Option.Unboxed.is_none !t with
358+
| false ->
359+
let (dag_node : Dag.node) = Option.Unboxed.get_exn !t in
351360
let (T dep_node_passed_first) = Dag.value dag_node in
352361
(* CR-someday amokhov: It would be great to restructure the code to rule
353362
out the potential inconsistency between [dep_node]s passed to
354363
[force]. *)
355364
assert (Id.equal dep_node.id dep_node_passed_first.id);
356365
dag_node
357-
| None ->
366+
| true ->
358367
let (dag_node : Dag.node) =
359368
if !Counters.enabled then incr Counters.nodes_in_cycle_detection_graph;
360369
Dag.create_node (Dep_node_without_state.T dep_node)
361370
in
362-
t := Some dag_node;
371+
t := Option.Unboxed.some dag_node;
363372
dag_node
364373
end
365374

@@ -525,13 +534,13 @@ module M = struct
525534
and State : sig
526535
type 'a t =
527536
| Cached_value of 'a Cached_value.t
528-
| Out_of_date of { old_value : 'a Cached_value.t option }
537+
| Out_of_date of { old_value : 'a Cached_value.t Option.Unboxed.t }
529538
| Restoring of
530539
{ restore_from_cache :
531540
'a Cached_value.t Cache_lookup.Result.t Computation0.t
532541
}
533542
| Computing of
534-
{ old_value : 'a Cached_value.t option
543+
{ old_value : 'a Cached_value.t Option.Unboxed.t
535544
; compute : 'a Cached_value.t Computation0.t
536545
}
537546
end =
@@ -978,7 +987,9 @@ module State = struct
978987
| Computing _ -> Dyn.variant "Computing" [ Opaque ]
979988
| Out_of_date { old_value } ->
980989
Dyn.variant "Out_of_date"
981-
[ Dyn.record [ ("old_value", Dyn.option Cached_value.to_dyn old_value) ]
990+
[ Dyn.record
991+
[ ("old_value", Option.Unboxed.to_dyn Cached_value.to_dyn old_value)
992+
]
982993
]
983994
end
984995

@@ -1028,7 +1039,8 @@ end
10281039
let invalidate_dep_node (dep_node : _ Dep_node.t) =
10291040
match dep_node.state with
10301041
| Cached_value cached_value ->
1031-
dep_node.state <- Out_of_date { old_value = Some cached_value }
1042+
dep_node.state <-
1043+
Out_of_date { old_value = Option.Unboxed.some cached_value }
10321044
| Out_of_date { old_value = _ } -> ()
10331045
| Restoring _ ->
10341046
Code_error.raise "invalidate_dep_node called on a node in Restoring state"
@@ -1067,7 +1079,7 @@ let make_dep_node ~spec ~input : _ Dep_node.t =
10671079
{ id = Id.gen (); input; spec }
10681080
in
10691081
{ without_state = dep_node_without_state
1070-
; state = Out_of_date { old_value = None }
1082+
; state = Out_of_date { old_value = Option.Unboxed.none }
10711083
; has_cutoff =
10721084
(match spec.allow_cutoff with
10731085
| Yes _equal -> true
@@ -1112,11 +1124,13 @@ end = struct
11121124
are set to [Deps.empty]), so we can't use [deps_changed] in this
11131125
case. *)
11141126
Fiber.return
1115-
(Cache_lookup.Result.Failure (Out_of_date { old_value = None }))
1127+
(Cache_lookup.Result.Failure
1128+
(Out_of_date { old_value = Option.Unboxed.none }))
11161129
| Error { reproducible = false; _ } ->
11171130
(* We do not cache non-reproducible errors. *)
11181131
Fiber.return
1119-
(Cache_lookup.Result.Failure (Out_of_date { old_value = None }))
1132+
(Cache_lookup.Result.Failure
1133+
(Out_of_date { old_value = Option.Unboxed.none }))
11201134
| Ok _ | Error { reproducible = true; _ } -> (
11211135
(* We cache reproducible errors just like normal values. We assume that
11221136
all [Memo] computations are deterministic, which means if we rerun a
@@ -1174,14 +1188,15 @@ end = struct
11741188
| Unchanged ->
11751189
cached_value.last_validated_at <- Run.current ();
11761190
Cache_lookup.Result.Ok cached_value
1177-
| Changed -> Failure (Out_of_date { old_value = Some cached_value })
1191+
| Changed ->
1192+
Failure (Out_of_date { old_value = Option.Unboxed.some cached_value })
11781193
| Cancelled { dependency_cycle } ->
11791194
Failure (Cancelled { dependency_cycle }))
11801195

11811196
and compute :
11821197
'i 'o.
11831198
dep_node:('i, 'o) Dep_node.t
1184-
-> old_value:'o Cached_value.t option
1199+
-> old_value:'o Cached_value.t Option.Unboxed.t
11851200
-> stack_frame:Stack_frame_with_state.t
11861201
-> 'o Cached_value.t Fiber.t =
11871202
fun ~dep_node ~old_value ~stack_frame ->
@@ -1196,9 +1211,10 @@ end = struct
11961211
| Error errors -> Error errors
11971212
in
11981213
let deps_rev = Stack_frame_with_state.deps_rev stack_frame in
1199-
match old_value with
1200-
| None -> Cached_value.create value ~deps_rev
1201-
| Some old_cv -> (
1214+
match Option.Unboxed.is_none old_value with
1215+
| true -> Cached_value.create value ~deps_rev
1216+
| false -> (
1217+
let old_cv = Option.Unboxed.get_exn old_value in
12021218
match Cached_value.value_changed dep_node old_cv.value value with
12031219
| true -> Cached_value.create value ~deps_rev
12041220
| false -> Cached_value.confirm_old_value ~deps_rev old_cv)
@@ -1227,7 +1243,7 @@ end = struct
12271243
and start_computing :
12281244
'i 'o.
12291245
dep_node:('i, 'o) Dep_node.t
1230-
-> old_value:'o Cached_value.t option
1246+
-> old_value:'o Cached_value.t Option.Unboxed.t
12311247
-> 'o Cached_value.t Fiber.t =
12321248
fun ~dep_node ~old_value ->
12331249
let computation = Computation.create () in
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#7108: foo-bar is a valid public name, we should accept it.
2+
3+
$ dune init lib foo_bar --public foo-bar
4+
dune: option '--public': invalid component name `foo-bar'
5+
Library names must be non-empty and composed only of the
6+
following
7+
characters: 'A'..'Z', 'a'..'z', '_' or '0'..'9'.
8+
Usage: dune init library [OPTION]… NAME [PATH]
9+
Try 'dune init library --help' or 'dune --help' for more information.
10+
[1]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
01_module is not a valid module name, this should be detected before trying to `dune build`:
2+
3+
$ dune init project 01_module
4+
Entering directory '01_module'
5+
Success: initialized project component named 01_module
6+
Leaving directory '01_module'

0 commit comments

Comments
 (0)