haskell / vector

An efficient implementation of Int-indexed arrays (both mutable and immutable), with a powerful loop optimisation framework .
Other
366 stars 139 forks source link

Hint to GHC that indices are to be used strictly #485

Closed Bodigrim closed 8 months ago

Bodigrim commented 8 months ago

basicUnsafe{Read/Write/IndexM} are class members and, unless a call site was already specialised to a specific vector instance, GHC has no clue that the index is most certainly to be used eagerly. Bang before the index provides this vital for optimizer information.

I've been recently looking at Core for programs, where vectors did not specialise to a specific instance for one reason or another. It's really horrible: even if a specific instance remains unknown, we should tell GHC that passing boxed indices around is not OK.

Shimuuar commented 8 months ago

@Bodigrim I extended same treatment to unsafeSlice and converted comment to GHC note. This seems to be a good format for long form comment which are referenced from multiple places in source code

If you're fine with this I'd like to merge this PR

Bodigrim commented 8 months ago

@Shimuuar sure, go ahead.