Closed last-genius closed 9 hours ago
Due to the size of this PR, I will be pushing fixup commits to ease the review process. Will squash these at the end.
~Pedantically, there is a case where you can η-reduce
(fun s -> Stunnel.disconnect s)
.~ - nevermind, we shouldn't be making unrelated changes here (I guess do them if you want so long as they are obviously correct and won't impair review?).
Nice catch! I've been trying to keep this PR to changes that do not change the logic of code -- this one does not, however, a simple grep indicates there are at least 50 such cases in the codebase!
$ unbuffer rg 'fun\s+(\w+)\s+->\s+\w+\s+\1\)' --pcre2 --no-heading | tee >(wc -l)
[....]
50
Might just as well put this in a separate ticket/PR - though there is little practical benefit, it gets boiled down to the same code
Also, if you want to be consistent with using
Option.map
and friends to outline casing behaviour, there are a few cases wherefold
could be used, e.g.:
I myself find that the parseability of match
is better than that of Option.fold
-- perhaps it's just a question of style and preference. match
is not so nice when one of the arms is heavy and the other is empty, so that's why I've used .map
and .iter
to immediately indicate the intention without having to search for the other arm.
Might just as well put this in a separate ticket/PR - though there is little practical benefit, it gets boiled down to the same code
Indeed, it's only a stylistic concern; this case is a minor one but there are areas of the codebase where eta-reduction could be applied several times, which cleans things up a lot, visually (typical examples would be with List.fold_left
). It's one of the more pedantic style changes, but it's generally accepted as good practice (so long as you don't get carried away with point-free style and get caught out by the value restriction).
Had to rebase on top of master to get the Clock module, so hashes have changed. Otherwise review fixes are still in separate fixup commits.
Has your comment being addressed, @psafont? Please revisit this such that we can merge this.
Please squash the commits
Squashed the fixes. Commits are still split into several as was suggested by Christian initially, so that we could revert only one if needed later (especially in the case of the more complex refactored files)
This PR starts the transition away from exception-raising OCaml's stdlib functions
Unix.getenv
andHashtbl.find
in favour ofSys.getenv_opt
andHashtbl.find_opt
respectively.This is beneficial because:
.find
functions where gated by.mem
functions to avoid raising exceptions, instead doing just one.A naive benchmark shows the benefit:
.mem
) and getting its value (.find
).mem
would be changed but its corresponding.find
would not be.===========
This PR is structured in the following way:
Unix.getenv -> Sys.getenv_opt
change along with the quality gate test for it. Unix.getenv usage has been completely eliminated.Hashtbl.find -> find_opt
Hashtbl.find -> find_opt
, in one case I've eliminated unnecessaryHashtbl
operations altogether.Hashtbl.find
- there are 36 usages left that do not handle exceptions currently and would need to introduce it on the appropriate level.Even though the PR is relatively large, most changes are trivial and fall into several classes:
Option.value
_opt
by doingtry Some (x.find) with _ -> None
=> justx.find_opt
.find
gated by.mem
=> transition to match statement /Option.iter
/Option.map
depending on the case===========
These changes passed the BST+BVT test suites.