Skip to content

Commit

Permalink
Get rid of Dyn.Make
Browse files Browse the repository at this point in the history
Signed-off-by: Rudi Grinberg <rudi.grinberg@gmail.com>
  • Loading branch information
rgrinberg committed Apr 24, 2019
1 parent aae17cb commit 3c0c21f
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 164 deletions.
31 changes: 13 additions & 18 deletions src/blang.ml
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,19 @@ let rec eval t ~dir ~f =
and y = String_with_vars.expand y ~mode:Many ~dir ~f in
Op.eval op (Value.L.compare_vals ~dir x y)

include (
Dyn.Make(struct
type nonrec t = t

let rec to_dyn =
let open Dyn.Encoder in
function
| Const b -> constr "Const" [bool b]
| Expr e -> constr "Expr" [via_sexp String_with_vars.to_sexp e]
| And t -> constr "And" (List.map ~f:to_dyn t)
| Or t -> constr "Or" (List.map ~f:to_dyn t)
| Compare (o, s1, s2) ->
constr "Compare"
[ Op.to_dyn o
; via_sexp String_with_vars.to_sexp s1
; via_sexp String_with_vars.to_sexp s2
]
end))
let rec to_dyn =
let open Dyn.Encoder in
function
| Const b -> constr "Const" [bool b]
| Expr e -> constr "Expr" [via_sexp String_with_vars.to_sexp e]
| And t -> constr "And" (List.map ~f:to_dyn t)
| Or t -> constr "Or" (List.map ~f:to_dyn t)
| Compare (o, s1, s2) ->
constr "Compare"
[ Op.to_dyn o
; via_sexp String_with_vars.to_sexp s1
; via_sexp String_with_vars.to_sexp s2
]

let ops =
[ "=", Op.Eq
Expand Down
2 changes: 1 addition & 1 deletion src/blang.mli
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ val eval
-> f:Value.t list option String_with_vars.expander
-> bool

include Dyn.S with type t := t
val to_dyn : t -> Dyn.t

val decode : t Stanza.Decoder.t
190 changes: 80 additions & 110 deletions src/dune_project.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module Name : sig
| Named of string
| Anonymous of Path.t

include Dyn.S with type t := t
val to_dyn : t -> Dyn.t

val compare : t -> t -> Ordering.t

Expand Down Expand Up @@ -54,14 +54,11 @@ end = struct

let anonymous_root = Anonymous Path.root

include Dyn.Make (struct
type nonrec t = t
let to_dyn =
let open Dyn.Encoder in
function
| Named n -> constr "Named" [string n]
| Anonymous p -> constr "Anonymous" [Path.to_dyn p]
end)
let to_dyn =
let open Dyn.Encoder in
function
| Named n -> constr "Named" [string n]
| Anonymous p -> constr "Anonymous" [Path.to_dyn p]

let to_string_hum = function
| Named s -> s
Expand Down Expand Up @@ -134,34 +131,27 @@ module Project_file = struct
; project_name : Name.t
}

include(
Dyn.Make(struct
type nonrec t = t
let to_dyn { file; exists; project_name } =
let open Dyn.Encoder in
record
[ "file", Path.Source.to_dyn file
; "exists", bool exists
; "project_name", Name.to_dyn project_name
]
end))
let to_dyn { file; exists; project_name } =
let open Dyn.Encoder in
record
[ "file", Path.Source.to_dyn file
; "exists", bool exists
; "project_name", Name.to_dyn project_name
]
end

module Source_kind = struct
type t =
| Github of string * string
| Url of string

include Dyn.Make(struct
type nonrec t = t
let to_dyn =
let open Dyn.Encoder in
function
| Github (user,repo) ->
constr "Github" [string user; string repo]
| Url url ->
constr "Url" [string url]
end)
let to_dyn =
let open Dyn.Encoder in
function
| Github (user,repo) ->
constr "Github" [string user; string repo]
| Url url ->
constr "Url" [string url]

let pp fmt = function
| Github (user,repo) ->
Expand Down Expand Up @@ -271,20 +261,15 @@ module Opam = struct
sum (ops @ logops)
end

