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

Stop using polymorphic comparison when comparing switch_selections #6102

Merged
merged 1 commit into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ users)
## Shell

## Internal
* Stop using polymorphic comparison when comparing `OpamTypes.switch_selections` [#6102 @kit-ty-kate]

## Internal: Windows

Expand Down Expand Up @@ -151,5 +152,6 @@ users)
## opam-solver

## opam-format
* Add `OpamTypesBase.switch_selections_{compare,equal}`: proper comparison functions for `OpamTypes.switch_selections` [#6102 @kit-ty-kate]

## opam-core
13 changes: 13 additions & 0 deletions src/format/opamTypesBase.ml
Original file line number Diff line number Diff line change
Expand Up @@ -332,3 +332,16 @@ let string_of_path_format = function
let char_of_separator = function
| SSemiColon -> ';'
| SColon -> ':'

let switch_selections_compare x
{sel_installed; sel_roots; sel_compiler; sel_pinned} =
let cmp = OpamPackage.Set.compare x.sel_installed sel_installed in
if cmp <> 0 then cmp else
let cmp = OpamPackage.Set.compare x.sel_roots sel_roots in
if cmp <> 0 then cmp else
let cmp = OpamPackage.Set.compare x.sel_compiler sel_compiler in
if cmp <> 0 then cmp else
OpamPackage.Set.compare x.sel_pinned sel_pinned

let switch_selections_equal x y =
switch_selections_compare x y = 0
5 changes: 5 additions & 0 deletions src/format/opamTypesBase.mli
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ val raw_of_op: euok_writeable env_update_op_kind -> OpamParserTypes.FullPos.env_
(* Path transformers & separator functions *)
val string_of_path_format: path_format -> string
val char_of_separator: separator -> char

kit-ty-kate marked this conversation as resolved.
Show resolved Hide resolved
(** Comparators **)
(* Switch selections *)
val switch_selections_compare : switch_selections -> switch_selections -> int
val switch_selections_equal : switch_selections -> switch_selections -> bool
5 changes: 4 additions & 1 deletion src/state/opamSwitchAction.ml
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,10 @@ let update_switch_state ?installed ?installed_roots ?reinstall ?pinned st =
in
let st = { st with compiler_packages } in
if not OpamStateConfig.(!r.dryrun) then (
if OpamSwitchState.selections st <> old_selections then write_selections st;
if not (OpamTypesBase.switch_selections_equal
(OpamSwitchState.selections st)
old_selections) then
write_selections st;
if not (OpamPackage.Set.equal reinstall0 reinstall) then
OpamFile.PkgList.write
(OpamPath.Switch.reinstall st.switch_global.root st.switch)
Expand Down
2 changes: 1 addition & 1 deletion src/state/opamUpdate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@ let dev_packages st ?autolock ?(working_dir=OpamPackage.Set.empty) packages =
(* The following is needed for pinned packages that may have changed
version *)
let selections1 = OpamSwitchState.selections st in
if selections0 <> selections1 then
if not (OpamTypesBase.switch_selections_equal selections0 selections1) then
OpamFile.SwitchSelections.write
(OpamPath.Switch.selections st.switch_global.root st.switch)
selections1;
Expand Down
Loading