@@ -1920,9 +1920,11 @@ let rec perform_atomic ~progress_callback ?result (op : atomic)
1920
1920
debug " Ignoring error during best-effort operation: %s"
1921
1921
(Printexc. to_string e)
1922
1922
)
1923
- | Parallel (_id , description , atoms ) ->
1923
+ | Parallel (_id , description , atoms ) as atom ->
1924
+ check_nesting atom ;
1924
1925
parallel_atomic ~progress_callback ~description ~nested: false atoms t
1925
- | Nested_parallel (_id , description , atoms ) ->
1926
+ | Nested_parallel (_id , description , atoms ) as atom ->
1927
+ check_nesting atom ;
1926
1928
parallel_atomic ~progress_callback ~description ~nested: true atoms t
1927
1929
| Serial (_ , _ , atoms ) ->
1928
1930
List. iter (Fun. flip (perform_atomic ~progress_callback ) t) atoms
@@ -2352,6 +2354,34 @@ let rec perform_atomic ~progress_callback ?result (op : atomic)
2352
2354
debug " VM.soft_reset %s" id ;
2353
2355
B.VM. soft_reset t (VM_DB. read_exn id)
2354
2356
2357
+ and check_nesting atom =
2358
+ let msg_prefix = " Nested atomics error" in
2359
+ let rec check_nesting_inner found_parallel found_nested = function
2360
+ | Parallel (_ , _ , rem ) ->
2361
+ if found_parallel then (
2362
+ warn
2363
+ " %s: Two or more Parallel atoms found, use Nested_parallel for the \
2364
+ inner atom"
2365
+ msg_prefix ;
2366
+ true
2367
+ ) else
2368
+ List. exists (check_nesting_inner true found_nested) rem
2369
+ | Nested_parallel (_ , _ , rem ) ->
2370
+ if found_nested then (
2371
+ warn
2372
+ " %s: Two or more Nested_parallel atoms found, there should only be \
2373
+ one layer of nesting"
2374
+ msg_prefix ;
2375
+ true
2376
+ ) else
2377
+ List. exists (check_nesting_inner found_parallel true ) rem
2378
+ | Serial (_ , _ , rem ) ->
2379
+ List. exists (check_nesting_inner found_parallel found_nested) rem
2380
+ | _ ->
2381
+ false
2382
+ in
2383
+ ignore @@ check_nesting_inner false false atom
2384
+
2355
2385
and parallel_atomic ~progress_callback ~description ~nested atoms t =
2356
2386
(* parallel_id is a unused unique name prefix for a parallel worker queue *)
2357
2387
let redirector =
0 commit comments