Commit Graph

5783 Commits

Author SHA1 Message Date
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
NevinBR
a62bf48e68 [stdlib] [NFC] FloatingPointRandom.swift created (#33463)
* Moved `random` methods out of FloatingPoint.swift

* Added `random` methods to FloatingPointRandom.swift

* Added FloatingPointRandom.swift to CMakeLists.txt

* Added FloatingPointRandom.swift to GroupInfo.json

* Moved filename within CMakeLists.txt
2020-08-18 18:12:35 -04:00
Kuba (Brecka) Mracek
7a9f894c88 Avoid using -sil-inline-generics and -sil-partial-specialization when building MinSizeRel stdlib to save ~15% on codesize (#33444) 2020-08-17 20:58:54 -07:00
Stephen Canon
457b9990e9 Add checks that the endpoints of partial ranges are not-NaN. (#33378)
We can't actually check for NaN (because the notion doesn't exist for Comparable), but we can require that the endpoint is non-exceptional by checking if it equals itself.
2020-08-10 14:06:46 -04:00
Slava Pestov
3ae31d5173 Sema: Don't need to derive CaseIterable's AllCases associated type
Just declaring a default in the standard library works fine.
2020-08-07 16:48:40 -04:00
Ben Rimmington
d3f0de804d [SE-0163] Migrate from deprecated Unicode APIs (part 3) (#33175) 2020-08-06 23:44:55 +01:00
Erik Eckstein
e7efa6cb15 stdlib: Make Result methods inlinable
The "Result" type is expected to have no overhead when used.
This requires the member functions to be inlinable.
Which is probably okay for library evolution, because it's unlikely that those methods change in an incompatible way.
2020-07-29 21:57:51 +02:00
Vedant Kumar
2308bb18b1 Add _getMetadataSection{,Count,Name} to API digester allow list (#33138)
These APIs are needed to build SwiftReflectionTest.swift when testing
Release builds.

This rolls back 014918c0, which hid these APIs in non-asserts builds
causing a failure:

  https://ci-external.swift.org/job/oss-swift-RA-linux-ubuntu-16.04-android-arm64/5708/consoleText

rdar://66103895
2020-07-28 15:19:18 -07:00
eeckstein
5fffeb81fb Merge pull request #33128 from eeckstein/string-optimization
SIL optimizer: Add a new string optimization
2020-07-28 10:17:28 +02:00
Mishal Shah
3a50f93c60 Merge pull request #33142 from natecook1000/nate/stdlib-stability-abi
[stdlib] Only include _getMetadataSection functions in stdlib builds w/ assertions
2020-07-28 00:03:53 -07:00
Nate Cook
014918c0ca Only include _getMetadataSection functions in stdlib builds w/ assertions 2020-07-27 17:12:27 -05:00