Skip to content

Commit 01322f7

Browse files
committed
feat(dune_lang): add Ordered_set_lang.Unexpanded.has_include
Mirrors the existing `has_standard`. Callers that need to summarise an `Unexpanded.t` syntactically — without reading the file an `(:include FN)` directive points to — must now check `has_include` and widen their answer accordingly, since `fold_strings` skips `Include` AST nodes entirely. Used by the menhir auto-injection in opam-create (ocaml#14434, fixes ocaml#14428): a `(modules (:include FN))` library would otherwise be mis-summarised as compiling no modules. Signed-off-by: Robin Bate Boerop <me@robinbb.com>
1 parent 5fa4ca0 commit 01322f7

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

src/dune_lang/ordered_set_lang.ml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,17 @@ module Unexpanded = struct
356356
loop t.ast
357357
;;
358358

359+
let has_include t =
360+
let rec loop ast =
361+
match ast with
362+
| Ast.Include _ -> true
363+
| Ast.Standard | Ast.Element _ -> false
364+
| Ast.Union l -> List.exists ~f:loop l
365+
| Ast.Diff (l, r) -> loop l || loop r
366+
in
367+
loop t.ast
368+
;;
369+
359370
type position =
360371
| Pos
361372
| Neg

src/dune_lang/ordered_set_lang.mli

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@ module Unexpanded : sig
7272

7373
val has_standard : t -> bool
7474

75+
(** Whether [t] contains any [(:include FN)] directive. {!fold_strings}
76+
skips these, so callers needing a static summary must widen
77+
accordingly. *)
78+
val has_include : t -> bool
79+
7580
type position =
7681
| Pos
7782
| Neg

0 commit comments

Comments
 (0)