include (
Dyn.Make(struct
type nonrec t = t

let rec to_dyn =
let open Dyn.Encoder in
function
| Bvar (QVar v) -> constr "Bvar" [Dyn.String v]
| Bvar (Var v) -> constr "Bvar" [Dyn.String (":" ^ v)]
| Uop (b, QVar v) -> constr "Uop" [Op.to_dyn b; Dyn.String v]
| Uop (b, Var v) -> constr "Uop" [Op.to_dyn b; Dyn.String (":" ^ v)]
| And t -> constr "And" (List.map ~f:to_dyn t)
| Or t -> constr "Or" (List.map ~f:to_dyn t)
end))
let rec to_dyn =
let open Dyn.Encoder in
function
| Bvar (QVar v) -> constr "Bvar" [Dyn.String v]
| Bvar (Var v) -> constr "Bvar" [Dyn.String (":" ^ v)]
| Uop (b, QVar v) -> constr "Uop" [Op.to_dyn b; Dyn.String v]
| Uop (b, Var v) -> constr "Uop" [Op.to_dyn b; Dyn.String (":" ^ v)]
| And t -> constr "And" (List.map ~f:to_dyn t)
| Or t -> constr "Or" (List.map ~f:to_dyn t)
end

type t =
Expand Down Expand Up @@ -335,16 +320,12 @@ module Opam = struct
| None -> pkg
| Some c -> Option (nopos, pkg, [c])

include (
Dyn.Make(struct
type nonrec t = t
let to_dyn { name; constraint_ } =
let open Dyn.Encoder in
record
[ "name", Package.Name.to_dyn name
; "constr", Dyn.Option (Option.map ~f:Constraint.to_dyn constraint_)
]
end))
let to_dyn { name; constraint_ } =
let open Dyn.Encoder in
record
[ "name", Package.Name.to_dyn name
; "constr", Dyn.Option (Option.map ~f:Constraint.to_dyn constraint_)
]
end

module Package = struct
Expand Down Expand Up @@ -377,19 +358,15 @@ module Opam = struct
; conflicts
})

include (
Dyn.Make(struct
type nonrec t = t
let to_dyn { name; synopsis; depends; conflicts; description } =
let open Dyn.Encoder in
record
[ "name", Package.Name.to_dyn name
; "synopsis", string synopsis
; "description", string description
; "depends", list Dependency.to_dyn depends
; "conflicts", list Dependency.to_dyn conflicts
]
end))
let to_dyn { name; synopsis; depends; conflicts; description } =
let open Dyn.Encoder in
record
[ "name", Package.Name.to_dyn name
; "synopsis", string synopsis
; "description", string description
; "depends", list Dependency.to_dyn depends
; "conflicts", list Dependency.to_dyn conflicts
]
end

type t =
Expand All @@ -399,17 +376,14 @@ module Opam = struct
; packages : Package.t list
}

include Dyn.Make (struct
type nonrec t = t
let to_dyn { tags; depends ; packages ; conflicts } =
let open Dyn.Encoder in
record
[ "tags", list string tags
; "depends", list Dependency.to_dyn depends
; "conflicts", list Dependency.to_dyn conflicts
; "packages", list Package.to_dyn packages
]
end)
let to_dyn { tags; depends ; packages ; conflicts } =
let open Dyn.Encoder in
record
[ "tags", list string tags
; "depends", list Dependency.to_dyn depends
; "conflicts", list Dependency.to_dyn conflicts
; "packages", list Package.to_dyn packages
]

let decode =
let open Stanza.Decoder in
Expand Down Expand Up @@ -466,34 +440,30 @@ let file t = t.project_file.file
let implicit_transitive_deps t = t.implicit_transitive_deps
let allow_approx_merlin t = t.allow_approx_merlin

