Commit Graph

368 Commits

Author SHA1 Message Date
Doug Gregor
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Guillaume Lessard
d4ae6b0ce8 [gardening] move String.withCString to String.swift
- it has been at an unexpected location for unremembered reasons.
2025-01-09 22:16:58 -08:00
Guillaume Lessard
29a4b8abff Merge pull request #75622 from glessard/rdar132941798-aEIC-private-consternation 2024-08-06 20:31:04 -07:00
Guillaume Lessard
dd854faad1 [stdlib] use temporary rebinding as appropriate 2024-08-01 16:26:34 -07:00
Guillaume Lessard
a77b8cea70 [stdlib] alter inconsistent declarations
`private` declarations should never be allowed to carry the `@_alwaysEmitIntoClient` attribute. This has been allowed by mistake for a while, but newer compilers should make this an error.
2024-08-01 16:26:34 -07:00
Ben Rimmington
66e6c009eb [stdlib] Move unused functions to LegacyABI.swift (#75462) 2024-07-27 04:45:31 +01:00
Karl
7a57bd8ae4 [stdlib] Refactor Unicode normalization (#73590)
* [stdlib] Refactor Unicode normalization

* Tweak inlining
2024-05-31 08:22:37 -06:00
Kuba Mracek
7ae20b7039 [embedded] Port Swift.String to embedded Swift 2024-05-08 11:11:37 -07:00
Mishal Shah
96d61d3c5c Merge remote-tracking branch 'origin/main' into bump-swift-version-to-6 2024-02-20 14:31:55 -08:00
Mishal Shah
af112c1591 Update the Swift version to 6.0 from 5.11 2024-02-19 17:47:16 -08:00
Alejandro Alonso
aadf4a13a2 Do a fast NFC check over the slice instead of guts 2024-02-08 10:50:03 -08:00
Guillaume Lessard
8d0991f9d0 [se-0405] improve examples in documentation 2024-01-10 14:32:26 -08:00
Guillaume Lessard
b869a3cabe [se-0405] improve readability of double-optional unwrapping 2023-12-21 10:44:52 -08:00
Guillaume Lessard
566fbf4fec [se-0405] update availability to a realistic release target 2023-12-21 10:44:52 -08:00
Guillaume Lessard
92df9b4bdb Apply suggestions from code review
Co-authored-by: Ben Rimmington <me@benrimmington.com>
2023-12-21 10:44:52 -08:00
Guillaume Lessard
f7006880c7 [se-0405] adapt implementation from staging package 2023-12-21 10:44:52 -08:00
Ben Rimmington
98ada1b200 [stdlib] Fix buffer size of small-capacity strings (#67929) 2023-08-16 10:00:42 +01:00
Nate Chandler
cda365ca8d [stdlib] Collection types are eagerMove.
Types that have "value semantics" should not have lexical lifetimes.
Value types are not expected to have custom deinits. Are not expected to
expose unsafe interior pointers. And cannot have weak references because
they are structs. Therefore, deinitialization barriers are irrelevant.

rdar://107076869
2023-03-30 11:04:47 -07:00
Karoy Lorentey
108bc0e7b2 [stdlib] Add String._isIdentical(to:)
rdar://104828814
2023-01-30 12:08:35 -08:00
Karoy Lorentey
1241df3fab [stdlib] String.debugDescription: Fix quoting behavior
`String.debugDescription` currently fails to protect the contents of
the string from combining with the opening or closing `”` characters
or one of the characters of a quoted scalar:

```swift
let s = “\u{301}A\n\u{302}B\u{70F}”
print(s.debugDescription)
// ⟹ “́A\n̂B܏”  (characters: “́, A, \, n̂, B, ܏”)
```

This can make debug output difficult to read, as string contents are
allowed to spread over and pollute neighboring meta-characters.

This change fixes this by force-quoting the problematic scalars in
these cases:

```swift
let s = “\u{301}A\n\u{302}B\u{70F}”
print(s.debugDescription)
// ⟹ “\u{301}A\n\u{302}B\u{70F}”
```

Of course, Unicode scalars that don’t engage in such behavior are
still allowed to pass through unchanged:

```swift
let s = “Cafe\u{301}”
print(s.debugDescription)
// ⟹ “Café”
```
2023-01-16 01:15:39 -08:00
David Smith
9dd8d3ad1a Actually slice things in _StringGutsSlice 2022-05-17 14:31:11 -07:00
Alejandro Alonso
c9115e1cec Create wrapper types with availability NFD and NFC
Swap the bases to unicodeScalarView
2022-04-05 09:06:32 -07:00
Alejandro Alonso
ac6c08f157 [stdlib] Make the rest of the scalar properties native (#40233)
* Factor out the scalar bit array index mechanism

* Implement native numeric scalar properties

* Implement native scalar name aliases

* Implement native scalar mappings

* Implement native scalar names

* Implement native scalar age

* Implement native scalar general category

* Address Michael's and others comments

fix special mappings

fix bug
2021-11-30 12:40:32 -08:00
Karoy Lorentey
6d255658ca Merge pull request #39994 from lorentey/adopt-availability-macros
[stdlib] Adopt availability macros
2021-11-01 14:45:33 -07:00
Karoy Lorentey
8ed81ae063 [stdlib] Adopt availability macros 2021-10-31 15:00:58 -07:00
Alex Martini
1186fc7f13 Remove "iff" from doc comments.
This abbreviation for "if and only if" is confusing to those not coming
from a background in formal mathematics, and is frequently reported as a
type by developers reading the documentation.

This commit also changes doc comments in internal and private members,
which don't become part of the public documentation, because omitting
"iff" everywhere makes it much easier to check for any later changes
that reintroduce it.
2021-10-29 10:16:27 -07:00
Alejandro Alonso
014e822cb2 Address Michael's comments
fix infinite recursion bug

NFC: Remove early ccc check

remember that false is turned on
2021-09-29 14:20:22 -07:00
Alejandro Alonso
98aaa157ec Implement native normalization for String
use >/< instead of !=

fix some bugs

fix
2021-09-29 14:20:21 -07:00
heoblitz
20ffc036ed Add whitespace to markup 2021-04-14 14:43:14 +09:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Doug Gregor
422fb5cd57 Move String conformance to ConcurrentValue out-of-line. 2021-02-04 13:14:24 -08:00
Doug Gregor
1a1f79c0de Introduce safety checkin for ConcurrentValue conformance.
Introduce checking of ConcurrentValue conformances:
- For structs, check that each stored property conforms to ConcurrentValue
- For enums, check that each associated value conforms to ConcurrentValue
- For classes, check that each stored property is immutable and conforms
  to ConcurrentValue

Because all of the stored properties / associated values need to be
visible for this check to work, limit ConcurrentValue conformances to
be in the same source file as the type definition.

This checking can be disabled by conforming to a new marker protocol,
UnsafeConcurrentValue, that refines ConcurrentValue.
UnsafeConcurrentValue otherwise his no specific meaning. This allows
both "I know what I'm doing" for types that manage concurrent access
themselves as well as enabling retroactive conformance, both of which
are fundamentally unsafe but also quite necessary.

The bulk of this change ended up being to the standard library, because
all conformances of standard library types to the ConcurrentValue
protocol needed to be sunk down into the standard library so they
would benefit from the checking above. There were numerous little
mistakes in the initial pass through the stsandard library types that
have now been corrected.
2021-02-04 03:45:09 -08:00
Karoy Lorentey
90d58fef8c [stdlib] Encourage more inlining on String’s UTF-8 decoding fast path 2020-12-04 02:06:21 -08:00
Erik Eckstein
b42bce4ba4 stdlib: changes for the StringOptimization
To be able to constant fold string interpolation, the right semantic attributes must be in place.
Also, the interpolation's write function must be inlinable.
For the _typeName constant folding, a semantic attribute is required.
2020-07-27 21:32:56 +02:00
Mishal Shah
272c466e47 Update master to build with Xcode 12 beta 2020-06-22 15:43:20 -07:00
Valeriy Van
04e6373f28 Removes redundant buffer zeroing in lowercased() and uppercased() 2020-05-27 22:24:17 +02:00
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