Commit Graph

540 Commits

Author SHA1 Message Date
Mishal Shah
c2fd49cebb Merge pull request #39473 from apple/rebranch
Update swift:main to support llvm-project:stable/20210726 changes (Rebranch merge)
2021-10-11 09:00:51 -07:00
Doug Gregor
2551a04621 Back-deploy @objc actor types.
@objc actors implicitly inherit from the new, hidden
`SwiftNativeNSObject` class that inherits from `NSObject` yet provides
Swift-native reference counting, which is important for the actor
runtime's handling of zombies. However, `SwiftNativeNSObject` is only
available in the Swift runtime in newer OS versions (e.g., macOS
12.0/iOS 15.0), and is available in the back-deployed _Concurrency
library, but there is no stable place to link against for
back-deployed code. Tricky, tricky.

When back-deploying @objc actors, record `NSObject` as the superclass
in the metadata in the binary, because we cannot reference
`SwiftNativeNSObject`. Then, emit a static initializer to
dynamically look up `SwiftNativeNSObject` by name (which will find it
in either the back-deployment library, on older systems, or in the
runtime for newer systems), then swizzle that in as the superclass of
the @objc actor.

Fixes rdar://83919973.
2021-10-05 23:04:57 -07:00
swift-ci
b736faa703 Merge remote-tracking branch 'origin/main' into rebranch 2021-09-23 14:53:57 -07:00
Arnold Schwaighofer
4d7854f02a Use AvailabilityContext to check for concurrency availability 2021-09-23 10:34:58 -07:00
Arnold Schwaighofer
16a5d69b92 IRGen: Emit a weak reference to swift_async_extendedFramePointerFlags when neccessary
When we deploy to a minimum target that is not known to support extended
frame information the function prolog of Swift async functions will
contain a reference to swift_async_extendedFramePointerFlags. This
reference needs to be weak like any async symbols.

rdar://83412550
2021-09-23 09:21:25 -07:00
Saleem Abdulrasool
e7965cefc4 IRGen: remove ELF autolink discard gadget
The ELF autolink section was previously relying on the SHF_EXCLUDE flag
being applied through module-level assembly.  Remove this gadget and
sink the handling down into LLVM.  The latest improvements to LLVM now
cause this workaround to be insufficient as the section is explicitly
marked as SHF_ALLOC, which will implicitly negate the SHF_EXCLUDE.  As a
result, we no longer discard the metadata.  Once this is sunk into LLVM
the attribute is unnecessary.  Furthermore, due to uniquing, will
actually cause a problem as there is no uniform handling for metadata
section prefixes.

