Commit Graph

6024 Commits

Author SHA1 Message Date
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
Erik Eckstein
b42bce4ba4 stdlib: changes for the StringOptimization
To be able to constant fold string interpolation, the right semantic attributes must be in place.
Also, the interpolation's write function must be inlinable.
For the _typeName constant folding, a semantic attribute is required.
2020-07-27 21:32:56 +02:00
Robert Widmann
d1ae69383d Merge pull request #32312 from valeriyvan/RemoveRedundantBufferZeroingUnicodeScalarProperties
[stdlib] Eliminates redundant buffer zeroing in UnicodeScalarProperties
2020-07-26 12:53:23 -07:00
Augusto Noronha
3cb8f9b6fc Add entrypoints to the runtime that exposes metadata necessary for reflection tests on Linux (#32339) 2020-07-24 15:26:15 -07:00
Erik Eckstein
666c5e087c stdlib: enable COW sanity checks with an environment variable
Instead of doing the sanity checks by default (with an assert-build of the stdlib), only do the checks if the environment variable SWIFT_DEBUG_ENABLE_COW_SANITY_CHECKS is set to true.

The checks can give false alarms in case a binary is built against a no-assert stdlib but run with an assert-stdlib.
Therefore only do the checks if it's explicitly enabled at runtime.

rdar://problem/65475776
2020-07-20 11:23:42 +02:00
Brent Royal-Gordon
4394e92c3f Merge pull request #32700 from brentdax/magical-and-evolutionary
Revise #file changes from SE-0274
2020-07-17 01:57:23 -07:00
swift-ci
1224d8b2d3 Merge pull request #32915 from airspeedswift/transparent-stringpointer 2020-07-16 10:53:54 -07:00
Erik Eckstein
0102fe8b15 stdlib: remove some inlinable annotations from Substring's and String's subscript
Inlining those operations does not really give any benefit.
Those operations are complex and most likely, cannot be folded into simpler patterns after inlining, anyway.
Reduces some code size for cases where those functions were inlined (due to a not perfect inlining heuristics).
2020-07-16 12:46:42 +02:00
Ben Cohen
7adafcaaaa Make _convertConstStringToUTF8PointerArgument transparent 2020-07-15 17:27:33 -07:00
Stephen Canon
103961a7d5 Make Float16 unavailable on macOS and macCatalyst, mirroring Xcode's Swift. (#32868)
LLVM doesn't have a stable ABI for Float16 on x86 yet; we're working with Intel to get that fixed, but we don't want to make the type available on macOS until a stable ABI is actually available, because we'd break binaries compiled before any calling convention changes if we do.
2020-07-14 20:42:12 -04:00