Commit Graph

31 Commits

Author SHA1 Message Date
Doug Gregor
22eecacc35 Adopt unsafe annotations throughout the standard library 2025-02-26 14:28:01 -08:00
Kuba Mracek
7ae20b7039 [embedded] Port Swift.String to embedded Swift 2024-05-08 11:11:37 -07:00
Alejandro Alonso
f9f640b141 Sendablize the standard library
oops dont add this flag

no more nonisolated
2024-03-05 15:02:09 -08:00
Karoy Lorentey
626582ce5f [stdlib] Mark String.IndexDistance as deprecated and stop mentioning it in method signatures
`IndexDistance` is an artifact of ancient history — it used to be an associated type of Collection in the Swift 3 era. The Collection requirement got replaced with a deprecated typealias of Int in Swift 4, the same release that re-introduced the Collection conformance for String.

However, the typealias declaration for String.IndexDistance has fallen through the cracks. It was accidentally left un-deprecated and it’s still actively mentioned in String API declarations to this day. (These usages leak into the API docs, which can be a source of unnecessary confusion.)

Let’s put an end to this and add the missing deprecation attribute, replacing `IndexDistance` usages with `Int`.

While we’re here, also bring `String.index(_:offsetBy:)` and `String.index(_:offsetBy:limitedBy:)` in sync with their declarations in Collection by renaming the second argument from `n` to `distance`.

(These method declaration changes do get emitted into .swiftinterface files, but they aren’t breaking any client code — the argument names are only relevant to the docs (and the method implementation). They do not affect callers of these functions.)
2022-02-25 17:32:04 -08:00
Slava Pestov
c0adf40758 stdlib: Move Generator and _Element typealiases to Sequence and Collection protocols
The requirement machine does not allow 'where' clauses to reference
typealiases defined in protocol extensions.

