Commit Graph

18 Commits

Author SHA1 Message Date
David Smith
0038b92e2b Speed up -isEqual:/isEqualToString: (#83894)
Fixes rdar://159058877
2025-08-25 18:03:54 -07:00
Gábor Horváth
35b5c817b2 Merge pull request #83520 from Xazax-hun/check-safety-function-types 2025-08-08 06:39:39 +01:00
Gabor Horvath
402ad33463 [StrictMemorySafety] Check the safety of return types of calls
Previously, we skipped checking the return type of a function for safety
as we expected to warn at the use of the returned value:

  let x = returnsUnsafe()
  usesUnsafe(x) // warn here

Unfortunately, this resulted in missing some unsafe constructs that can
introduce memory safety issues when the use of the return value had a
different shape resulting in false negatives for cases like:

  return returnsUnsafe()

or

  usesUnsafe(returnsUnsafe())

This PR changes the analysis to always take return types of function
calls into account.

rdar://157237301
2025-08-05 12:16:44 +01:00
David Smith
051d0b68aa Override -_fastUTF8StringContents:utf8Length: to give bridged Strings O(1) access to their UTF8 contents (#83499)
Fixes rdar://157337605
2025-08-04 12:41:51 -07:00
David Smith
cee927e2d5 Fix lengthOfBytes(using:) semantics (#83334)
Fixes rdar://156675395
2025-07-25 16:29:45 -07:00
David Smith
1a56da655f Native implementation of -lengthOfBytesUsingEncoding, plus handling ASCII-subset MacRoman in a few places (#81791)
Fixes rdar://154341146
2025-06-27 13:48:10 -07:00
Doug Gregor
050a514588 [Strict memory safety] Update standard library for unsafe treated as a call effect 2025-04-25 21:54:23 -07:00
Allan Shortlidge
60e66f3613 stdlib: Address StrictMemorySafety warnings in String related code. 2025-03-31 16:45:08 -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
73f349cb15 [stdlib] Rework String breadcrumbs initialization/loading
This is a wild guess at what might be causing our persistent, random
String failures on the main branch:

```
  Swift(macosx-x86_64) :: Prototypes/CollectionTransformers.swift
  Swift(macosx-x86_64) :: stdlib/NSSlowString.swift
  Swift(macosx-x86_64) :: stdlib/NSStringAPI.swift
  Swift(macosx-x86_64) :: stdlib/StringIndex.swift
  Swift-validation(macosx-x86_64) :: stdlib/String.swift
  Swift-validation(macosx-x86_64) :: stdlib/StringBreadcrumbs.swift
  Swift-validation(macosx-x86_64) :: stdlib/StringUTF8.swift
```

FWIW, it appears this is *not* caused by https://github.com/apple/swift/pull/62717:
that change has also landed on release/5.8, and I haven’t seen these
issues on that branch.

Our atomic breadcrumbs initialization vs its non-atomic loading
gives me an uneasy feeling that this may in fact be a long standing
synchronization issue that is only now causing problems (for whatever
reason). I am unable to reproduce these issues locally, so this guess
may be (and probably is) wildly off the mark, but this PR is likely
to be a good idea anyway, if only to rule out this possibility.

rdar://104751936
2023-02-10 20:23:56 -08:00
David Smith
3292f4e97e Separate out ASCII and UTF8 in NSString accessors, and use the ASCII one where we really need ASCII (#61086)
Separate out ASCII and UTF8 in NSString accessors, and use the ASCII one where we really need ASCII
2022-09-23 12:31:45 -07:00
Karoy Lorentey
8ed81ae063 [stdlib] Adopt availability macros 2021-10-31 15:00:58 -07:00
David Smith
30a3b6d3f5 Expose __SwiftNativeNSString for Foundation's use, as well as an initializer to create Strings from them 2021-09-10 01:26:11 -07: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
David Smith
5ad4b15af6 Avoid attempting to create SmallStrings for constant tagged CFStrings 2020-04-15 12:30:20 -07:00
Michael Ilseman
7ff3ecf2e5 [string] Skip unnecessary self UTF-16 length in isEqual
For isEqual bridging comparisons, skip checking our own UTF-16 length when the
string we're comparing against is known to be ASCII.
2020-03-05 16:13:15 -08:00
Michael Ilseman
8463e53df3 [stdlib] [gardening] Refactor bridging from StringStorage.swift
Add StringStorageBridge.swift to separate out ObjC interop
functionality.

NFC
2019-11-01 17:25:08 -07:00