Commit Graph

576 Commits

Author SHA1 Message Date
Nate Chandler
8e2b1277cc [NFC] Clang-formatted 8e9dec23fc.
The commit with the following message wasn't previously formatted.  That
oversight is fixed here.

    [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-05 13:37:23 -08:00
swift_jenkins
36503e0c58 Merge remote-tracking branch 'origin/main' into next 2020-11-05 06:59:09 -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
swift_jenkins
3e5db601d7 Merge remote-tracking branch 'origin/main' into next 2020-11-02 10:06:47 -08:00
Nate Chandler
c502e97a25 [Async CC] Auth'd parent context pointer. 2020-10-28 12:48:54 -07:00
swift_jenkins
3d854c3013 Merge remote-tracking branch 'origin/main' into next 2020-10-28 10:00:57 -07:00
swift_jenkins
01491db27e Merge remote-tracking branch 'origin/main' into next 2020-10-27 18:14:28 -07:00
Nate Chandler
80d1f83b6d [Async CC] Add coroutine fields to context.
The following fields are now available when the function is a coroutine:
- TaskContinuationFunction * __ptrauth(...) yieldToCaller?
- TaskContinuationFunction * __ptrauth(...) resumeFromYield?
- TaskContinuationFunction * __ptrauth(...) abortFromYield?
- ExecutorRef calleeActorDuringYield?
- YieldTypes yieldValues...

These fields have yet to be filled in.

The following field are now available when the function is NOT a
coroutine (whereas previously they were always available):
- ResultTypes directResults...
2020-10-27 18:11:58 -07:00
Nate Chandler
c22c0c523a [Async CC] Add Flags to context. 2020-10-27 18:07:50 -07:00
Nate Chandler
e3f92e4d15 [NFC] Added lambda to add executor.
Filtered code for adding ResumeParentExecutor to the async layout
through the new lambda.
2020-10-27 18:07:39 -07:00
Nate Chandler
5a6290f887 [NFC] Added lambda to add task continuation func.
Filtered code for adding ResumeParent to the async layout through the
new lambda.
2020-10-27 18:06:53 -07:00
Nate Chandler
2ff6ea3693 [Async CC] Pass executor along to callee. 2020-10-27 13:52:59 -07:00
Nate Chandler
ddb739e301 [Async CC] Pass task along from caller to callee. 2020-10-27 13:52:59 -07:00
Nate Chandler
f73eff7e8e [Async CC] Save parent executor into context.
When an async function is called from an async function, the caller
stores its own executor into the the callee's context in the
ResumeParentExecutor field.
2020-10-27 13:52:58 -07:00
David Smith
0180aca9fc Merge branch 'main' into david/fix-merge-conflict 2020-10-27 13:05:20 -07:00
Nate Chandler
c9e567b530 [Async CC] Save parent context into child context.
When an async function is called from an async function, it stores its
own context pointer into the callee's callerContext.
2020-10-27 12:40:54 -07:00
Nate Chandler
904876e6bd [Async CC] Pass the function's task to task_[de]alloc.
Previously, a null task was always passed to
swift_task_alloc/swift_task_dealloc.  Now that the current task is
available as one of the arguments to every async function, pass that
value along to the runtime de/allocation functions.
2020-10-27 12:40:49 -07:00
Nate Chandler
1e0d6f39d7 [Async CC] Add ResumeParentExecutor to context. 2020-10-27 12:40:42 -07:00
Nate Chandler
f29f43907f [Async CC] Add ResumeParent to async context. 2020-10-27 12:40:40 -07:00
Nate Chandler
5d67c4a74b [Async CC] Add parent to async context. 2020-10-27 12:39:56 -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
Nate Chandler
a963d0a66b [Async CC] Added TODO for codesize improvement. 2020-10-23 11:09:46 -07:00
Nate Chandler
b8a5b62f72 [NFC] Cached the layout in AsyncCallEmission. 2020-10-23 11:08:38 -07:00
swift-ci
64ec60bbd4 Merge pull request #34370 from nate-chandler/concurrency/irgen/partial-apply 2020-10-22 13:54:37 -07:00
Nate Chandler
506473dfba [Async CC] Supported partial application.
The majority of support comes in the form of emitting partial
application forwarders for partial applications of async functions.
Such a partial application forwarder must take an async context which
has been partially populated at the apply site.  It is responsible for
populating it "the rest of the way".  To do so, like sync partial
application forwarders, it takes a second argument, its context, from
which it pulls the additional arguments which were capture at
partial_apply time.

The size of the async context that is passed to the forwarder, however,
can't be known at the apply site by simply looking at the signature of
the function to be applied (not even by looking at the size associated
with the function in the special async function pointer constant which
will soon be emitted).  The reason is that there are an unknown (at the
apply site) number of additional arguments which will be filled by the
partial apply forwarder (and in the case of repeated partial
applications, further filled in incrementally at each level).  To enable
this, there will always be a heap object for thick async functions.
These heap objects will always store the size of the async context to be
allocated as their first element.  (Note that it may be possible to
apply the same optimization that was applied for thick sync functions
where a single refcounted object could be used as the context; doing so,
however, must be made to interact properly with the async context size
stored in the heap object.)

To continue to allow promoting thin async functions to thick async
functions without incurring a thunk, at the apply site, a null-check
will be performed on the context pointer.  If it is null, then the async
context size will be determined based on the signature.  (When async
function pointers become pointers to a constant with a size i32 and a
relative address to the underlying function, the size will be read from
that constant.)  When it is not-null, the size will be pulled from the
first field of the context (which will in that case be cast to
<{%swift.refcounted, i32}>).

To facilitate sharing code and preserving the original structure of
emitPartialApplicationForwarder (which weighed in at roughly 700 lines
prior to this change), a new small class hierarchy, descending from
PartialApplicationForwarderEmission has been added, with subclasses for
the sync and async case.  The shuffling of arguments into and out of the
final explosion that was being performed in the synchronous case has
been preserved there, though the arguments are added and removed through
a number of methods on the superclass with more descriptive names.  That
was necessary to enable the async class to handle these different
flavors of parameters correctly.

To get some initial test coverage, the preexisting
IRGen/partial_apply.sil and IRGen/partial_apply_forwarder.sil tests have
been duplicated into the async folder.  Those tests cases within these
files which happened to have been crashing have each been extracted into
its own runnable test that both verifies that the compiler does not
crash and also that the partial application forwarder behaves correctly.
The FileChecks in these tests are extremely minimal, providing only
enough information to be sure that arguments are in fact squeezed into
an async context.
2020-10-22 12:21:56 -07:00
Nate Chandler
03f4e40f20 [Async CC] Move self after formal arguments.
Partial applies of methods supply only self.  When applies of the
resulting thick function are performed, that self was one of the
arguments is not known.  As a result, self must appear after the fields
that might be supplied at the apply site, which  is to say all the
arguments.
2020-10-21 16:20:51 -07:00
Nate Chandler
63b5ba457e [NFC] Used consistent style for casting. 2020-10-21 16:19:29 -07:00
Nate Chandler
0356c9f4c0 [NFC] Simplify saving of self to async context. 2020-10-21 16:19:20 -07:00
Nate Chandler
a9aee1b9dd [Async CC] Put bindings after formal arguments.
Bindings will always be supplied by the first partial apply, so they
will only be added to the async context when its full layout is known.
If they are earlier in the layout, subsequent partial applies will put
their arguments into the wrong position because they will not be privy
to the space requirements of the bindings.
2020-10-21 16:18:29 -07:00
Nate Chandler
97202faee5 [Async CC] Put direct returns after indirect returns.
For callers who do not know the actual type of the called function, e.g.
when the called function is the result of a partial apply, the offset to
the direct returns would otherwise not be known.
2020-10-21 16:18:25 -07:00
swift-ci
7e16e3b4d2 Merge pull request #30630 from martinboehme/cxx-constructors 2020-10-20 14:37:29 -07:00
zoecarver
1d3b051151 [cxx-interop] Remove logic around applying attributes.
Removes the logic around applying attributes to C++ constructor's
indirect results.

Also fixes some commenting.
2020-10-15 13:10:55 -07:00
zoecarver
20222bb2ad [cxx-interop] Bail if trying to convert call result to void.
Don't try to coerce the result of a call to void. If the "expected"
result type is void, just bail.
2020-10-15 13:10:54 -07:00
Robert Widmann
0d6a16258a Silence a Deprecation Warning with FixedVectorType 2020-10-14 13:31:14 -07:00
zoecarver
5774610eaf [cxx-interop] Fix patch formatting with clang-format.
Fix all formatting of the changes made by this patch.
2020-10-09 10:42:55 -07:00
zoecarver
f04de9f128 [cxx-interop] Skip metatypes when lowering C++ constructor SIL function type.
When lowering a C++ constructor's function type to a SIL function type,
skip over the "self" metatype parameter.
2020-10-09 10:42:54 -07:00
zoecarver
7635443915 [cxx-interop] Update ABIArgInfo::Indirect case in expandExternalSignatureTypes to handle thin metatype parameters.
Add second list of SILParameterInfos that excludes thin metatypes so
that the "Indirect" argument path below will select the correct
parameter info.
2020-10-09 10:42:54 -07:00
Martin Boehme
1ce3753d08 Another response to review comments. 2020-10-09 10:42:51 -07:00
Martin Boehme
beaaa742c3 Don't put an sret attribute on the this argument. 2020-10-09 10:42:49 -07:00
Martin Boehme
b2c5a3eeed Add a constructor thunk if required to add additional constructor
arguments.

Also add more IR tests and make various other changes.
2020-10-09 10:42:48 -07:00
Martin Boehme
a5e953b690 Add support for calling C++ constructors.
Because C++ constructors always take a `this` pointer to the object to
be initialized, we mark the SIL function return type with the `@out`
attribute.

On the IRGen side, we retrofit support for formal indirect return values as
well as thin metatypes.
2020-10-09 10:42:46 -07:00
swift_jenkins
833e4c1eb4 Merge remote-tracking branch 'origin/main' into next 2020-10-07 14:46:15 -07:00
swift_jenkins
63df033221 Merge remote-tracking branch 'origin/main' into next 2020-10-06 20:37:03 -07:00
Nate Chandler
4c298db529 [NFC] Extracted async call emission loading.
Previously the code for loading indirect returns was inline in the
member function where it was performed.  Here it is pulled out into a
private method.
2020-10-06 17:03:38 -07:00
Nate Chandler
6e0d894325 [NFC] Deduped async call emission code.
Previously the same code was used for saving values into the async
context.  Here, that code is extracted into a private method.
2020-10-06 17:03:35 -07:00
Nate Chandler
7d74a8614d [Concurrency] Async CC supports witness methods.
Previously, the AsyncContextLayout did not make space for the trailing
witness fields (self metadata and self witness table) and the
AsyncNativeCCEntryPointArgumentEmission could consequently not vend
these fields.  Here, the fields are added to the layout.
2020-10-06 17:03:03 -07:00
Nate Chandler
eba39cffe6 [Concurrency] Corrected ordering of indirect results.
Previously, the indirect results were claimed from the explosion after
the arguments were claimed.  That failed to match the order in which
arguments actually appear in the explosion.  Here the order is reversed.
2020-10-06 17:03:01 -07:00
Nate Chandler
72051efa03 [Concurrency] Async CC for protocol extension methods.
Use the TypeInfo for the argument lowering type of the self parameter
rather than for the self parameter's type itself.
2020-10-06 11:55:29 -07:00