-
Notifications
You must be signed in to change notification settings - Fork 450
Dune_project refactor #12597
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Dune_project refactor #12597
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Member
rgrinberg
commented
Oct 19, 2025
- Stop opening Decoder everywhere
- Wrap things to 80 chars
- Extract a helper
Signed-off-by: Rudi Grinberg <[email protected]>
* Stop opening Decoder everywhere * Wrap things to 80 chars * Extract a helper JJ: diff --git a/src/dune_lang/dune_project.ml b/src/dune_lang/dune_project.ml JJ: index dca3584..1bd07ad 100644 JJ: --- a/src/dune_lang/dune_project.ml JJ: +++ b/src/dune_lang/dune_project.ml JJ: @@ -1,5 +1,4 @@ JJ: open Import JJ: -open Decoder JJ: module Versioned_file = Dune_sexp.Versioned_file JJ: module Execution_parameters = Dune_engine.Execution_parameters JJ: module Compound_user_error = Dune_rpc_private.Compound_user_error JJ: @@ -42,6 +41,7 @@ JJ: ;; JJ: JJ: let decode = JJ: + let open Decoder in JJ: let check ver = Syntax.since Stanza.syntax ver in JJ: enum' JJ: [ "true", check (1, 7) >>> return Enabled JJ: @@ -103,9 +103,9 @@ JJ: JJ: let get_exn () = JJ: get () JJ: - >>| function JJ: - | Some t -> t JJ: - | None -> Code_error.raise "Current project is unset" [] JJ: + |> Decoder.map ~f:(function JJ: + | Some t -> t JJ: + | None -> Code_error.raise "Current project is unset" []) JJ: ;; JJ: JJ: let equal : t -> t -> bool = ( == ) JJ: @@ -268,6 +268,7 @@ JJ: JJ: let register_unit syntax stanzas = JJ: let unit_stanzas = JJ: + let open Decoder in JJ: let+ r = stanzas in JJ: (), r JJ: in JJ: @@ -335,44 +336,46 @@ JJ: | Ok map -> map JJ: ;; JJ: JJ: +let make_parsing_context ~(lang : Lang.Instance.t) extensions = JJ: + let init = JJ: + let init = Univ_map.singleton (Syntax.key lang.syntax) (Active lang.version) in JJ: + let extensions = JJ: + List.fold_left extensions ~init:[] ~f:(fun acc (ext : Extension.automatic) -> JJ: + match ext with JJ: + | Not_selected _ -> acc JJ: + | Selected ext -> JJ: + let syntax = JJ: + let (Extension.Packed ext) = ext.extension in JJ: + ext.syntax JJ: + in JJ: + (syntax, ext.version) :: acc) JJ: + in JJ: + Univ_map.set JJ: + init JJ: + String_with_vars.decoding_env_key JJ: + (Pform.Env.initial ~stanza:lang.version ~extensions) JJ: + in JJ: + List.fold_left extensions ~init ~f:(fun acc (ext : Extension.automatic) -> JJ: + let syntax = JJ: + let (Extension.Packed ext) = JJ: + match ext with JJ: + | Selected e -> e.extension JJ: + | Not_selected e -> e JJ: + in JJ: + ext.syntax JJ: + in JJ: + let status : Syntax.Key.t = JJ: + match ext with JJ: + | Selected ext -> Active ext.version JJ: + | Not_selected (Packed e) -> JJ: + Inactive { lang = e.syntax; dune_lang_ver = lang.version } JJ: + in JJ: + Univ_map.set acc (Syntax.key syntax) status) JJ: +;; JJ: + JJ: let interpret_lang_and_extensions ~(lang : Lang.Instance.t) ~explicit_extensions = JJ: let extensions = Extension.automatic ~explicitly_selected:explicit_extensions in JJ: - let parsing_context = JJ: - let init = JJ: - let init = Univ_map.singleton (Syntax.key lang.syntax) (Active lang.version) in JJ: - let extensions = JJ: - List.fold_left extensions ~init:[] ~f:(fun acc (ext : Extension.automatic) -> JJ: - match ext with JJ: - | Not_selected _ -> acc JJ: - | Selected ext -> JJ: - let syntax = JJ: - let (Extension.Packed ext) = ext.extension in JJ: - ext.syntax JJ: - in JJ: - (syntax, ext.version) :: acc) JJ: - in JJ: - Univ_map.set JJ: - init JJ: - String_with_vars.decoding_env_key JJ: - (Pform.Env.initial ~stanza:lang.version ~extensions) JJ: - in JJ: - List.fold_left extensions ~init ~f:(fun acc (ext : Extension.automatic) -> JJ: - let syntax = JJ: - let (Extension.Packed ext) = JJ: - match ext with JJ: - | Selected e -> e.extension JJ: - | Not_selected e -> e JJ: - in JJ: - ext.syntax JJ: - in JJ: - let status : Syntax.Key.t = JJ: - match ext with JJ: - | Selected ext -> Active ext.version JJ: - | Not_selected (Packed e) -> JJ: - Inactive { lang = e.syntax; dune_lang_ver = lang.version } JJ: - in JJ: - Univ_map.set acc (Syntax.key syntax) status) JJ: - in JJ: + let parsing_context = make_parsing_context ~lang extensions in JJ: let extension_args, extension_stanzas = JJ: List.fold_left JJ: extensions JJ: @@ -381,7 +384,6 @@ JJ: match ext with JJ: | Not_selected (Packed e) -> JJ: let stanzas = JJ: - let open Decoder in JJ: let stanzas = JJ: match Syntax.greatest_supported_version e.syntax with JJ: | None -> [] JJ: @@ -395,21 +397,26 @@ JJ: (Syntax.key e.syntax) JJ: (Active greatest_supported_version) JJ: in JJ: - parse (enter e.stanzas) parsing_context (List (Loc.of_pos __POS__, [])) JJ: + Decoder.parse JJ: + (Decoder.enter e.stanzas) JJ: + parsing_context JJ: + (List (Loc.of_pos __POS__, [])) JJ: |> snd JJ: in JJ: List.map stanzas ~f:(fun (name, _) -> JJ: ( name JJ: - , let+ _ = Syntax.get_exn e.syntax in JJ: - (* The above [get_exn] will raise because the extension is JJ: + , Syntax.get_exn e.syntax JJ: + |> Decoder.map ~f:(fun _ -> JJ: + (* The above [get_exn] will raise because the extension is JJ: inactive *) JJ: - assert false )) JJ: + assert false) )) JJ: in JJ: args_acc, stanzas :: stanzas_acc JJ: | Selected instance -> JJ: let (Packed e) = instance.extension in JJ: let args_acc, stanzas = JJ: let args = JJ: + let open Decoder in JJ: let+ arg, stanzas = Decoder.set_many parsing_context e.stanzas in JJ: Univ_map.set args_acc e.key arg, stanzas JJ: in JJ: @@ -417,8 +424,10 @@ JJ: in JJ: args_acc, stanzas :: stanzas_acc) JJ: in JJ: - let stanzas = List.concat (lang.data :: extension_stanzas) in JJ: - let stanza_parser = Decoder.(set_many parsing_context (sum stanzas)) in JJ: + let stanza_parser = JJ: + let stanzas = List.concat (lang.data :: extension_stanzas) in JJ: + Decoder.(set_many parsing_context (sum stanzas)) JJ: + in JJ: parsing_context, stanza_parser, extension_args JJ: ;; JJ: JJ: @@ -688,8 +697,12 @@ JJ: let map_workspace_root t = t.map_workspace_root JJ: let executables_implicit_empty_intf t = t.executables_implicit_empty_intf JJ: let accept_alternative_dune_file_name t = t.accept_alternative_dune_file_name JJ: -let () = Extension.register_simple Action.Action_plugin.syntax (return []) JJ: -let dune_site_extension = Extension.register_unit Site.dune_site_syntax (return []) JJ: +let () = Extension.register_simple Action.Action_plugin.syntax (Decoder.return []) JJ: + JJ: +let dune_site_extension = JJ: + Extension.register_unit Site.dune_site_syntax (Decoder.return []) JJ: +;; JJ: + JJ: let strict_package_deps t = t.strict_package_deps JJ: let allow_approximate_merlin t = t.allow_approximate_merlin JJ: let cram t = t.cram JJ: @@ -841,6 +854,7 @@ JJ: ;; JJ: JJ: let parse ~dir ~(lang : Lang.Instance.t) ~file = JJ: + let open Decoder in JJ: String_with_vars.set_decoding_env JJ: (Pform.Env.initial ~stanza:lang.version ~extensions:[]) JJ: @@ fields JJ: @@ -1068,6 +1082,7 @@ JJ: ;; JJ: JJ: let _oxcaml_extension = JJ: - (* This is required to register the extension because OxCaml doesn't have a specific decoder. *) JJ: + (* This is required to register the extension because OxCaml doesn't have a JJ: + specific decoder. *) JJ: Extension.register Oxcaml.syntax (Decoder.return ((), [])) Dyn.unit JJ: ;; Signed-off-by: Rudi Grinberg <[email protected]>
davesnx
added a commit
to davesnx/dune
that referenced
this pull request
Oct 22, 2025
…without-system * 'main' of github.com:/ocaml/dune: (33 commits) Fix difference between bootstrap & dune behaviour w.r.t include-subdirs ambiguity (ocaml#12607) Revert "Fix difference between bootstrap & dune behaviour w.r.t include-subdirs ambiguity" fix(include-subdirs-qualified): prefer closer module of the same name Add 2 tests showing difference between bootstrap & dune w.r.t include-subdirs dune init: use source path (ocaml#12601) chore(deps): bump actions/setup-node from 5 to 6 test(melange): show melange compilation isn't part of `@all` alias (ocaml#12603) Disable flaky test (ocaml#12600) Rename path to dir in dune_init (ocaml#12599) Dune project: remove dead code (ocaml#12598) Dune_project refactor (ocaml#12597) doc(melange): reference `dirs` stanza (ocaml#12596) Stanza simplifications (ocaml#12595) Reduce stanza definition boilerplate (ocaml#12592) Rename Stanza_common to Stanza_pkg (ocaml#12593) Remove copied code between library and library_parameter stanzas (ocaml#12594) Split modules settings (ocaml#12591) Move the (include_subdirs qualified) check to a single place (ocaml#12590) refactor: simplify loc/ocamllex/ocamlyacc stanza handling (ocaml#12589) pkg: Implement a package search command ...
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.