include (Dyn.Make(
struct
type nonrec t = t
let to_dyn
{ name ; root ; version ; source; license; authors
; opam; project_file ; parsing_context = _
; extension_args = _; stanza_parser = _ ; packages
; implicit_transitive_deps ; dune_version
; allow_approx_merlin } =
let open Dyn.Encoder in
record
[ "name", Name.to_dyn name
; "root", via_sexp Path.Source.to_sexp root
; "version", (option string) version
; "source", (option Source_kind.to_dyn) source
; "license", (option string) license
; "authors", (list string) authors
; "opam", (option Opam.to_dyn) opam
; "project_file", Project_file.to_dyn project_file
; "packages",
(list (pair Package.Name.to_dyn Package.to_dyn))
(Package.Name.Map.to_list packages)
; "implicit_transitive_deps",
bool implicit_transitive_deps
; "dune_version", Syntax.Version.to_dyn dune_version
; "allow_approx_merlin", bool allow_approx_merlin
]
end))
let to_dyn
{ name ; root ; version ; source; license; authors
; opam; project_file ; parsing_context = _
; extension_args = _; stanza_parser = _ ; packages
; implicit_transitive_deps ; dune_version
; allow_approx_merlin } =
let open Dyn.Encoder in
record
[ "name", Name.to_dyn name
; "root", via_sexp Path.Source.to_sexp root
; "version", (option string) version
; "source", (option Source_kind.to_dyn) source
; "license", (option string) license
; "authors", (list string) authors
; "opam", (option Opam.to_dyn) opam
; "project_file", Project_file.to_dyn project_file
; "packages",
(list (pair Package.Name.to_dyn Package.to_dyn))
(Package.Name.Map.to_list packages)
; "implicit_transitive_deps",
bool implicit_transitive_deps
; "dune_version", Syntax.Version.to_dyn dune_version
; "allow_approx_merlin", bool allow_approx_merlin
]

let find_extension_args t key =
Univ_map.find t.extension_args key
Expand Down Expand Up @@ -736,14 +706,14 @@ let key =
; parsing_context ; implicit_transitive_deps ; dune_version
; allow_approx_merlin } ->
Sexp.Encoder.record
[ "name", Name.to_sexp name
[ "name", Dyn.to_sexp (Name.to_dyn name)
; "root", Path.Source.to_sexp root
; "license", Sexp.Encoder.(option string) license
; "authors", Sexp.Encoder.(list string) authors
; "source", Sexp.Encoder.(option Source_kind.to_sexp) source
; "source", Dyn.to_sexp (Dyn.Encoder.(option Source_kind.to_dyn) source)
; "version", Sexp.Encoder.(option string) version
; "opam", Sexp.Encoder.(option Opam.to_sexp) opam
; "project_file", Project_file.to_sexp project_file
; "opam", Dyn.to_sexp (Dyn.Encoder.(option Opam.to_dyn) opam)
; "project_file", Dyn.to_sexp (Project_file.to_dyn project_file)
; "parsing_context", Univ_map.to_sexp parsing_context
; "implicit_transitive_deps", Sexp.Encoder.bool implicit_transitive_deps
; "dune_version", Syntax.Version.to_sexp dune_version
Expand Down
18 changes: 9 additions & 9 deletions src/dune_project.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Name : sig
| Named of string
| Anonymous of Path.t

include Dyn.S with type t := t
val to_dyn : t -> Dyn.t

val compare : t -> t -> Ordering.t

Expand All @@ -36,15 +36,17 @@ end

module Project_file : sig
type t
include Dyn.S with type t := t
val to_dyn : t -> Dyn.t
end

module Source_kind : sig
type t =
| Github of string * string
| Url of string

include Dyn.S with type t := t
val pp : t Fmt.t

val to_dyn : t -> Dyn.t
end

module Opam : sig
Expand All @@ -54,7 +56,7 @@ module Opam : sig

val opam_depend : t -> OpamParserTypes.value

include Dyn.S with type t := t
val to_dyn : t -> Dyn.t
end

module Package : sig
Expand All @@ -65,7 +67,7 @@ module Opam : sig
; depends: Dependency.t list
; conflicts: Dependency.t list
}
include Dyn.S with type t := t
val to_dyn : t -> Dyn.t
end

type t = private
Expand All @@ -77,14 +79,14 @@ module Opam : sig

type package_name

include Dyn.S with type t := t
val to_dyn : t -> Dyn.t

val find : t -> package_name -> Package.t option
end with type package_name := Package.Name.t

type t

include Dyn.S with type t := t
val to_dyn : t -> Dyn.t

val packages : t -> Package.t Package.Name.Map.t
val version : t -> string option
Expand Down Expand Up @@ -183,5 +185,3 @@ val set_parsing_context : t -> 'a Dune_lang.Decoder.t -> 'a Dune_lang.Decoder.t
val implicit_transitive_deps : t -> bool

val dune_version : t -> Syntax.Version.t

val pp : t Fmt.t
Loading

0 comments on commit 3c0c21f

Please sign in to comment.