Commit Graph

357 Commits

Author SHA1 Message Date
Alex Langford
3d9a28925b [CMake] Modify swift_install_in_component to support cmake install components
CMake supports the notion of installation components. Right now we have some
custom code for supporting swift components. I think that for installation
purposes, it would be nice to use the CMake component system.

This should be a non-functional change. We should still only be generating
install rules for targets and files in components we want to install, and we
still use the install ninja target to install everything.
2019-04-19 14:06:11 -07:00
Stephen Canon
57a4553832 SE-0246: Protocols and static functions (#23824)
This implements the protocols and static functions proposed in SE-0246, plus some initial test coverage. It also has some rough accompanying cleanup of tgmath. It does not include the globals (on scalars or SIMD types) nor does it deprecate much in tgmath.h.
2019-04-17 23:57:33 +02:00
Zhuowei Zhang
5cdb32f624 [stdlib] fix prototype declaration in RuntimeShims.h
_swift_stdlib_getHardwareConcurrency's declaration isn't a proper prototype:
it's missing `void` inside the brackets.

Found while compiling the stdlib to WebAssembly, which fails with:

Functions with 'no-prototype' attribute must take varargs: _swift_stdlib_getHardwareConcurrency

This shouldn't impact existing platforms.
2019-04-15 19:03:28 -07:00
swift-ci
388c21ac64 Merge pull request #24000 from Catfish-Man/thread-specific-doh 2019-04-15 18:08:06 -07:00
David Smith
584fbfc245 Avoid the overhead of looking up the current CFAllocator in String bridging 2019-04-15 15:28:00 -07:00
Ross Bayer
1a31c3ad9c [Build System: CMake] Install the Swift shims in the stdlib component. 2019-04-09 13:00:26 -07:00
Stephen Canon
c5e3f85378 Revert SE-0246 (#23800)
* Revert "Merge pull request #23791 from compnerd/you-know-nothing-clang"

This reverts commit 5150981150, reversing
changes made to 8fc305c03e.

* Revert "Merge pull request #23780 from compnerd/math-is-terrible"

This reverts commit 2d7fedd25f, reversing
changes made to 0205150b8f.

* Revert "Merge pull request #23140 from stephentyrone/mafs"

This reverts commit 777750dc51, reversing
changes made to 0c8920e747.
2019-04-04 19:35:25 -04:00
Saleem Abdulrasool
c697ddd42e Shims: include math.h on Windows
Since we use `_hypotf` on Windows rather than `__builtin_hyptof` due to
a bug in LLVM with the TLI lowering to the wrong builtin, include the
math header to get the proper declaration.
2019-04-04 09:29:58 -07:00
Saleem Abdulrasool
af6d9e3fc3 Shims: use _hypotf on Windows rather than __builtin_hypot
Unfortunately, `hypotf` is an inline in MSVCRT which forwards to
`_hypotf`.  This repairs the Windows build.
2019-04-03 16:11:42 -07:00
Steve (Numerics) Canon
3fda509805 Implementation of ElementaryFunctions / Real protocols.
This commit implements SE-0246, by adding conformance to Real to the Float, CGFloat, Double, and Float80 types, implemented either in terms of the system's C math library, existing standard library functionality, or LLVM intrinsics. It includes basic test coverage for these new functions, and deprecates and obsoletes *some* existing functionality in the Platform overlay. We still need to make a decision about how to handle the remaining "tgmath" functions, because obsoleting them is technically a source-breaking change (if users have unqualified names like "exp(1)", it's fine, but it would break users who have used qualified names like "Darwin.exp(1)".)
2019-04-02 18:49:31 -04:00
Steve (Numerics) Canon
2f7435da7d First non-intrinsic functions. 2019-04-02 18:48:08 -04:00
Saleem Abdulrasool
d26ca1cd3c SwiftShims: update shims copying logic
Update the shims logic to make sure that it works for Xcode as well.
Rather than adding additional rules, just simplify it down to the one
canonical way in modern LLVM land.  The headers are always installed to
the LLVM_LIBRARY_OUTPUT_INTDIR which will be defined for us in both the
standalone and unified build mode.  This allows us to just remove all
the work to find the headers since they will always be in one location.
2019-02-28 17:11:30 -08:00
Saleem Abdulrasool
0983ea66ae stdlib: use placement new on Windows, disable asserts
The assertions here are based around the idea that `std::atomic` is
trivially constructible which is not a guarantee that the standard fully
provides.  The default initialization of the `std::atomic` type may
leave it in an undetermined state.  These were caught using the Visual
C++ preview runtime.

Ideally, the object constructor would use a placement new operator.
However, prior to C++17, the C++ standard mandated that there be a
NULL pointer check in the placement new operator.  This is something
which is no longer the case with C++17.  Switch to the placement new
operator for C++17 and newer and enable that codepath for Windows as
well (which seemingly elides the null-pointer check with clang-cl).
2019-02-27 15:29:06 -08:00
Saleem Abdulrasool
90fd8a5d34 stdlib: define and use SWIFT_{,UN}LIKELY
Rather than directly using the extension `__builtin_expect`, use a macro
to permit the removal of the builtin on compilers which do not support
this (i.e. cl).  This permits us to build the swift compiler with MSVC
again.
2019-02-24 13:58:18 -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
Saleem Abdulrasool
7bb6185bbf Shims: make the __swift_ssize_t handling more portable
Unfortunately, `cl` does not support C11.  Guard the `_Generic` approach and in
C++ mode use `std::make_signed`.  Thanks to Jordan Rose for the reminder about
the type_traits helper!
2019-01-17 14:53:42 -08:00
Joe Groff
9669c3a703 KeyPaths: Don't relative-reference selector refs.
ld64 doesn't like this. Instead, generate a stub function to grab the instantiated selector. Fixes rdar://problem/47184763.
2019-01-10 14:32:50 -08:00
Jordan Rose
aea1ef8175 Move API notes out of the arch-specific subdirectories in lib/swift/ (#21690)
They're all the same anyway, and no longer even need to be compiled,
just copied in as text.

And drastically simplify how we "generate" them. Instead of attaching
their build jobs to the appropriate overlays, if present, "just" have
one job to copy them all and attach it to the Darwin overlay. That's
what we do for the overlay shim headers, and it's good enough.
(Eventually we want to get out of the business of shipping them
altogether.)

This does have the same flaw as the shim headers: if you /just/ change
API notes, the corresponding overlay does not get rebuilt. You have to
touch that too. But in practice that'll happen most of the time
anyway.

Part of rdar://problem/43545560
2019-01-09 14:06:21 -08:00
Andrew Trick
0b5fa792e1 Force manual allocation (via Unsafe*Pointer) to use >= 16 alignment.
This fixes the Windows platform, where the aligned allocation path is
not malloc-compatible. It won't have any observable difference on
Darwin or Linux, aside from manually allocated memory on Linux now
being consistently 16-byte aligned (heap objects will still be 8-byte
aligned on Linux).

It is unfortunate that we can't guarantee Swift-allocated memory via
Unsafe*Pointer is malloc compatible on Windows. It would have been
nice for that to be a cross platform guarantee since it's normal to
allocate in C and deallocate in Swift or vice-versa. Now we have to
tell developers to always use _aligned_malloc/_aligned_free when
transitioning between Swift/C if they expect their code to work on
Windows.

Even though this fix isn't required today on Darwin/Linux, it makes
good sense to guarantee that the allocation/deallocation paths are
consistent.

This is done by specifying a constant that stdlib can use to round up
alignment, _swift_MinAllocationAlignment. The runtime asserts that
this constant is greater than MALLOC_ALIGN_MASK for all platforms.
This way, manually allocated buffers will always use the aligned
allocation path. If users specify an alignment less than m

round up so users don't need
to pass the same alignment to deallocate the buffer). This constant
does not need to be ABI.

Alternatives are:

1. Require users of Unsafe*Pointer to specify the same alignment
   during deallocation. This is obviously madness.

2. Introduce new runtime entry points:
   swift_alignedAlloc/swift_alignedDealloc, introduce corresponding
   new builtins, and have Unsafe*Pointer always call those. This would
   make the runtime API a little more obvious but would introduce
   complexity in other areas of the compiler and it doesn't have any
   other significant benefit. Less than 16-byte alignment of manually
   allocated buffers on Linux is a non-goal.
2019-01-03 12:35:51 -08:00
Saleem Abdulrasool
8d08d5cd70 Merge pull request #21552 from compnerd/circular-logic
SwiftShims: break circular dependency in MSVCRT
2019-01-02 08:20:36 -08:00
Saleem Abdulrasool
65da2148e1 Merge pull request #21561 from compnerd/canonical-path-separator
build: convert paths to CMake paths before use
2019-01-02 08:19:56 -08:00
Saleem Abdulrasool
509060c78a build: convert paths to CMake paths before use
This converts the path separators to the CMake way.  This is primarily
important for Windows where the path separator is \ rather than /.  This
conversion allows the specification of the path in the proper windows
path style.
2018-12-30 12:27:16 -08:00
Saleem Abdulrasool
19a73ad135 SwiftShims: always define TARGET_IS_SIMULATOR
This is used as a conditional guard rather than checked for a
definition.  Ensure that a value is always defined.  Silences a -Wundef
warning.  NFC
2018-12-30 10:28:37 -08:00
Saleem Abdulrasool
39621a51e7 SwiftShims: break circular dependency in MSVCRT
The inclusion of Windows.h would cause the Shims to depend on WinSDK, which
would in turn depend on MSVCRT.  However, the SwiftShims are using in MSVCRT
causing a circular dependency between WinSDK and MSVCRT preventing a clean build
from succeeding.  Break the dependency by only including libc headers in the
shims header.
2018-12-26 14:11:04 -08:00
John McCall
6936ce7d90 Future-proof the ARM64 ABI by not reserving the entire top byte.
Targets that want to use armv8.5a memory tagging will need this.
Hopefully nobody comes up with a brilliant reason they need to use
anything else.
2018-12-20 00:30:28 -05:00
John McCall
190943ea05 Revert "Future-proof the ARM64 ABI by not reserving the entire top byte."
This reverts commit d44851304b.
This patch does not work with our current assumptions about BridgeObject.
2018-12-12 12:01:22 -05:00
Saleem Abdulrasool
41d9c2cc59 stdlib: restructure for OS family layout of SDK overlay
The SDK directory is now confusing as the Windows target also has a SDK
overlay.  In order to make this more uniform, move the SDK directory to
Darwin which covers the fact that this covers the XNU family of OSes.
The Windows directory contains the SDK overlay for the Windows target.
2018-12-06 11:32:05 -08:00
John McCall
d44851304b Future-proof the ARM64 ABI by not reserving the entire top byte.
Targets that want to use armv8.5a memory tagging will need this.
Hopefully nobody comes up with a brilliant reason they need to use
anything else.
2018-12-04 01:43:08 -05:00
Xiaodi Wu
f9e8b6363e [gardening] Make edits for stdlib style [NFC] 2018-12-02 15:26:35 -05:00
Harlan Haskins
01bfdc162e Merge pull request #20835 from nordicio/stdlib-NSStringGetCString-nullability
[stdlib] adds nullability type specifier to NSStringGetCStringTrampoline
2018-11-30 11:24:55 -08:00
swift-ci
e012655e57 Merge pull request #20623 from Catfish-Man/bridgecleanup 2018-11-28 17:03:49 -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
Andreas Jönsson
452230ae33 [stdlib] adds nullability type specifier to NSStringGetCStringTrampoline 2018-11-28 21:08:58 +01:00
Michael Ilseman
9a96666ef8 [ABI] Define generic 64-bit address space and spare bits.
Define a generic 64-bit address space ABI which is capped at 56
bits. Switch ppc64 and s390x over to it.

This also allows String to have (roughly) the same representation
across 64-bit platforms.
2018-11-28 09:48:03 -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
David Smith
96691208e9 Bridged Strings should have some different/additional overrides for performance 2018-11-08 11:08:03 -08:00
Mike Ash
66563ed6c5 Merge pull request #20372 from mikeash/remove-swiftprivate-swiftdarwin-dependency
[Stdlib] Remove SwiftPrivate's dependency on Darwin.
2018-11-07 11:04:52 -05:00
Daniel Rodríguez Troitiño
15c6b378ac [android] Fix function signature to match usage in libdispatch.
The function signature in libdispatch doesn't use a dispatch_function_t
so compiling for Android should have fail, since the Swift code uses the
function without any parameters.

See
https://github.com/apple/swift-corelibs-libdispatch/blob/master/private/queue_private.h#L345
in which the function is defined with the signatured used in this
change.
2018-11-06 17:34:30 -08:00
Mike Ash
45693049bf [Stdlib] Remove SwiftPrivate's dependency on Darwin.
Revert #20194, which seems to be more trouble than it's worth. Instead, move the functions that SwiftPrivate needs back into LibcShims.h/cpp as SPI.

rdar://problem/45817565
2018-11-06 17:41:56 -05:00
Joe Groff
65a4531467 IRGen/Runtime: Make key path pattern format true-const.
Use relative references instead of pointers so that the pattern can be true-const. Instead of trying
to instantiate a constant key path literal in-place, point to a cache variable that we can store
a pointer to the shared instance into when instantiated. Now that the pattern format has diverged
significantly from the instance format, simplify and refactor the instantiation code using a walker
for the pattern format instead of trying to reuse the code for working with instantiated instances.
rdar://problem/42674576
2018-11-05 12:30:49 -08:00
rposts
ab2dd1098e Towards s390x support (#19822)
* Towards s390x support

* Fix case index on Big Endian
2018-10-29 09:37:02 -07:00
Saleem Abdulrasool
1e89bf01ea shims: adjust dispatch shim for LLP64
Adjust the block type to use `intptr_t` which is a register-wide integral type.
This allows the same declaration to be portable across LP64 and LLP64
environents.
2018-10-18 14:03:38 -07:00
Arnold Schwaighofer
42af92112c Make _swift_dispatch_block_create_with_qos_class NS_RETURNS_RETAINED
Otherwise, we return in the autorelease pool and this can keep the block
alive longer than a surrounding withoutActuallyEscaping expression
causing verification failures.

rdar://45226617
SR-8955
2018-10-12 10:53:59 -07:00
Mike Ash
794ff31d73 Merge pull request #19794 from mikeash/fix-instruments-and-retain-counts
[Runtime] Fix swift_retainCount for deiniting objects and BridgeObject tagged values. Make swift_bridgeObjectRetain/Release bail out early for tagged values.
2018-10-11 14:32:43 -04:00
Mike Ash
1afd079b78 [Runtime] Fix swift_retainCount for deiniting objects and BridgeObject tagged values. Make swift_bridgeObjectRetain/Release bail out early for tagged values.
The Allocations Instrument overrides swift_retain with a function that records the retain count by calling swift_retainCount. Its assert for bits.getIsDeiniting() is incorrect in that case, so remove it.

The recent change to ObjC tagged pointer bits on x86-64 also caused the various bridgeObjectRetain/Release functions to call through to swift_retain for BridgeObject tagged values on Mac. swift_retain ignored those values so there was no functional change, except when Instruments overrode it and passed them to swift_retainCount, which tried to dereference them and crashed. Modify bridgeObjectRetain/Release to bail out early again. Also modify swift_retainCount to ignore those values in case anything else expects retainCount to work on any pointer swift_retain accepts.

rdar://problem/45102538
2018-10-09 10:04:06 -04:00
Saleem Abdulrasool
66a84617c7 Merge pull request #19770 from compnerd/bionic-malloc
stdlib: correct declaration for `malloc_usable_size` on android
2018-10-08 15:19:34 -07:00
Saleem Abdulrasool
04185aacdf stdlib: correct declaration for malloc_usable_size on android
`malloc_usable_size` is provided on Android with API Level 17 or newer.
However, the signature between bionic and glibc is slightly different, with
android marking the parameter as `const`.  This results in a type mismatch error
when building the standard library for android.  Adjust it to match the target
system.
2018-10-08 11:59:57 -07:00
Saleem Abdulrasool
92ef7e46dc stdlib: use some clever C11 to define ssize_t
`ssize_t` is not universally available as it is not a standard type.
However, we require clang to build the runtime due to custom calling
convention support.  As a result, we know that the compiler will support
the `_Generic` keyword from the C11 standard.  Use this with an
expansion to map the type appropriately for all targets.  This avoids
having to have a sanity check in the runtime that the type definition
matches the underlying system.
2018-10-08 11:49:02 -07:00