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

Audit iterator specializations for side effects #28810

Closed
alexcrichton opened this Issue Oct 2, 2015 · 16 comments

Comments

Projects
None yet
7 participants
@alexcrichton
Copy link
Member

alexcrichton commented Oct 2, 2015

After some discussion about #28125 the libs subteam decided that iterator adaptors should always preserve the same semantics in terms of the convenience methods and such. This was not audited for when all the initial specializations landed, so we should take a look and make sure that everything adheres to this policy.

Additionally, documentation should be added to the Iterator trait methods indicating what form of guarantees you are given (e.g. calling last is equivalent to exhausting the iterator).

triage: I-nominated

@Stebalien

This comment has been minimized.

Copy link
Contributor

Stebalien commented Oct 2, 2015

I've checked libcore/iter.rs. core::iter::Chain::last should exhaust a before b but that's the only bug I found (and it wasn't my bug for once 🎉).

Unless, of course, you care about drop order. I haven't tried to reason about that.

@Stebalien

This comment has been minimized.

Copy link
Contributor

Stebalien commented Oct 2, 2015

The slice iterators (libcore/slice.rs) are fine because they are side-effect free.

@Stebalien

This comment has been minimized.

Copy link
Contributor

Stebalien commented Oct 2, 2015

libcollections/vec and libcore/str are fine because they are also side-effect free.

bors pushed a commit that referenced this issue Oct 3, 2015

bors added a commit that referenced this issue Oct 3, 2015

@Stebalien

This comment has been minimized.

Copy link
Contributor

Stebalien commented Oct 3, 2015

I'd appreciate it if someone else double checked but I think that's all of them.

@nagisa

This comment has been minimized.

Copy link
Contributor

nagisa commented Oct 4, 2015

Unless, of course, you care about drop order.

This is relevant as well, because implementations of Drop may also (and usually do, in form of memory deallocation) contain side effects.

Can we make a

  • list
  • of iterators which were specialised
  • like this?
@Stebalien

This comment has been minimized.

Copy link
Contributor

Stebalien commented Oct 4, 2015

This is relevant as well, because implementations of Drop may also (and usually do, in form of memory deallocation) contain side effects.

I strongly disagree. Drop has side effects but programmers should never rely on drop order except stack drop order because drop order is often unspecified (e.g. within structs).


Drop out of order

  • core::iter::Chain::last
  • core::iter::Peekable::last
  • core::iter::Peekable::count (fixable)
  • core::iter::Skip::last (fixable?)

Audited

  • core::iter::Chain
  • core::iter::Enumerate
  • core::iter::Peekable
  • core::iter::Skip
  • core::iter::Take
  • core::iter::Fuse
  • core::str::Bytes
  • core::slice::Iter
  • core::slice::IterMut
  • core::slice::Windows
  • core::slice::Chunks
  • core::slice::ChunksMut
  • collections::vec::IntoIter
@nagisa

This comment has been minimized.

Copy link
Contributor

nagisa commented Oct 4, 2015

I strongly disagree. Drop has side effects but programmers should never rely on drop order except stack drop order because drop order is often unspecified (e.g. within structs).

Ah right, this will be decided by rust-lang/rfcs#744 anyway.

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Oct 4, 2015

Awesome, thanks for the work here @Stebalien!

@Stebalien

This comment has been minimized.

Copy link
Contributor

Stebalien commented Oct 4, 2015

Updated list of out-of-order drops (didn't notice Peekable::count).

@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Oct 7, 2015

triage: P-medium

@rust-highfive rust-highfive added P-medium and removed I-nominated labels Oct 7, 2015

@aturon

This comment has been minimized.

Copy link
Member

aturon commented Oct 7, 2015

(Need to make sure this behavior is documented/explicitly promised.)

@huonw

This comment has been minimized.

Copy link
Member

huonw commented Jan 6, 2016

Is this done? (Everything in the list above is 'd)

@Stebalien

This comment has been minimized.

Copy link
Contributor

Stebalien commented Jan 6, 2016

I believe this is left open as to-be-documented. Also, I don't see any decision as to whether out of order drop is ok.

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Jan 6, 2016

re-tagging as docs

@steveklabnik

This comment has been minimized.

Copy link
Member

steveklabnik commented Jan 7, 2016

So I believe that all of these are then documented in Iterator's methods, at least as far as I can tell. Can someone from libs double check me here and help provide any specifics as to what's not documented?

@steveklabnik steveklabnik added the T-libs label Jan 7, 2016

steveklabnik added a commit to steveklabnik/rust that referenced this issue Jan 7, 2016

Remove many instances of 'just'
Doing so is considered weaker writing. Thanks @Charlotteis!

Fixes rust-lang#28810

steveklabnik added a commit to steveklabnik/rust that referenced this issue Jan 9, 2016

Remove many instances of 'just'
Doing so is considered weaker writing. Thanks @Charlotteis!

Fixes rust-lang#28810

steveklabnik added a commit to steveklabnik/rust that referenced this issue Jan 9, 2016

Rollup merge of rust-lang#30766 - steveklabnik:gh28810, r=steveklabnik
Doing so is considered weaker writing. Thanks @Charlotteis!

Fixes rust-lang#28810
@alexcrichton

This comment has been minimized.

Copy link
Member Author

alexcrichton commented Jan 11, 2016

Looks good to me, thanks @steveklabnik!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.