Commit Graph

1699 Commits

Author SHA1 Message Date
Michael Gottesman
133901d6f6 [irgen] Emit shadow copies for ConstantDataVector.
LLVM seems to not support this today. With ownership SSA, we now produce these
for accelerate for some reason, causing lldb/TestAccelerateSIMD.py to fail. I
debugged this with Adrian and we got this fix. I filed the radar below against
Adrian to fix.

rdar://74287800
2021-02-12 23:20:17 -08:00
eeckstein
d6a7e9b532 Merge pull request #35935 from eeckstein/basicblock-worklist
SIL: A utility for processing basic blocks in a worklist.
2021-02-13 07:35:44 +01:00
Slava Pestov
72e1f02ae2 IRGen: Fix async dispatch thunk emission with loadable return value
Fixes <rdar://problem/74246091>.
2021-02-12 14:06:07 -05:00
Erik Eckstein
214b7a9929 Use the new BasicBlockWorklist utility in various places in the compiler.
It's a refactoring which simplifies the code.
NFC.
2021-02-12 11:15:55 +01:00
Erik Eckstein
fe10f98cf0 SIL: rename the SILBitfield.h header file to BasicBlockBits.h
NFC
2021-02-12 11:15:55 +01:00
Nate Chandler
e2a8abc9e5 [Async CC] Make error indirect.
Previously, the error stored in the async context was of type SwiftError
*.  In order to enable the context to be callee released, make it
indirect and change its type to SwiftError **.

rdar://71378532
2021-02-11 11:34:47 -08:00
Arnold Schwaighofer
5a6de1ba77 IRGen: Use opaque storage types for non-fixed indirect result types
LLVM does type based analysis on sret storage types. This is a problem
with non-fixed types whose storage type does not contain the non-fixed
part.

rdar://73778591
2021-02-10 16:19:12 -08:00
Erik Eckstein
44f07aea2b IRGen: a small refactoring in GenConstant
Just moving a few functions around and make emitConstantValue the main entry point for creating constants.

NFC
2021-02-09 19:56:43 +01:00
Adrian Prantl
b3f5ac3281 Add debug info support for boxed arguments in async functions.
Usually debug info only ever describes the *result* of a projectBox
call. To display a boxed parameter of an async continuation object,
however, the debug info can only describe the box itself and thus also
needs to emit a box type for it so the debugger knows to call into
Remote Mirrors to unbox the value.

SR-14059
rdar://problem/73358988
2021-02-03 14:40:36 -08:00
swift-ci
d0d8027d7c Merge pull request #35579 from devincoughlin/tsan-empty-types 2021-02-03 00:42:03 -08:00
Devin Coughlin
38503da505 [TSan] Don't instrument inout accesses on known-empty types
Empty types (such as structs without stored properties) have a
meaningless value for their address. To avoid crashes in the Thread
Sanitizer runtime, rather than passing this unspecified value as
the address of the inout access, skip emission of the runtime call.

The bug allowing unspecified behavior here has been present since we
first added TSan support for checking Swift access races -- but codegen
changes on arm64 have recently made crashes due to the bug much more
likely.

rdar://problem/47686212
2021-02-02 21:22:04 -08:00
Slava Pestov
844ce09124 IRGen: Refer to dispatch thunk async function pointers when making calls
Part of rdar://problem/73625623.
2021-01-28 18:04:27 -05:00
Slava Pestov
c79de40225 IRGen: Emit async function pointers for resilient class and protocol dispatch thunks
This adds new kinds of link entities corresponding to the three
dispatch thunk link entity kinds:

