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

List prefix functions for Misc.Stdlib.List #2283

Merged
merged 3 commits into from
Mar 6, 2019

Conversation

mshinwell
Copy link
Contributor

The work to improve the types of symbols requires some more prefix-related functions on lists, as presented here. I don't think we have anywhere to put unit tests for such things at present. These have been tested in the toplevel, which I think will suffice, nonetheless.

utils/misc.ml Outdated
first_without_longest_common_prefix = l1;
second_without_longest_common_prefix = l2;
}
| elt1::l1_tail, elt2::l2_tail ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using a when guard (when equal elt1 elt2), and a wildcard pattern for all other cases; this would avoid the code duplication.

utils/misc.ml Outdated
| _::_, [] -> false
| [], _::_ -> true
| x1::t, x2::of_ ->
if equal x1 x2 then is_prefix ~equal t ~of_
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

equal x1 x2 && is_prefix ~equal t ~of_

utils/misc.mli Outdated
@@ -116,6 +116,29 @@ module Stdlib : sig
(** [split_at n l] returns the pair [before, after] where [before] is
the [n] first elements of [l] and [after] the remaining ones.
If [l] has less than [n] elements, raises Invalid_argument. *)

(** Returns [true] iff the given list, with respect to the given equality
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The style used in this module is to have docstrings after definitions. It would seem better to stick to it.

Copy link
Contributor

@alainfrisch alainfrisch left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code LGTM. Minor suggestions, which are not blocking.

My only concern is that we accumulate dead code in the compiler, with the hope that they become useful through later PRs. I understand that the idea is to split a bigger work into smaller, more easily reviewable chunks, but it would be better if this could be done through coherent chunks that add actual logic, not just helper functions. Reviewing code for internal helper functions without any context about the intended use cases seems a bit weird (but that's only my personal opinion, perhaps others are fully ok with it).

}

let find_and_chop_longest_common_prefix ~equal ~first ~second =
let rec find_prefix ~longest_common_prefix_rev l1 l2 =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function could be shorter and no less clear:

let rec find_prefix acc l1 l2 =
  match l1, l2 with
  | x :: l1, x' :: l2 when equal x x' ->
    find_prefix (x :: acc) l1 l2
  | l1, l2 ->
    { longest_common_prefix = List.rev acc;
      first_without_longest_common_prefix = l1;
      second_without_longest_common_prefix = l2 }

@mshinwell
Copy link
Contributor Author

@alainfrisch Well it works both ways. Functions such as these (which should really be in the stdlib) should be standalone and completely independent of the context, in terms of semantics, so in some ways it's perhaps better not to see the calling context. As far as accumulating dead code goes, well, the only way to reasonably submit very large changes at the moment is from the bottom up. If we had better workflow management tools it might be possible to do otherwise, but we're not there yet. For these particular changes, the uses should appear in patches next week, depending on how review of existing pending GPRs goes.

@mshinwell
Copy link
Contributor Author

@alainfrisch Please see the new version and merge if you are happy, thanks.

@alainfrisch alainfrisch merged commit c975b15 into ocaml:trunk Mar 6, 2019
@alainfrisch
Copy link
Contributor

FWIW, I don't think a Changelog entry is needed for such PRs which don't impact users (we really don't want to advocate the use of those internal helper functions for users of compiler-libs).

@mshinwell
Copy link
Contributor Author

Really? I tend to think that if we're going to have a Changes file it should contain everything. (I don't buy the argument that users of compilerlibs will change their behaviour just based on what's in the Changes file, in particular.) In fact, as I was just saying to @dra27, I am hoping that we can find a solution to autogenerate the Changes file or equivalent -- the amount of wasted work due to merge conflicts is excessive.

@alainfrisch
Copy link
Contributor

I don't see the point of an exhaustive, auto-generated Changes file. Commit messages and PR history are good enough for that. In my opinion, the goal of the Changes file is to inform users about changes which matter to them. I don't think that the addition of internal helpers functions, split in its own PR to help reviewing a subsequent PR, fall in this category.

@mshinwell
Copy link
Contributor Author

@alainfrisch I suggest we take the Changes topic to caml-devel.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants