diff --git a/src/dune_load.ml b/src/dune_load.ml index 1ac8e68fea66..3de5b499461d 100644 --- a/src/dune_load.ml +++ b/src/dune_load.ml @@ -26,6 +26,18 @@ module Dune_file = struct ; stanzas ; kind } + + let rec fold_stanzas l ~init ~f = + match l with + | [] -> init + | t :: l -> inner_fold t t.stanzas l ~init ~f + + and inner_fold t inner_list l ~init ~f = + match inner_list with + | [] -> fold_stanzas l ~init ~f + | x :: inner_list -> + inner_fold t inner_list l ~init:(f t x init) ~f + end module Dune_files = struct diff --git a/src/dune_load.mli b/src/dune_load.mli index 464eaa3fcc11..30993673b5ed 100644 --- a/src/dune_load.mli +++ b/src/dune_load.mli @@ -7,6 +7,12 @@ module Dune_file : sig ; stanzas : Dune_file.Stanzas.t ; kind : Dune_lang.File_syntax.t } + + val fold_stanzas : + t list + -> init:'acc + -> f:(t -> Stanza.t -> 'acc -> 'acc) + -> 'acc end module Dune_files : sig diff --git a/src/gen_rules.ml b/src/gen_rules.ml index 549dc6a935ee..d9909ff33f4c 100644 --- a/src/gen_rules.ml +++ b/src/gen_rules.ml @@ -359,7 +359,7 @@ let gen ~contexts | Some pkgs -> let visible_libraries = stanzas - |> List.concat_map ~f:(fun (dir_conf : Dune_load.Dune_file.t) -> dir_conf.stanzas) + |> Dune_load.Dune_file.fold_stanzas ~init:[] ~f:(fun _ s acc -> s::acc) |> visible_libraries pkgs in List.map stanzas ~f:(fun (dir_conf : Dune_load.Dune_file.t) -> diff --git a/src/super_context.ml b/src/super_context.ml index b3dece866119..3c1347d4e96a 100644 --- a/src/super_context.ml +++ b/src/super_context.ml @@ -372,13 +372,11 @@ let create | _ -> None)) in let internal_implementations = - List.concat_map stanzas - ~f:(fun { Dune_load.Dune_file.stanzas; _ } -> - List.filter_map stanzas ~f:(fun stanza -> - match (stanza : Stanza.t) with - | Dune_file.External_variant impl -> Some impl - | _ -> None) - ) + Dune_load.Dune_file.fold_stanzas stanzas + ~init:[] + ~f:(fun _ stanza acc -> match stanza with + | Dune_file.External_variant impl -> impl::acc + | _ -> acc) in let scopes, public_libs = let lib_config = Context.lib_config context in diff --git a/test/blackbox-tests/test-cases/variants-external-declaration-conflict/run.t b/test/blackbox-tests/test-cases/variants-external-declaration-conflict/run.t index 9039f4c17500..d68ea5ce2d2d 100644 --- a/test/blackbox-tests/test-cases/variants-external-declaration-conflict/run.t +++ b/test/blackbox-tests/test-cases/variants-external-declaration-conflict/run.t @@ -3,8 +3,8 @@ It is forbidden to declare two external implementations with the same variant. $ dune build --root 1/ Entering directory '1' Error: Two implementations of vlibfoo have the same variant "somevariant": - - impl1 (dune:6) - impl2 (dune:11) + - impl1 (dune:6) [1] It is forbidden to declare an external implementation and have a local