Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use functions from newer primitive and primitive-unlifted #63

Merged
merged 11 commits into from
May 9, 2024

Conversation

andrewthad
Copy link
Member

The implementation UnliftedArray in primitive-unlifted-2.1 penalizes the creation of an uninitialized unlifted array. When shrinking and resizing unlifted arrays, there are primitives that we can use to avoid this.

Also, primitive itself now has shims for common operations on PrimArray, so this commit also cleans up the Shim module.

The implementation UnliftedArray in primitive-unlifted-2.1
penalizes the creation of an uninitialized unlifted array. When
shrinking and resizing unlifted arrays, there are primitives that
we can use to avoid this.

Also, primitive itself now has shims for common operations on
PrimArray, so this commit also cleans up the Shim module.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd change line 142 to:
-- | Resize a mutable array without growing it. It may be shrunk in place.

Copy link
Contributor

Choose a reason for hiding this comment

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

I'd still like line 142 changed (to add " It may be shrunk in place."). :)

Comment on lines +883 to +886
{-# INLINE shrink #-}
shrink !arr !n = do
shrinkSmallMutableArray arr n
pure arr
Copy link
Contributor

Choose a reason for hiding this comment

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

Excellent! I'd do these 4 lines for PrimArray also, using shrinkMutablePrimArray, thanks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. I've done this in 95e48d0.

Comment on lines 1271 to 1275
-- Note [Shrinking Unlifted Arrays]
-- ================================
-- This implementation copies the array rather than freezing it in place.
-- But at least it is able to avoid assigning all of the elements to
-- a nonsense value before replacing them with memcpy.
Copy link
Contributor

@DaveBarton DaveBarton Apr 25, 2024

Choose a reason for hiding this comment

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

Wow, very clever! But I think you want to apply this to lifted arrays also, right? Including defining a shrink using cloneMutableArray, and also in Shim.hs changing resizeArray to be like resizeUnliftedArray. Then maybe deleting or commenting out the default shrink?

Copy link
Member Author

Choose a reason for hiding this comment

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

Good idea. Added this change in 95e48d0.

@andrewthad
Copy link
Member Author

I've made the changed you suggested. I've also gone through and remove several of the default implementations for things. As I was looking at the code, I realized that the default implementations of all the functions related to shrinking and in-place freezing just made it hard to reason about what was going on, and those are operations where I really want to know what's going on.

Let me know if there are any other concerns.

Copy link
Contributor

@DaveBarton DaveBarton left a comment

Choose a reason for hiding this comment

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

Great progress! Just a few nits.

@DaveBarton
Copy link
Contributor

Ping? There are just a very few corrections left. Maybe it's better to make these now while your memory is still fresh. Also I'd like to use the new library. :) Thanks!

@andrewthad
Copy link
Member Author

Sorry, I had totally missed the notification when you left a review. I've merged all of your suggestions into the branch. Anything else, or should I go ahead and squash this down?

@DaveBarton
Copy link
Contributor

Looks great! I think the only thing left is the comment in Class.hs, adding "It may be shrunk in place.":

I'd change line 142 to:
-- | Resize a mutable array without growing it. It may be shrunk in place.

@andrewthad andrewthad merged commit 2774df7 into main May 9, 2024
4 checks passed
@andrewthad andrewthad deleted the upgrade-to-newer-functions branch May 9, 2024 19:49
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.

2 participants