Just some tbl things.#1699
Conversation
|
I do not understand travis' failure. It builds/tests fine locally and the various |
|
There is a |
|
I haven't got time to read this in detail right now, but will aim to do so in due course. I agree that cleanup here would be beneficial. This work seems related to some changes I am working on to integrate the |
This is not necessary. Magic numbers will be bumped unconditionally for each release. |
|
At a glance, this looks good to me (although, if I may, I think the word gross should possibly only be used when describing one's own work!). It's a basically internal change, so I agree it doesn't require a changes entry, but that does mean the work only gets credited in Git history, so feel free to add one if you'd like! |
Indeed! Making relevant data-structures in the compiler into
Ok, I will add one then. |
8c26653 to
9ce89b2
Compare
mshinwell
left a comment
There was a problem hiding this comment.
I've made some comments and suggestions. This is good work.
| (* Introduction of closures, uncurrying, recognition of direct calls *) | ||
|
|
||
| open Misc | ||
| open Numbers |
There was a problem hiding this comment.
Instead of a whole open, I would just use: module Int = Numbers.Int here.
| open Switch | ||
| open Clambda | ||
|
|
||
| module VarMap = Ident.Map |
There was a problem hiding this comment.
I think this is confusing ("ident"s versus "var"s). How about just replacing VarMap with Ident.Map throughout? That seems fine to me, and more clear in fact.
| type t = int | ||
| let compare (x:t) y = compare x y | ||
| end) | ||
| module IntSet = Numbers.Int.Set |
There was a problem hiding this comment.
Here, I would use module Int = Numbers.Int again, then this alias can be removed. Just use Int.Set instead of IntSet.
| sequentialization. *) | ||
|
|
||
| open Misc | ||
| open Numbers |
| open Asttypes | ||
| open Lambda | ||
|
|
||
| module VarMap = Ident.Map |
| end | ||
|
|
||
| module PathMap = Map.Make(Path) | ||
| module NameMap = Misc.StringMap |
There was a problem hiding this comment.
Name, as in the individual parts in an Longindent.t. I would like to call them ident, but that clashes with the individual parts of a Path.t. I insist on having a local redefinition on that one, as it's the original motivation for this whole patch. But I agree, the name is bad.
| | Field_class _ -> "class" | ||
| | Field_classtype _ -> "class type" | ||
|
|
||
| (** Map indexed field names. Allow to preserve namespaces. *) |
There was a problem hiding this comment.
This comment isn't very clear---can you reword?
There was a problem hiding this comment.
The new one is :
(** Map indexed by both field types and names.
This avoids name clashes between different sorts of fields
such as values and types. *)
| | Papply _ -> false | ||
| | Path.Pident _ -> true | ||
| | Path.Pdot(p, _, _) -> no_apply p | ||
| | Path.Papply _ -> false |
There was a problem hiding this comment.
FWIW, using disambiguation helps a lot for this kind of thing:
let can_alias env path =
let rec no_apply (path : Path.t) =
match path with
 | Pident _ -> true
