Commit Graph

1047 Commits

Author SHA1 Message Date
Slava Pestov
361d49a843 AST: Remove DeclContext::getSelfProtocolType() 2023-08-30 15:15:08 -04:00
Slava Pestov
b2ffac54d3 IRGen: Fulfill pack metadata from tuple metadata
When the SelfMetadata in a witness thunk is the tuple type (repeat each Self),
we can fulfill the pack shape and type metadata for Pack{repeat each Self}
from tuple metadata.

The length is trivially projected; the type metadata pack is slightly more
involved, because tuple metadata stores a list of element/offset pairs, so
we must stack allocate a pack and fill it in.
2023-08-24 17:57:10 -04:00
Slava Pestov
99d68ba14c IRGen: Some progress toward tuple conformances 2023-08-18 12:12:50 -04:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
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.
2023-06-27 09:03:52 -07:00
Slava Pestov
c84a14fdc1 IRGen: Conditional conformances for variadic types 2023-06-21 13:42:57 -04:00
Slava Pestov
a892b9196b IRGen: bindOpenedElementArchetypesAtIndex() should use bindGenericRequirement()
Fixes rdar://problem/107852985.
2023-04-20 22:05:34 -04:00
Slava Pestov
d3f0cbeea3 IRGen: Fix conformances of variadic generic types
Fixes rdar://107480494.
2023-04-05 23:42:16 -04:00
Slava Pestov
7ad2365278 AST: Introduce PackType::unwrapSingletonPackExpansion() 2023-04-02 23:04:00 -04:00
Slava Pestov
8a6bb30c4c IRGen: Heap-allocate metadata and witness table packs captured by escaping closures 2023-03-28 21:44:53 -04:00
Slava Pestov
cca91797ed IRGen: Hollow out NecessaryBindings
This removes the "optimization" where a function type, metatype or
tuple type was split up into structural components, because it seems
that in general we need this structural type metadata again.

Similarly, this no longer tries to split up dependent concrete
conformances and instead passes the witness table in the context.

This makes the context larger potentially, but it avoids calls to
metadata access functions and swift_getWitnessTable() every time the
closure is invoked.
2023-03-28 19:21:45 -04:00
Slava Pestov
5e69db0d52 IRGen: Start plumbing shapes through NecessaryBindings 2023-03-28 19:21:45 -04:00
Slava Pestov
a355c38a34 AST: Rename ProtocolConformance::getSubstitutions() to getSubstitutionMap() and remove ModuleDecl parameter 2023-03-21 16:16:34 -04:00
John McCall
ce9013a3f6 Fix IRGen to not use outlining for types with any kind of local archetype.
Previously it was testing for opened existentials specifically.

We should really teach outlining to handle local archetypes properly.
We'd have to build a generic signature for the lowered type, and that
probably means also adding requirements that are relevant to value
operations, but it would mean outlining would benefit all types, and
it would let us avoid bundling in unnecessary information from the
enclosing generic environment.

A minor side-effect of this is that we no longer bind names to
opened element type values.  The names were things like \tau_1_0,
which is not very useful, especially in LLVM IR where \tau is
printed with two UTF-8 escapes.
2023-03-10 19:00:28 -05:00
John McCall
0e932329c3 Fix fulfillments for type metadata and witness table packs
A lot of the fixes here are adjustments to compensate in the
fulfillment and metadata-path subsystems for the recent pack
substitutions representation change.  I think these adjustments
really make the case for why the change was the right one to make:
the code was clearly not considering the possibility of packs
in these positions, and the need to handle packs makes everything
work out much more cleanly.

There's still some work that needs to happen around type packs;
in particular, we're not caching them or fulfilling them as a
whole, and we do have the setup to do that properly now.
2023-03-10 12:52:37 -05:00
Slava Pestov
7d779a9b36 IRGen: Fulfillment of pack shapes from nominal type metadata 2023-03-10 12:15:55 -05:00
Slava Pestov
05849e6268 IRGen: Start to emit generic context metadata for packs 2023-03-03 14:16:54 -05:00
Slava Pestov
8af5bbedc3 AST: Factor out GenericSignatureImpl::getShapeClasses() 2023-03-03 14:16:54 -05:00
Slava Pestov
32caa17b11 Runtime: Finish removing the 'extra argument' notion 2023-03-03 02:21:08 -05:00
Arnold Schwaighofer
998c7ae4c4 IRGen: Outline some of the relative protocol witness table code generation to save on code size
rdar://98583748
2023-03-01 09:49:23 -08:00
Arnold Schwaighofer
38f51d68f3 Support witness table elimination in relative protocol witness tables mode
Needs https://reviews.llvm.org/D143204 which as merged here:

llvm-project/pull/6198
llvm-project/pull/6197

rdar://98583748
2023-02-23 07:39:52 -08:00
Arnold Schwaighofer
1fa68ff82b Sign relative protocol witness tables
rdar://98583748
2023-02-20 12:29:13 -08:00
Nate Chandler
210ef1f75a [IRGen] Emit witness tables for packs.
This mostly mirrors what's already implemented for metadata pack emission.
2023-02-07 10:30:08 -08:00
Nate Chandler
6a44de214d [GenericRequirement] Added pack variants.
Added pack flavors of requirement kinds for metadata and witness tables.

