<commit_before>open! Stdune
open Import

(** {1 Generals} *)

(** Representation of a library *)
type t

(** For libraries defined in the workspace, this is the [public_name] if
    present or the [name] if not. *)
val name : t -> Lib_name.t

(* CR-someday diml: this should be [Path.t list], since some libraries
   have multiple source directories because of [copy_files]. *)
(** Directory where the source files for the library are located. *)
val src_dir : t -> Path.t

(** Directory where the object files for the library are located. *)
val obj_dir : t -> Path.t

val private_obj_dir : t -> Path.t option

(** Same as [Path.is_managed (obj_dir t)] *)
val is_local : t -> bool

val synopsis     : t -> string option
val kind         : t -> Dune_file.Library.Kind.t
val archives     : t -> Path.t list Mode.Dict.t
val plugins      : t -> Path.t list Mode.Dict.t
val jsoo_runtime : t -> Path.t list

val foreign_objects : t -> Path.t list

val main_module_name : t -> Module.Name.t option Or_exn.t

val virtual_ : t -> Lib_info.Virtual.t option

val dune_version : t -> Syntax.Version.t option

(** A unique integer identifier. It is only unique for the duration of
    the process *)
val unique_id : t -> int

module Set : Set.S with type elt = t

module Map : Map.S with type key = t

val status : t -> Lib_info.Status.t

val package : t -> Package.Name.t option

(** Operations on list of libraries *)
module L : sig
  type nonrec t = t list

  val include_paths : t -> stdlib_dir:Path.t -> Path.Set.t
  val include_flags : t -> stdlib_dir:Path.t -> _ Arg_spec.t

  val c_include_flags : t -> stdlib_dir:Path.t -> _ Arg_spec.t

  val link_flags : t -> mode:Mode.t -> stdlib_dir:Path.t -> _ Arg_spec.t

  val compile_and_link_flags
    :  compile:t
    -> link:t
    -> mode:Mode.t
    -> stdlib_dir:Path.t
    -> _ Arg_spec.t

  (** All the library archive files (.a, .cmxa, _stubs.a, ...)  that
      should be linked in when linking an executable. *)
  val archive_files : t -> mode:Mode.t -> Path.t list

  val jsoo_runtime_files : t -> Path.t list

  val remove_dups : t -> t
end

(** Operation on list of libraries and modules *)
module Lib_and_module : sig
  type nonrec t =
    | Lib of t
    | Module of Module.t * Path.t (** obj_dir *)

  val link_flags : t list -> mode:Mode.t -> stdlib_dir:Path.t -> _ Arg_spec.t

end

(** {1 Errors} *)

module Error : sig
  module Library_not_available : sig
    module Reason : sig
      module Hidden : sig
        type t =
          { name   : Lib_name.t
          ; path   : Path.t
          ; reason : string
          }
      end

      type t =
        | Not_found
        | Hidden of Hidden.t

      val to_string : t -> string
      val pp : Format.formatter -> t -> unit
    end

    type nonrec t =
      { loc    : Loc.t (** For names coming from Jbuild files *)
      ; name   : Lib_name.t
      ; reason : Reason.t
      }
  end

  module No_solution_found_for_select : sig
    type t = { loc : Loc.t }
  end

  module Conflict : sig
    (** When two libraries in a transitive closure conflict *)
    type nonrec t =
      { lib1 : t * Dep_path.Entry.t list
      ; lib2 : t * Dep_path.Entry.t list
      }
  end

  module Overlap : sig
    (** A conflict that doesn't prevent compilation, but that we still
        consider as an error to avoid surprises. *)
    type nonrec t =
      { in_workspace : t
      ; installed    : t * Dep_path.Entry.t list
      }
  end

  module Private_deps_not_allowed : sig
    type nonrec t =
      { private_dep : t
      ; pd_loc      : Loc.t
      }
  end

  module Double_implementation : sig
    type t =
      { impl1 : Lib_name.t * Dep_path.Entry.t list
      ; impl2 : Lib_name.t * Dep_path.Entry.t list
      ; vlib  : Lib_name.t
      }
  end

  module No_implementation : sig
    type t =
      { for_vlib : Lib_name.t
      }
  end

  type t =
    | Library_not_available        of Library_not_available.t
    | No_solution_found_for_select of No_solution_found_for_select.t
    | Dependency_cycle             of (Path.t * Lib_name.t) list
    | Conflict                     of Conflict.t
    | Overlap                      of Overlap.t
    | Private_deps_not_allowed     of Private_deps_not_allowed.t
    | Double_implementation        of Double_implementation.t
    | No_implementation            of No_implementation.t
end

exception Error of Error.t

(** Raise a error about a library that is not available *)
val not_available
  :  loc:Loc.t
  -> Error.Library_not_available.Reason.t
  -> ('a, Format.formatter, unit, 'b) format4
  -> 'a

(** {1 Compilation contexts} *)
<commit_msg>Make No_implementation.t and Double_implementation.t abstract<commit_after>open! Stdune
open Import

