Commit Graph

173 Commits

Author SHA1 Message Date
Evan Wilde
e160e23dde [CMake] Connecting more flags and options
Making a more in-depth pass over the definition macros and flags in
SwiftSource.cmake _add_target_variant_swift_compile_flags.
These are only flags that actually matter for swiftCore though. This
does not include concurrency flags.
2024-11-12 11:31:10 -08:00
David Smith
de50b0a387 Eliminate pointer auth overhead in interposable refcount support (#71448)
Fixes rdar://122595662
2024-02-15 18:21:34 -08:00
Mike Ash
6606850232 [Runtime] Add option to remove override point for retain/release.
Add a `SWIFT_STDLIB_OVERRIDABLE_RETAIN_RELEASE` CMake option. When set to true, swift_retain/release and the other functions in InstrumentsSupport.h can be overridden by setting the appropriate global function pointer, as is already the case. When set to false, those function pointers are removed and the functions always go into the default implementation.

Set `SWIFT_STDLIB_OVERRIDABLE_RETAIN_RELEASE` to false when building the minimal stdlib, and set it to true otherwise by default.

rdar://115987924
2023-10-31 15:26:01 -04:00
Kuba (Brecka) Mracek
fbaff97c1a Don't #include <thread> in HeapObject.cpp, it's not used (#66059) 2023-05-22 20:38:53 -07:00
Mike Ash
dc3416bd72 [Runtime] Improve wording of deinit escape warning.
Describe in more detail how an object can end up with a non-zero refcount on deallocation, and the consequences.

rdar://109045333
2023-05-17 11:01:32 -04:00
swift-ci
8db4b9fb55 Merge pull request #65776 from mikeash/dealloc-partial-class-instance-setclass-readonly
[Runtime] Immediate release and return when destroying partial instance of pure ObjC class.
2023-05-09 19:08:22 -07:00
Mike Ash
3a396af086 [Runtime] Immediate release and return when destroying partial instance of pure ObjC class.
Make swift_deallocPartialClassInstance check if the object's class is a pure ObjC class, in which case there are no ivar destroyers and we can just return immediately.

It's possible for an allocWithZone: override to cause self to be a special object constructed in read-only memory. swift_deallocPartialClassInstance calls object_setClass to avoid running the dealloc method of any Swift subclasses, but this call crashes if self is read-only. It's unnecessary when the object's class is pure ObjC and therefore there are no Swift subclasses, so just skip it entirely.

rdar://107756747
2023-05-09 16:47:47 -04:00
Alastair Houghton
18a753cd87 [Runtime] Print type names in escape-from-deinit messages.
In addition to giving the object's address, we can print the name of its
type (since the object is still live at this point).

rdar://108882759
2023-05-05 11:51:49 +01:00
Dario Rexin
a8d4d57f11 [IRGen] Generate compressed representation of value witnesses (#63813)
rdar://105837040

* WIP: Store layout string in type metadata

* WIP: More cases working

* WIP: Layout strings almost working

* Add layout string pointer to struct metadata

* Fetch bytecode layout strings from metadata in runtime

* More efficient bytecode layout

* Add support for interpreted generics in layout strings

* Layout string instantiation, take and more

* Remove duplicate information from layout strings

* Include size of previous object in next objects offset to reduce number of increments at runtime

* Add support for existentials

* Build type layout strings with StructBuilder to support target sizes and metadata pointers

* Add support for resilient types

* Properly cache layout strings in compiler

* Generic resilient types working

* Non-generic resilient types working

* Instantiate resilient type in layout when possible

* Fix a few issues around alignment and signing

* Disable generics, fix static alignment

* Fix MultiPayloadEnum size when no extra tag is necessary

* Fixes after rebase

* Cleanup

* Fix most tests

* Fix objcImplementattion and non-Darwin builds

* Fix BytecodeLayouts on non-Darwin

* Fix Linux build

* Fix sizes in linux tests

* Sign layout string pointers

* Use nullptr instead of debug value
2023-02-24 15:40:28 -08:00
Julian Lettner
a60d354ef5 [SUA] Add test for allocation of classes without metadata (#63759)
Add test for allocating classes with pruned metadata and refactor
`computeMallocTypeSummary()` to make it easier to understand:

* Use early returns for error (metadata absent) conditions
* Remove reliance on implicit dependency---having a type descriptor
  currently implies that there is also class metadata---in case this
  ever changes

Co-authored-by: Julian Lettner <julian.lettner@apple.com>
2023-02-20 14:18:31 -08:00
Julian Lettner
ba3973bead [SUA] Do not access the field descriptor when absent (#63663)
Radar-Id: rdar://105461946

Co-authored-by: Julian Lettner <julian.lettner@apple.com>
2023-02-15 10:07:59 -08:00
Julian Lettner
5ad0331e55 Adopt malloc_type for allocating Swift objects from runtime (#63226)
Adopt malloc_type for allocating Swift objects from runtime

Radar-Id: rdar://98998492
2023-02-02 17:08:41 -08:00
Mike Ash
108f7805e5 [Runtime] Fatal error if self escapes from deinit.
When deallocating a class instance, we check the retain count of the instance and error if it's greater than 1.

Self is allowed to be temporarily passed to other code from deinit, but there's no way to extend the lifetime of the object. Retaining it no longer extensd the lifetime. If self escapes from deinit, the result is a dangling pointer and eventual crash.

Instead of crashing randomly due to a dangling pointer, crash deliberately when destroying an object that has escaped.

rdar://93848484
2022-12-07 12:42:41 -05:00
Mike Ash
b677b5676a [Runtime] Add register-specific entrypoints for retain/release calls on ARM64.
This will allow emitted code to condense a sequence like:

    mov x0, x21
    bl swift_retain

To:

    bl swift_retain_x21

Saving code size.

rdar://98884198
2022-11-15 09:53:49 -05:00
Mike Ash
b9391c03e5 Merge pull request #61794 from mikeash/retain-stack-frames
[Runtime] Eliminate stack frames in swift_retain and swift_bridgeObjectRetain on ARM64.
2022-11-08 15:32:55 -05:00
Mike Ash
724a9a7da4 [Runtime] Eliminate stack frames in swift_retain and swift_bridgeObjectRetain on ARM64.
Rearrange the slow paths a bit to make them tail calls, which allows the compiler to emit these functions without frames.

Clang is happy to emit frameless functions on ARM64 if no stack space is needed on all execution paths. However, when there's a fast path which doesn't need stack space, and a slow path which does, clang emits code that pushes a stack frame and then decides which path to take. This is fine, but it means we're paying more than we'd like to on the fast path.

We can work around that by manually outlining the slow path, and ensuring that it's invoked with a tail call. Then the original function doesn't need a stack frame on any path and clang omits the stack frame.

We tweak RefCounts::increment to return the object it's being called on, which allows `swift_retain` to tail-call it. We manually outline the objc_retain call in swift_bridgeObjectRetain, which allows the swift_retain path to be frameless.

rdar://101764509
2022-11-07 15:38:14 -05:00
Alsey Coleman Miller
62b7be4e9c [stdlib] Add RISCV64 support 2022-11-01 23:59:42 -07:00
Julian Lettner
0c53630afd Cleanup outdated comment
In the general case, the compiler should add ptrauth instructions even
for simple pointer equality checks.  We therefore need to manually avoid
these checks; making this workaround permanent.
2022-09-21 16:02:08 -07:00
Egor Zhdan
84a1ffcb33 [Shims] Include SwiftShims headers without ../
This replaces a number of `#include`-s like this:
```
#include "../../../stdlib/public/SwiftShims/Visibility.h"
```
with this:
```
#include "swift/shims/Visibility.h"
```

This is needed to allow SwiftCompilerSources to use C++ headers which include SwiftShims headers. Currently trying to do that results in errors:
```
swift/swift/include/swift/Demangling/../../../stdlib/public/SwiftShims/module.modulemap:1:8: error: redefinition of module 'SwiftShims'
module SwiftShims {
       ^
Builds.noindex/swift/swift/bootstrapping0/lib/swift/shims/module.modulemap:1:8: note: previously defined here
module SwiftShims {
       ^
```
This happens because the headers in both the source dir and the build dir refer to SwiftShims headers by relative path, and both the source root and the build root contain SwiftShims headers (which are equivalent, but since they are located in different dirs, Clang treats them as different modules).
2022-09-14 11:14:50 +01:00
Alastair Houghton
0e9318cec5 [Threading] Put everything through git clang-format.
Just formatting changes.

rdar://90776105
2022-06-07 07:39:53 +01:00
Alastair Houghton
f5bdb858e0 [Threading] Create new threading library and use it.
Moved all the threading code to one place.  Added explicit support for
Darwin, Linux, Pthreads, C11 threads and Win32 threads, including new
implementations of Once for Linux, Pthreads, C11 and Win32.

rdar://90776105
2022-06-07 07:39:51 +01:00
Alastair Houghton
0cf687aa2b [Build][Runtime] Replace SWIFT_STDLIB_SINGLE_THREADED_RUNTIME.
SWIFT_STDLIB_SINGLE_THREADED_RUNTIME is too much of a blunt instrument here.
It covers both the Concurrency runtime and the rest of the runtime, but we'd
like to be able to have e.g. a single-threaded Concurrency runtime while
the rest of the runtime is still thread safe (for instance).

So: rename it to SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY and make it just
control the Concurrency runtime, then add a SWIFT_STDLIB_THREADING_PACKAGE
setting at the CMake/build-script level, which defines
SWIFT_STDLIB_THREADING_xxx where xxx depends on the chosen threading package.

This is especially useful on systems where there may be a choice of threading
package that you could use.

rdar://90776105
2022-06-07 07:39:51 +01:00
Alex Hoppen
4aa2bbbf06 Revert "Merge pull request #42447 from al45tair/eng/PR-90776105"
This reverts commit 8bcb71140f, reversing
changes made to c4dd271d36.
2022-06-02 18:03:23 +02:00
Alastair Houghton
b5bd267ff1 [Threading] Put everything through git clang-format.
Just formatting changes.

rdar://90776105
2022-05-24 14:57:41 +01:00
Alastair Houghton
63a09007a1 [Threading] Create new threading library and use it.
Moved all the threading code to one place.  Added explicit support for
Darwin, Linux, Pthreads, C11 threads and Win32 threads, including new
implementations of Once for Linux, Pthreads, C11 and Win32.

rdar://90776105
2022-05-24 14:57:39 +01:00
Alastair Houghton
dadcb04ae2 [Build][Runtime] Replace SWIFT_STDLIB_SINGLE_THREADED_RUNTIME.
SWIFT_STDLIB_SINGLE_THREADED_RUNTIME is too much of a blunt instrument here.
It covers both the Concurrency runtime and the rest of the runtime, but we'd
like to be able to have e.g. a single-threaded Concurrency runtime while
the rest of the runtime is still thread safe (for instance).

So: rename it to SWIFT_STDLIB_SINGLE_THREADED_CONCURRENCY and make it just
control the Concurrency runtime, then add a SWIFT_STDLIB_THREADING_PACKAGE
setting at the CMake/build-script level, which defines
SWIFT_STDLIB_THREADING_xxx where xxx depends on the chosen threading package.

This is especially useful on systems where there may be a choice of threading
package that you could use.

rdar://90776105
2022-05-24 14:57:38 +01:00
Jonathan Grynspan
9644c7390f 58711 - swift_slowAlloc() and friends should be marked SWIFT_NODISCARD 2022-05-06 11:05:12 -04:00
Jonathan Grynspan
770fd107de 58686: swift_slowAlloc() _et al._ should be marked returns-nonnull to improve codegen 2022-05-05 23:18:48 -04:00
Saleem Abdulrasool
a8b0ee24dc runtime: blanket application of namespacing and inclusion of new
Apply a blanket pass of including `new` for the placement new allocation
and namespacing the call to the global placement new allocator.  This
should repair the Android ARMv7 builds.
2022-04-14 14:21:12 -07:00
Butta
7b2256f97b [android] Move the string and other tags in pointers to the second byte because Android enabled memory tagging
Starting with Android 11, AArch64 placed a tag in the top byte of pointers to
allocations, which has been slowly rolling out to more devices and collides
with Swift's tags. Moving these tags to the second byte works around this
problem.
2022-04-02 08:50:54 +05:30
Rokhini Prabhu
4c736b0507 Create the notion of an ActiveActorStatus which captures the atomic
state of the actor similar to the ActiveTaskStatus. Refactor the default
actor runtime implementation to set us up for priority escalation
support

Radar-Id: rdar://problem/86100521
2022-02-16 10:21:40 -08:00
Mike Ash
3e027b7cea [Runtime] Set fastDeallocSupported to false on i386 simulators.
The conditional should have been "Intel simulators" but it was actually "x86-64 simulators." The i386 simulator doesn't have the weak formation callout, which causes it to miss cleaning up associated objects when the Swift runtime thinks it does.

rdar://79672466
2021-06-23 16:45:06 -04:00
Alastair Houghton
21ac407a21 <rdar://64939529> Convert unnecessary dlsym() calls into direct references.
Added SWIFT_RUNTIME_WEAK_IMPORT/CHECK/USE macros.

Everything supports fast dealloc except x86 iOS simulators, so we no longer need
to look up objc_has_weak_formation_callout.

Added direct references for

  objc_setHook_lazyClassNamer
	_objc_realizeClassFromSwift
	objc_setHook_getClass
	os_system_version_get_current_version
	_dyld_is_objc_constant
2021-06-18 10:16:30 +01:00
Robert Widmann
0149ccd0ca Add arm64_32 support for Swift
Commit the platform definition and build script work necessary to
cross-compile for arm64_32.

arm64_32 is a variant of AARCH64 that supports an ILP32 architecture.
2021-04-20 14:59:04 -07: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
Mike Ash
630aff7b19 [Runtime] Change SimpleGlobalCache to use ConcurrentReadableHashMap instead of ConcurrentMap.
This gives us faster lookups and a small advantage in memory usage. Most of these maps need stable addresses for their entries, so we add a level of indirection to ConcurrentReadableHashMap for these cases to accommodate that. This costs some extra memory, but it's still a net win.

A new StableAddressConcurrentReadableHashMap type handles this indirection and adds a convenience getOrInsert to take advantage of it.

ConcurrentReadableHashMap is tweaked to avoid any global constructors or destructors when using it as a global variable.

ForeignWitnessTables does not need stable addresses and it now uses ConcurrentReadableHashMap directly.

rdar://problem/70056398
2020-10-08 14:57:39 -04:00
Kuba (Brecka) Mracek
1fec2b5584 Respect SWIFT_STDLIB_SINGLE_THREADED_RUNTIME and use nonatomic refcounting in swift_retain, swift_release, etc. (#33644) 2020-08-27 10:25:32 -07: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
Mike Ash
22cfe461ec [Tools] Super rough draft of swiftdt dumping MetadataAllocator contents.
rdar://problem/55481578
2020-05-29 08:31:03 -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
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
Kuba Mracek
84c4864911 [arm64e] Add Swift compiler support for arm64e pointer authentication 2020-02-27 16:10:31 -08:00
David Smith
c6a428f3d9 Update fast dealloc to match libobjc 2020-01-24 15:32:27 -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
Mike Ash
922b71f900 [Runtime] Refactor HeapObject override checks to use a macro.
This gives us a one-stop shop for making changes to the override mechanism.

rdar://problem/54752086
2019-10-04 16:43:16 -04:00
Mike Ash
51987245f3 [Runtime] Initialize function pointers with the original values, check against those values to call directly.
Instruments relies on the old values being there so it can call the original implementation. This has very slightly worse codegen but the impact should be minimal.
2019-08-16 14:41:12 -04:00
Mike Ash
9fd03e24ad [Runtime] Avoid function pointer indirection in refcounting functions.
Functions like swift_retain call through a function pointer so that Instruments can interpose. This slows down the common case where there is no interposition. Instead, initialize the function pointers to NULL and call through directly to the real implementation when it's NULL. The compiler is smart enough to inline this call and the result is a single conditional branch rather than a function pointer call.

rdar://problem/18307425
2019-08-06 14:29:51 -04:00
David Smith
a84af6f68b Revert "Revert "Revert "Use the remaining half bit in the refcount to bypass ObjC deallocation overhead"""
This reverts commit c51294671b.
2019-07-01 14:29:40 -07:00