These should probably be removed entirely since they're not useful
anymore, but I'd rather that decision was made by the stdlib folks.
2022-02-17 19:40:58 -05:00
Kuba (Brecka) Mracek
404badb49a Introduce SWIFT_ENABLE_REFLECTION to turn on/off the support for Mirrors and reflection (#33617) 2021-09-08 13:08:13 -07:00
Guillaume Lessard
09ea2fbda5 bring customPlaygroundQuickLook availability message in line with reality
- all other instances of the customPlaygroundQuickLook availability message
  mention "a future Swift version" rather than "Swift 5.0".
2021-05-28 15:11:11 -06:00
Hamish Knight
1bc56dcc11 [stdlib] Mark some parameters @_nonEphemeral
These include the pointer-to-pointer and pointer-to-buffer-pointer
initialiser parameters amongst a couple of others, such as
`Unmanaged.fromOpaque`, and the source for the `move[...]` family of
methods.
2019-11-03 08:42:26 -08:00
Paul Hudson
06f82a53b5 Replaced the majority of ' : ' with ': '. 2019-07-18 20:46:07 +01: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
Ted Kremenek
4beb673b8e Bump compiler version to Swift 5.1 (#24671)
* Bump version to Swift 5.1

* Update tests with compiler version bump

* Undo flatMap and math obsolescences
2019-05-13 07:32:39 -07:00
fischertony
eff8a789fc Stdlib: Fix ReversedIndex compatibility alias 2019-04-25 01:39:56 +03:00
Maxim Moiseev
d00307202b Uncomment 'obsoleted: 5.0' on a flatMap variant 2019-01-29 16:26:46 -08:00
Ben Cohen
80f0a697fc Remove a couple of obsoleted-in-4.0 methods 2019-01-25 13:33:21 -08:00
Ben Cohen
fc7830a4ed Remove Swift 3-only Compatibility Shims (#21019) 2018-12-04 18:22:27 -08:00
Ben Cohen
df2307e035 [stdlib][DNM] Collapse sequence and collection wrappers (#20221)
* Concretize dropFirst/Last/sufix/prefix from Sequence

Remove split customization point

Eliminate SubSequence from Sequence protocol

Collapse LazyCollection

Collapse LazyMapCollection

Eliminate _SequenceWrapper

Collapse LazyFilterCollection

Collapse LazyDrop/PrefixWhileCollection

Fix tests, ABI stability update

Collapse FlattenSequence

* Add entries to source/ABI compatible expected results.

* Update tests to avoid pre-10.14 objc runtime bug

* Expunge _preprocessingPass
2018-11-14 10:05:58 -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
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(&copy)
    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
Nate Cook
dfb01b6a6a [stdlib] Minor documentation revisions (#20045)
* [stdlib] Minor documentation revisions
* [docs] Convert 'nonoptional' to 'non-optional'
We're switching to 'non-optional' across the board, as the unhyphenated
form is too easy to read as 'no-noptional'.
2018-10-26 00:05:45 -05:00
Stephen Canon
c88d4e407f Remove unsafe arithmetic operations deprecated in 4.2 (#19426) 2018-09-24 11:00:28 -04: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
Ben Cohen
412a045f71 [stdlib] JAFIA (#19074)
* Lazy/generic types needing specialization

* Move DictionaryLiteral typealias to compatibility shims file

* Static String is mainly transparent so needs no inlining

* UnboundedRange hack doesn't need inlining

* Unmanaged needs unsafe performance

* Onone enum namespace

* Output stream specialize-never and calls to lock/unlock don't need inlining

* no need for @_frozen on internal enum

* DropWhile needs lazy-performance
2018-09-19 19:41:06 -07:00
Max Moiseev
e8b6091755 [stdlib] Deprecate Collection.index(of:) and index(where:) (#19071)
This should have been done for Swift 4.2 according to SE-0204, but
better later than never. Deprecating these methods as of Swift 5.0.

Also modfying the tests to check for the deprecation message.

Fixes: <rdar://problem/43694210>
2018-08-30 19:32:27 -07:00
Ben Cohen
83823f5f7f [stdlib] Obsolete various compatibility shims in 5.0 (#19008)
* Obsolete ModifierSlice typealiases in 5.0

* Obsolete *Indexable in 5.0

* Obsolete IteratorOverOne/EmptyIterator in 5.0

* Obsolete lazy typealiases in 5.0

* Drop .characters from tests

* Obsolete old literal protocols in 5.0

* Obsolete Range conversion helpers in 5.0

* Obsolete IndexDistance helpers in 5.0

* Obsolete Unsafe compat helpers in 5.0

* Obsolete flatMap compatibility helper in 5.0

* Obsolete withMutableCharacters in 5.0

* Obsolete customPlaygroundQuickLook in 5.0

* Deprecate Zip2Sequence streams in 5.0

* Replace * with swift on lotsa stuff

* Back off obsoleting playground conformances for now
2018-08-28 13:20:25 -07:00
Ben Cohen
293da8fa3e [stdlib] YAIAPR (#18956)
* Scrap Comparable conformance for _SwiftNSOperatingSystemVersion

* Lazy performance needs specialization

* Uninline dump/stdout

* Bool consistency

* fixup CollectionOld

* Uninline printing functions
2018-08-24 14:00:19 -07:00
Michael Ilseman
d3f7a1615b [stdlib] Eviscerate MigrationSupport String impl
Remove many of the implementations of obsoleted String functionality
by replacing it with unreachable. A few remain temporarily until the
Foundation overlay can be updated.

Also, update TestJSONEncoder.swift off of deprecated functionality.
2018-07-31 15:42:22 -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
Ben Cohen
57528ef458 De-gyb Stride.swift (#17956) 2018-07-16 16:02:22 -07:00
Mark Lacey
8ee52763f0 Remove the '++' and '--' operators.
We still had unavailable versions of these for floating-point types
only. We shouldn't need to keep these around, and can instead just
emit a helpful diagnostic for anyone that attempts to use them.

Unfortunately I don't see any way for the diagnostic to produce an
actual fix-it, so it just suggests '+= 1' or '-= 1' without actually
producing a fix.
2018-07-12 15:46:57 -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