[matching.ml cleanup] introductory changes#8768
Conversation
Enabled only on lambda/matching.ml And commit the config we decided to use for that file.
The assert didn't trigger, the tests passed even when returning v2.
…pecialize_default
|
My script to check that the generated code is the same within the compiler distribution is the following: make clean
./configure
make core -j
make coreboot -j
make partialclean
sed -i 's/COMPFLAGS=-strict-sequence/COMPFLAGS=-dlambda -dno-unique-ids -dump-into-file -strict-sequence/g' Makefile
make world -j
make opt -j
git checkout Makefile
mkdir -p lambda-dumps
for f in $(find . -name '*.dump')
do
cp --parents $f lambda-dumps
rm $f
done
make cleanMore precisely, this will create a directory (The way |
lambda/matching.ml
Outdated
| in | ||
| List.iter (fun ((_, lbl, _) as x) -> t.(lbl.lbl_pos) <- x) lbls; | ||
| Array.to_list t | ||
| | _ -> fatal_error "Parmatch.all_record_args" |
There was a problem hiding this comment.
Matching.all_record_args rather than Parmatch. ...
There was a problem hiding this comment.
Indeed. This has been here for two years now, but let's take the opportunity to change it.
lambda/matching.ml
Outdated
| However or-patterns are only half-simplified, | ||
| - aliases under or-patterns are kept | ||
| - or-patterns whose left-hand-side is simplifiable | ||
| are removed: (_|p) is changed into _ |
There was a problem hiding this comment.
Here, the code feels less specific than the comment since any or-pattern p|q where p ≤ q is simplified to p. Maybe we could add a for instance in the comment, or write down the effective rule. Or maybe,
- or-patterns whose right-hand-side is subsumed by their left-hand side are simplified to their left-hand-side:
For instance [( :: | 1 :: _ )] is changed into [ _ :: _ ]
lambda/matching.ml
Outdated
| | [] -> raise (Invalid_argument "cut") | ||
| | a :: l -> | ||
| let l1, l2 = cut (n - 1) l in | ||
| (a :: l1, l2) |
There was a problem hiding this comment.
Except for the Invalid_argument (and the behavior on negative integers), isn't this cut function the same as rev_split_at?
There was a problem hiding this comment.
Looks like it is indeed.
|
I started reading this PR a few weeks ago, and I won't have time to finish, so here are the few remarks I had in the meantime. I read until commit 181f2a7 (i.e. I haven't read the last 5 commits).
|
The [var_arg] field of a PmVar hold the first argument (which we force to be a variable) on which the inner pm would match. That information is obviously already stored in the inner pm.
Apparently ocamlformat isn't quite reliable in that area.
[matching.ml cleanup] introductory changes
[matching.ml cleanup] introductory changes
First wave of changes, joint work with @gasche (with help from @maranget).
I could add a changelog entry in this PR already, but I have a slight preference for delaying this until all the changes (more PRs are in preparation) have been submitted.
The commits here are focused on documenting, renaming, and dusting off some old code. The code emitted by the compiler should be strictly the same before and after this PR (we have checked that this is true on the compiler codebase).