Commit Graph

3150 Commits

Author SHA1 Message Date
Azoy
4b71d6776e [ABI] Introduce MetadataKind TypeRef 2020-10-22 18:24:28 -04:00
John McCall
c18331c837 Move swift_task_alloc/dealloc into the Concurrency library.
Also, rename them to follow the general namespacing scheme.
2020-10-22 00:53:15 -04:00
Mike Ash
17e31d89d2 [Runtime] Restore objc_addLoadImageFunc in ImageInspectionMacho.cpp.
The conditional use of objc_addLoadImageFunc was accidentally removed in b5759c9fd9. Put it back.

rdar://problem/70452221
2020-10-19 15:53:52 -04: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
swift-ci
8b5a55d13e Merge pull request #34180 from spevans/pr_static_executable_fix_1lib 2020-10-08 07:05:20 -07:00
nate-chandler
515f0db4ed Merge pull request #34141 from nate-chandler/concurrency/irgen/signature
[Concurrency] Async CC, part 1.
2020-10-06 07:43:02 -07:00
Simon Evans
960d0e30ee Linux: Fix -static-executable and remove swiftImageInspectionShared
- Remove references to swiftImageInspectionShared on Linux and dont have
  split libraries between static/non-static linked executables.

- -static-executable now links correctly Linux.

  Note: swift::lookupSymbol() will not work on statically linked
        executables but this can be worked around by using the
        https://github.com/swift-server/swift-backtrace package.
