Commit Graph

451 Commits

Author SHA1 Message Date
zoecarver
b2b7f7b853 [cxx-interop] Use user defined copy constructor to copy C++ objects.
If a user-defined copy constructor exists, use that to copy imported C++
types.
2021-02-03 14:34:07 -08:00
3405691582
4f24d895fc [stdlib] Use Clang type macros on OpenBSD.
Per the code comment, stdint.h is provided by clang and therefore
conflicts with Glibc; additionally, clang defines some particular
type macros for making the appropriate `typedef`s.

OpenBSD uses clang-10, so we can also use these types on this platform.
This also addresses a test case that has gone awry.
2021-01-19 21:58:29 -05:00
Evan
4f708fad7e Merge pull request #35215 from etcwilde/ewilde/async-main
Adding async-main support

Resolves: rdar://71828636
2021-01-15 10:57:14 -08:00
Evan Wilde
6b16657922 Explode on uncaught error thrown in main
This patch has two desirable effects for the price of one.
 1. An uncaught error thrown from main will now explode
 2. Move us off of using runAsyncAndBlock

The issue with runAsyncAndBlock is that it blocks the main thread
outright. UI and the main actor need to run on the main thread or bad
things happen, so blocking the main thread results in a bad day for
them.

Instead, we're using CFRunLoopRun to run the core-foundation run loop on
the main thread, or, dispatch_main if CFRunLoopRun isn't available.
The issue with just using dispatch_main is that it doesn't actually
guarantee that it will run the tasks on the main thread either, just
that it clears the main queue. We don't want to require everything that
uses concurrency to have to include CoreFoundation either, but dispatch
is already required, which supplies dispatch_main, which just empties
out the main queue.
2021-01-13 15:49:28 -08:00
Brent Royal-Gordon
e3e434f7bf Correct nullability of free() redeclaration
In the new clang, this declaration ends up influencing the redeclaration chain, altering the nullability of the `free(_:)` function imported into Swift.

Fixes rdar://71269128. Note that tests may fail unless a clean build is performed.
2021-01-12 17:31:45 -08:00
swift-ci
186717f583 Merge pull request #34628 from buttaface/native-clang 2021-01-06 15:54:22 -08:00
Mike Ash
6efd52dd0a Merge pull request #35122 from mikeash/refcount-always-inline
[Runtime] Add SWIFT_ALWAYS_INLINE to various refcounting helpers.
2020-12-21 10:32:20 -05:00
Saleem Abdulrasool
10b8ce596b shims: invert the condition and prefer the clang path
Because the shims are generally meant for the standard library build,
which requires clang, we can default to using the compiler vended
information for the types.
2020-12-17 18:06:28 -08:00
Mike Ash
405452198f [Runtime] Add SWIFT_ALWAYS_INLINE to various refcounting helpers.
Clang has decided not to inline certain functions on the refcounting fast paths, so we need to convince it otherwise.

rdar://problem/72150908
2020-12-16 10:27:48 -05:00
Butta
c74884ce30 [build] Make it possible to actually build the stdlib with a prebuilt clang 2020-12-13 18:22:33 +05:30
Saleem Abdulrasool
4cf189f0ae shims: add a workaround for sqrtf on Windows x86
When building for Windows x86, we have a few conspiring issues to
contend with.  `__builtin_sqrtf` is treated by clang as a `__builtin_`
prefixed libm call.  On windows, there is no libm, with the role being
taken up by ucrt.  However, on 32-bit x86 targets, ucrt does not provide
an implementation of `sqrtf` instead defining it inline as a wrapper
which widens the argument to a double precision and invokes `sqrt`, the
result of which is narrowed to the result.  This function is locally
defined and expected to be inlined and no out-of-line definition is
provided by ucrt that can be referenced.

Adjusting the shims to use the intrinsics would be the next option
(thanks @stephentyrone!) which would work.  However, when building the
standard library, we need to combine the system headers which results in
the use of the MSVCRT headers for `xmmintrin.h` rather than clang.  As a
result, we cannot directly use the intrinsics.

Opt to instead open-code the intrinsic path by using the compiler
builtin for sqrt.  This both yields the optimal implementation and
avoids providing an additional entry point in the runtime.  It also has
code size benefits.

