Commit Graph

366 Commits

Author SHA1 Message Date
tbkka
110e5136c1 Float16 optimal formatting (#30862)
Extend SwiftDtoa to provide optimal formatting for Float16 and use that for `Float16.description` and `Float16.debugDescription`.

Notes on signaling NaNs: LLVM's Float16 support passes Float16s on x86
by legalizing to Float32.  This works well for most purposes but incidentally
loses the signaling marker from any NaN (because it's a conversion as far
as the hardware is concerned), with a side effect that the print code never
actually sees a true sNaN.  This is similar to what happens with Float and
Double on i386 backends.  The earlier code here tried to detect sNaN in a
different way, but that approach isn't guaranteed to work so we decided to
make this code use the correct detection logic -- sNaN printing will just be
broken until we can get a better argument passing convention.

Resolves rdar://61414101
2020-04-09 09:37:38 -04:00
Stephen Canon
248c554524 Add Float16 to stdlib (#30130)
Add Float16 (IEEE 754 binary16) to the standard library, plus assorted runtime support operations.

Swift Evolution thread: https://forums.swift.org/t/se-0277-float16/33546
2020-04-06 17:57:44 -04:00
3405691582
5847726f51 Preliminary support for OpenBSD in the stdlib.
These should hopefully all be uncontroversial, minimal changes to deal
with progressing the build to completion on OpenBSD or addressing minor
portability issues. This is not the full set of changes to get a
successful build; other portability issues will be addressed in future
commits.

Most of this is just adding the relevant clauses to the ifdefs, but of
note in this commit:

* StdlibUnittest.swift: the default conditional in _getOSVersion assumes
  an Apple platform, therefore the explicit conditional and the relevant
  enums need filling out. The default conditional should be #error, but
  we'll fix this in a different commit.

* tgmath.swift.gyb: inexplicably, OpenBSD is missing just lgammal_r.
  Tests are updated correspondingly.

* ThreadLocalStorage.h: we use the pthread implementation, so it
  seems we should typedef __swift_thread_key_t as pthread_key_t.
  However, that's also a tweak for another commit.
2020-03-01 12:50:06 -05:00
Devin Coughlin
664e7cc00e [Availability] Make _stdlib_isOSVersionAtLeast() no longer inlinable
To make it possible to change the implementation of
_stdlib_isOSVersionAtLeast(), remove the @inlinable attribute from it.

Since it is currently inlinable and calls the helper function
_swift_stdlib_operatingSystemVersion(), we’ll have to keep the
helper around as ABI.

This change causes a minor pessimization where the LLVM optimizer can no
longer reason that, for example, a successful check for 10.12 availability
means that a later check for 10.11 will always succeed. I don't expect this
pessimization to be a problem, but if needed we could write a custom SIL
optimizer pass to claw back the performance.

<rdar://problem/59447474>
2020-02-13 20:08:48 -08:00
Max Desiatov
44a6475566 [WebAssembly] enable shims and stubs for WASI (#29505)
* [WebAssembly] enable shims and stubs for WASI

* Implement _swift_stdlib_getUnsafeArgvArgc for WASI

* Make include unconditional, add JIRA links
2020-01-28 18:29:52 -08:00
David Smith
f36a4db856 Update fast dealloc to use new-style interposing and support objc weak refs 2020-01-22 13:55:27 -08:00
David Smith
1cce12f20c Add an Array-based NSMutableArray subclass 2019-09-24 18:15:33 -07:00
Saleem Abdulrasool
64ed0a4077 stdlib: silence a unused function warning (NFC)
Pre-process away the unused function on Darwin.  NFC.
2019-09-20 17:34:17 -07:00
David Smith
1efa946caf Remove stdlib and runtime dependencies on Foundation and CF 2019-09-12 18:03:14 -07:00
Arnold Schwaighofer
fe69a86929 Revert "Remove stdlib and runtime dependencies on Foundation and CF"
It is causing bots to fail.

* Revert "The __has_include(<os/system_version.h>) branch here wasn't quite right, we'll just use the dlsym one for now"

This reverts commit f824922456.

* Revert "Remove stdlib and runtime dependencies on Foundation and CF"

This reverts commit 3fe46e3f16.

rdar://54709269
2019-08-26 13:00:08 -07:00
David Smith
f824922456 The __has_include(<os/system_version.h>) branch here wasn't quite right, we'll just use the dlsym one for now 2019-08-23 23:12:29 -07:00
swift-ci
3256392211 Merge pull request #26630 from Catfish-Man/shim-shim-sher-ee 2019-08-23 17:08:59 -07:00
David Smith
3fe46e3f16 Remove stdlib and runtime dependencies on Foundation and CF 2019-08-23 14:10:23 -07:00
Saleem Abdulrasool
cc9a567ec7 stdlib: use the destructor CC adjustment thunk
Use the wrapper for the CC adjustment as on Windows x86, the destructor
needs to be `__stdcall`.  This would fail otherwise with the following:

```
D:\a\1\s\swift\stdlib\public\stubs\ThreadLocalStorage.cpp(86,18):  error: no matching function for call to '_stdlib_thread_key_create'
    int result = SWIFT_THREAD_KEY_CREATE(&key, [](void *pointer) {
                 ^~~~~~~~~~~~~~~~~~~~~~~
D:\a\1\s\swift\stdlib\public\stubs/../runtime/ThreadLocalStorage.h(96,35):  note: expanded from macro 'SWIFT_THREAD_KEY_CREATE'
                                  ^~~~~~~~~~~~~~~~~~~~~~~~~
D:\a\1\s\swift\include\swift/Basic/Lazy.h(42,27):  note: expanded from macro 'SWIFT_ONCE_F'
  ::std::call_once(TOKEN, FUNC, CONTEXT)
                          ^~~~
D:\a\1\s\swift\stdlib\public\stubs\ThreadLocalStorage.cpp(43,1):  note: candidate function not viable: no known conversion from '(lambda at D:\a\1\s\swift\stdlib\public\stubs\ThreadLocalStorage.cpp:85:3)' to '__swift_thread_key_destructor _Nullable' (aka 'void (*)(void *) __attribute__((stdcall))') for 2nd argument
_stdlib_thread_key_create(__swift_thread_key_t * _Nonnull key,
^

```
2019-08-20 19:11:46 -07:00
David Zarzycki
1473e20c15 [Runtime] NFC: Fix -Wgnu-statement-expression warning 2019-08-19 08:10:49 +01:00
David Smith
f559a94f1b Redo CFStringCreateWithBytes shim 2019-08-12 15:15:10 -07:00
David Smith
5a1f068415 Remove dead shim code 2019-08-07 16:50:47 -07:00
swift-ci
b2d83d4c99 Merge pull request #26422 from Catfish-Man/its-about-sending-a-message 2019-08-07 15:57:00 -07:00
Daniel Rodríguez Troitiño
7e332e4437 Merge pull request #23208 from buttaface/droid
[android] Add support for natively building on Android
2019-08-05 08:39:40 -07:00
David Smith
c5fc715746 Reimplement the CF stub system using ObjC. The primary effect of this is to break the link-time dependency on the CF symbols, but it also improves performance a bit.
One additional tweak (setting the scalar-aligned bit on foreign indices) had to be made to avoid a performance regression for long non-ASCII foreign strings.
2019-08-01 19:56:45 -07:00
swift-ci
d5d4ac672b Merge pull request #26338 from xiaobai/debride-option 2019-08-01 18:42:33 -07:00
Butta
796d6ade9a [android] Add support for natively building on Android
Check if building on Android through the ANDROID_DATA environment variable, then set
SWIFT_ANDROID_NATIVE_SYSROOT to the default layout for the Termux app, and key all the
include, lib, and other SDK paths off of that. The system libc and a few other libraries
are linked against from /system/lib[64]. Finally, check if lit is running natively on
Android and don't use adb if so.
2019-07-30 00:38:36 +05:30
David Smith
e7b1107212 Merge pull request #26374 from Catfish-Man/unindex-set
Remove unused Foundation subclasses
2019-07-26 17:09:45 -07:00
David Smith
48266a6f56 Remove unused Foundation subclasses 2019-07-26 14:47:43 -07:00
Alex Langford
a16c71cc86 [CMake] Remove TARGET_LIBRARY option from add_swift_target_library
If you're calling add_swift_target_library, you already know it's a
target library.
2019-07-24 14:55:08 -07:00
Cory Benfield
c2b6c8aa16 Avoid uninitialized "random" bytes on Windows.
__swift_size_t on Windows is a size_t, which makes it potentially a
64-bit integer. ULONG, however, is always a 32-bit integer, and so this
cast risks shrinking the apparent size of the cbBuffer argument to
BCryptGenRandom. The effect of that will be to underfill the buffer,
leaving it full of uninitialized memory that we would treat as random.

The actual risk from this in the current implementation is basically
zero, as user code can only ever invoke this with an argument size of 8.
There's no good reason to leave this sharp edge on the API though.
2019-07-23 17:50:34 +01:00
Puyan Lotfi
6691fda8ec Appending SWIFT_STANDARD_LIBRARY_SWIFT_FLAGS to SWIFT_COMPILE_FLAGS.
There are situations where you want to build against a libc that is out
of tree or that is not the system libc (Or for cross build scenarios).
This is a change for passing the -sdk and include paths for things like
this.
2019-07-01 09:43:47 -07:00
Daniel Rodríguez Troitiño
19a1e2c07d [windows] Fix usage of strtof/d/ld function usage.
The error conditions for underflow or overflow weren't being checked,
which caused problems in some tests.
2019-06-06 13:09:15 -07:00
Saleem Abdulrasool
08dfdf0bff stubs: configure flags based on SDK target
Due to the custom build system implemented in CMake for Swift, we cannot
properly detect the target and set flags appropriately.  Instead, assume
that if the primary variant is an Apple target, that all targets are
Apple variants.  This fixes cross-compilation on macOS.
2019-05-09 08:09:32 -07:00
Mike Ash
3ad6e46930 [Stdlib] Fix warnings about designated initializers in SwiftNativeXXX classes. 2019-05-06 17:15:53 -04:00
Mike Ash
7506e9c4f8 [Stdlib] Make the SwiftNativeNSXXXBase classes gracefully handle being decoded with NSKeyedUnarchiver.
These would never be decoded in normal use, but it's possible to construct an archive that will attempt to decode them. Without this override, that throws an exception or worse.

rdar://problem/48429185
2019-05-01 10:04:14 -04:00
David Smith
584fbfc245 Avoid the overhead of looking up the current CFAllocator in String bridging 2019-04-15 15:28:00 -07:00
Saleem Abdulrasool
8ed5c1a4bc build: introduce and switch to GYB_SOURCES
This avoids us having to pattern match every source file which should
help speed up the CMake generation.  A secondary optimization is
possible with CMake 3.14 which has the ability to remove the last
extension component without having to resort to regular expressions.  It
also helps easily identify the GYB'ed sources.
2019-03-11 13:48:54 -07:00
Saleem Abdulrasool
6da949dda7 stdlib: address a compiler warning
Explicit template specialization may not have a storage class.  Remove
the extraneous storage class.
2019-02-28 23:56:12 -08:00
Saleem Abdulrasool
a227273ff4 stdlib: correct floating point parsing behaviour
These are supposed to be processed in the C locale always, irrespective
of the current locale.  We were not doing this and so we would parse the
value incorrectly.
2019-02-28 23:56:12 -08:00
swift-ci
7ea8768127 Merge pull request #22569 from Catfish-Man/cheating-the-reaper 2019-02-19 21:58:19 -08:00
David Smith
78c45e77b7 Add a flag to allow Swift objects (such as the singleton empty collections) to ignore refcounting 2019-02-19 18:22:39 -08:00
Ben Rimmington
7c65c14df7 [stdlib] Fix memory leaks in readLine()
<https://bugs.swift.org/browse/SR-6127>
2019-02-05 03:43:00 +00:00
Mike Ash
fa5888fb3f [Stdlib][Overlays] Rename various classes to avoid conflicting ObjC names.
Old Swift and new Swift runtimes and overlays need to coexist in the same process. This means there must not be any classes which have the same ObjC runtime name in old and new, because the ObjC runtime doesn't like name collisions.

When possible without breaking source compatibility, classes were renamed in Swift, which results in a different ObjC name.

Public classes were renamed only on the ObjC side using the @_objcRuntimeName attribute.

This is similar to the work done in pull request #19295. That only renamed @objc classes. This renames all of the others, since even pure Swift classes still get an ObjC name.

rdar://problem/46646438
2019-01-15 12:21:20 -05:00
Saleem Abdulrasool
5af85942d8 Merge pull request #21534 from compnerd/tee-ell-ess
runtime: correct `_stdlib_thread_key_create`
2019-01-02 08:21:54 -08:00
Saleem Abdulrasool
1d22ee886c stubs: add workaround for Windows c++ runtime behaviour
The conversion routines in MSVCPRT return "0" for the conversion of
"-inf" et al.  Provde template specializations for `float`, `double`,
and `long double` to use `strtof`, `strtod`, and `strtold` respectively.
This fixes the lossless conversion of floating point constants.
2018-12-27 21:23:01 -08:00
Saleem Abdulrasool
40da65a43f runtime: correct _stdlib_thread_key_create
The mapping of the return value of the `FlsAlloc` was flipped resulting
in the failure of the TLS key creation.  The test suite would fail to
generate the TLS key resulting in failures.
2018-12-23 10:02:49 -08:00
Saleem Abdulrasool
e918218b4c stdlib: make CommandLine inspection work
This implements commandline access on Windows by using the Windows Shell
API to access the commandline information and making it available in
Swift.  This is needed for the correct invocation of the child process
in the unit tests.
2018-12-16 14:04:38 -08:00
David Smith
ba2af14ffd Disable KVO auto-subclassing of internal Swift bridging types 2018-11-28 18:25:00 -08:00
David Smith
8b57921905 Assorted bridging changes:
• Convert _AbstractStringStorage to a protocol, and the free functions used to deduplicate implementations to extensions on that protocol.
• Move 'start' into the abstract type and use that to simplify some code
• Move the ASCII fast path for length into UTF16View.
• Add a weirder but faster way to check which (if any) of our NSString subclasses a given object is, and adopt it
2018-11-28 16:04:34 -08:00
swift-ci
f093925036 Merge pull request #20452 from Catfish-Man/stringtrampolines 2018-11-15 17:55:34 -08:00
David Smith
8bb6b78e36 Use super trampolines to let us override several more NSString methods (-UTF8String, -cStringUsingEncoding:, and -getCString:maxLength:encoding:) for performance 2018-11-15 17:10:51 -08:00
Saleem Abdulrasool
d51c92f181 Merge pull request #20398 from compnerd/winix
stdlib: conditionalise unistd.h
2018-11-12 11:41:53 -08:00
John McCall
3e5165d1ab Change the compiler ABI of keypaths.
Previously, the stdlib provided:

- getters for AnyKeyPath and PartialKeyPath, which have remained;

- a getter for KeyPath, which still exists alongside a new read
  coroutine; and

- a pair of owned mutable addressors that provided modify-like behavior
  for WritableKeyPath and ReferenceWritableKeyPath, which have been
  replaced with modify coroutines and augmented with dedicated setters.

SILGen then uses the most efficient accessor available for the access
it's been asked to do: for example, if it's been asked to produce a
borrowed r-value, it uses the read accessor.

Providing a broad spectrum of accessor functions here seems acceptable
because the code-size hit is fixed-size: we don't need to generate
extra code per storage declaration to support more alternatives for
key paths.

Note that this is just the compiler ABI; the implementation is still
basically what it was.  That means the implementation of the setters
and the read accessor is pretty far from optimal.  But we can improve
the implementation later; we can't improve the ABI.

The coroutine accessors have to be implemented in C++ and used via
hand-rolled declarations in SILGen because it's not currently possible
to declare independent coroutine accessors in Swift.
2018-11-10 02:08:04 -05:00
David Smith
96691208e9 Bridged Strings should have some different/additional overrides for performance 2018-11-08 11:08:03 -08:00