(** {1 Generals} *)

(** Representation of a library *)
type t

(** For libraries defined in the workspace, this is the [public_name] if
    present or the [name] if not. *)
val name : t -> Lib_name.t

(* CR-someday diml: this should be [Path.t list], since some libraries
   have multiple source directories because of [copy_files]. *)
(** Directory where the source files for the library are located. *)
val src_dir : t -> Path.t

(** Directory where the object files for the library are located. *)
val obj_dir : t -> Path.t

val private_obj_dir : t -> Path.t option

(** Same as [Path.is_managed (obj_dir t)] *)
val is_local : t -> bool

val synopsis     : t -> string option
val kind         : t -> Dune_file.Library.Kind.t
val archives     : t -> Path.t list Mode.Dict.t
val plugins      : t -> Path.t list Mode.Dict.t
val jsoo_runtime : t -> Path.t list

val foreign_objects : t -> Path.t list

val main_module_name : t -> Module.Name.t option Or_exn.t

val virtual_ : t -> Lib_info.Virtual.t option

val dune_version : t -> Syntax.Version.t option

(** A unique integer identifier. It is only unique for the duration of
    the process *)
val unique_id : t -> int

module Set : Set.S with type elt = t

module Map : Map.S with type key = t

val status : t -> Lib_info.Status.t

val package : t -> Package.Name.t option

(** Operations on list of libraries *)
module L : sig
  type nonrec t = t list

  val include_paths : t -> stdlib_dir:Path.t -> Path.Set.t
  val include_flags : t -> stdlib_dir:Path.t -> _ Arg_spec.t

  val c_include_flags : t -> stdlib_dir:Path.t -> _ Arg_spec.t

  val link_flags : t -> mode:Mode.t -> stdlib_dir:Path.t -> _ Arg_spec.t

  val compile_and_link_flags
    :  compile:t
    -> link:t
    -> mode:Mode.t
    -> stdlib_dir:Path.t
    -> _ Arg_spec.t

  (** All the library archive files (.a, .cmxa, _stubs.a, ...)  that
      should be linked in when linking an executable. *)
  val archive_files : t -> mode:Mode.t -> Path.t list

  val jsoo_runtime_files : t -> Path.t list

  val remove_dups : t -> t
end

(** Operation on list of libraries and modules *)
module Lib_and_module : sig
  type nonrec t =
    | Lib of t
    | Module of Module.t * Path.t (** obj_dir *)

  val link_flags : t list -> mode:Mode.t -> stdlib_dir:Path.t -> _ Arg_spec.t

end

(** {1 Errors} *)

module Error : sig
  module Library_not_available : sig
    module Reason : sig
      module Hidden : sig
        type t =
          { name   : Lib_name.t
          ; path   : Path.t
          ; reason : string
          }
      end

      type t =
        | Not_found
        | Hidden of Hidden.t

      val to_string : t -> string
      val pp : Format.formatter -> t -> unit
    end

    type nonrec t =
      { loc    : Loc.t (** For names coming from Jbuild files *)
      ; name   : Lib_name.t
      ; reason : Reason.t
      }
  end

  module No_solution_found_for_select : sig
    type t = { loc : Loc.t }
  end

  module Conflict : sig
    (** When two libraries in a transitive closure conflict *)
    type nonrec t =
      { lib1 : t * Dep_path.Entry.t list
      ; lib2 : t * Dep_path.Entry.t list
      }
  end

  module Overlap : sig
    (** A conflict that doesn't prevent compilation, but that we still
        consider as an error to avoid surprises. *)
    type nonrec t =
      { in_workspace : t
      ; installed    : t * Dep_path.Entry.t list
      }
  end

  module Private_deps_not_allowed : sig
    type nonrec t =
      { private_dep : t
      ; pd_loc      : Loc.t
      }
  end

  module Double_implementation : sig
    type t
  end

  module No_implementation : sig
    type t
  end

  type t =
    | Library_not_available        of Library_not_available.t
    | No_solution_found_for_select of No_solution_found_for_select.t
    | Dependency_cycle             of (Path.t * Lib_name.t) list
    | Conflict                     of Conflict.t
    | Overlap                      of Overlap.t
    | Private_deps_not_allowed     of Private_deps_not_allowed.t
    | Double_implementation        of Double_implementation.t
    | No_implementation            of No_implementation.t
end

exception Error of Error.t

(** Raise a error about a library that is not available *)
val not_available
  :  loc:Loc.t
  -> Error.Library_not_available.Reason.t
  -> ('a, Format.formatter, unit, 'b) format4
  -> 'a

(** {1 Compilation contexts} *)

{'fraction_non_alphanumeric': 0.09721150666813623, 'fraction_numerical': 0.0015430397883831148, 'mean_word_length': 2.3044428259286236, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 89, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1587657', 'n_tokens_mistral': 3036, 'n_tokens_neox': 2907, 'n_words': 972}