Open sgraf812 opened 3 years ago
What do you suggest? Should I just change all INLINE
pragmas to INLINABLE
or something more nuanced?
Yes: INLINABLE, then have a look at the Core in the testsuite to see whether the call sites specialise appropriately. Maybe SPECIALISE key functions to the different vector implementations, although that always has rather huge compile-time overhead. Better do it at call sites, although that requires users to be aware... You can add SPECIALISE pragmas in the testsuite to see when specialisation is impossible because of a missing unfolding. But no way to be sure without looking at Core, I think.
We might see that Comparison
doesn't specialise properly, so we might have to get a little creative.
Ideally code like vector-algorithms
would have inspection-testing
tests in its testsuite to ensure that the algorithms can be adequately specialised. This would take much of the guess-work out of determining which pragmas are necessary where.
@bgamari Pointers to examples or documentation for inspection-testing
?
@erikd You can have a look at the testsuite of optics
, it uses inspection-testing extensively.
I'm interested to maybe try tackling this issue if someone can give me some rough guidance on what I am aiming for.
While going through https://gitlab.haskell.org/ghc/ghc/-/issues/19283, @bgamari noticed that many call sites in
statistics
fail to inlinevector-algorithm
functions, probably because some of them are recursive or just too huge to inline.I haven't looked at the Core, but the use of
Comparison
and delegation ofsort
tosortBy
suggests that the comparator won't properly specialise in some cases, namely when the function binding theComparison
isn't inlined.I think it might be better to mark them
INLINABLE
and have clientsSPECIALISE
if needed. Although theComparison
matter might need special handling, by re-introducing it as a type class. This way, call sites pay for specialisation if they want.That might also substantitally speed up compilation of
tests/properties/Tests.hs
, which took 20s on my machine, about as long as it took to compile the whole package.