2020-10-05 10:16:03 +01:00
Saleem Abdulrasool
563c99bc7c Merge pull request #34160 from buttaface/arm
[android] Add support for building the toolchain for ARMv7
2020-10-04 14:40:44 -07:00
Butta
f7576a7bef [android] Add support for building the toolchain for ARMv7 2020-10-03 18:55:23 +05:30
John McCall
0fb407943f [NFC] Rename swift_runtime_unreachable to swift_unreachable and make it use LLVM's support when available. 2020-10-03 02:54:56 -04:00
Nate Chandler
607772aaa2 [Runtime] Stubbed entry points for task de/alloc. 2020-09-30 18:57:48 -07:00
Kuba (Brecka) Mracek
6b40a092b9 Move the actual Obj-C parts of ReflectionMirror.mm into a separate file, make ReflectionMirror.mm a .cpp file (#34025) 2020-09-25 07:29:03 -07:00
swift-ci
3921871b77 Merge pull request #34009 from eeckstein/fix-cow-checks 2020-09-21 05:36:56 -07:00
Xiaodi Wu
45299909bc [runtime] Silence unreachable code warning (#33912) 2020-09-21 07:30:43 -04: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
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
Kuba (Brecka) Mracek
7f26d97746 Don't use resilient getter for playgroundPrintHook when resilience is off (#33848) 2020-09-10 14:06:58 -07:00
tbkka
a61e7044c4 Witness tables have special ptrauth requirements (#33876) 2020-09-10 08:24:20 -07:00
Kuba (Brecka) Mracek
084ff3d408 Avoid using a resilient offset in swift_readAtKeyPath (#33847) 2020-09-10 08:02:07 -07:00
Saleem Abdulrasool
d80d7cf561 Merge pull request #33838 from shabalind/topic/fix-fallthrough-warning
Add missing SWIFT_FALLTHROUGH to the tryCastToString
2020-09-10 07:56:18 -07:00
Dave Lee
389d099705 [stdlib] Silence a few assert related warnings 2020-09-09 09:43:56 -07:00
Denys Shabalin
78c957f485 Move fallthrough one line up 2020-09-09 17:14:16 +02:00
Doug Gregor
b5759c9fd9 [Concurrency] Allow overload 'async' with non-async and disambiguate uses.
Allow an 'async' function to overload a non-'async' one, e.g.,

    func performOperation(_: String) throws -> String { ... }
    func performOperation(_: String) async throws -> String { ... }

Extend the scoring system in the type checker to penalize cases where
code in an asynchronous context (e.g., an `async` function or closure)
references an asychronous declaration or vice-versa, so that
asynchronous code prefers the 'async' functions and synchronous code
prefers the non-'async' functions. This allows the above overloading
to be a legitimate approach to introducing asynchronous functionality
to existing (blocking) APIs and letting code migrate over.
2020-09-08 16:51:10 -07:00
Denys Shabalin
87906df2fe Add missing SWIFT_FALLTHROUGH to the tryCastToString 2020-09-07 16:09:38 +02:00
Kuba (Brecka) Mracek
41f1285b99 Don't use lookupSymbol when SWIFT_RUNTIME_MACHO_NO_DYLD (#33792) 2020-09-03 18:43:52 -07:00
Mike Ash
50ea66d1d9 Merge pull request #33585 from mikeash/type-lookup-error-reporting
Add error reporting when looking up types by demangled name.
2020-08-28 17:42:47 -04:00
Mike Ash
fd6922f92d Add error reporting when looking up types by demangled name. 2020-08-28 14:43:51 -04: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
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
Kuba (Brecka) Mracek
9de7b59388 Subsume SWIFT_STDLIB_USE_NONATOMIC_RC into SWIFT_STDLIB_SINGLE_THREADED_RUNTIME (#33643) 2020-08-26 21:28:30 -07:00
Kuba (Brecka) Mracek
9ead8d57fa Add a single-threaded stdlib mode, use it for the 'minimal' stdlib (#33437) 2020-08-25 06:03:14 -07:00
Mike Ash
39d4e0125e Merge pull request #33487 from mikeash/concurrenthashmap
[Runtime] Reimplement protocol conformance cache with a hash table
2020-08-21 12:14:23 -04:00
Mike Ash
ecd6d4ddec Add a new ConcurrentReadableHashMap type. Switch the protocol conformance cache
to use it.

ConcurrentReadableHashMap is lock-free for readers, with writers using a lock to
ensure mutual exclusion amongst each other. The intent is to eventually replace
all uses ConcurrentMap with ConcurrentReadableHashMap.

ConcurrentReadableHashMap provides for relatively quick lookups by using a hash
table. Rearders perform an atomic increment/decrement in order to inform writers
that there are active readers. The design attempts to minimize wasted memory by
storing the actual elements out-of-line, and having the table store indices into
a separate array of elements.

The protocol conformance cache now uses ConcurrentReadableHashMap, which
provides faster lookups and less memory use than the previous ConcurrentMap
implementation. The previous implementation caches
ProtocolConformanceDescriptors and extracts the WitnessTable after the cache
lookup. The new implementation directly caches the WitnessTable, removing an
extra step (potentially a quite slow one) from the fast path.

The previous implementation used a generational scheme to detect when negative
cache entries became obsolete due to new dynamic libraries being loaded, and
update them in place. The new implementation just clears the entire cache when
libraries are loaded, greatly simplifying the code and saving the memory needed
to track the current generation in each negative cache entry. This means we need
to re-cache all requested conformances after loading a dynamic library, but
loading libraries at runtime is rare and slow anyway.

rdar://problem/67268325
2020-08-20 13:05:30 -04:00
Kuba Mracek
b3509fcab3 Fix build with SWIFT_RUNTIME_MACHO_NO_DYLD=1 in ImageInspectionStatic.cpp 2020-08-19 08:35:21 -07:00
Kuba (Brecka) Mracek
db18deaf91 Add a SWIFT_RUNTIME_MACHO_NO_DYLD stdlib mode that doesn't dynamically look up sections in modules, and only assumes a single static module (#33441) 2020-08-18 11:46:42 -07:00
Kuba (Brecka) Mracek
4cfaeee6df Match the #ifdefs between _swift_isNonPointerIsaObjCClass and objectUsesNativeSwiftReferenceCounting (#33510) 2020-08-17 17:34:11 -07:00
Kuba Mracek
99e518bb85 Guard Obj-C specifics in Metadata.cpp with SWIFT_OBJC_INTEROP 2020-08-14 21:20:34 -07:00
Kuba (Brecka) Mracek
aa924196ff Add a flag to build the stdlib without COMPATIBILITY_OVERRIDE (#33438) 2020-08-14 17:06:38 -07:00
Nate Chandler
a5a7c98be0 [metadata prespecialization] getGenericMetadata finds records.
Previously, the metadata accessor for which canonical prespecializations
had been formed included checks against the passed-in arguments to
determine whether the access matched a prespecialized record or not.

Now that the prespecialized records are attached to the nominal type
descriptor for the type, eliminate this hard-coded generated code and
instead let swift_getGenericMetadata do the work of looking through the
prespecializations.
2020-08-14 11:19:10 -07:00
nate-chandler
6dddf96faf Merge pull request #33442 from nate-chandler/generic-metadata-prespecialization-components/record-canonical-prespecializations
[metadata prespecialization] Add canonical prespecialization to end of type descriptors.
2020-08-14 09:59:26 -07:00
David Zarzycki
c2fc2108d0 Merge pull request #33448 from davezarzycki/pr33448
[NFC] Fix -Wsuggest-override warnings
2020-08-14 04:46:12 -04:00
Nate Chandler
b1408028a7 [metadata prespecialization] Allow more noncanonical records.
Previously, noncanonical records were only allowed if one of the
arguments was from the module where the record was to be emitted.

Here, that restriction is lifted.  Now getSpecializedGenericMetadata
will, on first run, register all canonical metadata with the global
cache before attempting to bless the passed-in noncanonical record,
allowing noncanonical records to be for the same arguments as a
canonical record (since in the case that a canonical record does exist,
it will be returned).
2020-08-13 17:44:49 -07:00
Kuba (Brecka) Mracek
e2e69578a6 For the 'minimal' stdlib, disable Objective-C interop (#33427) 2020-08-13 15:26:04 -07:00
David Zarzycki
1e940c2c7e [NFC] Fix -Wsuggest-override warnings
LLVM, as of 77e0e9e17daf0865620abcd41f692ab0642367c4, now builds with
-Wsuggest-override. Let's clean up the swift sources rather than disable
the warning locally.
2020-08-13 16:17:46 -04:00
Mike Ash
e57961c95f [Runtime] Fix the ISA mask assert for ARM64 running on ARM64e hardware. 2020-08-07 14:18:16 -04:00
Mike Ash
e26aeca7eb [Runtime] Fix the isa mask assert for ARM64e.
Swift's isa mask includes the signature bits. objc_debug_isa_class_mask does not. Switch to objc_absolute_packed_isa_class_mask instead, which does.

While we're at it, get rid of the now-unnecessary guards for back-deployment.

rdar://problem/60148213
2020-08-06 16:33:59 -04:00
Varun Gandhi
3882beb85d [NFC] Use consistent naming scheme for predicate methods. (#33265)
bool throws() -> isThrowing(), bool async() -> isAsync()
2020-08-03 16:37:29 -07:00
Doug Gregor
41817229d5 Merge pull request #33147 from DougGregor/async-function-types
[Concurrency] Add `async` to the Swift type system.
2020-07-29 08:59:34 -07:00
Nate Cook
6d534ecb09 Fix swift_reflectionMirror_recursive* when called on pure ObjC classes. (#33143) 2020-07-28 12:13:43 -05:00
Doug Gregor
f6e9f352f0 [Concurrency] Add async to the Swift type system.
Add `async` to the type system. `async` can be written as part of a
function type or function declaration, following the parameter list, e.g.,

  func doSomeWork() async { ... }

`async` functions are distinct from non-`async` functions and there
are no conversions amongst them. At present, `async` functions do not
*do* anything, but this commit fully supports them as a distinct kind
of function throughout:

* Parsing of `async`
* AST representation of `async` in declarations and types
* Syntactic type representation of `async`
* (De-/re-)mangling of function types involving 'async'
* Runtime type representation and reconstruction of function types
involving `async`.
* Dynamic casting restrictions for `async` function types
* (De-)serialization of `async` function types
* Disabling overriding, witness matching, and conversions with
differing `async`
2020-07-27 18:18:03 -07:00