[core.match] Vector rest pattern issues

72 views
Skip to first unread message

Chas Emerick

unread,
Apr 22, 2013, 1:09:55 PM4/22/13
to cloju...@googlegroups.com
I hit a couple of bugs in core.match involving & rest vector patterns. I made some progress (reflected in the attached WIP .diff), but have hit a wall.

First bug:

(match [[:x]]
[[m n & _]] 1)
=> IndexOutOfBoundsException

Essentially, vector rest patterns weren't producing necessary size checks prior to using subvec. I fixed this by adding another variant of `test-inline` that is emitted only by vector rest patterns.

That change is safe and does not cause any regressions in the core.match test cases, but did in my app's. I boiled it down to this minimal example:

(match [[[:x "t"]]]
[[[:x & a] & tail]] :a
[[[:y & p] [:x & a] & tail]] :b)
=> nil

In the emitted code, the first case would never be matched. I tweaked the relevant return values in pattern-compare (which always returned 0 for patterns of the same size?). That fixed this case, but regressed vector-pattern-rest-2.

It was at this point that I realized that pattern-compare wasn't isomorphic to other *compare fns (it only is used to determine equality or not?), and discovered the & rest vector pattern dropping logic in `first-column-chosen-case` (neither of which I've come to grok at all).

My app is doing well enough with a SNAPSHOT that uses the "fixes" so far, but I'd like to nail down that regression. The addition of test-with-min-size-inline (or something like it) is necessary in any case to avoid the IOOBE, but I feel quite over my head at this point w.r.t. the pattern "ordering" / rest vector pattern pruning. Any hints?

Thanks,

- Chas

vector-rest-WIP.diff

David Nolen

unread,
Apr 22, 2013, 1:15:25 PM4/22/13
to cloju...@googlegroups.com
Can you create a ticket and add your current patch and I'll review?

Thanks!
David



--
You received this message because you are subscribed to the Google Groups "Clojure Dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojure-dev...@googlegroups.com.
To post to this group, send email to cloju...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojure-dev?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.



Chas Emerick

unread,
Apr 22, 2013, 1:42:00 PM4/22/13
to cloju...@googlegroups.com

Thanks for taking a look.  I guess I should just buckle down and read the paper(s) so I can stop playing whack-a-bug. ;-)

- Chas

David Nolen

unread,
Apr 22, 2013, 1:43:10 PM4/22/13
to cloju...@googlegroups.com
Thanks. It's really just the Maranget paper that's relevant :)
Reply all
Reply to author
Forward
0 new messages