A special thanks to @stephentyrone for all the discussion and help with
this!
2020-12-11 13:44:25 -08:00
Richard Wei
de2dbe57ed [AutoDiff] Bump-pointer allocate pullback structs in loops. (#34886)
In derivatives of loops, no longer allocate boxes for indirect case payloads. Instead, use a custom pullback context in the runtime which contains a bump-pointer allocator.

When a function contains a differentiated loop, the closure context is a `Builtin.NativeObject`, which contains a `swift::AutoDiffLinearMapContext` and a tail-allocated top-level linear map struct (which represents the linear map struct that was previously directly partial-applied into the pullback). In branching trace enums, the payloads of previously indirect cases will be allocated by `swift::AutoDiffLinearMapContext::allocate` and stored as a `Builtin.RawPointer`.
2020-11-30 15:49:38 -08:00
Parker Schuh
4e39e59a8a Add a field reflection function that constructs keypaths. (#34815)
While the existing _forEachField in ReflectionMirror.swift
already gives the offsets and types for each field, this isn't
enough information to construct a keypath for that field in
order to modify it.

For reference, this should be sufficent to implement the features
described here: (https://forums.swift.org/t/storedpropertyiterable/19218/62)
purely at runtime without any derived conformances for many types.

Note: Since there isn't enough reflection information for
`.mutatingGetSet` fields, this means that we're not able to support
reflecting certain types of fields (functions, nonfinal class fields,
etc). Whether this is an error or not is controlled by the `.ignoreUnknown`
option.
2020-11-30 09:17:23 -08:00
Eric Miotto
0fb40805d5 Fix destination for clang-builtin-headers-in-clang-resource-dir (#34364)
`LLVM_LIBRARY_OUTPUT_INTDIR` already points to the `lib` subdirectory of
LLVM build folder.

Addresses rdar://70486284
2020-10-23 07:12:47 -07:00
tbkka
5d30503894 When parsing floating-point from String, underflow to 0, overflow to infinity (#34339)
Previously, overflow and underflow both caused this to return `nil`, which causes several problems:
* It does not distinguish between a large but valid input and a malformed input.  `Float("3.402824e+38")` is perfectly well-formed but returns nil
* It differs from how the compiler handles literals.  As a result, `Float(3.402824e+38)` is very different from `Float("3.402824e+38")`
* It's inconsistent with Foundation Scanner()
* It's inconsistent with other programming languages

This is exactly the same as #25313

Fixes rdar://problem/36990878
2020-10-19 09:44:57 -04:00
John McCall
8ac4362754 Implement a simple library for task cancellation and status management.
There are things about this that I'm far from sold on.  In
particular, I'm concerned that in order to implement escalation
correctly, we're going to have to add a status record for the
fact that the task is being executed, which means we're going
to have to potentially wait to acquire the status lock; overall,
that means making an extra runtime function call and doing some
atomics whenever we resume or suspend a task, which is an
uncomfortable amount of overhead.

The testing here is pretty grossly inadequate, but I wanted to
lay down the groundwork here.
2020-10-15 00:36:36 -04:00
Zoe Carver
722cc755f8 [cxx-interop] Cast data to the correct type. (#34266)
The implicit conversions are OK in C but C++ will error. To make this
header valid in both C and C++ we should just always cast.
2020-10-14 09:29:32 -07:00
John McCall
4481e3bf35 Generalize SWIFT_RUNTIME_EXPORT to work for other runtime libraries.
I intend to use this in the _Concurrency library.
2020-10-09 23:51:24 -04:00
Eric Miotto
a482c9c646 [build] Remove FILES_MATCHING from SwiftShims/CMakeLists.txt (#34241)
This is not an ideal solution, as we are likely installing more that we
should with those instructions -- but it would unblock quickly the
Source Compatibility suite.

Addresses rdar://70040046
2020-10-09 13:52:08 -07:00
Cassie Jones
20995ae0bb [build] Add FILES_MATCHING to CMakeLists.txt
The bare "PATTERN" argument by default does nothing, you need either
"EXCLUDE" or "FILES_MATCHING" to make it do something. This likely
wasn't previously a problem because clang is only installing headers,
but it should be fixed for robustness.
2020-10-05 15:07:02 -04:00
Karoy Lorentey
c8523e59e4 [shims] Add AppKit overlay shims 2020-09-10 18:53:26 -07:00
Mike Ash
937e141316 Merge pull request #28968 from 3405691582/environ_llvm_assert
[stdlib] Fix a LLVM assert on *BSD.
2020-08-15 13:41:49 -04:00
Dario Rexin
7e60a73335 Merge pull request #33168 from drexin/wip-fix-resource-folder
Properly compute resource folder when linking statically
2020-08-04 12:52:38 -07:00
Dario Rexin
0850436d9f Properly compute resource folder when linking statically
- deduplicate the logic to compute the resource folder
- install headers and module files in shared and static resource folders
- forward -static flag when calling swiftc with -print-target-info
2020-07-30 15:07:03 -07:00
Doug Gregor
9b0266cf6a [Concurrency] Stub out an experimental concurrency support library.
The experimental concurrency model will require a supporting runtime
and possibly end-user-visible library constructs. Introduce a stub of
such a library, enabled by a new `build-script` option
`--enable-experimental-concurrency`, so we have a place to put this
work.
2020-07-29 16:32:27 -07:00
zoecarver
3e4ddb13d6 [NFC] Remove __swift_mode_t.
Removes the "__swift_mode_t" type from SwiftShims. This type is no longer used anywhere.
2020-07-10 08:38:10 -07:00
Karoy Lorentey
d966dbb511 Merge pull request #32676 from lorentey/simplify-checkclass
[Foundation] Update & simplify class name stability check
2020-07-09 18:50:25 -07:00
Zoe Carver
7eff49c1b6 [cxx-interop] [nfc] Remove swift namespace from SwiftShims in C++ mode. (#32715)
Most SwiftShims were put in the swift namespace in C++ mode which broke certain things when importing them in a swift file in C++ mode. This was OK when they were only imported as part of the swift runtime but, now they are used in C++ mode both in the swift runtime and when C++ interop is enabled.

This broke when C++ interop was enabled because the `Swift` module contains references to symbols in the SwiftShims headers which are built without C++ interop enabled (no "swift" namespace). But, when C++ interop is enabled, the SwiftShims headers would put everything in the swift namespace meaning the symbols couldn't be found in the global namespace. Then, the compiler would error when trying to deserialize the Swift module.
2020-07-08 08:43:26 -07:00
Karoy Lorentey
f44cbe4697 [Foundation] Update & simplify class name stability check
Move the ObjC class name stability check logic to the Swift runtime, exposing it as a new SPI called _swift_isObjCTypeNameSerializable.

Update the reporting logic. The ObjC names of generic classes are considered stable now, but private classes and classes defined in function bodies or other anonymous contexts are unstable by design.

On the overlay side, rewrite the check’s implementation in Swift and considerably simplify it.

rdar://57809977
2020-07-02 19:32:22 -07:00
Augusto Noronha
5cee6f3d6a Unify 'MetadataSections' data structure, as well as common ELF and COFF procedures 2020-06-29 19:35:44 -03:00
3405691582
a6b0e926fd [stdlib] Both FreeBSD and OpenBSD use environ.
However, when building Glibc with assertions enabled, LLVM asserts in
CodeGenModule::EmitGlobal with "Cannot emit local var decl as global".
This assert is _probably_ wrong in LLVM because the local extern
reference isn't being handled properly and needs to be addressed there.
We could move the declaration to global scope, but that is not ideal
because it makes the pointer declaration visible to Swift.

OpenBSD needs to implement _swift_stdlib_getEnviron regardless, so
let's do so.
2020-06-24 18:42:59 -04:00
Augusto Noronha
8c8360b660 Move 'MetadataSections' from 'ImageInspectionElf.h' to SwiftShims 2020-06-22 16:12:01 -03:00
3405691582
9cc07c7a4a [test][stdlib] Define stdio stubs for OpenBSD.
These are macros on OpenBSD, which don't get imported to an equivalent
symbol in Swift.
2020-06-11 20:17:35 -04:00
Erik Eckstein
3bfebf10f7 runtime lib: a mechanism to set an "immutable" flag on an object for COW buffer runtime checking.
In an assert built of the library, store an extra boolean flag (isImmutable) in the object side-buffer table.
This flag can be set and get by the Array implementation to sanity check the immutability status of the buffer object.
2020-06-08 15:01:29 +02:00
Saleem Abdulrasool
4fc0419e1c Merge pull request #31634 from compnerd/no-support-structure
runtime: remove `llvm/Support` header usage
2020-05-09 11:27:43 -07:00
Saleem Abdulrasool
135f3489b3 runtime: add and switch to SWIFT_NODISCARD (NFC)
This duplicates and converts the runtime to use `SWIFT_NODISCARD` rather
than LLVM's LLVM_NODISCARD.
2020-05-07 14:17:29 -07:00
Saleem Abdulrasool
ec31346c4b Merge pull request #31629 from compnerd/fall-into-the-gap
runtime: add and switch to `SWIFT_FALLTHROUGH` (NFC)
2020-05-07 14:16:27 -07:00
Saleem Abdulrasool
04eeff5b8d runtime: remove llvm/Support header usage
This reduces the dependency on `LLVMSupport`.  This is the first step
towards helping move towards a local fork of the LLVM ADT to ensure that
static linking of the Swift runtime and core library does not result in
ODR violations.
2020-05-07 13:36:13 -07:00
Saleem Abdulrasool
a7415423e6 runtime: add and switch to SWIFT_FALLTHROUGH (NFC)
This duplicates and switches the uses of `LLVM_FALLTHROUGH` to a local
macro for the same annotation.
2020-05-07 11:50:22 -07:00
Saleem Abdulrasool
e0b0d20cd8 runtime: add and switch to SWIFT_NORETURN (NFC)
Remove the use of the `LLVM_ATTRIBUTE_NORETURN` to trim dependencies on
LLVMSupport.
2020-05-07 09:22:39 -07:00
Saleem Abdulrasool
b74f42602a runtime: add and switch to SWIFT_USED (NFC)
This further trims dependencies to LLVMSupport by introducing the
equivalent `SWIFT_USED` macro.
2020-05-06 21:19:14 -07:00
Saleem Abdulrasool
f465ec0345 runtime: add and switch to SWIFT_NOINLINE (NFC)
This switches the `LLVM_ATTRIBUTE_NOINLINE` to a local copy which is
namespaced in Swift.
2020-05-06 14:07:20 -07:00
Saleem Abdulrasool
9731704cc7 runtime: replace LLVM_LIBRARY_VISIBILITY with SWIFT_LIBRARY_VISIBILITY (NFC)
This replaces `LLVM_LIBRARY_VISIBILITY` with `SWIFT_LIBRARY_VISIBILTIY`
througout the runtime.  The purpose of this attribution is unclear -
building with `-fvisibility=hidden` would accomplish this.  This is an
entirely mechanical change replacing the macro with the Swift namespaced
variant instead.
2020-05-06 08:30:17 -07:00
Saleem Abdulrasool
c29c42f003 Merge pull request #31560 from compnerd/un-inlined-inlining
runtime: replace `LLVM_ATTRIBUTE_ALWAYS_INLINE` with `SWIFT_INLINE` (…
2020-05-06 08:00:30 -07:00
Saleem Abdulrasool
61ddd09199 runtime: replace LLVM_ATTRIBUTE_ALWAYS_INLINE with SWIFT_INLINE (NFC)
This replaces the `LLVM_ATTRIBUTE_ALWAYS_INLINE` with `SWIFT_INLINE`
which is equivalent but namespaced to Swift instead.  This reduces the
unnecessary reliance on LLVMSupport.
2020-05-05 11:19:15 -07:00
Saleem Abdulrasool
5408593967 Runtime: simplify SWIFT_LIBRARY_VISIBILITY
This removes the GNUC version check as the runtime does require ABI
support which is not present in GCC.  Remove the unnecessary check and
simplify the condition by checking the file format that the visibility
attribute is being applied to and limit it to the ones supporting it.
2020-05-05 09:30:23 -07:00
Joe Groff
9cdfb0edfc Merge pull request #30560 from 3405691582/OpenBSD_StringStorage_AvoidMallocSize
[stdlib] Avoid malloc_size on OpenBSD.
2020-04-29 11:02:06 -07:00
Karoy Lorentey
057b27b31c [shims] Re-add Foundation shims removed in #28918
The current version of the Foundation overlay doesn’t use these, but we should still keep them in case a toolchain snapshot build picks up on overlay module from one of the SDKs in Xcode 11.

rdar://62339802
2020-04-28 15:44:33 -07:00
3405691582
7830028f55 [stdlib] Avoid malloc_size on OpenBSD.
malloc introspection is a platform feature that is unavailable on
OpenBSD. There is no workaround for the feature, so we have to assume
that allocations succeed in allocating exactly the amount of memory
requested, and nothing more.

Here a new mallocSize shim is introduced so the feature check for malloc
introspection is pushed to the shims, rather than using os checks
directly from Swift. Not every use of malloc_size has been converted
yet; ManagedBuffer.swift still remains. However, this module requires
special care to fix, which will be done separately.
2020-04-27 15:52:37 -04:00
Arnold Schwaighofer
048e78ef79 Revert "Merge pull request #30024 from Azoy/calling-metadata-accessor-from-swift!"
This reverts commit 5fd6e98b2f, reversing
changes made to 3aee49d9d0.

Revert "XFAIL test/Interpreter/metadata_access.swift on arm64e"

This reverts commit 8fe216b004.

Revert "XFAIl test on os stdlib bots"

This reverts commit aea5fa4842.
2020-04-24 12:28:24 -07:00