| Pdot(p, _, _) -> no_apply p
| Papply _ -> false
in
...
There was a problem hiding this comment.
Unfortunately, this part of the compiler has warning 40 turned on (and fatal). I think changing default warnings in the implementation of the typechecker shouldn't be discussed in this PR.
| let compare = compare | ||
| end | ||
| module Set = Set.Make(T) | ||
| module Map = Map.Make(T) |
There was a problem hiding this comment.
You could probably use Identifiable.Make for this instead.
There was a problem hiding this comment.
Identifiable.Make require (two) printers and an equal function. I would prefer to leave that for later.
| exception Error_forward of Location.error | ||
|
|
||
| (** Map indexed by type variable names. *) | ||
| module VarMap = Misc.StringMap |
There was a problem hiding this comment.
Here is an example of why I recommended not having the VarMap alias up above in closure.ml: here the same alias means something completely different! (And it's not like it's a one-letter alias.)
There was a problem hiding this comment.
I removed all instances of VarMap outside of the typechecker and renamed that one as TyVarMap, which should make things clearer.
|
Oh, and please add a |
ce9a7a6 to
bfa53aa
Compare
|
@mshinwell Thanks for the detailed review! I think I addressed most of your comments. I also fixed the change entry and rebased. There are a few things (cleanup the 3 extended stdlibs, add even more identifiable everywhere) that would be very beneficial, but I would prefer to do them later, as the risk of conflict between this patchset and other changes is quite high. |
|
While replacing ocamltest's StringMap and Sets, I realized the function |
|
I rebased and added some fixed related to various recent additions. I think I already addressed all of @mshinwell 's comment. Is there a remaining blocker? I plan to squash things before the merge. |
b5120ed to
fee2843
Compare
|
You don't have to squash, just state that it should be squashed and we just use GitHub's "Squash and merge" option. |
|
"Squash and merge" is generally terrible except for PRs that obviously fit in just one commit. If it's a series of nicely separated commits ("Remove Tbl in Foo" fits the pattern) plus some junk, you have to squash manually. On the other hand, @Drup is making a mistake by not squashing right away. He is trying to save his time, but introduces complexity, delay, communication needs and mistake points in the process instead. One might even go as far as saying as he deserves to get his entry squashed! |
|
@gasche I'm going to quote @mshinwell In another PR of mine:
New commits are not squashed immediately with the old ones so that reviewers don't have to make high order diffs between stack of patchs. Unfortunately, we're not using Iron for OCaml PR reviews. |
|
I would disagree with Mark on this one, but given that he is the one who should give you his seal of approval, it makes sense to please him. |
|
"Squash and merge" is generally the right thing to do, because most PRs have an uninteresting history and uninteresting commit message, e.g. "Typos", "Going home", or "Add a Changes entry". Indeed this PR has one commit titled "Really?!" and another titled "Depend". I don't want to see this nor the 18 intermediate states of this PR in OCaml's commit log. I want to see one entry in the log with one message that summarizes what the PR does in its final state. |
|
If you want to tidy the history, then I'm sure @mshinwell can be persuaded to merge a clean commit history! However, before this is merged, please could check-typo violations be dealt with: |
|
It is generally a bad idea to squash before the end because the commits get out of sync with the discussion and it becomes hard to make sense of them. |
|
@dra27 All fixed, and rebased on top of trunk to take advantage of the nice typocleaning. |
|
Thanks for the |
|
4.07 is released, the world cup is finished. @mshinwell, can I get a review? :) |
|
Please add a comment in env.ml on the "NameMap" definition to say what "Name" means here, since we can't come up with anything better. OK to merge with that change. Thanks for taking the time to do this, it seems like a real improvement. |
|
Done, rebased, and history somewhat cleaned up. |
|
CI is green. |
|
I'm a bit worried by the last commit fixing a test failure. This means that the testsuite fails if I am bisecting and end in the middle of your patchset, right? Could you maybe fixup this commit at the first point where the change is required, to maintain the invariant that intermediate states are clean? |
|
I was planning to squash the whole lot; I'm not sure any intermediate state is useful here. |
|
@mshinwell Do as you wish. :p |
I always felt that the
Tblmodule was agrossslight violation of the DRY principle, so this patchset removes it.On the way, I removed almost all the duplicated
(String|Int)(Map|Set)in the compiler, and a few others.This is my small contribution towards making the compiler feel like one code base, instead of the collision of five different ones. ;)
Details on
TblTblis basically a polymorphicMapmodule, using the polymorphic comparison with a few more hacks (such asTbl.find_strwhich hardcodes the string comparison for speed. It is used for some string tables ... but not all of them). It has the exact same structure and semantics as Map, making it completely redundant.On top of that, relying on the generic Tbl make local modifications fairly painful and invasive. For example, in the eliom patches, names are a couple of a string and a "location" (in eliom vocabulary) with a custom comparison function. With this patch, it can be implemented as a simple change in the implementation of
Env.NameMap.Patchset
The first 10 commits should be fairly consensual. They were mostly done through paste and replace.
The last 3 commits, particularly 484c79b , might be less consensual: Tbl made its way into the format for cmo files though the symbol tables for global variables and primitives. I replaced them by an
Ident.Map(for global ids) and aStringMap(for primitives). I didn't bump the magic number (yet).I'm not sure if I need a change entry for this.
Perfs
I don't expect any perf differences (the "hot" paths were already using
Tbl.find_str). My non-scientific benchmark show a very minor speedup (around 1%, so probably noise). Is there some command to measure performance changes of the compiler on itself?