Skip to content

Commit

Permalink
Simplify types in 0install one bit further
Browse files Browse the repository at this point in the history
Signed-off-by: Ambre Austen Suhamy <ambre@tarides.com>
  • Loading branch information
ElectreAAS committed Oct 23, 2024
1 parent b14c0f4 commit 0b4e4c6
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 15 deletions.
6 changes: 1 addition & 5 deletions src/0install-solver/src/solver/s.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ module type CORE_MODEL = sig
dep_importance : [ `Essential | `Recommended | `Restricts ]
}

(* The top-level requirements from the user. *)
type requirements = { role : Role.t }

(** Get an implementation's dependencies.
The dependencies should be ordered with the most important first.
Expand Down Expand Up @@ -145,7 +142,7 @@ module type SELECTIONS = sig

val to_map : t -> impl RoleMap.t
val get_selected : Role.t -> t -> impl option
val requirements : t -> requirements
val requirements : t -> Role.t
end

module type SOLVER_RESULT = sig
Expand All @@ -160,7 +157,6 @@ module type SOLVER_RESULT = sig
with module Role = Input.Role
and type dependency = Input.dependency
and type dep_info = Input.dep_info
and type requirements = Input.requirements

val unwrap : impl -> Input.impl

Expand Down
9 changes: 4 additions & 5 deletions src/0install-solver/src/solver/solver_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -345,8 +345,7 @@ struct
in
let+ () =
(* This recursively builds the whole problem up. *)
(let { Model.role } = root_req in
let+ impl = lookup_impl role in
(let+ impl = lookup_impl root_req in
impl#get_vars)
>>| S.at_least_one sat ~reason:"need root" (* Must get what we came for! *)
in
Expand All @@ -370,7 +369,7 @@ struct
; dep_importance : [ `Essential | `Recommended | `Restricts ]
}

type requirements = Model.requirements = { role : Role.t }
type requirements = Role.t

let dep_info = Model.dep_info
let requires role impl = Model.requires role impl.impl
Expand Down Expand Up @@ -412,7 +411,7 @@ struct
let sat = S.create () in
let dummy_impl = if closest_match then Some Model.dummy_impl else None in
let+ impl_clauses = build_problem root_req sat ~dummy_impl in
let lookup { Model.role } = (ImplCache.get_exn role impl_clauses :> candidates) in
let lookup role = (ImplCache.get_exn role impl_clauses :> candidates) in
(* Run the solve *)
let decider () =
(* Walk the current solution, depth-first, looking for the first undecided interface.
Expand All @@ -438,7 +437,7 @@ struct
we'll handle it when we get to them.
If noone wants it, it will be set to unselected at the end. *)
None
else find_undecided { Model.role = dep_role }
else find_undecided dep_role
in
List.find_map check_dep deps)
in
Expand Down
2 changes: 1 addition & 1 deletion src/0install-solver/src/solver/zeroinstall_solver.mli
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ module Make
every interface, so we can always select something. Useful for diagnostics.
Note: always try without [closest_match] first, or it may miss a valid solution.
@return None if the solve fails (only happens if [closest_match] is false). *)
val do_solve : closest_match:bool -> Input.requirements -> Output.t option Monad.t
val do_solve : closest_match:bool -> Input.Role.t -> Output.t option Monad.t
end

(** Explaining why a solve failed or gave an unexpected answer. *)
Expand Down
2 changes: 0 additions & 2 deletions src/opam-0install/lib/model.ml
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,6 @@ struct
; dep_importance : [ `Essential | `Recommended | `Restricts ]
}

type requirements = { role : Role.t }

let dummy_impl = Dummy

(* Turn an opam dependency formula into a 0install list of dependencies. *)
Expand Down
4 changes: 2 additions & 2 deletions src/opam-0install/lib/solver.ml
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ struct
let impl = Input.virtual_impl ~context ~depends:pkgs () in
Input.virtual_role [ impl ]
in
{ Input.role }
role
;;

module Solver = Zeroinstall_solver.Make (Monad) (Input)
module Diagnostics = Zeroinstall_solver.Diagnostics (Monad) (Solver.Output)

type t = Context.t
type selections = Solver.Output.t
type diagnostics = Input.requirements (* So we can run another solve *)
type diagnostics = Input.Role.t (* So we can run another solve *)

let solve context pkgs =
let req = requirements ~context pkgs in
Expand Down

0 comments on commit 0b4e4c6

Please sign in to comment.