Skip to content

Conversation

@Shimuuar
Copy link
Contributor

@Shimuuar Shimuuar commented Oct 3, 2025

We provide handwritten specializations for enumFromTo but don't test that they work same as standard enumFromTo. This PR adds tests and simplifies rewrite rules in vector-streaming.

Rewrite rules in Bundle could be improved but that's quite a bit of work so I submitting first part as a PR

Streams don't have size estimation so they don't need any complicated machinery
for that.
Copy link
Contributor

@lehins lehins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice simplification and it is good to finally have some tests for it.


"enumFromTo<Float> [Stream]"
enumFromTo = enumFromTo_double :: Monad m => Float -> Float -> Stream m Float #-}
"Stream.enumFromTo[Int]" enumFromTo @Int = enumFromTo_integral
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add SPECIALIZE pragma on enumFromTo_integral in order for such specialization to actually work?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my understanding RHS of rewrite rule will get inlined afterward. But it's always better to measure than to guess. Speaking of which I only test rewrite rules from Bundle and not ones from vector-stream. I need to think how to write them

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ive checked. With these rewrite rules GHC can produce nonallocating loop and fails to do so if they're disabled.

vector-stream rewrite rules are not reused in Bundle.
@Shimuuar Shimuuar merged commit 8943433 into master Oct 4, 2025
22 checks passed
@Shimuuar Shimuuar deleted the simplify-enumFromTo-stream branch October 4, 2025 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants