Commit Graph

172 Commits

Author SHA1 Message Date
Michael Ilseman
415cc8fb0c [String.Index] Deprecate encodedOffset var/init
String.Index has an encodedOffset-based initializer and computed
property that exists for serialization purposes. It was documented as
UTF-16 in the SE proposal introducing it, which was String's
underlying encoding at the time, but the dream of String even then was
to abstract away whatever encoding happend to be used.

Serialization needs an explicit encoding for serialized indices to
make sense: the offsets need to align with the view. With String
utilizing UTF-8 encoding for native contents in Swift 5, serialization
isn't necessarily the most efficient in UTF-16.

Furthermore, the majority of usage of encodedOffset in the wild is
buggy and operates under the assumption that a UTF-16 code unit was a
Swift Character, which isn't even valid if the String is known to be
all-ASCII (because CR-LF).

This change introduces a pair of semantics-preserving alternatives to
encodedOffset that explicitly call out the UTF-16 assumption. These
serve as a gentle off-ramp for current mis-uses of encodedOffset.
2019-02-13 18:42:40 -08:00
Lance Parker
15aaa1e777 [stdlib]String normalization functions (#21026)
* fast/foreignNormalize functions
2019-01-08 13:55:29 -08:00
Michael Ilseman
b01ee7267a [String] Custom iterator for UTF16View (#20929)
Defining a custom iterator for the UTF16View avoid some redundant
computation over the indexing model. This speeds up iteration by
around 40% on non-ASCII strings.
2018-12-01 09:35:27 -08:00
Ben Cohen
1673c12d78 [stdlib] Replace "sanityCheck" with "internalInvariant" (#20616)
* Replace "sanityCheck" with "internalInvariant"
2018-11-15 20:50:22 -08:00
Michael Ilseman
abe101c5b9 [String] Custom iterator for UnicodeScalarView
Provide a custom iterator rather than relying a the IndexingIterator,
as an indexing model is less efficient for stateful processing of
strings. Provides around a 30% speedup.
2018-11-08 18:00:39 -08:00
Michael Ilseman
948655e850 [String] Cleanups, comments, documentation
After rebasing on master and incorporating more 32-bit support,
perform a bunch of cleanup, documentation updates, comments, move code
back to String declaration, etc.
2018-11-04 10:42:42 -08:00
Michael Ilseman
7aea40680d [String] NFC iterator fast-paths
Refactor and rename _StringGutsSlice, apply NFC-aware fast paths to a
new buffered iterator.

Also, fix bug in _typeName which used to assume ASCIIness and better
SIL optimizations on StringObject.
2018-11-04 10:42:41 -08:00
Michael Ilseman
8851bac1be [String] Inlining, NFC fast paths, and more.
Add inlinability annotations to restore performance parity with 4.2 String.

Take advantage of known NFC as a fast-path for comparison, and
overhaul comparison dispatch.

RRC improvements and optmizations.
2018-11-04 10:42:41 -08:00
Michael Ilseman
9d9f9005e3 [String] Define performance flags and plumb them throughout 2018-11-04 10:42:41 -08:00
Michael Ilseman
c51aa5988f [String] Cleanup normalization code.
Clean up some of the code surrounding the normalized code unit
iterator.
2018-11-04 10:42:41 -08:00
Lance Parker
f1a35bd1c9 String comparison iterator for UTF8 strings 2018-11-04 10:42:41 -08:00
Michael Ilseman
a0e639eaf5 [String] Grapheme breaking fast-paths
Add in our scalar-based fast-paths for UTF-8 and foreign strings, and
update the grapheme cache.
2018-11-04 10:42:40 -08:00
Michael Ilseman
fe7c3ce2e4 [String] Refactorings and cleanup
* Refactor out RRC implementation into dedicated file.

* Change our `_invariantCheck` pattern to generate efficient code in
  asserts builds and make the optimizer job's easier.

* Drop a few Bidi shims we no longer need.

* Restore View decls to String, workaround no longer needed

* Cleaner unicode helper facilities
2018-11-04 10:42:40 -08:00
Michael Ilseman
f23a3c19b8 [String] Bounds checking and Index cleanup 2018-11-04 10:42:40 -08:00
Michael Ilseman
89d18e1a3a [String] Refactor helper code into UnicodeHelpers.swift.
Clean up some of the index assumptions, stick index-aware methods on
_StringGuts, and otherwise migrate code over to UnicodeHelpers.swift.
2018-11-04 10:42:40 -08:00
Michael Ilseman
4ab45dfe20 [String] Drop in initial UTF-8 String prototype
This is a giant squashing of a lot of individual changes prototyping a
switch of String in Swift 5 to be natively encoded as UTF-8. It
includes what's necessary for a functional prototype, dropping some
history, but still leaves plenty of history available for future
commits.

My apologies to anyone trying to do code archeology between this
commit and the one prior. This was the lesser of evils.
2018-11-04 10:42:40 -08:00
Michael Ilseman
8294c0003a [string] Drop _StringGuts subscript; NFC
_StringGuts shouldn't expose a subscript, implying efficient
access. Switch to the explicit code unit fetch method. Update tests
accordingly, and switch off of deprecated typealiases.
2018-08-02 16:34:22 -07:00
Ben Cohen
a4230ab2ad [stdlib] Update stdlib to 4.0 and reorganize compatibility shims (#17580)
* Update stdlib to 4.0 and move all compatibility shims into a dedicated source file
2018-06-29 06:26:52 -07:00
Ben Cohen
92b6d8cb8f Remove inlineability from mirrors (#17476) 2018-06-25 19:54:13 -07:00
Michael Ilseman
3ee17102ed [String.Index] Restore compound offsets.
Move the shifts to index creation time rather than index comparison
time. This seems to benefit micro benchmarks and cover up
inefficiencies in our generic index distance calculations.
2018-05-25 09:54:35 -07:00
Michael Ilseman
4a368ab46c [string] Drop many @inlinable from big API.
Drop append-related @inlinable annotations for String, StringGuts,
StringStorage, and the Views. Drop several for larger operations, such
as case conversion. Drop as many as we can from StringGuts for now.
2018-05-13 07:38:55 -07:00
Nate Cook
58933d88c5 [stdlib] Rename index(...) methods to firstIndex(...)
A la SE-204.
2018-04-21 18:07:25 -05:00
Slava Pestov
2e5aef9c8d stdlib: Remove redundant @usableFromInline attributes 2018-04-06 00:02:30 -07:00
Slava Pestov
e1f50b2d36 SE-0193: Rename @_inlineable to @inlinable, @_versioned to @usableFromInline 2018-03-30 21:55:30 -07:00
Michael Ilseman
93d6130066 [string] Integrate small strings.
Switch StringObject and StringGuts from opaquely storing tagged cocoa
strings into storing small strings. Plumb small string support
throughout the standard library's routines.
2018-03-27 14:00:59 -07:00
Michael Ilseman
1229af8e0f [string] Adopt _StringGuts visitor pattern.
Use the visitor pattern in most of the opaque-by-hand call
sites. Inspecting the compiler output does not show excessive and
unanticipated ARC, but there may need to be further tweaks.

One downside of the visitor pattern as written is that there's extra
shuffling around of registers for the closure CC. Hopefully this will
also be fixed soon.
2018-03-13 15:32:19 -07:00
Michael Ilseman
12fe85fad1 [string] Establish opaque branching pattern.
Stop inlining _asOpaque into user code. Inlining it bloats user code
as there's a bit-test-and-branch to a block containing the _asOpaque
call, followed up some operations to e.g. manipulate the range or
re-align the calling convention, etc., followed by a final branch to
opaque stdlib code.

Instead, branch directly into opaque stdlib code. In theory, this
means that supporting all opaque patterns can be done with minimal
bloat. On ARM, this is a single tbnz instruction.
2018-03-13 15:32:19 -07:00
Michael Ilseman
444796a66b [gardening] Strip trailing whitespace; NFC 2018-03-13 15:32:19 -07:00
Connor Wakamo
a2aacd73dd [stdlib] Deprecated PlaygroundQuickLook and CustomPlaygroundQuickLookable.
Deprecated the `PlaygroundQuickLook` enum and `CustomPlaygroundQuickLookable`
protocol. These are being targeted for removal in Swift 5, so we want to
unconditionally deprecate them now to encourage use of
`CustomPlaygroundDisplayConvertible` instead.

This commit includes deprecated the various `CustomPlaygroundQuickLookable`
conformances across the standard library and overlay libraries.
2018-02-21 13:38:31 -08:00
Michael Ilseman
3be2faf5d3 [String] Initial implementation of 64-bit StringGuts.
Include the initial implementation of _StringGuts, a 2-word
replacement for _LegacyStringCore. 64-bit Darwin supported, 32-bit and
Linux support in subsequent commits.
2018-01-21 12:32:26 -08:00
Michael Ilseman
75463e30f3 [stdlib] Rename _StringCore to _LegacyStringCore. NFC.
In grand LLVM tradition, the first step to redesigning _StringCore is
to first rename it to _LegacyStringCore. Subsequent commits will
introduce the replacement, and eventually all uses of the old one will
be moved to the new one.

NFC.
2018-01-21 12:28:56 -08:00
Ben Cohen
9361a6b66f [stdlib] Nest Iterator and Index types for various stdlib types (#13489)
* Nest various top-level Iterator and Index types, and flatten extensions.

* Fix tests from nesting iterator

* Nest Unsafe*BufferPointer.Iterator, extensionify UnsafeBufferPointer

* Degyb LazyCollection

* Nest Flatten iterator and index
2017-12-18 15:27:35 -08:00
Ben Cohen
4ddac3fbbd [stdlib] Eradicate IndexDistance associated type (#12641)
* Eradicate IndexDistance associated type, replacing with Int everywhere

* Consistently use Int for ExistentialCollection’s IndexDistance type.

* Fix test for IndexDistance removal

* Remove a handful of no-longer-needed explicit types

* Add compatibility shims for non-Int index distances

* Test compatibility shim

* Move IndexDistance typealias into the Collection protocol
2017-12-08 12:00:23 -08:00
Max Moiseev
a24998a5b1 [stdlib] Add missing @_fixed_layout attributes to fix resilience build 2017-10-02 15:19:06 -07:00
Max Moiseev
53b8419279 [stdlib] Make all the stdlib APIs @_inlineable
This change in theory should allow us to remove a special stdlib-only
sil-serialize-all compilation mode.

<rdar://problem/34138683>
2017-09-29 11:26:56 -07:00
Michael Ilseman
2415a4df52 [stdlib] Drop Unicode 8 tries in stdlib (entirely)
This drops the last vestage of Unicode 8 tries from the standard
library. Switches everything over to use ICU.
2017-08-09 19:17:56 -07:00
Nate Cook
a51e32ad37 [stdlib] String API revisions
- Clarify StringProtocol conformance
- Deprecate ExpressibleByStringInterpolation
- String index conversions docs
- Describe shared string indices
2017-07-31 10:56:54 -05:00
Dave Abrahams
41c53ae729 [stdlib] Give Substring its own views
This necessary for ensuring the property that String doesn't keep
inaccessible memory alive.  For example, before this change,

    String(s.dropFirst().unicodeScalars)

would compile and produce a String that owned inaccessible memory.
Now it no longer compiles.

String's view's SubSequences are the same as the Substring's
view. E.g. String.UnicodeScalarView.SubSequence is
Substring.UnicodeScalarView.

New compatibility inits added, to work around the fact that many
previously failable initializers are now non-failable.
2017-07-26 15:59:51 -07:00
Dave Abrahams
38828872b9 [stdlib] Add missing unwraps for backward compatibility
Otherwise, the result would have been an infinite recursion.
2017-07-14 15:30:06 -07:00
Dave Abrahams
4f71d9e35c [stdlib] Spot fix for https://bugs.swift.org/browse/SR-5401
The simplest way to keep the string buffer alive is simply to always grab its
iterator, even if we're not going to use it.  Thanks @milseman for that idea and
@jckarter for the diagnosis help!
2017-07-11 14:58:29 -07:00
Dave Abrahams
9159239995 Un-revert "[stdlib] String index interchange, etc." (#10812)
I failed to merge the upstream changes to swift-corelibs-foundation at the same
time as I merged that #9806, and it broke on linux. Going to get it right this
time.
2017-07-07 12:13:25 -07:00
Xi Ge
d9fb110674 Revert "[stdlib] String index interchange, etc." (#10812)
rdar://33186295
2017-07-07 12:03:16 -07:00
Dave Abrahams
b1d2f4c68e [stdlib] String index interchange, part III (UTF8) 2017-07-07 06:15:24 -07:00
Dave Abrahams
2e0bb2f533 [stdlib] String index interchange, part II (UTF16) 2017-07-07 06:15:23 -07:00
Dave Abrahams
e523c80339 [stdlib] Index interchange, part I 2017-07-07 00:59:04 -07:00
Dave Abrahams
d6fee05375 [stdlib] Enable interchange among StringProtocol models 2017-05-17 17:21:43 -07:00
Ben Cohen
ea2f64cad2 [stdlib] Add Sequence.Element, change ExpressibleByArrayLiteral.Element to ArrayLiteralElement (#8990)
* Give Sequence a top-level Element, constrain Iterator to match

* Remove many instances of Iterator.

* Fixed various hard-coded tests

* XFAIL a few tests that need further investigation

* Change assoc type for arrayLiteralConvertible

* Mop up remaining "better expressed as a where clause" warnings

* Fix UnicodeDecoders prototype test

* Fix UIntBuffer

* Fix hard-coded Element identifier in CSDiag

* Fix up more tests

* Account for flatMap changes
2017-05-14 06:33:25 -07:00
Nate Cook
f650e0a7da [stdlib] String and range expressions
* finish string documentation revisions
* revise examples throughout to use range expressions instead of e.g.
  prefix(upTo: _)
2017-05-13 10:06:12 -05:00
Dave Abrahams
ddf7ad517f UnicodeScalar => Unicode.Scalar 2017-05-11 15:23:25 -07:00
practicalswift
6d1ae2a39c [gardening] 2016 → 2017 2017-01-06 16:41:22 +01:00