Guillaume Lessard
9341973700
[stdlib] update doc-comments
2025-07-08 14:29:21 -07:00
Guillaume Lessard
77f34f4f29
[stdlib] update doc-comment and add a code comment
2025-07-08 13:20:11 -07:00
Guillaume Lessard
62115791c0
[stdlib] make makeContiguousUTF8 stricter
2025-07-08 13:20:11 -07:00
Guillaume Lessard
dfb2e2f12e
[stdlib] annotate uses of Range.init(_uncheckedBounds:)
2025-03-05 18:52:11 -08:00
Doug Gregor
22eecacc35
Adopt unsafe annotations throughout the standard library
2025-02-26 14:28:01 -08:00
Karoy Lorentey
3616a05d97
[stdlib] Substring.makeContiguousUTF8: Do not lose context in base
2022-03-29 20:10:40 -07:00
ensan
b24892becf
rename hasPrefix(_ prefix: String) -> Bool to hasSuffix(_ suffix: String) -> Bool ( #37336 )
2021-05-08 12:31:14 -04:00
Karoy Lorentey
d1ef4c4386
[stdlib] Use [Closed]Range.init(_uncheckedBounds:) in more places
...
When the stdlib says not to check, it’s a good idea to actually not have any checking, so that we leave existing code paths unchanged. (And because we do trust that the stdlib is responsible about such things.)
2020-12-04 19:27:19 -08:00
Paul Hudson
06f82a53b5
Replaced the majority of ' : ' with ': '.
2019-07-18 20:46:07 +01: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
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
Michael Ilseman
e44972dcea
[String] Expunge _StringGutsSlice from ABI
...
_StringGutsSlice is an implementation helper that's no longer needed
from inlinable code. Internalize it.
2018-11-27 15:07: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
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
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
Ben Cohen
fa4c8a6f7b
Give StringProtocol.SubSequence a default of Substring to supress warning
2018-11-04 10:42:41 -08:00
Michael Ilseman
de893b66a2
[String] Fix overlays to request index interchange for native strings
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
7cee5d18ba
Give StringProtocol.SubSequence a default of Substring to supress warning
2018-09-19 20:44:17 -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
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
4e573f47f8
[stdlib] Split StringProtocol out from String.swift; NFC
2018-03-13 15:34:35 -07:00