Commit Graph

3157 Commits

Author SHA1 Message Date
Doug Gregor
d844d0b82b Merge pull request #39102 from DougGregor/back-deploy-standalone
Make the back-deployed concurrency dylibs depend only on what's available in older runtimes
2021-08-31 09:05:21 -07:00
Doug Gregor
6fd85ac7a3 Clone exclusivity save/restore for tasks into back-deployment library
The code that saves/restores the exclusivity checks for tasks was
newly introduced into the runtime. Clone that code into the back-
deployed version of the runtime.
2021-08-30 16:39:33 -07:00
Saleem Abdulrasool
0a292fdaf9 Differentiation: correct the storage annotation for runtime functions
The runtime support functions are currently vended by
swiftCore.{dll,dylib,so} rather than
swift_Differentiation.{dll,dylib,so}.  This corrects the annotations to
indicate that reality.  This never could have worked as declared in the
first place.  swift_Differentiation never links against swiftRuntime
and swiftCore effectively whole-archives swiftRuntime into itself.  This
change is now reflecting that reality.  If the desire is to move this
(even on Darwin, where this may have already shipped and thus would
break ABI), we could split up the swiftRuntime into swiftRuntime and
swiftDifferentiationRuntime and link that as we do with the runtime into
swiftCore.
2021-08-24 14:24:18 -07:00
Kuba (Brecka) Mracek
aaff37ffb8 Add a SWIFT_STDLIB_HAS_DARWIN_LIBMALLOC flag to allow/disallow uses of Darwin libmalloc APIs (malloc_default_zone, malloc_zone_malloc, etc.) (#33812) 2021-08-23 19:37:43 -07:00
Kuba (Brecka) Mracek
62e7139574 Disable bincompat checks in Bincompat.cpp when SWIFT_RUNTIME_OS_VERSIONING is off. (#39009) 2021-08-23 19:05:26 -07:00
Alastair Houghton
5b6f183d0e Merge pull request #38904 from al45tair/problem/37170485
[Tests] Re-add round-trip type test.
2021-08-17 23:11:42 +01:00
Alastair Houghton
cd99995d84 [Tests] Re-add round-trip type test.
This was reverted in 12fa024 because it broke the iOS simulator build.

rdar://37170485
2021-08-17 09:51:22 +01:00
Alastair Houghton
4b2e31654e [Demangler][Tests] Re-add getObjcClassByMangledName test.
This was reverted in ec3ccd72 because it broke the iOS simulator build.
2021-08-17 09:46:21 +01:00
Mishal Shah
12fa0246b8 Merge pull request #38897 from apple/revert-38649-problem/37170485
Revert "[Tests] Add a test to round-trip types through mangled names."
2021-08-16 14:08:01 -07:00
Mishal Shah
f45195454f Revert "[Tests] Add a test to round-trip types through mangled names." 2021-08-16 14:03:39 -07:00
Mishal Shah
34350e45cd Revert "[Demangler][Tests] Add an explicit test for getObjCClassByMangledName." 2021-08-16 14:00:39 -07:00
Alastair Houghton
1cc1036ec9 Merge pull request #38649 from al45tair/problem/37170485
[Tests] Add a test to round-trip types through mangled names.
2021-08-16 14:21:38 +01:00
Alastair Houghton
d50f533b8f Merge pull request #38746 from al45tair/objc-getclass-test
[Demangler][Tests] Add an explicit test for getObjCClassByMangledName.
2021-08-16 14:21:11 +01:00
Alastair Houghton
8e12cd0b62 [Tests] Add a test to round-trip types through mangled names.
Added a new test to the test suite that round trips Swift types through
mangled names and checks that we get the same type back that we started
with.

rdar://37170485
2021-08-16 11:22:21 +01:00
Alastair Houghton
fb351be64f [Demangler][Tests] Address Doug's comments.
Moved the test for the metadata kind to MetadataLookup.cpp.

Added an assertion (for debug builds) to Metadata.cpp to catch the case where
something manages to bypass that test.
2021-08-16 10:59:01 +01:00
Alastair Houghton
8db56f09a3 [Demangler][Tests] Add an explicit test for getObjCClassByMangledName.
Added a special test for getObjCClassByMangledName; this needs testing
separately as it uses the DecodedMetadataBuilder, which doesn't get exercised
by the normal demangling tests.

Added all the test cases from rdar://63485806, rdar://63488139, rdar://63496478,
rdar://63410196 and rdar://68449341.  The test cases from rdar://63485806 are
disabled for now because the problem there is the error handling mechanism (or
lack thereof), rather than us not handling errors.

Fixes the remaining cases from

rdar://63488139
rdar://63496478
2021-08-04 16:21:32 +01:00
Alastair Houghton
ad147308af Merge pull request #38309 from al45tair/problem/47902425
[Runtime] Add ObjC support to isKnownUniquelyReferenced.
2021-08-02 17:39:49 +01:00
Saleem Abdulrasool
21405d89f4 Merge pull request #38698 from compnerd/static-mutex
runtime: replace use of `std::mutex` with `StaticMutex`
2021-07-30 14:15:27 -07:00
Saleem Abdulrasool
6c50325c2a runtime: replace use of std::mutex with StaticMutex
Replace the `static std::mutex` with Swift's `StaticMutex` so that we
avoid triggering an error due to an exit time destructor.  Repairs the
build after #38562.
2021-07-30 09:16:12 -07:00
Mike Ash
aec4ec4c4a [Runtime] Weakly import dyld protocol conformance functions.
This allows us to build against a macOS 12 SDK and test on macOS 11.

rdar://81133606
2021-07-29 14:42:30 -04:00
Alastair Houghton
abec55f432 [Runtime] Add ObjC support to isKnownUniquelyReferenced.
Add code to support detecting uniquely referenced Objective-C and Core
Foundation objects.

rdar://47902425
rdar://66805490
2021-07-29 16:29:48 +01:00
Michael Gottesman
3e64d03a52 [exclusivity] Split out of Exclusivity.cpp FunctionReplacement and the Global TLSContext.
Some notes:

1. Even though I refactored out AccessSet/Access from Exclusivity.cpp ->
ExclusivityPrivate.h, I left the actual implementations of insert/remove in
Exclusivity.cpp to allow for the most aggressive optimization for use in
Exclusivity.cpp without exposing a bunch of internal details to other parts of
the runtime. Smaller routines like getHead() and manipulating the linked list
directly I left as methods that can be used by other parts of the runtime. I am
going to use these methods to enable backwards deployment of exclusivity support
for concurrency.

2. I moved function replacements out of the Exclusivity header/cpp files since
it has nothing to do with Exclusivity beyond taking advantage of the TLS context
that we are already using.
2021-07-26 12:26:08 -07:00
Doug Gregor
7b791cff9c Merge pull request #38515 from mikeash/fix-protocol-conformance-superclass-recursion
[Runtime] Fix infinite recursion in protocol conformance checking on class Sub: Super<Sub>.
2021-07-23 09:32:34 -07:00
Michael Gottesman
e662a146de [exclusivity] Add logging lock/flushing to prevent output interleaving. 2021-07-22 13:25:10 -07:00
Michael Gottesman
f79108caf7 [exclusivity] Introduce an env variable to in asserts builds cause the exclusivity part of the runtime to emit logging information.
The specific environment variable is SWIFT_DEBUG_RUNTIME_EXCLUSIVITY_LOGGING. We only
check the environment the first time we try to lookup the TLSContext, so it
shouldn't impact exclusivity performance.

My intention is to use this to write some FileCheck tests so that we can really
be sure that the runtime is doing what we think it is. As such I also changed
the small amount of logging routines meant for use in the debugger to use stdout.
2021-07-22 13:25:10 -07:00
Michael Gottesman
0aec81614d [exclusivity] Add support for Task local exclusivity access sets.
The implemented semantics are that:

1. Tasks have separate exclusivity access sets.
2. Any synchronous context that creates tasks will have its exclusive access set
   merged into the Tasks while the Task is running.

rdar://80492364
2021-07-22 13:25:10 -07:00
Mike Ash
b37252d418 [Runtime] Fix infinite recursion in protocol conformance checking on class Sub: Super<Sub>.
Conformance checks now walk the superclass chain in two stages: stage 1 only walks superclasses that have already been instantiated. When there's a negative result and there's an uninstantiated superclass, then stage 2 will walk the uninstantiated superclasses.

The infinite recursion would occur in this scenario:

    class Super<T: P> {}
    class Sub: Super<Sub>, P {}

Instantiating the metadata for Super requires looking up the conformance for Sub: P. Conformance checking for Sub would instantiate the metadata for Super to check for a Super: P conformance.

The compiler does not allow the conformance to come from a superclass in this situation. This does not compile:

    class Super<T: P>: P {}
    class Sub: Super<Sub> {}

Therefore it's not necessary to look at Super when finding the conformance for Sub: P in this particular case. The trick is knowing when to skip Super.

We do need to instantiate Super in the general case, otherwise we can get false negatives. This was addressed in a80fe8536b, which walks the full superclass chain during conformance checks, even if the superclass has not yet been instantiated. Unfortunately, that causes this infinite recursion.

This fix modifies that fix to make superclass instantiation conditional. The result is the ability to choose between the old algorithm (which skipped uninstantiated superclasses, albeit somewhat by accident) and the new one. A small wrapper then runs the check with the old algorithm, and then only if the old algorithm fails and there is an uninstantiated superclass, it runs with the new one.

Uninstantiated superclasses are uncommon and transient (you only run into this while metadata is in the process of being constructed) so 99.9999% of the time we'll just run the first stage and be done, and performance should remain the same as before.

rdar://80532245
2021-07-22 13:46:01 -04:00
Kavon Farvardin
70b7b34f09 add assertion to catch AccessSet usage errors
I ran into this while implementing
async actor inits; where I was emitting
an actor hop in the middle of
an access region, which caused the
access set to be unexpectedly empty.
2021-07-16 15:01:12 -07:00
Mike Ash
06ff648825 [Runtime] Fix protocol conformance checks on pure ObjC classes.
The getSuperclassForMaybeIncompleteMetadata function assumes Swift metadata, and can malfunction strangely when given a pure ObjC class. This is rare, as we usually get the Swift wrapper metadata instead, but possible when using calls like objc_copyClassList.

Fix this by checking for isTypeMetadata before doing anything that assumes Swift-metadata-ness.

rdar://80336030
2021-07-08 17:45:43 -04:00
OneUpWallStreet
25df5d2c48 Fixed some common grammatical errors in the comments. (#38248) 2021-07-05 01:00:48 -07:00
Mike Ash
2d6a6927e9 Merge pull request #38162 from mikeash/concurrency-constant-pthread-keys
[Concurrency] Use pthread_specific for thread-local storage on Darwin.
2021-07-02 13:22:15 -04:00
nate-chandler
5e0d0fb91b Merge pull request #36765 from nate-chandler/generic-metadata-prespecialization-components/generic-value-witnesses
[IRGen] Use generic value witnesses for prespecialized types.
2021-06-30 07:03:40 -07:00
Mike Ash
190d3fd22e [Concurrency] Use pthread_specific for thread-local storage on Darwin.
The pthread_specific APIs are better than C++ thread_local storage on Darwin since we can use Swift's reserved pthread keys there.

rdar://79504652
2021-06-29 16:56:59 -04:00
Nate Chandler
07ba7a6f3c [runtime] Exported multi payload enum witnesses.
When witness tables for enums are instantiated at runtime via

    swift::swift_initEnumMetadataMultiPayload

the witnesses

    getEnumTagSinglePayload
    storeEnumTagSinglePayload

are filled with swift_getMultiPayloadEnumTagSinglePayload (previously
getMultiPayloadEnumTagSinglePayload) and
swift_storeMultiPayloadEnumTagSinglePayload (previously
storeMultiPayloadEnumTagSinglePayload).  Concretely, that occurs when
instantiating the value witness table for a generic enum which has more
than one case with a payload, like Result<T>.  To enable the compiler to
do the same work, those functions need to be visible to it.

Here, those functions are made visible to the compiler.  Doing so
requires changing the way they are declared and adding them to
RuntimeFunctions.def which in turn requires the definition of some
functions to describe the availability of those functions.
2021-06-25 21:03:56 -07: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
Mike Ash
53fe241c0e Merge pull request #37973 from mikeash/fix-protocol-conformance-KVO
[Runtime] Fix crash in protocol conformance checks on KVO artificial subclasses.
2021-06-23 09:12:32 -04:00
Alastair Houghton
00df48c92d Merge pull request #37972 from al45tair/problem/73364629
[Runtime] Detect and log redundant subclass/superclass conformances.
2021-06-23 09:20:42 +01:00
Alastair Houghton
a55f9cf08c Merge pull request #37884 from al45tair/problem/64939529
<rdar://64939529> Convert unnecessary dlsym() calls into direct refs
2021-06-23 09:19:04 +01: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
Mike Ash
c3aa44368a [Runtime] Fix crash in protocol conformance checks on KVO artificial subclasses.
tryGetCompleteMetadataNonblocking crashes on artificial subclasses due to the NULL type descriptor. Explicitly check for artificial subclasses in getSuperclassForMaybeIncompleteMetadata and immediately return their Superclass field. Artificial subclasses are always fully initialized so we don't need to do anything special for them.

rdar://72583931
2021-06-17 14:45:58 -04:00
Alastair Houghton
4794b4b28c [Runtime] Detect and log redundant subclass/superclass conformances.
When we rely on a protocol conformance, and the type in question has multiple
conformances to that protocol in its inheritance chain, emit a runtime warning.

It's quite tricky to cause this problem - you need a type in one dylib that is
extended to conform to a protocol in another dylib, subclassed in another module
and then some subclass has protocol conformance added as well.  If they're in
the same module, the compiler will give an error and prevent the problem
completely.

rdar://73364629
2021-06-17 19:28:27 +01:00
tbkka
c0ccec35a9 Speed up class_getImageName (#37913)
When building for Apple OS, dyld_image_path_containing_address
is much, much faster than dladdr.

Resolves rdar://42137685
Resolves SR-14759
2021-06-15 16:15:50 -07:00
Mishal Shah
5a7b8c7922 Merge pull request #37823 from apple/xcode-13-beta-main
[main] Support Xcode 13 beta
2021-06-10 09:21:09 -07:00
Doug Gregor
0cd0cbc02a Merge pull request #37794 from DougGregor/isolated-parameters
[SE-0313] Implement type system, ABI, and runtime support for isolated parameters
2021-06-08 19:46:20 -07:00
swift-ci
e65ae80172 Merge pull request #36955 from mininny/add-dynamic-subclass-kvo-doc 2021-06-08 18:59:17 -07:00
Minhyuk Kim
dd5e2aab30 [doc] Reduce the length of the docs 2021-06-08 23:03:15 +09:00
Doug Gregor
58f49692ed Add mangling, metadata, and reflection support for "isolated" parameters.
Isolated parameters are part of function types. Encode them in function
type manglings and metadata, and ensure that they round-trip through
the various mangling and metadata facilities. This nails down the ABI
for isolated parameters.
2021-06-08 00:00:11 -07:00
Mishal Shah
23c3b15f5f Support Xcode 13 beta
* Updating availability versions
* Remove all remaining overlays in stdlib/public/Darwin/*:
   - ObjectiveC
   - Dispatch
   - CoreFoundation
   - CoreGraphics
   - Foundation
2021-06-07 12:04:31 -07:00
Saleem Abdulrasool
f0f81f75df runtime: annotate _environ DLL storage, exclude in WinRT
`_environ` is meant to be DLL imported when linking against the C
runtime dynamically (`/MD` or `/MDd`).  However, when building for
the Windows Runtime environment, we cannot support the use of `_environ`
and thus disable the support for that.  `_WINRT_DLL` identifies the
combination of `/ZW` and `/LD` or `/LDd`.  Windows Runtime builds cannot
be executables (and obviously not static libraries as they are not
executable), and thus we properly disable `ENVIRON` in all Windows
Runtime builds.
2021-06-06 19:40:02 -07:00
Mike Ash
4f27dc5470 Merge pull request #37656 from mikeash/fix-concurrent-typeByName
[Runtime] Fix concurrent _typeByName with generic arguments, protocol conformances, and superclasses.
2021-06-03 17:23:05 -04:00