close
Skip to content

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

Merged
stephentyrone merged 3 commits intoswiftlang:masterfrom
stephentyrone:nan-endpoints
Aug 10, 2020
Merged

Add checks that the endpoints of partial ranges are not-NaN.#33378
stephentyrone merged 3 commits intoswiftlang:masterfrom
stephentyrone:nan-endpoints

Conversation

@stephentyrone
Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

[This needs tests before it lands]

@stephentyrone
Copy link
Copy Markdown
Contributor Author

@swift-ci please test

@swift-ci
Copy link
Copy Markdown
Contributor

swift-ci commented Aug 9, 2020

Build failed
Swift Test OS X Platform
Git Sha - cf39b60

@swift-ci
Copy link
Copy Markdown
Contributor

swift-ci commented Aug 9, 2020

Build failed
Swift Test Linux Platform
Git Sha - cf39b60

@stephentyrone
Copy link
Copy Markdown
Contributor Author

@swift-ci test

@swift-ci
Copy link
Copy Markdown
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 7b4b264

@swift-ci
Copy link
Copy Markdown
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