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

matching: simplify can_group #9417

Merged
merged 2 commits into from Apr 7, 2020
Merged

Conversation

trefis
Copy link
Contributor

@trefis trefis commented Apr 3, 2020

Note: there are already some comments from a previous review in the commit message.

lambda/matching.ml Outdated Show resolved Hide resolved
@gasche
Copy link
Member

gasche commented Apr 4, 2020

(This is the next change from #9321, after #9361 was merged.)

Copy link
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.

Replacing fifteen predicate functions by one match is a really nice simplification. If the CI failure on 32 bit is transient, this seems good to go.

trefis and others added 2 commits April 7, 2020 06:41
review of can_group factorization by @gasche:

> I reviewed the change to `can_group` and believe it is correct.
> (I knew it would be nicer as a binary operation!)
>
> The different treatments of Lazy and Tuple/Record does look a bit odd,
> but I believe that it is actually the right thing to write.
>
> In the Tuple or Record case, the idea is that we can group Any heads
> with the Tuple/Record case and just explode all of them (including the
> Any cases) according to the tuple/record arity.
>
> In the Lazy case, the corresponding choice would be to add Any values
> to the Lazy group, and force all the elements of the group. This is
> not so nice, because intuitively we shouldn't force Lazy values unless
> we have to.
>
> One may expect that in general the argument of the pattern will be
> forced anyway, as long as there is at least one Lazy pattern above in
> the matrix, so it doesn't really matter whether we include the Any
> patterns in the forced group or not. I would argue that (1) even if
> that was true, it would be semantically dubious to handle Any that way
> (see a more precise criterion below), (2) I am not actually sure that
> this is true, what if the first group gets found unreachable by
> splits in following columns?
>
>     # type void = | ;;
>     # match (lazy (print_endline "foo"), (None : void option)) with
>       | lazy (), Some _ -> .
>       | _, None -> false;;
>     - : bool = false
>
> This gives the following decision tree for whether Any is included in
> the group:
>
> - Can the absence of Any be used to generate nice/efficient tests for
>   the heads of the group? In that case, don't include Any.
>   (Not included: all the Constant cases, Array (discriminate on size),
>    String, etc.)
>
> - Is Any always exactly equivalent to a more-defined head for values
>   of this type? In that case, do include Any, otherwise do not.
>   (Included: Variant, Record)
>   (Not included: Lazy)
@gasche gasche force-pushed the rematch-can_group-simplif branch from 63f852f to d05f86e Compare April 7, 2020 04:45
@gasche
Copy link
Member

gasche commented Apr 7, 2020

(There was a failure in lib-random/random.ml; I rebased and re-pushed so we will see whether it was transient.)

@gasche
Copy link
Member

gasche commented Apr 7, 2020

(The failure was transient, merging. @trefis I'll add the missing Changes entry in trunk directly.)

@gasche gasche merged commit 019cd43 into ocaml:trunk Apr 7, 2020
@gasche
Copy link
Member

gasche commented Apr 7, 2020

@trefis I added a Changes entry in 2e82c0e, could you edit it with new PR numbers as we submit them? This makes it easy to find these PRs again later, which may be useful on some occasions.

@trefis
Copy link
Contributor Author

trefis commented Apr 7, 2020

Ack.

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

Successfully merging this pull request may close these issues.

None yet

3 participants