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 perf side effect docs to Iterator::cloned() #92955

Merged
merged 1 commit into from
Mar 23, 2022

Conversation

llogiq
Copy link
Contributor

@llogiq llogiq commented Jan 16, 2022

Now that #90209 has been closed, as the current state of affairs is neither here nor there, this at least adds a paragraph + example on what to expect performance-wise and how to deal with it to the .cloned() docs.

cc @the8472

@rust-highfive
Copy link
Collaborator

r? @yaahc

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 16, 2022
@rust-log-analyzer

This comment has been minimized.

@scottmcm scottmcm added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 16, 2022
@rust-log-analyzer

This comment has been minimized.

@llogiq llogiq force-pushed the cloned-side-effect-doc branch 2 times, most recently from 5e9b487 to d3227fd Compare January 16, 2022 11:50
@rust-log-analyzer

This comment has been minimized.

/// // instead call `cloned` late:
/// let good: Vec<_> = a.iter().filter(|s| s.len() == 1).cloned().collect();
/// assert_eq!(&[".".to_string()], &good[..]);
/// ```
Copy link
Member

Choose a reason for hiding this comment

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

I think this part should be fairly uncontroversial (modulo readability nits), it simply adds an implementation hint.

/// There is no guarantee whatsoever about the `clone` method actually
/// being called *or* optimized away. So code should not depend on
/// either.
///
Copy link
Member

@the8472 the8472 Jan 18, 2022

Choose a reason for hiding this comment

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

This one seems a little more troublesome to me. I don't think this adds anything new, it simply makes the "no guarantee in either direction" which was previously implicit in the absence of detailed specification explicit. But some libs team members interpret API contracts differently than I do, so I want some extra eyes on this. Wait, I'm not assigned reviewer, nevermind 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

At least making it explicit allows us to point the user to the docs when they bemoan their code breaking should we ever decide to improve perf on this.

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 mind making the lack of a guarantee explicit, I don't believe this restricts us in any way which is the main thing I worry about with docs changes

library/core/src/iter/traits/iterator.rs Outdated Show resolved Hide resolved
@the8472 the8472 added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jan 18, 2022
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 12, 2022
@JohnCSimon JohnCSimon added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 20, 2022
@Dylan-DPC Dylan-DPC added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 21, 2022
@Dylan-DPC
Copy link
Member

@yaahc this is waiting for review

@yaahc
Copy link
Member

yaahc commented Mar 22, 2022

@bors r+ rollup=always

@bors
Copy link
Contributor

bors commented Mar 22, 2022

📌 Commit 1fb43f6 has been approved by yaahc

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 22, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 23, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#91608 (Fold aarch64 feature +fp into +neon)
 - rust-lang#92955 (add perf side effect docs to `Iterator::cloned()`)
 - rust-lang#94713 (Add u16::is_utf16_surrogate)
 - rust-lang#95212 (Replace `this.clone()` with `this.create_snapshot_for_diagnostic()`)
 - rust-lang#95219 (Modernize `alloc-no-oom-handling` test)
 - rust-lang#95222 (interpret/validity: improve clarity)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0e86cab into rust-lang:master Mar 23, 2022
@rustbot rustbot added this to the 1.61.0 milestone Mar 23, 2022
@llogiq llogiq deleted the cloned-side-effect-doc branch March 24, 2022 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet