Commit Graph

5783 Commits

Author SHA1 Message Date
Matt Zanchelli
be13b470aa Fix typos
becuase -> because
preceeds -> precedes
initalizer -> initializer
intialize -> initialize
libary -> library
notfication -> notification
reciever -> receiver
collecton -> collection
exlcusive -> exclusive
techincal -> technical
compatability -> compatibility
setps -> steps
accomodate -> accommodate
brakcet -> bracket
fraciton -> fraction
programm -> program
concequently -> consequently
ecoding -> encoding
timeIntervalforSelfEnd -> timeIntervalForSelfEnd
2020-12-21 18:44:03 -05:00
Nate Cook
c35b567001 Temporary removal of RangeSet/DiscontiguousSlice (#35076) 2020-12-14 08:42:01 -06:00
Karoy Lorentey
8082b58365 Merge pull request #34961 from lorentey/buffers-need-to-be-fast-but-not-too-fast
[stdlib] Review and fix some problems with unsafe buffer and Range initialization
2020-12-12 19:13:20 -08:00
Karoy Lorentey
94a7eeebe5 [stdlib] Document sources of code bloat 2020-12-11 18:31:00 -08:00
Karoy Lorentey
1f92df093c [stdlib] Add an unsafe U[M]BP initializer to work around some inliner test failures 2020-12-09 19:31:28 -08:00
Stephen Canon
95309e1dce Fixup Float16 availability for macCatalyst/x86_64 2020-12-09 13:51:51 -05:00
Karoy Lorentey
282a1408de [stdlib] U[R]BP: Restore compile-time condition lost with removed precondition 2020-12-08 22:25:16 -08:00
Karoy Lorentey
93368213cf [stdlib] Don’t use unbound ranges (foo[…]) in String → Substring conversions
The UnboundRange → Range conversion path is complicated and it involves at least one unnecessary _precondition check for startIndex ..< endIndex.
2020-12-04 19:55:39 -08: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
Karoy Lorentey
513a7d9e19 [stdlib] Substring: Restore original Range paths
This eliminates a couple of _debugPreconditions which seem to change inlining enough to interfere with some benchmarks.
2020-12-04 18:35:08 -08:00
Karoy Lorentey
2607428347 [stdlib] U[M]RBP.count: Let the compiler assume that the result is nonnegative 2020-12-04 02:06:22 -08:00
Karoy Lorentey
27978d16b9 [stdlib] Eliminate an overflow check in U[M]BP.distance 2020-12-04 02:06:22 -08:00
Karoy Lorentey
d52cd8243a [stdlib] Add a missing debug mode check to U*BP.init(rebasing:)
`Slice` does not technically guarantee that its indices are valid in its base, so these initializers accidentally allowed the creation of obviously out-of-bounds buffers.
2020-12-04 02:06:22 -08:00
Karoy Lorentey
c5c27c7c69 [stdlib] Add a missing debug precondition to [Closed]Range.init(uncheckedBounds:)
Unchecked APIs must still perform checks in debug builds to ensure that invariants aren’t violated.
(I.e., these aren’t a license to perform invalid operations — they just let us get rid of the checks when we know for sure they are unnecessary.)
2020-12-04 02:06:22 -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
Karl
83c14bca9c Make raw buffer nil/count checks debug-mode only 2020-12-04 02:06:21 -08:00
Karl
74a8254d40 Make UBP nil/count checks debug-mode only
Every other Unsafe(Mutable)BufferPointer precondition in this file is debug-mode only.

This information is already part of the documentation for this function, and it's really hard to get rid of these branches and traps otherwise.
2020-12-04 02:06:21 -08:00
Andrew Trick
820b2c6182 Merge pull request #34879 from Lukasa/cb-simpler-buffer-initializer
[stdlib] Simplify buffer pointer initialization.
2020-12-01 14:18:58 -08:00
Robert Widmann
48614412c4 Merge pull request #34885 from LucianoPAlmeida/warn-class-protocol-inheritance
[Sema] Adding deprecation warning for protocol inheritance 'class' syntax
2020-12-01 10:36:41 -08:00
Karoy Lorentey
c51b10abd0 Merge pull request #34814 from lorentey/partitioning-cleanup
[stdlib][NFC] Simplify partition(by:)’s implementation
2020-11-30 11:33:32 -08:00
Stephen Canon
74e2cb6c6d Partially revert Float16 availability changes (#34847)
* Partially revert Float16 availability changes

Specifically, when building for macOS/x86_64, use the old availability annotation instead of marking Float16 unconditionally unavailable to give downstream clients a window to adjust their own annotations.
2020-11-30 12:59:15 -05:00
Parker Schuh
4e39e59a8a Add a field reflection function that constructs keypaths. (#34815)
While the existing _forEachField in ReflectionMirror.swift
already gives the offsets and types for each field, this isn't
enough information to construct a keypath for that field in
order to modify it.

For reference, this should be sufficent to implement the features
described here: (https://forums.swift.org/t/storedpropertyiterable/19218/62)
purely at runtime without any derived conformances for many types.

Note: Since there isn't enough reflection information for
`.mutatingGetSet` fields, this means that we're not able to support
reflecting certain types of fields (functions, nonfinal class fields,
etc). Whether this is an error or not is controlled by the `.ignoreUnknown`
option.
2020-11-30 09:17:23 -08:00
Luciano Almeida
338faab324 [test] Adjusting stdlib ocurrences where class syntax is used for protocol inheritance 2020-11-29 21:44:42 -03:00
Cory Benfield
300f4da1bb [stdlib] Simplify buffer pointer initialization.
UnsafeRawBufferPointer was not made self-slicing, but is instead sliced
by Slice<UnsafeRawBufferPointer>. When working with
UnsafeRawBufferPointer objects it is quite common to want to transform
back into the underlying collection, which is why the
UnsafeRawBufferPointer provides a constructor from its subsequence:
UnsafeRawBufferPointer.init(rebasing:).

Unfortunately for an initializer on this extremely low-level type, this
initializer is surprisingly expensive. When disassembled on Linux it
emits 7 separate traps and 11 branches. This relative heft means this
method often gets outlined, which is a shame, as several of the branches
could often be eliminated due to checks elsewhere in functions where
this initializer is used.

Almost all of these branches and almost all of the traps are
unnecessary. We can remove them by noting that it is impossible to
construct a Slice whose endIndex is earlier than its startIndex. All
Slice inits are constructed with bounds expressed as Range, and Range
enforces ordering on its endpoints.

For this reason, we can do unchecked arithmetic on the start and end
index of the slice, and remove 5 traps in one fell swoop. This greatly
cheapens the cost of the initializer, improving its odds of being
inlined and having even more of its branches optimised away.

For what it's worth, I also considered trying to remove the last two
preconditions. Unfortunately I concluded I couldn't confidently do that.
I wanted to remove them based on the premise that a valid Slice must
have indices that were in-bounds for its parent Collection, and so we
could safely assume that if the parent base address was nil the count
would have to be zero, and that adding start index to the base address
would definitely not overflow. However, the existence of the
Slice.init(base:bounds:) constructor led me to be a bit suspicions of
removing those checks. Given that
UnsafeRawBufferPointer.init(start:count:) enforces those invariants, I
decided it was safest for us to continue to do that.
2020-11-27 16:57:50 +00:00
Stephen Canon
abea46ea59 Make Float16 available for macOS on Apple Silicon (#34821)
Due to an unstable (and undesirable) calling convention in the LLVM layer for x86, I had previously marked Float16 unconditionally unavailable on macOS. My hope was that Intel would stabilize the calling convention and we could make it available on both macOS platforms at the same time. Unfortunately, that hasn't happened, and we want to make the type available for macOS/arm users.

So, I am making the availability mirror Float80--the type will be unavailable for macOS on x86_64, and available on all other platforms (the other x86 platforms don't have a binary-stability guarantee to worry about). This isn't ideal. In particular, if/when the calling conventions for Float16 stabilize in LLVM, we would want to make the type available, but it would then have _different_ availability for different architectures of macOS, which the current availability system is not well-equipped to handle (it's possible, but not very ergonomic). Nonetheless, this seems like the best option.

The good news is that because the full API is already built in Swift (and simply marked unavailable), we can simply add macOS 11.0 availability for these API and it will work.
2020-11-19 09:36:03 -05:00
Karoy Lorentey
cb8ceed2af [stdlib][NFC] Make partition(by:)’s implementation easier to follow
Also, fix a case in the description of the loop invariant
2020-11-18 14:37:39 -08:00
Nate Cook
cae81eece0 Fix issues with discontiguous-slice assignment (#34708)
The mutating collection subscript for discontiguous slices assigns to the wrong group
of indices. This fixes the behavior and adds test coverage.

rdar://problem/70690643
2020-11-18 11:16:26 -06:00
Butta
8574fe7204 [build] Remove remaining dependencies on libatomic, for Android, BSD and Haiku
Follow suit from linux, #29581, tested on Android.
2020-11-16 10:16:12 +05:30
Mike Ash
2442ba29fc Merge pull request #34729 from mikeash/referencewritablekeypath-dynamic-dispatch-writes
[Stdlib] Fix swift_setAtWritableKeyPath to check for ReferenceWritableKeyPaths.
2020-11-13 16:42:19 -05:00
Mike Ash
ee8480fe71 [Stdlib] Fix swift_setAtWritableKeyPath to check for ReferenceWritableKeyPaths.
Call through to swift_setAtReferenceWritableKeyPath in that case. This fixes an assertion failure (or worse) when upcasting a ReferenceWritableKeyPath and then using subscript(keyPath:) to write a value with it.

rdar://problem/70609888
2020-11-13 13:00:16 -05:00
Erik Eckstein
7f6d86655e stdlib: add availability attributes to the COW debug checking functions.
This is only relevant for assert builds of the library.
Fixes an undefined symbol error if an executable, compiled with an assert build of the stdlib, is back deployed on a platform which does not support lazy symbol binding.

rdar://problem/71201102
2020-11-13 10:41:25 +01:00
Robert Widmann
e201c73c5c Merge pull request #34631 from kateinoigakukun/use-_resolveRelativeAddress
[stdlib][NFC] Resolve relative address in consistent way
2020-11-10 14:21:10 -08:00
Erik Eckstein
6d0bbba156 stdlib: update comments for the array buffer endCowMutation functions. 2020-11-09 15:30:23 +01:00
Erik Eckstein
51c2bd0a1c stdlib: remove a wrong internal check for COW array mutation
Don't complain if the empty array buffer singleton is set to mutable.
This can happen if reserveCapacity is called with a 0-capacity for an empty array.
In this case the resulting array is still the empty array singleton.
For the compiler, it's safe to treat the empty array singleton as "mutable", because there is never anything written to an array with zero capacity:
all mutating array operations do any form of capacity/size > 0 check in addition to the uniqueness check.

Unfortunately the empty array singleton sometimes needs such special handling with is not obvious (not to say hacky).

This wrong check only fired in very specific optimization scenarios, where the inliner and the COW optimizations must play together in a certain way.
I could not find an isolated test case for this problem.

rdar://problem/71107908
2020-11-09 15:29:41 +01:00
Yuta Saito
dcdf66832b [stdlib] Resolve relative address in consistent way 2020-11-09 11:25:41 +09:00
Ben Rimmington
824e4d0cad [SE-0270] Reset availability of RangeSet APIs (#34567) 2020-11-04 16:49:18 -06:00
Andrew Trick
3128eae3f0 Add NestedSemanticFunctionCheck diagnostic
to check for improperly nested '@_semantic' functions.

Add a missing @_semantics("array.init") in ArraySlice found by the
diagnostic.

Distinguish between array.init and array.init.empty.

Categorize the types of semantic functions by how they affect the
inliner and pass pipeline, and centralize this logic in
PerformanceInlinerUtils. The ultimate goal is to prevent inlining of
"Fundamental" @_semantics calls and @_effects calls until the late
pipeline where we can safely discard semantics. However, that requires
significant pipeline changes.

In the meantime, this change prevents the situation from getting worse
and makes the intention clear. However, it has no significant effect
on the pass pipeline and inliner.
2020-10-26 17:02:33 -07:00
Kyle Macomber
3a1b9cd36c Merge pull request #34349 from sunbohong/patch-1
[Docs] Clarifies `ObjectIdentifier` guarantees
2020-10-26 15:20:08 -07:00
Karoy Lorentey
58d07a4efd Merge pull request #34426 from lorentey/array-cannot-append
[stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray
2020-10-26 14:12:49 -07:00
Andrew Trick
7f09bbf80c Merge pull request #33698 from atrick/fix-smallstring
Fix undefined behavior in SmallString.withUTF8
2020-10-26 08:24:35 -07:00
Karoy Lorentey
184367ca8f [stdlib] Fix Array.append(contentsOf:) for arguments of type NSArray
Due to a couple of unfortunate circumstances, appending an NSArray instance to an Array instance does not actually append any elements.

The cause is https://github.com/apple/swift/pull/29220, which accidentally optimized away the actual loop that appends the elements in this particular case. (And only this particular case, which is why this wasn’t detected by the test suite.)

When the argument to `Array.append(contentsOf:)` is of type NSArray, the `newElements is [Element]` expression is compiled into a runtime check that returns true, eliminating the subsequent loop over the remaining items of the iterator. Sadly, NSArray.underestimatedCount` currently returns 0, so the earlier _copyContents call is a noop, so no elements get added to `self` at all.

Turning the `is` test into a direct equality check between the metatype instances resolves the issue.
2020-10-24 18:17:52 -07:00
Nate Cook
a43cb01cbb Update ObjectIdentifier.swift
Co-authored-by: Xiaodi Wu <13952+xwu@users.noreply.github.com>
2020-10-23 15:13:03 -05:00
酷酷的哀殿
9c9c5da944 Update ObjectIdentifier.swift 2020-10-23 21:10:04 +08:00
酷酷的哀殿
16e541709e Update ObjectIdentifier.swift 2020-10-23 21:09:33 +08:00
酷酷的哀殿
a9af098560 Update ObjectIdentifier.swift 2020-10-22 22:43:31 +08:00
酷酷的哀殿
4a4c6c0f63 Update ObjectIdentifier.swift 2020-10-21 22:50:12 +08:00
酷酷的哀殿
c2159e2401 Update ObjectIdentifier.swift 2020-10-21 00:23:14 +08:00
酷酷的哀殿
59aff3e850 Update ObjectIdentifier.swift 2020-10-21 00:22:44 +08:00
酷酷的哀殿
e6fbb4b247 Update ObjectIdentifier.swift 2020-10-19 22:06:19 +08:00
酷酷的哀殿
cd74534052 [Docs] Clarifies ObjectIdentifier guarantees (#31472)
[SR-13564](https://bugs.swift.org/browse/SR-13564)
rdar://69169351
2020-10-19 21:54:50 +08:00