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

added core::mem::reshape #130849

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

hazelwiss
Copy link

tracking issue: #130848

@rustbot
Copy link
Collaborator

rustbot commented Sep 25, 2024

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @workingjubilee (or someone else) some time within the next two weeks.

Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (S-waiting-on-review and S-waiting-on-author) stays updated, invoking these commands when appropriate:

  • @rustbot author: the review is finished, PR author should check the comments and take action accordingly
  • @rustbot review: the author is ready for a review, this PR will be queued again in the reviewer's queue

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Sep 25, 2024
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer
Copy link
Collaborator

The job mingw-check failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)
#16 2.838 Building wheels for collected packages: reuse
#16 2.839   Building wheel for reuse (pyproject.toml): started
#16 3.090   Building wheel for reuse (pyproject.toml): finished with status 'done'
#16 3.091   Created wheel for reuse: filename=reuse-4.0.3-cp310-cp310-manylinux_2_35_x86_64.whl size=132715 sha256=dfa09868353292d98f811d3efdb0d54d07389e808efc71d68e3b93c514bf8bec
#16 3.091   Stored in directory: /tmp/pip-ephem-wheel-cache-fnbbmtkz/wheels/3d/8d/0a/e0fc6aba4494b28a967ab5eaf951c121d9c677958714e34532
#16 3.094 Installing collected packages: boolean-py, binaryornot, tomlkit, reuse, python-debian, markupsafe, license-expression, jinja2, chardet, attrs
#16 3.485 Successfully installed attrs-23.2.0 binaryornot-0.4.4 boolean-py-4.0 chardet-5.2.0 jinja2-3.1.4 license-expression-30.3.0 markupsafe-2.1.5 python-debian-0.1.49 reuse-4.0.3 tomlkit-0.13.0
#16 3.486 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
#16 DONE 3.6s

Comment on lines +904 to +905
let result = ptr::read(dest);
ptr::write(dest, f(result));
Copy link
Member

Choose a reason for hiding this comment

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

this is not sound if f unwinds, as the value will be dropped twice. see https://docs.rs/replace_with/latest/replace_with/ for details. the design space here is nontrivial, as there are many possible behaviors to do on unwind. this should at least go through an ACP, but probably better for more general discussion on internals.rust-lang.org. i'd also suggesting searching there for previous discussion about "replace_with", which is what this function is generally called

Copy link
Author

Choose a reason for hiding this comment

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

yeah I just detected that myself and ran into a wall. Sounds good 👍

Copy link
Author

Choose a reason for hiding this comment

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

has there been any discussion about a feature to ensure a closure does not panic?

Copy link
Member

Choose a reason for hiding this comment

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

hm. this has probably come up in vague ways in many places but nothing concrete.

Copy link
Member

Choose a reason for hiding this comment

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

either way it's definitely both that will arrive any time soon, so it probably makes sense to close the PR and tracking issue for now

Copy link
Member

Choose a reason for hiding this comment

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

thank you for it anyways :3

Copy link
Author

Choose a reason for hiding this comment

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

👍

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you execute the closure inside an extern "C" wrapper func that would abort on unwind? I think I recently saw a PR on a helper that exposed abort on unwind (mirroring the catch_unwind function) using that technique

Copy link
Member

Choose a reason for hiding this comment

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

You're thinking of #130339

@workingjubilee workingjubilee added S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 26, 2024
///
/// let mut v: Vec<i32> = vec![1, 2];
///
/// mem::replace(&mut v, |mut v| { v.push(3); v });
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
/// mem::replace(&mut v, |mut v| { v.push(3); v });
/// mem::reshape(&mut v, |mut v| { v.push(3); v });

Should this be reshape?

/// ```
#[inline]
#[unstable(feature = "mem_reshape", issue = "130848")]
pub fn reshape<T>(dest: &mut T, f: impl FnOnce(T) -> T) {
Copy link
Member

Choose a reason for hiding this comment

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

I don't think this is a good name. When I first came across the tracking issue in the issue list, I though this was something transmute related.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-ACP Status: PR has an ACP and is waiting for the ACP to complete. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants