Commit Graph

7762 Commits

Author SHA1 Message Date
Guillaume Lessard
4c1d46bc09 [gardening] add public SR bug number to rdar link 2021-11-11 09:56:14 -07:00
Guillaume Lessard
5ef8c544e9 [docs] clarify todo about deinitializing a single element 2021-11-11 09:41:41 -07:00
Erik Eckstein
802a2e0a8b cmake: fix a libswift bootstrapping problem with -enable-array-cow-checks
The checks must not be enabled in the first 2 bootstrapping stages.
2021-11-09 11:51:45 +01:00
Guillaume Lessard
bbd6759cbd Merge pull request #40056 from HassanElDesouky/stdlib-internalPrecondition
[stdlib] Replace `precondition` with the internal `_precondition`
2021-11-08 17:25:08 -07:00
Guillaume Lessard
4f7f9f5e61 Merge pull request #40042 from HassanElDesouky/stdlib-internalInvariant
[stdlib] Replace `assert` with the internal `_internalInvariant`
2021-11-08 10:47:36 -07:00
Guillaume Lessard
e87a3e30ca [stdlib] replace precondition with guard-else-_assertionFailure 2021-11-06 20:12:04 +02:00
Robert Widmann
ad0a5bf12b Merge pull request #39979 from amartini51/managed_buffer_59618453 2021-11-06 08:52:18 -07:00
swift-ci
d954e46524 Merge pull request #40027 from glessard/wCSIA-clarification 2021-11-05 20:26:43 -07:00
eeckstein
ee95f3f7ed Merge pull request #40068 from eeckstein/fix-libswift-bootstrapping
libswift: fixes and improvements for the bootstrapping build
2021-11-05 22:49:47 +01:00
Karoy Lorentey
6d33683c15 Merge pull request #40012 from lorentey/set-on-fire2
[stdlib] Optimize high-level Set operations
2021-11-05 13:48:40 -07:00
Erik Eckstein
e30688da82 libswift: fix dependencies in the bootstrapping build mode
swiftDarwin and swiftOnoneSupport  didn't depend on building the Swift core library.
This was a subtle bug, because the compiler just picked up the module from the SDK instead of the (still building) Swift module.
It only resulted in compiler errors if the SDK swiftinterface was too new to be parsable by the compiler.
2021-11-05 18:33:21 +01:00
Erik Eckstein
09552abc44 libswift: improve the bootstrapping-with-hostlibs build mode
Don't build the swiftCore module files in the bootstrapping phases. Instead use the module files in the SDK.
This reduces the build time overhead from 3min -> 30seconds.
2021-11-05 18:32:25 +01:00
Hassan
1d4f220ed4 [stdlib] Replace precondition with the internal _precondition 2021-11-04 23:51:10 +02:00
Karoy Lorentey
d54e56bf1d Merge pull request #40006 from lorentey/deninenineninenine-codable-additions 2021-11-03 22:05:42 -07:00
Hassan
bca4f2a6be [stdlib] Replace assert with the internal _internalInvariant 2021-11-03 23:06:26 +02:00
Guillaume Lessard
0d1d49da4f [gardening] fix copy-pasta 2021-11-03 04:50:04 -06:00
Guillaume Lessard
bbe8fbc15a [stdlib] improve documentation of withContiguous[Mutable]StorageIfAvailable
- clarify the requirement that the entire collection must be accessible
- clarify the requirement surrounding subsequences / slices
- add parameter descriptions
- specify that buffer cannot be replaced
2021-11-03 03:43:19 -06:00
Karoy Lorentey
af06df90b6 [stdlib] Optimize Set.subtracting even more 2021-11-02 20:16:35 -07:00
Karoy Lorentey
f82b2996ab [stdlib] Delete bogus assert 2021-11-02 19:30:43 -07:00
Karoy Lorentey
2e3e88cab8 [stdlib] Optimize Set.intersection(_:)
Use a temporary bitset to speed up the `Sequence` variant by roughly a factor of ~4-6, and the set/set variant by a factor of ~1-4, depending on the ratio of overlapping elements.
2021-11-01 21:38:10 -07:00
Karoy Lorentey
db80c78809 [stdlib] Optimize Set.filter(_:)
This works the same way as `Set.subtracting<S>(_:)`, and has similar performance benefits.
2021-11-01 21:38:10 -07:00
Karoy Lorentey
80296bb606 [stdlib] Optimize Set.subtracting(_:)
Use a temporary bitset to avoid hashing elements more than once, and to prevent rehashings during the creation of the result set.

This leads to a speedup of about 0-4x, depending on the number of elements removed.
2021-11-01 21:38:10 -07:00
Karoy Lorentey
8612f2f960 [stdlib] Add a fast path to Set.isDisjoint<S>(with: S)
Have the generic variant call out to the specialized overload if the argument happens to be a `Set`.
2021-11-01 21:38:10 -07:00
Karoy Lorentey
a2540c27b7 [stdlib] Optimize Set.isStrictSuperset(of:)
- Use a temporary bitset to speed up the `Sequence` variant by roughly a factor of 4.
- Fix a logic error causing the `a == b` case for the set variant to be O(n) instead of O(1).
2021-11-01 21:38:10 -07:00
Karoy Lorentey
725ee55fbc [stdlib] Optimize Set.isSuperset<S>(of: S)
Call into the specialized overload if the argument happens to be a `Set`.
2021-11-01 21:38:10 -07:00
Karoy Lorentey
9043c71bd7 [stdlib] Optimize Set.isStrictSubset<S>(of: S)
Use a temporary bitset to speed up the Sequence variant by roughly a factor of 3.
2021-11-01 21:38:09 -07:00
Karoy Lorentey
5e642d2b8d [stdlib] Optimize Set.isSubset<S>(of: S)
Use a temporary bitset to speed up the Sequence variant by roughly a factor of 3.
2021-11-01 21:38:09 -07:00
Karoy Lorentey
6b1f6c075c [stdlib] _SetVariant.convertedToNative: New convenience function 2021-11-01 21:38:09 -07:00
Karoy Lorentey
e2415f78d7 [stdlib] _UnsafeBitset.withTemporaryBitset: New internal function 2021-11-01 21:38:09 -07:00
Alejandro Alonso
5a0bbb9f89 [stdlib] Implement native grapheme breaking for String (#37864)
* Implement GraphemeWalker that does native grapheme breaking

* Bridged strings use native grapheme breaking for forward strides

* Implement bidirectional native grapheme breaking for native and foreign strings

* Remove ICU's grapheme breaking support

* Use UnicodeScalarView to implement GraphemeWalker

use an Iterator approach

remove Iterator conformance

* Incorporate Michael's feedback

more comments addressed

fix crlf bug

* Try bringing back some old fast paths

* Parameterize nextBoundary and previousBoundary

Parameterize nextBoundary and previousBoundary

* Implement Michael's suggestions
2021-11-01 16:52:28 -07:00
Karoy Lorentey
5d6b0bace6 [stdlib][SE-0320] Update availability of new Codable additions 2021-11-01 16:45:04 -07: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
Alex Martini
29e0a31941 Merge pull request #39977 from amartini51/remove_iff_31371832
Remove "iff" from doc comments.
2021-11-01 11:26:44 -07:00
Karoy Lorentey
1dbcf23515 [stdlib] Availability macros don't work in inlinable code 😩 2021-10-31 15:00:59 -07:00
Karoy Lorentey
8ed81ae063 [stdlib] Adopt availability macros 2021-10-31 15:00:58 -07:00
Morten Bek Ditlevsen
0251957ae3 [SE-0320] Added protocol CodingKeyRepresentable (#34458) 2021-10-30 11:33:42 +01:00
Michael Gottesman
3a5049fa15 [stdlib] Mark _move as public.
Just a thinko on my part.
2021-10-29 15:37:46 -07:00
Michael Gottesman
f9122a79b7 [moveOnly] Implement a new _copy function that performs an explicit copy value.
The key thing is that the move checker will not consider the explicit copy value
to be a copy_value that can be rewritten, ensuring that any uses of the result
of the explicit copy_value (consuming or other wise) are not checked.

Similar to the _move operator I recently introduced, this is a transparent
function so we can perform one level of specialization and thus at least be
generic over all concrete types.
2021-10-29 15:37:46 -07:00
Alex Martini
f81d11492a Remove repetitive wording.
Fixes <rdar://59618453>
2021-10-29 11:05:21 -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
Erik Eckstein
a5030a63b0 stdlib: add a _unsafePerformance function which disable performance diagnostics in the passed closure. 2021-10-28 18:44:44 +02:00
Michael Gottesman
114789707c [moveOnly] Implement a semi-generic _move function that can be used on non-generic, non-existential values.
This patch introduces a new stdlib function called _move:

```Swift
  @_alwaysEmitIntoClient
  @_transparent
  @_semantics("lifetimemanagement.move")
  public func _move<T>(_ value: __owned T) -> T {
  #if $ExperimentalMoveOnly
    Builtin.move(value)
  #else
    value
  #endif
  }
```

It is a first attempt at creating a "move" function for Swift, albeit a skleton
one since we do not yet perform the "no use after move" analysis. But this at
leasts gets the skeleton into place so we can built the analysis on top of it
and churn tree in a manageable way. Thus in its current incarnation, all it does
is take in an __owned +1 parameter and returns it after moving it through
Builtin.move.

Given that we want to use an OSSA based analysis for our "no use after move"
analysis and we do not have opaque values yet, we can not supporting moving
generic values since they are address only. This has stymied us in the past from
creating this function. With the implementation in this PR via a bit of
cleverness, we are now able to support this as a generic function over all
concrete types by being a little clever.

The trick is that when we transparent inline _move (to get the builtin), we
perform one level of specialization causing the inlined Builtin.move to be of a
loadable type. If after transparent inlining, we inline builtin "move" into a
context where it is still address only, we emit a diagnostic telling the user
that they applied move to a generic or existential and that this is not yet
supported.

The reason why we are taking this approach is that we wish to use this to
implement a new (as yet unwritten) diagnostic pass that verifies that _move
(even for non-trivial copyable values) ends the lifetime of the value. This will
ensure that one can write the following code to reliably end the lifetime of a
let binding in Swift:

```Swift
  let x = Klass()
  let _ = _move(x)
  // hypotheticalUse(x)
```

Without the diagnostic pass, if one were to write another hypothetical use of x
after the _move, the compiler would copy x to at least hypotheticalUse(x)
meaning the lifetime of x would not end at the _move, =><=.

So to implement this diagnostic pass, we want to use the OSSA infrastructure and
that only works on objects! So how do we square this circle: by taking advantage
of the mandatory SIL optimzier pipeline! Specifically we take advantage of the
following:

1. Mandatory Inlining and Predictable Dead Allocation Elimination run before any
   of the move only diagnostic passes that we run.

2. Mandatory Inlining is able to specialize a callee a single level when it
   inlines code. One can take advantage of this to even at -Onone to
   monomorphosize code.

and then note that _move is such a simple function that predictable dead
allocation elimination is able to without issue eliminate the extra alloc_stack
that appear in the caller after inlining without issue. So we (as the tests
show) get SIL that for concrete types looks exactly like we just had run a
move_value for that specific type as an object since we promote away the
stores/loads in favor of object operations when we eliminate the allocation.

In order to prevent any issue with this being used in a context where multiple
specializations may occur, I made the inliner emit a diagnostic if it inlines
_move into a function that applies it to an address only value. The diagnostic
is emitted at the source location where the function call occurs so it is easy
to find, e.x.:

```
func addressOnlyMove<T>(t: T) -> T {
    _move(t) // expected-error {{move() used on a generic or existential value}}
}

moveonly_builtin_generic_failure.swift:12:5: error: move() used on a generic or existential value
    _move(t)
    ^
```

To eliminate any potential ABI impact, if someone calls _move in a way that
causes it to be used in a context where the transparent inliner will not inline
it, I taught IRGen that Builtin.move is equivalent to a take from src -> dst and
marked _move as always emit into client (AEIC). I also took advantage of the
feature flag I added in the previous commit in order to prevent any cond_fails
from exposing Builtin.move in the stdlib. If one does not pass in the flag
-enable-experimental-move-only then the function just returns the value without
calling Builtin.move, so we are safe.

rdar://83957028
2021-10-27 19:36:49 -07:00
Jonathan Grynspan
31b44c8f22 Merge pull request #39925 from apple/jgrynspan/84672024-fix
Fix incorrect precondition test (gt instead of gte) in TemporaryAllocation.swift
2021-10-27 11:58:56 -04:00
Jonathan Grynspan
208b8d493a Fix incorrect precondition test (gt instead of gte) in TemporaryAllocation.swift 2021-10-26 14:19:25 -04:00
Xiaodi Wu
3927e78f64 Add to-do for Stride* implementation of _customContainsEquatableElement (#39908) 2021-10-25 21:00:06 -04:00
Jonathan Grynspan
687cee9bfa Merge pull request #37666 from grynspan/jgrynspan/temporary-buffers
[SE-0322] Temporary uninitialized buffers
2021-10-25 15:53:50 -04:00
Xiaodi Wu
fa4d08ab9f Fix _customContainsEquatableElement implementation for Stride* types (#39903)
* Fix `_customContainsEquatableElement` implementation for `Stride*` types

* Add tests for `Stride*.contains`
2021-10-25 14:07:01 -04:00
Jonathan Grynspan
f1bf7badba [SE-0322] Temporary uninitialized buffers
Adds two new IRGen-level builtins (one for allocating, the other for deallocating), a stdlib shim function for enhanced stack-promotion heuristics, and the proposed public stdlib functions.
2021-10-25 11:20:10 -04:00
Guillaume Lessard
8eea64271a Merge pull request #39824 from glessard/urbp-copycontents-optimization
[stdlib] a minor optimization
2021-10-21 11:39:43 -06:00
Guillaume Lessard
17c19fba06 [stdlib] fix an indexing inconsistency
This iteration ranged from `buffer.startIndex` to `buffer.count`, rather than to `buffer.endIndex`.
Using `buffer.indices` is a better solution in any case.
2021-10-16 12:47:16 -06:00