Skip to content

Commit

Permalink
deforestation
Browse files Browse the repository at this point in the history
Signed-off-by: Lucas Pluvinage <[email protected]>
  • Loading branch information
TheLortex committed May 22, 2019
1 parent 2ae82b6 commit a20befc
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 9 deletions.
12 changes: 12 additions & 0 deletions src/dune_load.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions src/dune_load.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/gen_rules.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down
12 changes: 5 additions & 7 deletions src/super_context.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a20befc

Please sign in to comment.