* [SUA][IRGen] Add stub for swift_coroFrameAlloc that weakly links against the runtime function
This commit modifies IRGen to emit a stub function `__swift_coroFrameAllocStub` instead of the
newly introduced swift-rt function `swift_coroFrameAlloc`. The stub checks whether the runtime has the symbol
`swift_coroFrameAlloc` and dispatches to it if it exists, uses `malloc` otherwise. This ensures the
ability to back deploy the feature to older OS targets.
rdar://145239850
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".
I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
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.
Here, the following is implemented:
- Construction of SwiftContext struct with the fields needed for calling
functions.
- Allocating and deallocating these swift context via runtime calls
before calling async functions and after returning from them.
- Storing arguments (including bindings and the self parameter but not
including protocol fields for witness methods) and returns (both
direct and indirect).
- Calling async functions.
Additional things that still need to be done:
- protocol extension methods
- protocol witness methods
- storing yields
- partial applies
The goals here are four-fold:
- provide cleaner internal abstractions
- avoid IR bloat from extra bitcasts
- avoid recomputing function-type lowering information
- allow more information to be propagated from the function
access site (e.g. class_method) to the call site
Use this framework immediately for class and protocol methods.
SubstitutionList is going to be a more compact representation of
a SubstitutionMap, suitable for inline allocation inside another
object.
For now, it's just a typedef for ArrayRef<Substitution>.
Now we can discern the types of values in heap boxes at runtime!
Closure reference captures are a common way of creating reference
cycles, so this provides some basic infrastructure for detecting those
someday.
A closure capture descriptor has the following:
- The number of captures.
- The number of sources of metadata reachable from the closure.
This is important for substituting generics at runtime since we
can't know precisely what will get captured until we observe a
closure.
- The number of types in the NecessaryBindings structure.
This is a holding tank in a closure for sources of metadata that
can't be gotten from the captured values themselves.
- The metadata source map, a list of pairs, for each
source of metadata for every generic argument needed to perform
substitution at runtime.
Key: The typeref for the generic parameter visible from the closure
in the Swift source.
Value: The metadata source, which describes how to crawl the heap from
the closure to get to the metadata for that generic argument.
- A list of typerefs for the captured values themselves.
Follow-up: IRGen tests for various capture scenarios, which will include
MetadataSource encoding tests.
rdar://problem/24989531
Similarly to how we've always handled parameter types, we
now recursively expand tuples in result types and separately
determine a result convention for each result.
The most important code-generation change here is that
indirect results are now returned separately from each
other and from any direct results. It is generally far
better, when receiving an indirect result, to receive it
as an independent result; the caller is much more likely
to be able to directly receive the result in the address
they want to initialize, rather than having to receive it
in temporary memory and then copy parts of it into the
target.
The most important conceptual change here that clients and
producers of SIL must be aware of is the new distinction
between a SILFunctionType's *parameters* and its *argument
list*. The former is just the formal parameters, derived
purely from the parameter types of the original function;
indirect results are no longer in this list. The latter
includes the indirect result arguments; as always, all
the indirect results strictly precede the parameters.
Apply instructions and entry block arguments follow the
argument list, not the parameter list.
A relatively minor change is that there can now be multiple
direct results, each with its own result convention.
This is a minor change because I've chosen to leave
return instructions as taking a single operand and
apply instructions as producing a single result; when
the type describes multiple results, they are implicitly
bound up in a tuple. It might make sense to split these
up and allow e.g. return instructions to take a list
of operands; however, it's not clear what to do on the
caller side, and this would be a major change that can
be separated out from this already over-large patch.
Unsurprisingly, the most invasive changes here are in
SILGen; this requires substantial reworking of both call
emission and reabstraction. It also proved important
to switch several SILGen operations over to work with
RValue instead of ManagedValue, since otherwise they
would be forced to spuriously "implode" buffers.
This should cover most temporary buffers, except for those used by indirected value arguments, which need some cooperation with CallEmission to properly mark lifetime end after the call's completed.
Share the code that does elementwise coercions, which already behaved correctly, with the code that does struct-to-struct coercions, which still had the overly-conservative constraint. Fixes rdar://problem/21294916.
Swift SVN r29399
As part of this, re-arrange the argument order so that
generic arguments come before the context, which comes
before the error result. Be more consistent about always
adding a context parameter on thick functions, even
when it's unused. Pull out the witness-method Self
argument so that it appears last after the error
argument.
Swift SVN r26667
was incomplete; we do use it on i386 for arbitrary small
aggregates, and unfortunately this means we have to learn
how to expand quite a lot of types.
Tested by the i386-simulator build. I still think
we can completely remove this code relatively soon.
Swift SVN r24981
the C calling convention.
You might notice the absence of tests. Older versions of Clang
used Expand for ARM64 homogeneous aggregates. Trunk Clang no
longer does this, and indeed, on Apple platforms we no longer
use Expand to pass any kind of argument at all. The only target
in trunk that uses it is the Windows target's vectorcall
alternative CC, which I have no way to convince Swift to
generate a call against. Therefore this code is completely
dead in trunk, and thus untestable.
Removing Expand completely from Clang would be the ideal solution,
but that's politically tricky because this is a part of Clang
that's frequently edited by people supporting out-of-tree backends.
I've started the process, but until then, if we're going to have
dead code, it ought to at least be correct dead code.
This commit fixes rdar://19199427, or at least it will
when it's merged to branches that actually use Expand.
Swift SVN r24949
Until now, we treated all value parameters as +1, and all indirect parameters as +0 by reference, which is totally bogus. Now that we'll be partially applying guaranteed parameters, for instance to implement SomeType.foo curried method references, we need to get this right.
This breaks curries that capture dependent-layout parameters by value, but they were already broken due to us treating them as 'inout' captures. I'll fix this by adding NecessaryBindings and NonFixedOffsets to HeapLayout next.
Swift SVN r24475
Modeling builtins as first-class function values doesn't really make sense because there's no real function value to emit, and modeling them this way complicates passes that work with builtins because they have to invent function types for builtin invocations. It's much more straightforward to have a single instruction that references the builtin by ID, along with the type information for the necessary values, type parameters, and results, so add a new "builtin" instruction that directly represents a builtin invocation. NFC yet.
Swift SVN r22690
it means that the argument should be passed as that
expanded sequence of types.
It turns out that LLVM makes an effort to automatically
break apart such arguments during CC lowering, but (1) it's
friendlier to break them apart ourselves and (2) it's
necessary to break them apart if we want to call inline
functions from the header.
Fixes rdar://17631440
Swift SVN r21420
Implement the init_block_storage_header SIL instruction by teaching IRGen how to produce block descriptors, including copy/dispose helpers and block signatures.
Swift SVN r16478
Adds generation of signext/zeroext for return value and arguments when
generating C/ObjC entrypoints.
<rdar://problem/16056735> tracks doing this more generally for call
sites as well as for native entrypoints.
Swift SVN r13862
Updates to signature expansion, entrypoint lowering, and callsite
lowering so that each selects the ABI types for all arguments at once
rather than an argument at a time (as well as considering whether the
return value is returned indirectly). This is required to get the
correct behavior in cases where we run out of argument registers and
need to pass arguments as indirect byvals.
This is mostly just refactoring existing code to move loops inside inner
functions as well as dealing with return values at the same time as
arguments.
Swift SVN r13781
Reapply r13532 fixes for dealing with arguments that should be exploded
for C/Obj-C functions.
This gets us a bit closer to properly generating the correct types for
arguments. The remaining piece is generating all the argument types at
once rather than one at a time, which also requires being able to always
generate Clang types for the Swift types we see in the signatures of
these functions.
Swift SVN r13638
Make ApplyInst and PartialApplyInst directly take substitutions for generic functions instead of trying to stage out substitutions separately. The legacy reasons for doing this are gone.
Swift SVN r8747
Now that SILGen and IRGen can both handle capturing archetypes from generic scopes, we can set the DeclContext of ImplicitClosureExprs correctly, so that SILGen captures their context archetypes. &&, and ||, and assert now work in generic contexts, at least in simple test cases.
Swift SVN r5476
If a specialization is partially applied, emit a single thunk bundling the bound polymorphic arguments and the partially-applied argument values into a single context object. This should almost get closures in generic contexts (at least, ones that never cross abstraction boundaries) working.
Swift SVN r5475
Delete the non-placement operator new/delete in the SILAllocated CRTP base so that the compiler saves us from accidentally allocating and leaking SILInstructions on the main heap instead of the owning SILModule's BPA.
Swift SVN r5468
Teach IRGen how to emit thunks for SpecializeInsts that aren't immediately called and actually get used as values. This allows generic function instance to get passed around as values (again), and is a step along the way to making closures in generic contexts work (so we can specialize the local function, then partially apply its specialized context).
This doesn't work yet if we specialize to local archetypes--SIL needs to learn that we need a [thick]-typed thunk for local archetype specializations, in order to pack the metadata and wtables for the local type variables.
Swift SVN r5083