(************************************************************************)
(*         *   The Coq Proof Assistant / The Coq Development Team       *)
(*  v      *         Copyright INRIA, CNRS and contributors             *)
(* <O___,, * (see version control and CREDITS file for authors & dates) *)
(*   \VV/  **************************************************************)
(*    //   *    This file is distributed under the terms of the         *)
(*         *     GNU Lesser General Public License Version 2.1          *)
(*         *     (see LICENSE file for the text of the license)         *)
(************************************************************************)

open Constr
open Univ
open Sorts

type 'a universe_map = 'a Level.Map.t
type universe_subst = Universe.t universe_map
type universe_subst_fn = Level.t -> Universe.t option
type universe_level_subst_fn = Level.t -> Level.t

type quality_subst = Quality.t QVar.Map.t
type quality_subst_fn = QVar.t -> Quality.t

val level_subst_of : universe_subst_fn -> universe_level_subst_fn
(** The resulting function must never be called on a level which would produce an algebraic. *)

val subst_univs_constraints : universe_subst_fn -> Constraints.t -> Constraints.t

val nf_binder_annot : (Sorts.relevance -> Sorts.relevance) ->
  'a Context.binder_annot -> 'a Context.binder_annot

(** Full universes substitutions into terms *)

val nf_evars_and_universes_opt_subst
  : (existential -> constr option)
  -> quality_subst_fn
  -> universe_subst_fn
  -> constr -> constr

val subst_univs_universe : universe_subst_fn -> Universe.t -> Universe.t

val pr_universe_subst : (Level.t -> Pp.t) -> universe_subst -> Pp.t

val enforce_eq : Universe.t constraint_function
val enforce_leq : Universe.t constraint_function

val enforce_eq_sort : Sorts.t -> Sorts.t -> Univ.Constraints.t -> Univ.Constraints.t
val enforce_leq_sort : Sorts.t -> Sorts.t -> Univ.Constraints.t -> Univ.Constraints.t

(** Picks an arbitrary set of constraints sufficient to ensure [u <= v]. *)
val enforce_leq_alg_sort : Sorts.t -> Sorts.t -> UGraph.t -> Univ.Constraints.t * UGraph.t