Fixes the function signatures for variadic generic functions which
previously used %swift.type* for variadic generic parameters--those are
lists of metadata and should actually be %swift.type**.
2023-02-02 12:48:39 -08:00
Nate Chandler
28c8c6e0b1 [NFC] GenericRequirement vends an llvm::Type *.
The mapping from requirement kind to llvm::Type is repeated several
places.  Pull it into a helper.
2023-02-02 12:48:39 -08:00
Arnold Schwaighofer
2a4e0ffd7d IRGen: Don't use relative pointers for value witness tables under relative procotol witness tables mode 2023-01-30 07:21:22 -08:00
John McCall
d25a8aec8b Add explicit lowering for value packs and pack expansions.
- SILPackType carries whether the elements are stored directly
  in the pack, which we're not currently using in the lowering,
  but it's probably something we'll want in the final ABI.
  Having this also makes it clear that we're doing the right
  thing with substitution and element lowering.  I also toyed
  with making this a scalar type, which made it necessary in
  various places, although eventually I pulled back to the
  design where we always use packs as addresses.

- Pack boundaries are a core ABI concept, so the lowering has
  to wrap parameter pack expansions up as packs.  There are huge
  unimplemented holes here where the abstraction pattern will
  need to tell us how many elements to gather into the pack,
  but a naive approach is good enough to get things off the
  ground.

- Pack conventions are related to the existing parameter and
  result conventions, but they're different on enough grounds
  that they deserve to be separated.
2023-01-29 03:29:06 -05:00
Arnold Schwaighofer
8a38738abf IRGen: Initial support for relative protocol witness table emission 2023-01-18 13:43:25 -08:00
Slava Pestov
6e31af6dda IRGen: Simplify enumerateFulfillments() 2022-12-13 11:56:33 -05:00
Slava Pestov
c5ab1042fb IRGen: Stub out more support for type parameter packs 2022-12-13 11:56:33 -05:00
Slava Pestov
e5e4e266c8 IRGen: Implement emitPackShapeExpression() 2022-12-13 11:56:33 -05:00
Slava Pestov
aae03550b4 IRGen: Basic support for computing function signatures with shape parameters 2022-12-13 11:56:33 -05:00
Slava Pestov
32d3905bf3 IRGen: Simplify PolymorphicConvention::enumerateUnfulfilledRequirements 2022-12-12 23:26:41 -05:00
nate-chandler
7768b005a7 Merge pull request #62501 from nate-chandler/remove-in-constant
[SIL] Removed Indirect_In_Constant convention.
2022-12-12 07:29:12 -08:00
Slava Pestov
0c3a9d8d55 IRGen: Replace FulfillmentKey with GenericRequirement 2022-12-11 22:14:37 -05:00
Slava Pestov
65d2d4d621 IRGen: Encapsulate fields of GenericRequirement better 2022-12-11 22:14:37 -05:00
Nate Chandler
8d8577e5b0 [SIL] Removed Indirect_In_Constant convention.
It is no different from @in.

Continue parse @in_constant in textual and serialized SIL, but just as
an alias for @in.
2022-12-09 21:54:00 -08:00
Slava Pestov
78bddc66ea IRGen: Remove some dead code from NecessaryBindings.cpp 2022-12-06 14:15:17 -05:00
Arnold Schwaighofer
ae77e795c6 IRGen: Fix the computation of the number of type metadata pointers for distributed thunks under opaque pointer IR
When using opaque pointers we can no longer depend on the LLVM IR type
to perform the computation. Instead compute the number while we are
building a signature.
2022-10-24 09:04:30 -07:00
Holly Borla
38a2c8218b [Requirement] Rename RequirementKind::SameCount to SameShape. 2022-10-06 20:48:40 -07:00
Arnold Schwaighofer
d810b0f7e4 IRGen: Pass the elementType of pointers through to operations
In preparation for moving to llvm's opaque pointer representation
replace getPointerElementType and CreateCall/CreateLoad/Store uses that
dependent on the address operand's pointer element type.

This means an `Address` carries the element type and we use
`FunctionPointer` in more places or read the function type off the
`llvm::Function`.
2022-10-03 15:27:12 -07:00
Alex Lorenz
a5043c354d [interop][SwiftToCxx] add support for invoking methods in generic structs 2022-08-31 20:19:19 -07:00
Slava Pestov
046c2040ce Merge pull request #60726 from slavapestov/variadic-generics-bits
AST: Plumbing for pack conformances and a few other variadic generics bits
2022-08-24 08:59:40 -04:00
Slava Pestov
5c32f2136e AST: Introduce RequirementKind::SameCount 2022-08-23 11:12:00 -04:00
Alastair Houghton
62f54019af [IRGen] Rearrange fix slightly and add a test case.
isDependentConformance() should always check for synthesized conformances,
so do that further up the function.

Also add a test.

rdar://97290618
2022-08-23 09:50:06 +01:00
Alastair Houghton
7e1050b98c [IRGen] Fix witness table miscompilation.
If a foreign type conforms to a protocol, and that conformance is not
resilient, we were emitting an instantantiation function but it would
never be called because we weren't emitting the `GenericWitnessTable`
that would have contained a reference to it.

This was happening because of a missing `isSynthesizedNonUnique()` call
in `isDependentConformance()`.

rdar://97290618
2022-08-23 09:50:06 +01:00
swift-ci
71c6bd422e Merge remote-tracking branch 'origin/main' into rebranch 2022-08-09 13:14:18 -07:00
Slava Pestov
9d96ed940f AST: Rename 'canonical wrt. generic signature' to 'reduced'
We had two notions of canonical types, one is the structural property
where it doesn't contain sugared types, the other one where it does
not contain reducible type parameters with respect to a generic
signature.

Rename the second one to a 'reduced type'.
2022-08-09 12:46:31 -04:00
swift-ci
37dacefe15 Merge remote-tracking branch 'origin/main' into rebranch 2022-07-29 00:33:45 -07:00
Alex Lorenz
32723f7e67 [interop][SwiftToCxx] initial generic function support: pass generic parameters
Only primitive types are supported at the moment from C++ as the type traits aren't emitted for all types yet
2022-07-28 22:52:21 +01:00