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

Add documentation for realloc and resize possibly not modifying argument #235

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

crtrott
Copy link
Member

@crtrott crtrott commented Dec 22, 2022

No description provided.

@@ -9,6 +9,7 @@ Usage:
```

Reallocates a view to have the new dimensions. Can grow or shrink, and will not preserve content.
May not modify the view, if sizes already match.
Copy link
Member

Choose a reason for hiding this comment

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

Maybe a native speaker can chime in but I feel like "may not" is unfortunate because it could be interpreted as "[presumably the implementation] is not allowed"

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah, that is a reasonable mis-interpretation. The intended meaning would be conveyed (with more explicit precision) by "Might not modify the view, if its extents match those requested"

Copy link
Contributor

Choose a reason for hiding this comment

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

@PhilMiller , @dalg24 - regarding line 12 above; why not be definitive, and say "if sizes already match, the View will not be modified." Here, "may" suggests other possible outcomes, and there are none, if the requested sizes are the same as the current sizes , correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

This is reaching back to very old discussion, but I believe the intention was to avoid committing the implementation to any particular outcome. Once it's documented to definitely do something, that's a nearly-eternal promise.

Comment on lines +168 to +175
## Possibly Unexpected Behavior Warning

`realloc` will only modify the specific `View` instance passed to it.
Any other `View` which aliases the same allocation will be unmodified.
Consequently, if the `use_count()` of the `View` is larger than 1, the
old allocation will not be deleted.
Note that if the size arguments already match the extents of the `View`
argument, that `realloc` may not create a new `View`.
Copy link
Member

Choose a reason for hiding this comment

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

Did you consider having a code snippet to illustrate how this may have potentially surprising behavior?
Also should we spell out that it is best to think of if as what std::realloc is to raw pointers, that is the original view is "invalidated" and that keep using another object that aliases that same original view is a bad idea.

@PhilMiller
Copy link
Contributor

I agree that this (with the noted rewording) accurately enough describes the current behavior, but I strongly feel that it's not the behavior we should provide.

@PhilMiller
Copy link
Contributor

For cross-reference purposes, this was opened to start addressing kokkos/kokkos#5589

@fnrizzi
Copy link
Collaborator

fnrizzi commented Mar 27, 2023

this will need to be redone on top of the rst file

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.

5 participants