becls/swish

Fix code duplication caused by recent two-clause match optimization

Closed this issue · 0 comments

I introduced this bug in df3a2e5.

The criteria used there are not strong enough. In particular, that expansion will end up duplicating the code for the second clause if the pattern in the first clause contains pairs or a vector or tuple containing literal patterns or ,@var patterns.

Okay:

(expand '(match input [,@var 'ok] [,other "don't duplicate"]))
(expand '(match input [#(,x) x] [,other "don't duplicate"]))
(expand '(match input [#(,x ,y) x] [,other "don't duplicate"]))

Not okay:

(expand '(match input [(,x) x] [,other "don't duplicate"]))
(expand '(match input [#(,@x) x] [,other "don't duplicate"]))
(expand '(match input [#(,x y) x] [,other "don't duplicate"]))

We could scrutinize the pattern more closely to determine whether or not it is safe, but I'm inclined to revert the commit since the few places I was using this (on another branch) are not sufficiently compelling to motivate fixing this now.