rdar://82640394
2021-09-11 12:12:20 -07:00
swift-ci
b6289f17a4 Merge remote-tracking branch 'origin/main' into rebranch 2021-08-20 08:13:22 -07:00
Kuba (Brecka) Mracek
2fad6265fe When building stdlib, pass -prespecialize-generic-metadata from CMake, and respect the flag in IRGenModule::shouldPrespecializeGenericMetadata (#38946) 2021-08-20 07:58:39 -07:00
Arnold Schwaighofer
5a83172a55 Merge remote-tracking branch 'upstream/main' into rebranch 2021-08-05 12:04:56 -07: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
Evan Wilde
1e6787925f Fix IRGen datalayout
Same issue as with TBDGen. Clang doesn't hold onto the Datalayout object
anymore, but instead keeps the description string that is constructed on
the fly. This patch updates IRGen to behave the same way.
2021-07-08 16:59:11 -07:00
swift-ci
e0e2634b84 Merge remote-tracking branch 'origin/main' into rebranch 2021-07-06 09:35:07 -07:00
Evan Wilde
0919c2cd70 StringRef ends/startswith-lower -> insensitive
Updating StringRef startswith and endswith API to use insensitive rather
than lower.

(cherry picked from commit 1b8b39e6de)
2021-07-02 10:55:17 -07: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
Nate Chandler
dbe2a8c06e [IRGen] NFC: Removed duplicative check.
isOSDarwin is true on tvOS so there is no need to also check for isTvOS.
2021-06-25 21:04:00 -07: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
Doug Gregor
e7e922ea77 Introduce a createAsyncTaskInGroup SIL builtin.
Rather than using group task options constructed from the Swift parts
of the _Concurrency library and passed through `createAsyncTask`'s
options, introduce a separate builtin that always takes a group. Move
the responsibility for creating the options structure into IRGen, so
we don't need to expose the TaskGroupTaskOptionRecord type in Swift.
2021-06-24 07:53:18 -07:00
Arnold Schwaighofer
ea5fd19b26 IRGen: Try to fix taskCreate APIs on 32bit archs 2021-06-22 07:39:49 -07:00
Konrad `ktoso` Malawski
8536100354 [Concurrency] introduce task options, and change ABI to accept them
introduce new options parameter to all task spawning

[Concurrency] ABI for asynclet start to accept options

[Concurrency] fix unittest usages of changed task creation ABI

[Concurrency] introduce constants for parameter indexes in ownership

[Concurrency] fix test/SILOptimizer/closure_lifetime_fixup_concurrency.swift
2021-06-21 13:03:50 +09:00
Mike Ash
c2df2448ec [Concurrency] Reserve two more words in Job.
Keep Task the same size by pulling two words out of OpaquePrivateStorage.

rdar://79313908
2021-06-16 16:59:25 -04:00
Richard Howell
95ea3dd261 DebugTypeExtRefs=false when DisableClangModuleSkeletonCUs=true 2021-06-08 14:39:42 -07:00
Robert Widmann
f6b2294d5a Undo Force Load + Incremental Ban on Darwin Platforms
Gather 'round to hear tell of the saga of autolinking in incremental
mode.

In the beginning, there was Swift code, and there was Objective-C code.
To make one import bind two languages, a twinned Swift module named the same as an
Objective-C module could be imported as an overlay. But all was not
well, for an overlay could be created which had no Swift content, yet
required Swift symbols. And there was much wailing and gnashing of teeth
as loaders everywhere disregarded loading these content-less Swift
libraries.

So, a solution was found - a magical symbol _swift_FORCE_LOAD_$_<MODULE>
that forced the loaders to heed the dependency on a Swift library
regardless of its content. It was a constant with common linkage, and it
was good. But, along came COFF which needed to support autolinking but
had no support for such matters. It did, however, have support for
COMDAT sections into which we placed the symbol. Immediately, a darkness
fell across the land as the windows linker loudly proclaimed it had
discovered a contradiction: "_swift_FORCE_LOAD_$_<MODULE> cannot be
a constant!", it said, gratingly, "for this value requires rebasing."
Undeterred, we switched to a function instead, and the windows linker
happily added a level of indirection to its symbol resolution procedure
and all was right with the world.

But this definition was not all right. In order to support multiple
translation units emitting it, and to prevent the linker from dead
stripping it, Weak ODR linkage was used. Weak ODR linkage has the nasty
side effect of pessimizing load times since the dynamic linker must
assume that loading a later library could produce a more definitive
definition for the symbol.

A compromise was drawn up: To keep load times low, external linkage was
used. To keep the linker from complaining about multiple strong
definitions for the same symbol, the first translation unit in the
module was nominated to recieve the magic symbol. But one final problem
remained:

Incremental builds allow for files to be added or removed during the
build procedure. The placement of the symbol was therefore dependent
entirely upon the order of files passed at the command line. This was no
good, so a decree was set forth that using -autolink-force-load and
-incremental together was a criminal offense.

So we must compromise once more: Return to a symbol with common linkage,
but only on Mach-O targets. Preserve the existing COMDAT-friendly
approach everywhere else.

This concludes our tale.

rdar://77803299
2021-05-24 15:53:13 -07:00
Fred Riss
bbda706393 [Concurrency] Add a unique Task ID to AsyncTask
This commit changes JobFlags storage to be 32bits, but leaves the runtime
API expressed in terms of size_t. This allows us to pack an Id in the
32bits we freed up.

The offset of this Id in the AsyncTask is an ABI constant. This way
introspection tools can extract the currently running task identifier
without any need for special APIs.
2021-05-11 08:28:17 -07:00
John McCall
ec5215bf4f Remove the implicit nil inhabitant of Builtin.Executor,
and traffic in Optional<Builtin.Executor> in various places.
2021-04-30 03:11:56 -04:00
Konrad `ktoso` Malawski
ba615029c7 [Concurrency] Store child record when async let child task spawned 2021-04-19 10:06:23 +09:00
John McCall
82c190af21 Merge pull request #36751 from rjmccall/two-word-executor
Change ExecutorRef and fix the actor runtime
2021-04-08 16:49:37 -04:00
John McCall
156264f8e8 Make ExecutorRef two words. 2021-04-08 12:57:12 -04:00
Saleem Abdulrasool
ffd9c76f86 IRGen: repair the IRGen on Windows
The cross-module reference must be indirected through the moral
equivalent of the GOT - the IAT.  This indirects through the import
address table, permitting the pointer to be resolved.
2021-04-07 14:07:15 -07:00
Nate Chandler
3b6c070c06 [IRGen] Added mechanism to refer to known AFPs. 2021-04-05 18:08:33 -07:00
Dario Rexin
74fce8307c [IRGen] Disable pre-specialization for 32-bit ARM on Linux
This is a temporary workaround for segfaults we observed in TargetMetadata,
caused by invalid pointers.
2021-03-30 13:38:22 -07:00
John McCall
6b36a9ac86 Remove some incorrect references to ExecutorRef 2021-03-28 22:05:37 -04:00
John McCall
98711fd628 Revise the continuation ABI.
The immediate desire is to minimize the set of ABI dependencies
on the layout of an ExecutorRef.  In addition to that, however,
I wanted to generally reduce the code size impact of an unsafe
continuation since it now requires accessing thread-local state,
and I wanted resumption to not have to create unnecessary type
metadata for the value type just to do the initialization.

Therefore, I've introduced a swift_continuation_init function
which handles the default initialization of a continuation
and returns a reference to the current task.  I've also moved
the initialization of the normal continuation result into the
caller (out of the runtime), and I've moved the resumption-side
cmpxchg into the runtime (and prior to the task being enqueued).
2021-03-28 12:58:16 -04:00
Arnold Schwaighofer
340ccb2a5a Revert "arm64e: Workaround ptrauth-returns failure for swifttailcc"
This reverts commit 3c125a74f0.
2021-03-18 10:44:35 -07:00
Arnold Schwaighofer
3c125a74f0 arm64e: Workaround ptrauth-returns failure for swifttailcc
The current code generation will emit an autibsp after adjusting the
stack pointe for the tail call. If callee and caller argument area does
not match this would fail.
2021-03-17 07:41:10 -07:00
John McCall
6c879d6fd3 Change the async ABI to not pass the active task and executor.
Most of the async runtime functions have been changed to not
expect the task and executor to be passed in.  When knowing the
task and executor is necessary, there are runtime functions
available to recover them.

The biggest change I had to make to a runtime function signature
was to swift_task_switch, which has been altered to expect to be
passed the context and resumption function instead of requiring
the caller to park the task.  This has the pleasant consequence
of allowing the implementation to very quickly turn around when
it recognizes that the current executor is satisfactory.  It does
mean that on arm64e we have to sign the continuation function
pointer as an argument and then potentially resign it when
assigning into the task's resume slot.

rdar://70546948
2021-03-16 22:52:54 -04:00
Varun Gandhi
7e6fb9f127 Remove USE_SWIFT_ASYNC_LOWERING CMake setting.
It was added for staging; but that has been completed.
2021-03-12 10:51:08 -08:00
Mike Ash
bedca5ed61 Merge pull request #36139 from mikeash/async-task-dispatch-integration
[Concurrency] Make Job/AsyncTask minimally compatible with dispatch object layout
2021-03-11 18:04:04 -05:00
Arnold Schwaighofer
8c5fc073fd [IRGen] Use coro.end.async to return from an async function
The `coro.end.async` intrinsic allow specifying a function that is to be
tail-called as the last thing before returning.

LLVM lowering will inline the `must-tail-call` function argument to
`coro.end.async`. This `must-tail-call` function can contain a
`musttail` call.

```
define @my_must_tail_call_func(void (*)(i64) %fnptr, i64 %args) {
  musttail call void %fnptr(i64 %args)
  ret void
}

define @async_func() {
  ...
  coro.end.async(..., @my_must_tail_call_func, %return_continuation, i64 %args)
  unreachable
}
```
2021-03-10 10:15:27 -08:00
Mike Ash
bd62fdb2db [Concurrency] Make Job/AsyncTask minimally compatible with dispatch object layout
Create a TargetDispatchClassMetadata for Swift metadata that also has a dispatch-compatible vtable. Dispatch leaves room for ObjC class metadata so the two regions don't overlap. (The vtable currently consists of a single dummy entry; this will be filled out later.)

Rearrange the Job and AsyncTask hierarchy so that AsyncTask inherits only from Job, which in turn inherits from HeapObject. This gives all Job instances a dispatch-compatible isa field. It also gives them a refcount word, which is wasted on instances that aren't AsyncTask instances. Maybe we can find some use for that space in the future.

rdar://75227953
2021-03-10 10:04:30 -05:00
Varun Gandhi
1a1e97ca90 Merge pull request #36163 from varungandhi-apple/vg-tweak-clang-async-check
Change swiftasynccc IRGen check to use alternate API.
2021-02-26 16:10:26 -08:00
Varun Gandhi
755f1e3521 Change swiftasynccc IRGen check to use alternate API. 2021-02-25 09:41:24 -08:00
Konrad `ktoso` Malawski
6e525d7469 Merge branch 'main' into wip-no-escape-group 2021-02-25 10:37:20 +09:00
Arnold Schwaighofer
4f208fef25 Take clang's isSwiftAsyncCCSupported into account 2021-02-24 09:06:08 -08:00
Konrad `ktoso` Malawski
a226259d84 [Concurrency] TaskGroup moves out of AsyncTask, non escaping body 2021-02-22 13:26:27 +09:00
Arnold Schwaighofer
4373bdd6d0 Conditionally start using llvm::CallingConv::SwiftTail for async functions
This is conditional on UseAsyncLowering and in the future should also be
conditional on `clangTargetInfo.isSwiftAsyncCCSupported()` once that
support is merged.

Update tests to work either with swiftcc or swifttailcc.
2021-02-18 09:25:15 -08:00
Varun Gandhi
caf1a55eea Merge pull request #35229 from mininny/switch-find-to-contains
[NFC] Replace uses of find(x) != end() idiom with contains(x) for StringRef and Set-like types
2021-02-08 13:57:43 -08:00
Saleem Abdulrasool
726ce35044 IRGen: repair the windows build of Foundation
Foundation imports `free`, importing it as `dllimport dso_local` which
is not permitted.  Clean up the IRGen to ensure that the two are not
emitted together.
2021-02-03 19:43:02 -08:00
Minhyuk Kim
e924cf6104 Replace usages of StringRef.find(Key) != StringRef::npos to StringRef.contains(Key) 2021-02-04 00:42:04 +09:00
John McCall
b22407ef0c Add a builtin to convert a Task* to a Job*. 2020-12-10 17:06:14 -05:00
Erik Eckstein
9b77fef794 IRGen: fix the async task type for 32 bit platforms 2020-12-04 17:39:20 +01:00