Michael Ilseman
d02f5bc509
[string] Move wCSIA check higher than _HasContiguousBytes
2020-04-10 11:39:03 -07:00
Michael Ilseman
ae224cacdb
[string] Restore _HasContiguousBytes for untyped storage
...
UnsafeRawBufferPointer cannot implement
withContiguousStorageIfAvailable because doing so would potentially
create a typed pointer from untyped data.
2020-04-09 13:38:28 -07:00
Michael Ilseman
e536ad2342
[string] Outline cold path from initializer
...
Outline the cold, non-contiguous UTF-8 path from String(decoding:as:),
saving ~40 bytes (33%) of code size (x86_64 and arm64) from every call
site where the contiguity check cannot be constant folded away.
2020-04-09 13:38:28 -07:00
Michael Ilseman
c2631004d7
[string] _HasContiguousBytes -> withContiguousStorageIfAvailable
...
Switch String(decoding:as) and other entry points to call
withContiguousStorageIfAvailable rather than use _HasContiguousBytes.
2020-04-09 13:38:28 -07:00
Michael Ilseman
19b332c8e2
[gardening] Delete Trailing Whitespace
2020-04-09 13:38:27 -07:00
Ben Rimmington
b11856a93c
[SE-0263] Update documentation
...
Co-Authored-By: Nate Cook <natecook@apple.com >
2020-03-05 14:51:48 +00:00
Ben Rimmington
cf8988455f
[SE-0263] Rename internal API
2020-03-05 14:51:10 +00:00
David Smith
b9ddaa6e90
Make String(unsafeUninitializedCapacity:,initializingUTF8With:) public
2020-03-02 14:25:14 -08:00
Paul Hudson
06f82a53b5
Replaced the majority of ' : ' with ': '.
2019-07-18 20:46:07 +01:00
David Smith
b06137b283
Add a private implementation of a String initializer with access to uninitialized storage ( https://github.com/apple/swift-evolution/pull/1022 ) and use it to speed up uppercased() and lowercased()
2019-07-09 15:05:00 -07:00
Ben Cohen
e9d4687e31
De-underscore @frozen, apply it to structs ( #24185 )
...
* De-underscore @frozen for enums
* Add @frozen for structs, deprecate @_fixed_layout for them
* Switch usage from _fixed_layout to frozen
2019-05-30 17:55:37 -07:00
Ravi Kandhadai
a7b7db7854
[Constant Evaluator] Move "string.append" semantics attribute from
...
`String.+=` function to `String.append` function, and use a new
semantics attribute for String.+=.
Teach the constant evaluator about `String.Append` instead of `String.+=`.
2019-04-30 14:26:06 -07:00
Michael Ilseman
aab8063267
[SE-0247] Add contiguous string APIs
...
Adds API for querying, enforcing, and using contiguous strings.
2019-04-02 20:30:02 -07:00
Michael Ilseman
f87960746c
Merge pull request #22108 from milseman/en_gadus_offset
...
[String.Index] Obsolete encodedOffset var/init
2019-02-19 14:43:26 -08:00
Michael Ilseman
5ba5be3f43
[String] Speed up UTF-8 initialization from non-stdlib types
...
Avoid generic code paths if initializing for UTF-8 (the vast majority
of the time) from a non-stdlib type (such as Data).
2019-02-13 20:12:39 -08:00
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
swift-ci
aead660d91
Merge pull request #22147 from ravikandhadai/consteval-string-append
2019-02-12 16:11:41 -08:00
Michael Ilseman
877a20ead0
[String] Fix crash when given null UBP
2019-02-06 14:44:01 -08:00
Ravi Kandhadai
ee222c3fdf
[Constant Evaluator] Add support for string appends and equals to
...
the constant evaluator.
2019-01-25 18:51:33 -08:00
swift-ci
77ec709128
Merge pull request #21820 from freak4pc/sm/typo
2019-01-14 09:07:29 -08:00
swift-ci
b3a20520f7
Merge pull request #21711 from apple/marcrasi-const-evaluator-strings
2019-01-12 12:32:19 -08:00
Shai Mishali
6bfe3dadc5
Minor typo fix understimatedCap -> underestimatedCap
2019-01-12 15:37:01 +02:00
Lance Parker
15aaa1e777
[stdlib]String normalization functions ( #21026 )
...
* fast/foreignNormalize functions
2019-01-08 13:55:29 -08:00
Marc Rasi
0eff06e4f9
const evaluator: string values and init operations
2019-01-08 11:57: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
1939d165ae
Make corelibs-foundation build
...
Expose the old SPIs again so corelibs-foundation can build. We'll want
to wean them off of these and establish proper APIs soon.
2018-11-04 10:42:44 -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
d5da6fdbfd
[String] More comparison speedups and cleanup
2018-11-04 10:42:41 -08:00
Lance Parker
bacc7eecd5
fix the normalization unit tests
2018-11-04 10:42:41 -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
Lance Parker
7376009ccc
Add benchmarks and tests for the normalized iterator ( #32 )
...
Add benchmarks and tests for the normalized iterator
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
Ben Cohen
f56b0986a7
[stdlib] Add consuming/owned annotations to Collection implementations ( #19360 )
...
* Add consuming/owned annotations to Collection implementations
* Update SILOptimizer tests
* Fix access_marker_verify test
* XFAIL reconstruct_type_from_mangled_name
2018-11-04 10:42:41 -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
95ef4bc3a8
[String] Emit literals as UTF-8 rather than UTF-16
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
7c00552729
[String] In-place append and other RRC improvements
2018-11-04 10:42:40 -08:00
Michael Ilseman
9bf2c4d3d3
[String] Use small string at string creation
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
Brent Royal-Gordon
9bd1a26089
Implementation for SE-0228: Fix ExpressibleByStringInterpolation ( #20214 )
...
* [CodeCompletion] Restrict ancestor search to brace
This change allows ExprParentFinder to restrict certain searches for parents to just AST nodes within the nearest surrounding BraceStmt. In the string interpolation rework, BraceStmts can appear in new places in the AST; this keeps code completion from looking at irrelevant context.
NFC in this commit, but keeps code completion from crashing once TapExpr is introduced.
* Remove test relying on ExpressibleByStringInterpolation being deprecated
Since soon enough, it won’t be anymore.
* [AST] Introduce TapExpr
TapExpr allows a block of code to to be inserted between two expressions, accessing and potentially mutating the result of its subexpression before giving it to its parent expression. It’s roughly equivalent to this function:
func _tap<T>(_ value: T, do body: (inout T) throws -> Void) rethrows -> T {
var copy = value
try body(©)
return copy
}
Except that it doesn’t use a closure, so no variables are captured and no call frame is (even notionally) added.
This commit does not include tests because nothing in it actually uses TapExpr yet. It will be used by string interpolation.
* SE-0228: Fix ExpressibleByStringInterpolation
This is the bulk of the implementation of the string interpolation rework. It includes a redesigned AST node, new parsing logic, new constraints and post-typechecking code generation, and new standard library types and members.
* [Sema] Rip out typeCheckExpressionShallow()
With new string interpolation in place, it is no longer used by anything in the compiler.
* [Sema] Diagnose invalid StringInterpolationProtocols
StringInterpolationProtocol informally requires conforming types to provide at least one method with the base name “appendInterpolation” with no (or a discardable) return value and visibility at least as broad as the conforming type’s. This change diagnoses an error when a conforming type does not have a method that meets those criteria.
* [Stdlib] Fix map(String.init) source break
Some users, including some in the source compatibility suite, accidentally used init(stringInterpolationSegment:) by writing code like `map(String.init)`. Now that these intializers have been removed, the remaining initializers often end up tying during overload resolution. This change adds several overloads of `String.init(describing:)` which will break these ties in cases where the compiler previously selected `String.init(stringInterpolationSegment:)`.
* [Sema] Make callWitness() take non-mutable arrays
It doesn’t actually need to mutate them.
* [Stdlib] Improve floating-point interpolation performance
This change avoids constructing a String when interpolating a Float, Double, or Float80. Instead, we write the characters to a fixed-size buffer and then append them directly to the string’s storage.
This seems to improve performance for all three types, but especially for Double and Float80, which cannot always fit into a small string when stringified.
* [NameLookup] Improve MemberLookupTable invalidation
In rare cases usually involving generated code, an overload added by an extension in the middle of a file would not be visible below it if the type had lazy members and the same base name had already been referenced above the extension. This change essentially dirties a type’s member lookup table whenever an extension is added to it, ensuring the entries in it will be updated.
This change also includes some debugging improvements for NameLookup.
* [SILOptimizer] XFAIL dead object removal failure
The DeadObjectRemoval pass in SILOptimizer does not currently remove reworked string interpolations as well as the old design because their effects cannot be described by @_effects(readonly). That causes a test failure on Linux. This change temporarily silences that test. The SILOptimizer issue has been filed as SR-9008.
* Confess string interpolation’s source stability sins
* [Parser] Parse empty interpolations
Previously, the parser had an odd asymmetry which caused the same function to accept foo(), but reject “\()”. This change fixes the issue.
Already tested by test/Parse/try.swift, which uses this construct in one of its throwing interpolation tests.
* [Sema] Fix batch-mode-only lazy var bug
The temporary variable used by string interpolation needs to be recontextualized when it’s inserted into a synthesized getter. Fixes a compilation failure in Alamofire.
I’ll probably follow up on this bug a bit more after merging.
2018-11-02 19:16:03 -07:00
Ben Cohen
ae6f5dd604
[stdlib] Add consuming/owned annotations to Collection implementations ( #19360 )
...
* Add consuming/owned annotations to Collection implementations
* Update SILOptimizer tests
* Fix access_marker_verify test
* XFAIL reconstruct_type_from_mangled_name
2018-09-21 12:06:56 -07:00
Michael Ilseman
336ae86bc5
[string] Un-break Linux build
2018-08-02 10:17:03 -07:00
Michael Ilseman
ba6158d74e
[test] Internalize _StringGuts; Add shared testing struct; NFC
...
Create a _StringRepresentation struct to standardize internal testing
on. Internalize much of _StringGuts, except for some SPI hacks, and
update tests to use _StringRepresentation.
2018-08-01 14:23:56 -07:00
Michael Ilseman
4a66c4719f
[gardening] Move string creation internals to StringCreate.swift
...
NFC
2018-07-25 14:05:46 -07:00
Ben Cohen
df22c3647c
[stdlib] Build the standard library as Swift 5 ( #18121 )
...
* Update std lib to Swift 5.0
* Disable Unicode.* warnings for now
* Slow path to resiliently handle the case where an unknown rounding rule is passed
* Remove resilience from Encoding/DecodingError (which should only happen on slow paths anyway)
* internal typealiases now need @usableFromInline
* Force inlining on Array._owner.get
2018-07-24 20:47:58 -07:00
Tony Allevato
8eef50f6a9
Merge branch 'master' into unicode-properties
2018-07-04 08:42:35 -07:00
Ben Cohen
92b6d8cb8f
Remove inlineability from mirrors ( #17476 )
2018-06-25 19:54:13 -07:00
Michael Ilseman
fd1c861415
[string] ASCII/UTF-8 fast paths for String.init(decoding:as:)
...
Add some fast paths to String.init(decoding:as:) for inputs of
contiguously stored UTF-8 code units. Dramatically speeds up creation
when the String happens to be ASCII and we can form more small
strings.
2018-06-15 14:41:26 -07:00
Erik Little
863f3a19ff
Rename @effects to @_effects
...
@effects is too low a level, and not meant for general usage outside
the standard library. Therefore it deserves to be underscored like
other such attributes.
2018-06-06 12:53:03 -04:00