lspitzner / pqueue

Haskell priority queue package
Other
15 stars 13 forks source link

Use `coerce` instead of `fmap unDown`/`fmap Down` #97

Closed konsumlamm closed 1 year ago

konsumlamm commented 1 year ago

Since Down is a newtype, it's possible to use coerce instead of fmap unDown/fmap Down.

treeowl commented 1 year ago

Those are maps over lists, which should be rewritten to coerce by RULES in GHC.base.

konsumlamm commented 1 year ago

Yes, there's a rule for map coerce, but I'd rather not rely on that. In most cases it seems to be inlined, but there is at least one case where an fmap Down (on Maybe) is not optimized out.

treeowl commented 1 year ago

Interesting. There's no fmap/coerce rule for Maybe, but I'd have expected that fmap to inline. Why doesn't it?

konsumlamm commented 1 year ago

Interesting. There's no fmap/coerce rule for Maybe, but I'd have expected that fmap to inline. Why doesn't it?

It does inline, but it doesn't reduce to coerce, it still matches the Maybe.

treeowl commented 1 year ago

How odd! That likely will get cleaned up in the Cmm, but I suggest filing a GHC ticket anyway. Just making sure: you're looking at the compiled code and not the unfolding, right?

konsumlamm commented 1 year ago

I'm looking at the core, I always supress the unfoldings anyway.

treeowl commented 1 year ago

So ... GHC ticket it is.

treeowl commented 1 year ago

Did you end up opening a GHC ticket for this, or shall I?

konsumlamm commented 1 year ago

I didn't, feel free to open one.