Skip to content

Add checks that the endpoints of partial ranges are not-NaN. #33378

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
merged 3 commits into from
Aug 10, 2020

Conversation

stephentyrone
Copy link
Contributor

@stephentyrone stephentyrone commented Aug 7, 2020

We can't actually check for NaN (because the notion doesn't exist for Comparable), but we can require that the endpoint is non-exceptional by checking if it equals itself.

This will introduce a little bit of overhead for types that have non-trivial conformances to Comparable, but no worse than the check for creating a bounded range, so that should be acceptable (and it should be optimized away in concrete contexts, and it won't be noticed for the types where performance matters most).

Also updated the wording of the error message on the check for bounded ranges, to correctly reflect the actual condition being enforced when one of the endpoints is exceptional.

Addresses an issue that I noted on this SE thread: https://forums.swift.org/t/add-a-clamp-function-to-algorithm-swift/5405/45

We can't actually check for NaN (because the notion doesn't exist for Comparable), but we can require that the endpoint is non-exceptional by checking if it equals itself.
@stephentyrone stephentyrone requested a review from lorentey August 7, 2020 23:48
@stephentyrone
Copy link
Contributor Author

[This needs tests before it lands]

@stephentyrone
Copy link
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Contributor

swift-ci commented Aug 9, 2020

Build failed
Swift Test OS X Platform
Git Sha - cf39b60

@swift-ci
Copy link
Contributor

swift-ci commented Aug 9, 2020

Build failed
Swift Test Linux Platform
Git Sha - cf39b60

@stephentyrone
Copy link
Contributor Author

@swift-ci test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7b4b264

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 7b4b264

@stephentyrone stephentyrone merged commit 457b999 into swiftlang:master Aug 10, 2020
@stephentyrone stephentyrone deleted the nan-endpoints branch August 10, 2020 18:07
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.

3 participants