Skip to content

stdlib: Remove Collection.randomElement customization point. #17637

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

Merged

Conversation

jckarter
Copy link
Contributor

As proposed and accepted in amendment swiftlang/swift-evolution#863. rdar://problem/41067949

@jckarter jckarter requested a review from airspeedswift June 29, 2018 20:09
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@jckarter
Copy link
Contributor Author

@swift-ci Please test source compatibility

@Azoy
Copy link
Contributor

Azoy commented Jun 29, 2018

I don't believe this would pass the tests. You're going to need to move the implementation from Range.randomElement() into FixedWidthInteger.random(in:using:) because it used range.randomElement() as an implementation.

@jckarter
Copy link
Contributor Author

OK, thanks!

@jckarter jckarter force-pushed the remove-randomelement-customization-point branch from 75727ac to 21db37d Compare June 29, 2018 20:49
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 75727acb3543aa097e77acecfe185e8791a141a7

As proposed and accepted in amendment swiftlang/swift-evolution#863. rdar://problem/41067949
@jckarter jckarter force-pushed the remove-randomelement-customization-point branch from 21db37d to 04b5174 Compare June 29, 2018 20:49
@jckarter
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 21db37d381095256e77721820a66904c2d36592d

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 21db37d381095256e77721820a66904c2d36592d

Copy link
Member

@airspeedswift airspeedswift left a comment

Choose a reason for hiding this comment

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

LGTM

@jckarter jckarter merged commit b1c79fc into swiftlang:master Jun 30, 2018
return Self(truncatingIfNeeded: generator.next() as Magnitude)
}
// Need to widen delta to account for the right-endpoint of a closed range.
delta += 1
Copy link
Contributor

Choose a reason for hiding this comment

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

@stephentyrone It looks like the optimizer does figure out that it is not necessary to check for the overflow, because you did it manually in the if block above… but still, wouldn't it make sense to go with delta &+= 1 here?

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