- DispatchThunkAsyncFunctionPointer
- DispatchThunkInitializerAsyncFunctionPointer
- DispatchThunkAllocatorAsyncFunctionPointer
2021-01-27 15:21:22 -05:00
Slava Pestov
8440a8226f IRGen: More refactoring in preparation for emitting async function pointers for dispatch thunks 2021-01-27 13:50:34 -05:00
Erik Eckstein
c638a2f19f IRGen: replace SmallPtrSet<SILBasicBlock *> with BasicBlockSet in emitSILFunction() 2021-01-27 10:16:43 +01:00
Philippe Hausler
6e05240426 AsyncSequence and protocol conformance rethrows (#35224)
* Initial draft of async sequences

* Adjust AsyncSequence associated type requirements

* Add a draft implementation of AsyncSequence and associated functionality

* Correct merge damage and rename from GeneratorProtocol to AsyncIteratorProtocol

* Add AsyncSequence types to the cmake lists

* Add cancellation support

* [DRAFT] Implementation of protocol conformance rethrowing

* Account for ASTVerifier passes to ensure throwing and by conformance rethrowing verifies appropriately

* Remove commented out code

* OtherConstructorDeclRefExpr can also be a source of a rethrowing kind function

* Re-order the checkApply logic to account for existing throwing calculations better

* Extract rethrowing calculation into smaller functions

* Allow for closures and protocol conformances to contribute to throwing

* Add unit tests for conformance based rethrowing

* Restrict rethrowing requirements to only protocols marked with @rethrows

* Correct logic for gating of `@rethrows` and adjust the determinates to be based upon throws and not rethrows spelling

* Attempt to unify the async sequence features together

* Reorder try await to latest syntax

* revert back to the inout diagnosis

* House mutations in local scope

* Revert "House mutations in local scope"

This reverts commit d91f1b25b59fff8e4be107c808895ff3f293b394.

* Adjust for inout diagnostics and fall back to original mutation strategy

* Convert async flag to source locations and add initial try support to for await in syntax

* Fix case typo of MinMax.swift

* Adjust rethrowing tests to account for changes associated with @rethrows

* Allow parsing and diagnostics associated with try applied to for await in syntax

* Correct the code-completion for @rethrows

* Additional corrections for the code-completion for @rethrows this time for the last in the list

* Handle throwing cases of iteration of async sequences

* restore building XCTest

* First wave of feedback fixes

* Rework constraints checking for async sequence for-try-await-in checking

* Allow testing of for-await-in parsing and silgen testing and add unit tests for both

* Remove async sequence operators for now

* Back out cancellation of AsyncIteratorProtocols

* Restructure protocol conformance throws checking and cache results

* remove some stray whitespaces

* Correct some merge damage

* Ensure the throwing determinate for applying for-await-in always has a valid value and adjust the for-await-in silgen test to reflect the cancel changes

* Squelch the python linter for line length
2021-01-25 18:48:50 -08:00
Arnold Schwaighofer
17109ccfc7 IRGen: Fix unreachable lowering in async functions
We need to add the coro.end intrinsic call for lowering to process
functions correctly.

rdar://73274012
2021-01-19 08:48:11 -08:00
Konrad `ktoso` Malawski
9e1ecc539c [Concurrency] guard offer/poll with a lock for now; cleanups 2020-12-17 06:05:13 +09:00
Konrad `ktoso` Malawski
7b37554096 [Concurrency] Initial TaskGroup implementation working 2020-12-17 06:05:13 +09:00
Konrad `ktoso` Malawski
e294c7cbad [Concurrency] Implement TaskGroup.isEmpty via readyQueue
before reversing order of fragments; future must be last since dynamic
size

offer fixed

before implementing poll
2020-12-17 06:05:13 +09:00
Nate Chandler
d4664c8bc2 [Async CC] Never use simple partial apply for async functions.
Currently, the convention for partially applying an async function is to
form a thick function consisting of (1) a pointer to the partial apply
forwarder and (2) a thick context containing the async context size.

Previously, the partial application of async methods--specifically, for
which the partial application of the non-async analog produced a simple
partial apply (meaning that their context was a single ref-counted
object in the form of self)--would result in a simple partial
application.  Here, that error is addressed by never allowing the
partial application of async methods to produce a simple partial apply.

Eventually, when the complex temporary ABI for partial application of
async functions is unrolled, this change will need to be unrolled as
well.
2020-12-15 17:27:54 -08:00
Adrian Prantl
0e6a0b84d1 Add debug info support for function arguments in async functions.
This commit depends on changes to the coroutine-splitting pass in LLVM.  Shadow
copies are also turned off for async function arguments, because they make it
impossible to track debug info during coroutine splitting. Instead we are
relying on LLVM's CoroSplit.cpp to emit shadow copies. The Swift frontend gives
CoroSplit license to move do this by describing the arguments using a
dbg.declare intrinsic, even though it points to chain of load/GEP/bitcase
instructions into the Swift context function argument.

rdar://71866936
2020-12-11 16:59:09 -08:00
Slava Pestov
c133e13efd Merge pull request #34916 from slavapestov/with-unsafe-continuation
Concurrency: Implement withUnsafe[Throwing]Continuation
2020-12-03 11:18:49 -05:00
Erik Eckstein
4e296c0c5a IRGen: emit emit_hop_to_executor instructions.
This basically means to create a suspension point and call the swift_task_switch runtime function.

rdar://71099289
2020-12-03 12:42:41 +01:00
Slava Pestov
a2dbdecdab SIL: Refactor get_async_continuation[_addr] to return a RawUnsafeContinuation 2020-12-01 20:04:09 -05:00
Erik Eckstein
bf2be9eb5d [concurrency] IRGen: update task/executor/context on every suspend point
For this, store those 3 values on the stack at function entry and update them with the return values of coro_suspend_async intrinsic calls.

This fixes a correctness issue, because the executor may be different after a resume.
It also is more efficient, because this means that the 3 values don't have to preserved in the context over a suspension point.
2020-12-01 15:19:39 +01:00
Arnold Schwaighofer
b0be562ded Merge pull request #34829 from aschwaighofer/irgen_get_await_async_continuation
IRGen: get/await_async_continuation support
2020-11-30 11:22:55 -08:00
Augusto Noronha
89fab1b06b Allow the creation of a shadow variable when the type is a refcounted pointer (#34835) 2020-11-30 09:07:23 -08:00
Arnold Schwaighofer
d75e4c2bd2 IRGen: get/await_async_continuation support.
rdar://71124933
2020-11-19 08:43:26 -08:00
Arnold Schwaighofer
fbfcaabb83 IRGen: Allow calling a pre-defined async silgen_name function using the async convention
The function can then be implemented in the runtime.

Note: This is a temporary hack.
2020-11-17 15:02:13 -08:00
nate-chandler
f8556287c7 Merge pull request #34765 from nate-chandler/concurrency/irgen/thick-context-in-async-context
[Async CC] Move thick context into async context.
2020-11-16 14:21:46 -08:00
Nate Chandler
eba057fe88 [Async CC] Move thick context into async context.
Previously, the thick context was passed as a fourth parameter to
partial apply forwarders.  Here, the thick context is instead moved into
the async context at the local context position.  To support this, the
local context is made always available.
2020-11-16 12:02:32 -08:00
Arnold Schwaighofer
4ec01a8c05 IRGen: Fix debug emission for dynamically sized stack vars
rdar://71427419
2020-11-16 07:07:23 -08:00
Nate Chandler
357988ecf8 [Async CC] Unroll workaround where @main was async.
As part of concurrency bringup, some workarounds were put in place to
enable the async cc execution tests to continue to run while enabling
async function SIL verification (specifically, that an async function
must be called from an async function) to land before we have the
Task.runDetached mechanism.  Specifically, these workaround allow @main
to be annotated @async but continue to be emitted as if it were not
@async.

Now that we have a better mechanism in the form of runAsync, use that
instead.

rdar://problem/70597390
2020-11-14 15:28:05 -08:00
nate-chandler
9116af96db Merge pull request #34743 from nate-chandler/concurrency/irgen/rdar71260972
[Async CC] Never map to native explosions.
2020-11-14 13:20:38 -08:00
Nate Chandler
11723ccc55 [Async CC] Never map to native explosions.
Previously, when lowering the entry point of an async function, the
parameters were lowered to explosions that matched those of sync
functions, namely native explosions.  That is incorrect for async
functions where the structured values are within the async context.
Here, that error is fixed, by adding a new customization point to
NativeCCEntryPointArgumentEmission which behaves as before for sync
functions but which simply extracts an argument from the async context
for async functions.

rdar://problem/71260972
2020-11-13 19:45:03 -08:00
Arnold Schwaighofer
74419d0885 Lower asynchronous functions to LLVM async coroutine intrinsics
rdar://70097093
2020-11-13 10:41:42 -08:00
Nate Chandler
2d21932672 [Async CC] Add constant "pointer" for async func.
An AsyncFunctionPointer, defined in Task.h, is a struct consisting of
two i32s: (1) the relative address of the async function and (2) the
size of the async context to be allocated when calling that function.

Here, such structs are emitted for every async SILFunction that is
emitted.
2020-11-12 18:20:10 -08:00
Michael Gottesman
f36e8561f1 [ownership] Use a new ADT SwitchEnumBranch instead of SwitchEnumInstBase for generic operations on SwitchEnum{,Addr}Inst.
I have a need to have SwitchEnum{,Addr}Inst have different base classes
(TermInst, OwnershipForwardingTermInst). To do this I need to add a template to
SwitchEnumInstBase so I can switch that BaseTy. Sadly since we are using
SwitchEnumInstBase as an ADT type as well as an actual base type for
Instructions, this is impossible to do without introducing a template in a ton
of places.

Rather than doing that, I changed the code that was using SwitchEnumInstBase as
an ADT to instead use a proper ADT SwitchEnumBranch. I am happy to change the
name as possible see fit (maybe SwitchEnumTerm?).
2020-11-08 19:52:02 -08:00
Nate Chandler
8e9dec23fc [NFC] Construct AsyncContextLayout from module.
Previously, an IRGenFunction was being passed to the functions that
construct an AsyncContextLayout.  That was not actually necessary and
prevented construction of the layout in contexts where no IRGenFunction
was present.  Here that requirement is eased to requiring an IRGenModule
which is indeed required to construct an AsyncContextLayout.
2020-11-04 18:42:06 -08:00
John McCall
e35f077a9b Merge pull request #33349 from ellishg/master
[IRGen] Call objc_direct methods correctly
2020-10-30 03:03:54 -04:00
Erik Eckstein
f18a9b8ee8 [Concurrency] SIL: add hop_to_executor instruction
This instructions ensures that all instructions, which need to run on the specified executor actually run on that executor.
For details see the description in SIL.rst.
2020-10-28 18:17:43 +01:00
Nate Chandler
a5b9e86850 [NFC] Used convenience to retrieve context arg. 2020-10-26 20:27:52 -07:00
Nate Chandler
b65d71b24a [Async CC] Added conveniences to retrieve argumments.
Because all async functions have the same signature, namely

  void(%swift.task*, %swift.executor*, %swift.context*)

it is always possible to provide access to the three argument values
(the current task, current executor, and current context) within an
IRGenFunction which is async.  Here, that is provided in the form of
IRGenFunction::getAsyncExecutor,IRGenFunction::getAsyncContext, and
IRGenFunction::getAsyncTask.
2020-10-26 20:07:56 -07:00
Nate Chandler
b74052cdd2 [Async CC] Added task and executor args.
The previous stage of bringup only had async functions taking a single
argument: the async context.  The next stage will involve the task and
executor.  Here, arguments are added for those values.  To begin with,
null is always passed for these values.
2020-10-26 14:27:16 -07:00
nate-chandler
d1bfe027c0 Merge pull request #34402 from nate-chandler/concurrency/irgen/tests-all-async
[Async CC] Test: Mark functions that call async functions async.
2020-10-26 09:59:48 -07:00
Slava Pestov
360e406d3a SIL: Rename SILFunction::hasSelfMetadataParam()/getSelfMetadataArgument()
These are only for class types and are related to the usage of the
DynamicSelfType, so rename them to {has,get}DynamicSelfMetadata().
2020-10-23 21:35:11 -04:00
Nate Chandler
e066588460 [IRGen] Temporarily treat @async @convention(c) as not async. 2020-10-23 11:08:38 -07:00
Nate Chandler
128c7bc03a [NFC] Whitespace. 2020-10-23 11:08:38 -07:00
Ellis Hoag
3aa081c56e [IRGen] Call objc_direct methods correctly 2020-10-23 11:54:07 -05:00