Commit Graph

6693 Commits

Author SHA1 Message Date
Alejandro Alonso
e9c0b32497 Remove class support 2023-04-04 09:54:09 -07:00
Alejandro Alonso
3522a338a2 Create function to create an offset based keypath at runtime 2023-04-04 09:44:18 -07:00
nate-chandler
5e0267b9b7 Merge pull request #64553 from nate-chandler/eagermove_collections
[stdlib] Collection types are eagerMove.
2023-03-30 16:16:26 -07: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
Alejandro Alonso
aa3fd951d2 Merge pull request #64731 from Azoy/update-unicode-15
[stdlib] Update the stdlib to use Unicode 15 data
2023-03-29 22:49:38 -07:00
Alejandro Alonso
cc62bb1ddc Update copyright years 2023-03-29 10:35:30 -07:00
Alejandro Alonso
f16f0c3c23 Update the stdlib to use Unicode 15 data 2023-03-29 10:18:16 -07:00
Erik Eckstein
661264034b stdlib: fix the #if guard for Builtin.unprotectedStackAlloc
rdar://107274878
2023-03-28 20:16:40 +02:00
Doug Gregor
e13b104357 Add #warning and #error macro declarations to the standard library 2023-03-09 22:29:49 -08:00
Jonathan Grynspan
59d6f5c99c Make Zip2Sequence sendable (#64150) 2023-03-07 12:06:21 -05:00
Doug Gregor
2ac6aba256 Use proper feature check style for this 2023-03-06 12:29:20 -08:00
Doug Gregor
56249ccd47 Enable "Macros" feature in stdlib/Observation for older compilers 2023-03-06 08:50:30 -08:00
Doug Gregor
3321100c23 [Macros] Add #ifs around macro declarations in standard library
Older toolchain compilers don't have macros enabled by default, so we
need to keep these around longer.
2023-03-06 08:15:30 -08:00
Holly Borla
9b722b9bd2 Merge pull request #64097 from hborla/macro-expansion-validation
[Macros] Diagnose macro expansions containing invalid declarations.
2023-03-05 13:22:38 -08:00
swift-ci
b15957631a Merge pull request #64059 from kavon/staging-bootstrap-with-copyable
Turn on the `Copyable` as an inferred generic constraint by default
2023-03-04 22:46:40 -08:00
Holly Borla
2f81706e37 [Macros] Add introduced names to the OptionSet macro. 2023-03-04 18:47:47 -08:00
Kavon Farvardin
091d63a5c8 revise how the Copyable constraint is added
The _Copyable constraint was implemented as a marker protocol.
That protocol is part of the KnownProtocol's in the compiler.
When `ASTContext::getProtocol(KnownProtocolKind kind)` tries
to find the ProtocolDecl for Copyable, it will look in the
stdlib module (i.e., Swift module), which is where I initially
planned to put it.

That created problems initially when some regression tests
use `-parse-stdlib` failed to do that protocol lookup, which is
essential for adding the constraint (given the current implementation).

That led to believe we need to pull Copyable out of the stdlib, but that's
wrong. In fact, when building the Swift module itself, we do `-parse-stdlib`
but we also include `-module-name Swift`. This causes the _Copyable protocol
defined in the Stdlib to be correctly discovered while building the stdlib
itself (see the test case in this commit). So, the only downside of
having the Copyable protocol in the Stdlib is that `-parse-stdlib` tests
in the compiler can't use move-only types correctly, as they'll be
allowed in generic contexts. No real program would build like this.

Until I have time to do a further refactoring, this is an acceptable trade-off.

fixes rdar://104898230
2023-03-04 11:42:09 -08:00
Doug Gregor
0e9c3eff8a [Macros] Add OptionSet and plumb it through 2023-03-03 21:39:16 -08:00
Konrad `ktoso` Malawski
93decb6141 [Concurrency] Complement assume... APIs with the assert and precondition ones (#64062) 2023-03-04 08:03:29 +09:00
Doug Gregor
6d6988b649 Indentation fix 2023-03-02 20:34:58 -08:00
Doug Gregor
fa0bbcf59a [SE-0382] Stage in prototypes of macros defined in the standard library.
This are inactive at the moment; we'll conditionally take advantage of them
later on. Part of rdar://104346457.
2023-03-02 20:34:58 -08:00
Doug Gregor
f88d2c638f Clean up feature flags for macros.
Enable expression macros by default, and add separate feature flags for
attached and freestanding macros.
2023-03-02 14:34:59 -08:00
Alex Martini
61629eace9 Merge pull request #62352 from amartini51/string_count_91570469
Call out time complexity of `String.count`
2023-02-27 13:47:46 -08:00
Ben Rimmington
c94210c3b9 [stdlib] Update Codable.swift (NFC) (#63184)
* [stdlib] Update Codable.swift (NFC)

* fixup! [stdlib] Update Codable.swift (NFC)

* fixup! [stdlib] Update Codable.swift (NFC)

* fixup! [stdlib] Update Codable.swift (NFC)
2023-02-27 11:02:14 -08:00
Andrew Trick
ef8e4b4ffc Remove a confusing comment in Unmanaged.retain().
Users should not do this:

    class C {
        func getRetained() {
            let unmanaged = Unmanaged.passUnretained(self)
            //... maybe some condition
            unmanaged.retain()
        }
    }

But that should be obvious, and apparently this comment doesn't help.
2023-02-20 15:44:58 -08:00
Andrew Trick
928900cf1b Fix Unmanaged.passRetained
Unmanaged.passRetained was originally implemented as:
- store the passed referenced into an unowned(unsafe) reference
- (the reference will now be released if the store is the last use)
- reload the unowned(unsafe) reference
- retain the reloaded reference

It should be implemented as:
- retain the passed reference
- store the passed reference to an unowned(unsafe) reference

Fixes rdar://105609600
(🔥 non-deterministic miscompile in stdlib's
 _StringGuts.populateBreadcrumbs)
2023-02-18 08:37:47 -08:00
Karoy Lorentey
4cca9a6b76 Merge pull request #63646 from lorentey/fix-string-bitcast
[stdlib] Fix potentially undefined behavior in StringObject.nativeStorage and document Builtin.unsafeBitCast
2023-02-15 21:56:47 -08:00
Karoy Lorentey
3f5dfea4b1 [stdlib] String: Avoid retain/release operations around use sites of sharedStorage and cocoaObject 2023-02-15 14:21:46 -08:00
Erik Eckstein
abf9900be7 stdlib: loadUnaligned doesn't need stack protection for it's temporary
rdar://105231457
2023-02-15 08:20:48 +01:00
Erik Eckstein
b2512ab5cb stdlib: add an underscored _withUnprotectedUnsafeTemporaryAllocation
This function is similar to `withUnsafeTemporaryAllocation`, except that it doesn't trigger stack protection for the stack allocated memory.
2023-02-15 08:20:48 +01:00
Karoy Lorentey
7a11700d7b [stdlib] Avoid retaining storage in _StringGuts.updateNativeStorage 2023-02-14 18:51:15 -08:00
Karoy Lorentey
2086313f70 [stdlib] Work around the optimizer helpfully reintroducing retain/releases
This is just wild flailing at this point, but it does seem to get
us more plausible assembly.
2023-02-14 15:33:53 -08:00
Karoy Lorentey
cf1b9d9404 [stdlib] String: Fix more potential UB, and rework access patterns 2023-02-13 22:55:32 -08:00
Andrew Trick
86467bbe63 Fix potentially undefined behavior in StringObject.nativeStorage
Speculatively fixing this to rule out potential miscompiles.

The compiler needs to know if a reference is being materialized out of
thin air. The proper way to do that is with the Unmanaged API.

Under the hood, this forces the reference into an "unowned(unsafe)"
variable which the reference must be reloaded from. That tells the
compiler that it can't optimize some seemingly unrelated object which
the reference may happen to refer to at runtime.

/// Warning: Casting from an integer or a pointer type to a reference type
/// is undefined behavior. It may result in incorrect code in any future
/// compiler release. To convert a bit pattern to a reference type:
/// 1. convert the bit pattern to an UnsafeRawPointer.
/// 2. create an unmanaged reference using Unmanaged.fromOpaque()
/// 3. obtain a managed reference using Unmanaged.takeUnretainedValue()
/// The programmer must ensure that the resulting reference has already been
/// manually retained.
2023-02-13 22:14:54 -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
Erik Eckstein
fc6f1d862e stdlib: make type comparison functions transparent
This is needed to be able to optimize them at Onone
2023-02-09 06:49:58 +01:00
Bradley Mackey
78535a23c0 Revert "Format to 80w"
This reverts commit abf877ada2.
2023-02-06 19:50:48 +00:00
Bradley Mackey
abf877ada2 Format to 80w 2023-02-04 11:27:09 +00:00
Bradley Mackey
6f97ee2379 Fix signature of fatalError 2023-02-04 11:18:27 +00:00
Jonathan Grynspan
75dfb56b67 Clarify documentation for CommandLine.unsafeArgv re: the trailing nil. (#58484) (#63413) 2023-02-03 16:28:45 -05:00
swift-ci
d77fa0b016 Merge pull request #63307 from lorentey/identical-string-check
[stdlib] Add String._isIdentical(to:)
2023-02-02 21:04:20 -08:00
Arnold Schwaighofer
a96e5d06c6 Merge pull request #63350 from aschwaighofer/relative_protocol_witness_tables_test_config
Relative protocol witness tables test configuration
2023-02-02 06:48:20 -08:00
Kavon Farvardin
ab130883a3 Initial ban of move-only types from being used generically
Since values of generic type are currently assumed to always
support copying, we need to prevent move-only types from
being substituted for generic type parameters.

This approach leans on a `_Copyable` marker protocol to which
all generic type parameters implicitly must conform.

A few other changes in this initial implementation:

- Now every concrete type that can conform to Copyable will do so. This fixes issues with conforming to a protocol that requires Copyable.
- Narrowly ban writing a concrete type `[T]` when `T` is move-only.
2023-02-01 23:38:28 -08:00
Mike Ash
08e12243a2 Merge pull request #63302 from mikeash/keypath-big-32-bit-pointers
[Runtime] Fix key paths on 32-bit with KVC string pointers in the top half of memory.
2023-02-01 10:22:44 -05:00
Arnold Schwaighofer
90cb8056bd Fix _StringObject._dump() under SWIFT_STDLIB_STATIC_PRINT
It does not compile in this mode.

```
error: no exact matches in call to instance method 'appendInterpolation'
        owner: \(repr._objectIdentifier!), \
```
2023-02-01 07:12:49 -08:00
Karoy Lorentey
108bc0e7b2 [stdlib] Add String._isIdentical(to:)
rdar://104828814
2023-01-30 12:08:35 -08:00
Mike Ash
1f8acac3d4 [Runtime] Fix key paths on 32-bit with KVC string pointers in the top half of memory.
Key paths can store an offset or a pointer in the same field. On 32-bit, the field is considered to be an offset when it's less than the 4kB zero page, and a pointer otherwise.

The check uses a signed comparison, so pointers in the top half of memory would look like negative offsets. Add a check that the offset is zero or positive to avoid this.

rdar://103886537
2023-01-30 13:05:48 -05:00
Kyle Murray
1f0b2e59fa Remove a stale fixme comment.
Per Ben's feedback in the PR.
2023-01-30 10:42:42 -05:00
Kyle Murray
15ebec6e23 [stdlib] NFS: Restore documentation comment for Unsafe[Mutable]BufferPointer
Moves a `//` comment up above a `///` documentation comment, since the latter needs to be attached directly to the declaration or it won't be picked up as documentation.
2023-01-28 12:57:41 -05:00
Alex Martini
2f73addf6c Tighten phrasing.
Co-authored-by: Bradley Mackey <bradley@mcky.dev>
2023-01-27 13:43:41 -08:00