Skip to content

[matching.ml cleanup] structured rows#9322

Merged
trefis merged 11 commits intoocaml:trunkfrom
trefis:rematch-structured-rows
Mar 10, 2020
Merged

[matching.ml cleanup] structured rows#9322
trefis merged 11 commits intoocaml:trunkfrom
trefis:rematch-structured-rows

Conversation

@trefis
Copy link
Copy Markdown
Contributor

@trefis trefis commented Feb 20, 2020

Here we stop representing pattern rows as a list of patterns and instead switch to a pair of head pattern (previously the first element of the list) and the rest of the row (previously the tail of the list).

We also start using the Pattern_head.t type (from Parmatch) in places.

There were some patches on the file since our last series of patch that
didn't respect the formatting.
So we're calling ocamlformat again (the same version as before,
something < 0.10) so everything rebases cleanly.
@trefis trefis changed the title Rematch structured rows [matching.ml cleanup] structured rows Feb 20, 2020
@gasche
Copy link
Copy Markdown
Member

gasche commented Feb 20, 2020

(This is the first batch of changes of #9321, split because it makes sense as a unit to review on its own.)

@trefis trefis force-pushed the rematch-structured-rows branch from d8fdcd4 to c1d7714 Compare February 26, 2020 15:03
Copy link
Copy Markdown
Member

@Octachron Octachron left a comment

Choose a reason for hiding this comment

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

I like the general clarification, and I am pretty confident that there is no change in behaviour (I need one or more pass of review to be sure). However, I have few questions on interfaces, names and comments:


type clause = pattern Non_empty_clause.t

val try_no_or : Half_simple.pattern -> pattern option
Copy link
Copy Markdown
Member

@Octachron Octachron Mar 3, 2020

Choose a reason for hiding this comment

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

I found myself backtracking a few time on the name try_no_or. Maybe the function name could reflect what it is trying to do : Something like promote_no_or?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The rationale was to have assert_foo functions and try_foo functions, the first which does a cast or fail and the other which returns an option. assert_foo does not exist here, and try_foo is going to go away with the polymorphic-variant version anyway, so we propose to keep this name temporarily to avoid rebase pains.

)
| _ ->
(* I really want to assert false here. *)
{ args; cells = [] }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would prefer an assert false too.

pretty_precompiled_res next nexts
);
(next, nexts)

Copy link
Copy Markdown
Member

@Octachron Octachron Mar 3, 2020

Choose a reason for hiding this comment

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

The debug part in split_and_precompile_* is really noisy. I think it should be factorized, otherwise the small difference between the three variants are lost in the noise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

36961ba does this I believe.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Octachron remarked that this is duplication we introduced in this PR, so it would be better fixed now. I added two more commits to do it.

and compile_simplified repr partial ctx (m : Simple.clause pattern_matching) =
match m with
| { cases = []; args = [] } -> comp_exit ctx m
| { args = ((Lvar v as arg), str) :: argl } ->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The local precondition args = ((Lvar v as arg), str) :: argl is new. But compile_simplified is only called in do_compile_matching which is only called by compile_match and compile_half_compiled that respect this precondition.

(m : pattern Non_empty_clause.t pattern_matching) =
match m with
| { cases = []; args = [] } -> comp_exit ctx m
| { args = ((Lvar v as arg), str) :: argl } ->
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This also a new precondition, but compile_half_compiled is only called by compile_flattened, which is called by do_for_multiple_match on a argument list that respect this precondition too. (I have a series of commit at https://github.com/Octachron/ocaml/commits/argo_analysis that makes this point explicit).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have a series of commit at https://github.com/Octachron/ocaml/commits/argo_analysis that makes this point explicit

Thanks, but we're not going to integrate that right now.
Let's revisit once all the other PRs have been reviewed.

~mk_action:mk_new_action ~vars:(List.map fst vars) rem_cases
in
let handler =
{ provenance = [ [ orp (* FIXME? *) ] ];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What ought to be fixed here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

🤷‍♂️

The handler seems to be the same as before; and we can't remember why we added a FIXME. So we'll remove it.

@trefis trefis force-pushed the rematch-structured-rows branch from c1d7714 to 05b55b2 Compare March 10, 2020 11:07
@trefis trefis force-pushed the rematch-structured-rows branch from 05b55b2 to f3e6fc7 Compare March 10, 2020 11:14
Copy link
Copy Markdown
Member

@Octachron Octachron left a comment

Choose a reason for hiding this comment

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

The current state looks good to me: it is helpful to have the different stages of the pattern compilation reflected in the types.

@trefis trefis merged commit abeaef9 into ocaml:trunk Mar 10, 2020
@trefis trefis deleted the rematch-structured-rows branch March 10, 2020 16:03
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