Commit Graph

6693 Commits

Author SHA1 Message Date
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
Patrick Pijnappel
8ecd884b62 [stdlib] Expand integer conversion comment 2020-10-19 17:55:50 +11:00
Patrick Pijnappel
87c177c4b6 [stdlib] Change misleading comment 2020-10-19 10:51:18 +11:00
swift-ci
8b5a55d13e Merge pull request #34180 from spevans/pr_static_executable_fix_1lib 2020-10-08 07:05:20 -07:00
Meghana Gupta
141b032e7c Enable --build-sil-debugging-stdlib for all of swift/stdlib/public (#34197)
Previously it was enable only for swift/stdlib/public/core
2020-10-06 10:59:45 -07:00
Xiaodi Wu
23dc001364 Merge pull request #33910 from xwu/exactness-in-little-things-a-wonderful-source-of-cheerfulness
[stdlib] Simplify 'BinaryFloatingPoint.init?<T: BinaryFloatingPoint>(exactly: T)'
2020-10-05 12:14:27 -04:00
Simon Evans
960d0e30ee Linux: Fix -static-executable and remove swiftImageInspectionShared
- Remove references to swiftImageInspectionShared on Linux and dont have
  split libraries between static/non-static linked executables.

- -static-executable now links correctly Linux.

  Note: swift::lookupSymbol() will not work on statically linked
        executables but this can be worked around by using the
        https://github.com/swift-server/swift-backtrace package.
2020-10-05 10:16:03 +01:00
swift-ci
c5aaf1fa8b Merge pull request #33825 from valeriyvan/Array-fix-snippet-endianness 2020-09-28 20:49:38 -07:00
Valeriy Van
cdba663d80 Fixes example snippets in Array.swift considering endianness 2020-09-29 02:00:24 +02:00
Meghana Gupta
410b88ef07 Fix @effects of finalizeUninitializedArray when assertions are enabled (#34101)
When assertions are enabled _endCOWMutation writes to _native.isImmutable.
But finalizeUninitializedArray is marked as @effects(readnone). This
mismatch caused miscompile in the stdlib due to CodeSinking optimization
which relies on SILInstruction::mayReadOrWriteMemory which looks at
@effects.
2020-09-28 15:54:46 -07:00
Andrew Trick
5eafc20cdd Fix undefined behavior in SmallString.withUTF8
withUTF8 currently vends a typed UInt8 pointer to the underlying
SmallString. That pointer type differs from SmallString's
representation. It should simply vend a raw pointer, which would be
both type safe and convenient for UTF8 data. However, since this
method is already @inlinable, I added calls to bindMemory to prevent
the optimizer from reasoning about access to the typed pointer that we
vend.

rdar://67983613 (Undefinied behavior in SmallString.withUTF8 is miscompiled)

Additional commentary:

SmallString creates a situation where there are two types, the
in-memory type, (UInt64, UInt64), vs. the element type,
UInt8. `UnsafePointer<T>` specifies the in-memory type of the pointee,
because that's how C works. If you want to specify an element type,
not the in-memory type, then you need to use something other than
UnsafePointer to view the memory. A trivial `BufferView<UInt8>` would
be fine, although, frankly, I think UnsafeRawPointer is a perfectly
good type on its own for UTF8 bytes.

Unfortunately, a lot of the UTF8 helper code is ABI-exposed, so to
work around this, we need to insert calls to bindMemory at strategic
points to avoid undefined behavior. This is high-risk and can
negatively affect performance. So far, I was able to resolve the
regressions in our microbenchmarks just by tweaking the inliner.
2020-09-24 18:36:42 -07:00
Erik Eckstein
66d62ff144 stdlib: fix a back-deployment issue for array COW checks with a stdlib assert-build
And rename COWSanityChecks -> COWChecks.

rdar://problem/68181747
2020-09-21 12:21:11 +02:00
Xiaodi Wu
6216ccdcad [stdlib] Fix a Float16-to-integer conversion bug (#33893)
* [stdlib] Fix a Float16-to-integer conversion bug

* [stdlib] Add a test for 'Int(exactly: Float16.infinity)'
2020-09-16 14:53:06 -04:00
Xiaodi Wu
7898f0b7ad [stdlib] Silence signaling NaN in generic conversions (#33902) 2020-09-15 15:05:29 -04:00
Jordan Rose
fc6b14faf7 stdlib: Remove unused, unsafe helper function _withUninitializedString (#33704)
No functionality change.
2020-09-14 18:16:38 +01:00
Alexis Laferrière
aef50ab8d1 Merge pull request #33919 from xymus/fix-availability-float16
[stdlib] Align availability of a Float16 initializer with its type
2020-09-11 16:08:38 -07:00
Alexis Laferrière
a4bf73860b [stdlib] Align availability of a Float16 initializer with its type
The constructor `init?(text: Substring)` was more available than its
type Float16 for macOS and macCatalyst where the type is explicitly
unavailable. The compiler may report this as an error in the future.
2020-09-11 13:32:44 -07:00
Kuba (Brecka) Mracek
aa0f8e670b Add a SWIFT_STDLIB_OS_VERSIONING flag to avoid querying OS version at runtime, use it in the freestanding build (#33791) 2020-09-11 08:09:14 -07:00
Xiaodi Wu
26cda274ca [stdlib] Simplify 'BinaryFloatingPoint.init?<T: BinaryFloatingPoint>(exactly: T)' 2020-09-11 09:56:58 -04:00
Karoy Lorentey
55e7050ffc Merge pull request #32311 from Molanda/string_varargs_object_protocol
Added protocol to support CVarArg objects that need to be retained
2020-09-10 11:50:57 -07:00
Karoy Lorentey
a084d04500 Merge pull request #31686 from 3405691582/ManagedBuffer_WithoutMallocSize
[stdlib] ManagedBuffer independent of malloc_size.
2020-09-10 11:32:07 -07:00
Xiaodi Wu
48652077d8 Merge pull request #33826 from xwu/float-like-a-butterfly
[stdlib] Add another fast path for generic floating-point conversion
2020-09-10 09:59:48 -04:00
3405691582
cd7570fdee ManagedBuffer capacity is unavailable on OpenBSD.
On OpenBSD, malloc introspection (e.g., malloc_usable_size or
malloc_size) is not provided by the platform allocator. Since allocator
introspection is currently a load-bearing piece of functionality for
ManagedBuffer and ManagedBufferPointer, pending any API changes, as a
stopgap measure, this commit marks methods in ManagedBuffer and
ManagedBufferPointer calling _swift_stdlib_malloc_size and methods
dependent thereon unavailable on OpenBSD.

This may induce some compatibility issues for some files, but at least
this change ensures that we can get stdlib to build on this platform
until the evolution process addresses this problem more thoroughly.
2020-09-09 18:57:58 -04:00
Valeriy Van
ed30712ff3 Fixes example snippet in OutputStream.swift (#33844) 2020-09-08 13:36:21 -05:00
Xiaodi Wu
643834e7f5 [stdlib] Simplify generic floating-point conversion fast paths 2020-09-08 12:08:08 -04:00
Xiaodi Wu
45d69d58d0 [stdlib] Use 'truncatingIfNeeded:' in floating-point conversion fast paths 2020-09-08 11:32:09 -04:00
Xiaodi Wu
9a6900ad3a [stdlib] Refactor generic floating-point conversion fast paths 2020-09-07 18:47:01 -04:00
Xiaodi Wu
f40fd369cd [stdlib] Add another fast path for generic floating-point conversion 2020-09-07 18:47:01 -04:00
Xiaodi Wu
f0a6d6f69e Merge pull request #33803 from xwu/fp-init-specialization
[stdlib] Make use of protocol requirements to convert from concrete floating-point types
2020-09-05 11:37:21 -04:00
Xiaodi Wu
b6046352de 🤮 2020-09-04 17:51:39 -04:00
Xiaodi Wu
70b68d6ba9 [stdlib] Include Float16 among source types recognized for generic conversion 2020-09-04 16:16:10 -04:00
Xiaodi Wu
502258e6a1 Merge pull request #33610 from valeriyvan/Array-snippet
Fixes example snippet in Array.swift adding missing parameter label
2020-09-04 14:32:08 -04:00
Xiaodi Wu
42f79b0e87 [stdlib] Make use of protocol requirements to convert from concrete types 2020-09-04 14:23:53 -04:00
Benjamin Barnard
0bc48dea75 [stdlib] NFC: Fix typo in comment. 2020-09-01 19:09:39 -04:00
Stephen Canon
294bde951b Documentation fix: remainder matches sign of lhs, not rhs. 2020-08-31 08:46:24 -04:00
Valeriy Van
9d08f164ca Fixes example snippet in Array.swift adding missing parameter label 2020-08-30 19:19:05 +02:00
tbkka
524cfae1b2 [Dynamic Casting] Overhauled Runtime (#33561)
* Dynamic Cast Rework: Runtime

This is a completely refactored version of the core swift_dynamicCast
runtime method.

This fixes a number of bugs, especially in the handling of multiply-wrapped
types such as Optional within Any.  The result should be much closer to the
behavior specified by `docs/DynamicCasting.md`.

Most of the type-specific logic is simply copied over from the
earlier implementation, but the overall structure has been changed
to be uniformly recursive.  In particular, this provides uniform
handling of Optional, existentials, Any and other common "box"
types along all paths.  The consistent structure should also be
easier to update in the future with new general types.

Benchmarking does not show any noticable performance implications.

**Temporarily**, the old implementation is still available.  Setting the
environment variable `SWIFT_OLD_DYNAMIC_CAST_RUNTIME` before launching a program
will use the old runtime implementation.  This is only to facilitate testing;
once the new implementation is stable, I expect to completely remove the old
implementation.
2020-08-27 11:06:40 -07:00
Kyle Macomber
d71d92eced Merge pull request #31105 from valeriyvan/RemoveRedundantBufferZeroingUnicodeHelpers
[stdlib] Removes redundant buffer zeroing in foreignErrorCorrectedGrapheme func by using `init(unsafeUninitializedCapacity:initializingWith:)
2020-08-24 14:53:03 -07:00
Valeriy Van
84928c611d Fixes example snippet in Array.swift
Uses URL instead of NSURL, otherwise example deson't compile
2020-08-24 13:43:25 +02:00
Brian Gontowski
515c371be4 Avoid a warning when not modifying arg 2020-08-22 13:08:12 +09:00
Brian Gontowski
17c77ba703 Only use _CVarArgObject on non-ObjC platforms 2020-08-22 11:36:15 +09:00