Skip to content
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

refactor(pkg): pattern match on importance #11236

Merged
merged 1 commit into from
Dec 21, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions src/0install-solver/solver_core.ml
Original file line number Diff line number Diff line change
Expand Up @@ -237,21 +237,21 @@ module Make (Model : S.SOLVER_INPUT) = struct
in
let+ candidates = lookup_impl dep_role in
let pass, fail = candidates#partition meets_restrictions in
if dep_importance = `Essential
then
match dep_importance with
| `Essential ->
S.implies
sat
~reason:"essential dep"
user_var
pass (* Must choose a suitable candidate *)
else (
| `Restricts ->
(* If [user_var] is selected, don't select an incompatible version of the optional dependency.
We don't need to do this explicitly in the [essential] case, because we must select a good
version and we can't select two. *)
try S.at_most_one sat (user_var :: fail) |> ignore with
| Invalid_argument reason ->
(* Explicitly conflicts with itself! *)
S.at_least_one sat [ S.neg user_var ] ~reason)
(try S.at_most_one sat (user_var :: fail) |> ignore with
| Invalid_argument reason ->
(* Explicitly conflicts with itself! *)
S.at_least_one sat [ S.neg user_var ] ~reason)
;;

(* Add the implementations of an interface to the ImplCache (called the first time we visit it). *)
Expand Down Expand Up @@ -380,14 +380,14 @@ module Make (Model : S.SOLVER_INPUT) = struct
(* We've already selected a candidate for this component. Now check its dependencies. *)
let check_dep dep =
let { Model.dep_role; dep_importance } = Model.dep_info dep in
if dep_importance = `Restricts
then
match dep_importance with
| `Restricts ->
(* Restrictions don't express that we do or don't want the
dependency, so skip them here. If someone else needs this,
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 dep_role
| `Essential -> find_undecided dep_role
in
List.find_map ~f:check_dep deps)
in
Expand Down
Loading