Skip to content

[stdlib] Expose index rounding entry points #62798

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 2 commits into from
Jan 5, 2023

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Jan 1, 2023

These simply expose the preexisting algorithms that String views use to implicitly round indices down to the nearest valid index within the view. (Or, in the case of the encoding views, rounding down to the nearest scalar boundary.)

Being able to do this as a standalone, explicit, efficient operation is crucial when implementing some String algorithms that need to work with arbitrary string indices.

This PR exposes these operations as unstable, underscored entry points. Ideally these would get upgraded to public API soon, but first I'd like to prove these have the right semantics by experimenting with using them in their underscored form.

rdar://101652714

… views

These simply expose the preexisting internal
`_StringGuts.validate*Index` functions that indexing operations
use to implicitly round indices down to the nearest valid index. (Or, in the case of the encoding views, the nearest scalar boundary.)

Being able to do this as a standalone, explicit, efficient operation
is crucial when implementing some `String` algorithms that need to
work with arbitrary indices.
@lorentey
Copy link
Member Author

lorentey commented Jan 1, 2023

@swift-ci test

@lorentey lorentey requested a review from Azoy January 3, 2023 21:48
@@ -1086,3 +1086,90 @@ suite.test("Substring.removeSubrange entire range")
expectTrue(b.isEmpty)
#endif
}

if #available(SwiftStdlib 5.8, *) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor quibble: ideally skipped tests should be visible as having been skipped in the output.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed. Sadly we don't have a good way to express that in the current language -- the only thing we could do is to add the availability check as a skip condition while also repeating it within the test body, which seems unreasonably complicated. 😞

@lorentey lorentey merged commit d358ece into swiftlang:main Jan 5, 2023
@lorentey lorentey deleted the string-index-rounding branch January 5, 2023 05:24
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.

2 participants