Add Data.Constr casing to Case - #7914
Conversation
67382f3 to
d20120e
Compare
d20120e to
89ea27d
Compare
| {-# OPAQUE wrapUnsafeDataAsConstr #-} | ||
|
|
||
| wrapCaseData :: BuiltinData -> [BuiltinList BuiltinData -> a] -> a | ||
| wrapCaseData = BI.caseData |
There was a problem hiding this comment.
Are you sure we need this? It's possible that neither this nor wrapUnsafeDataAsConstr is needed any more.
If we do, then this needs to be mentioned in the Note below.
There was a problem hiding this comment.
If we don't have this, inliner won't inline the bindings it makes for each fields which prevents DeadCase and CollapseCase pass from running. Can't really think of other ways to make this work better
There was a problem hiding this comment.
On the side note, this method only works on quite specific case where each handler of the match must be lambda directly like so:
matchRich ...
(\a b c -> ...)
(\x y z k -> ...)
...
if we have non-lambda handler, this doesn't work at all!
let f = \a b c -> ...
in matchRich ...
f
(\x y z k -> ...)
...
All fields gets bounded for f.
There was a problem hiding this comment.
We could retire the matcher and try to optimize pattern matching in the plugin. The matcher is already inconvenient to begin with, compared to direct pattern matching. May not be easy to do though.
zliu41
left a comment
There was a problem hiding this comment.
It otherwise looks good, but this new feature must be gated by dijkstraPV, and I don't think it is gated properly.
|
Do we need this to be gated by dijkstra? I don't think adding this to older PV with builtin casing would have any issue. What do you think? |
Yes otherwise old node version rejects casing on Constr, new node version accepts it. |
| -> HeadSpine Text term (Some (ValueOf DefaultUni)) | ||
| caseBuiltinDataUnavailable someVal@(Some (ValueOf uni x)) branches = case uni of | ||
| DefaultUniUnit | ||
| | 1 == len -> HeadOnly $ branches Vector.! 0 |
There was a problem hiding this comment.
I don't think you need to duplicate the code for each branch. Can you not call caseBuiltin here?
There was a problem hiding this comment.
This would make it slower! aruond 5~10%
There was a problem hiding this comment.
Can you try some refactoring, such as defining a caseBuiltinForPV that takes PV as an argument? Explicit code duplication should rarely be needed for efficiency, and should be the last resort.
|
You may also want to check if any of the conformance tests need to be updated. |
|
Do we have a benchmark that covers casing on constants? If so can you run it on this PR to ensure there isn't regression. |
|
/benchmark validation |
|
/benchmark casing |
|
Click here to check the status of your benchmark. |
|
Comparing benchmark results of 'validation' on 'f424a79ad' (base) and '894db473c' (PR) Results table
|
|
Click here to check the status of your benchmark. |
|
Comparing benchmark results of 'casing' on 'f424a79ad' (base) and '894db473c' (PR) Results table
|
I discarded this idea originally as most of the cost would've been in the deconstruction of fields(
xshere). However, introduction ofDropListmade deconstruction ofxsreasonable fast so this approach actually gives a decent performance boost with minimal change!