Commit Graph

33 Commits

Author SHA1 Message Date
Slava Pestov
6eb112e3b6 AST: Factor out duplication between PackTypeParameterCollector and PackTypeVariableCollector 2023-06-06 14:18:37 -04:00
Slava Pestov
82a4826dcd AST: Introduce TypeBase::increasePackElementLevel() 2023-06-06 14:18:37 -04:00
Slava Pestov
654722bde7 AST: Fix PackTypeParameterCollector for PackElementType 2023-06-01 19:52:38 -04:00
Slava Pestov
c20532eb16 AST: Move TypeBase::isParameterPack() to ParameterPack.cpp 2023-06-01 19:20:11 -04:00
Pavel Yaskevich
b4ba68a80f [AST] containsPackExpansion should not be used when type variables are involved
The constraint solver has its own version of this method which
know how to deal with pack expansion type variables.
2023-05-02 09:31:57 -07:00
Pavel Yaskevich
dc8c05ac13 [Diagnostics] Suppress unused expression warning if result is discardable pack expansion
Examine pack expansion pattern to determine whether expression
result could be discarded without a warning (applies to tuples
with a single unlabeled pack expansion element as well).

Resolves: rdar://108064941
2023-04-26 13:43:49 -07:00
Slava Pestov
da7149a182 IRGen: Fix overly optimistic assumption in CanPackType::getSingletonPackExpansion() 2023-04-20 13:44:32 -04:00
Slava Pestov
2068dc82f9 AST: Refactor printing of generic types a bit 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
894b57eaf3 AST: Introduce TupleType::getNumScalarElements() 2023-04-02 23:04:00 -04:00
John McCall
251c089753 Remove some dead code; these operations are now done directly in
transformRec.
2023-03-26 04:12:59 -04:00
John McCall
c041d1061a Perform component-wise substitution of pack expansions immediately.
Substitution of a pack expansion type may now produce a pack type.
We immediately expand that pack when transforming a tuple, a function
parameter, or a pack.

I had to duplicate the component-wise transformation logic in the
simplifyType transform, which I'm not pleased about, but a little
code duplication seemed a lot better than trying to unify the code
in two very different places.

I think we're very close to being able to assert that pack expansion
shapes are either pack archetypes or pack parameters; unfortunately,
the pack matchers intentionally produce expansions of packs, and I
didn't want to add that to an already-large patch.
2023-03-26 04:12:59 -04:00
John McCall
2d72da3942 Add a few convenience functions for inducing pack types from tuples
and lowered pack types.

The "approximate" thing is kindof a representational/testing wart.
Really, all that we care about is that we have a formal pack type
with the right shape.  (We don't *really* need a formal pack type ---
we could use anything that can represent the shape --- but we seem
to be standardizing on `PackType` for that.)  We could just use the
reduced shape for that, but for some reason I've been resisting that.
Not sure I have a compelling reason, though, and if we decide to
use reduced shapes, we can eliminate the approximate formal packs
stuff.

Inducing packs from tuple slices is a more permanently-useful thing.
2023-03-09 02:08:37 -05:00
Slava Pestov
71e40317b3 AST: Remove PackArchetypeType::getSingletonPackType() 2023-03-07 23:19:25 -05:00
John McCall
bb05a0edc1 Add a convenience API to build canonical pack types from slices
of canonical tuple type elements.

This has come up more than you might think.
2023-03-07 03:15:31 -05:00
John McCall
157be3420c Implement the callee side of returning a tuple containing a pack expansion.
This required quite a bit of infrastructure for emitting this kind of
tuple expression, although I'm not going to claim they really work yet;
in particular, I know the RValue constructor is going to try to explode
them, which it really shouldn't.

It also doesn't include the caller side of returns, for which I'll need
to teach ResultPlan to do the new abstraction-pattern walk.  But that's
next.
2023-03-06 04:26:18 -05:00
John McCall
b3b90a82be Merge pull request #64048 from rjmccall/variadic-pack-expansion-arguments
Implement the emission of pack expansion arguments in SILGen
2023-03-03 11:46:00 -05:00
John McCall
06a7468e4f Implement the emission of pack expansion arguments in SILGen
Mostly fixing some existing code.
2023-03-03 02:52:32 -05:00
Holly Borla
ad3a385cd2 [Sema] Eliminate single-element tuples after parameter pack substitution. 2023-03-02 19:37:52 -08:00
Nate Chandler
6dca3e9b82 [AST] Fixed ::getReducedShape for SILPackType.
Made TypeBase's implementation dispatch to the implementation specific
to SILPackType.
2023-02-07 20:51:03 -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
Slava Pestov
44fe0dc415 AST: Introduce PackArchetypeType::getSingletonPackType() 2022-12-13 11:56:33 -05:00
Slava Pestov
f93620f03e AST: Simplify PackExpansionType::getReducedShape() 2022-12-12 23:26:33 -05:00
Slava Pestov
5c7de108f6 AST: Fix infinite recursion if TypeBase::getReducedShape() called with a type parameter 2022-12-02 11:15:43 -05:00
Slava Pestov
3ac6c58615 AST: Introduce {TypeAliasType,BoundGenericType}::getExpandedGenericArgsPack() 2022-12-02 11:15:43 -05:00
Holly Borla
6d65c11b4a [GenericEnvironment] Model opened pack element signatures as a complete clone
of the outer context signature, with an additional set of element type parameters
at depth + 1.
2022-11-23 11:16:27 -05:00
Holly Borla
6de85eea93 [ParameterPack] Use the 'getTypeParameterPacks' utility when computing the
reduced shape of a given type that is not directly a pack type or archetype.
2022-11-16 16:28:21 -08:00
Holly Borla
9eccfbd3ca [CSGen] Use a ShapeOf constraint when generating constraints for a pack
expansion expression.
2022-11-15 21:33:17 -08:00
Slava Pestov
5ee71250d5 AST: Fix TypeBase::getTypeParameterPacks() to not walk into nested PackExpansionTypes 2022-11-12 02:13:54 -05:00
Slava Pestov
30a1211a3b AST: Move getReducedShape() from CSSimplify.cpp to a method on TypeBase 2022-11-12 02:13:54 -05:00
Holly Borla
1ab9f8f7c6 [AST] Add helper methods to GenericTypeParamType for converting a given type
parameter to and from a pack type parameter.
2022-10-26 00:04:56 -07:00
Slava Pestov
a5453f1649 AST: Add new variant of swift::getParameterAt() which takes pack expansions into account 2022-10-16 21:37:25 -04:00
Slava Pestov
a10dc8e40b AST: New ParameterPack.cpp file with new algorithms for pack expansion substitution 2022-10-16 21:37:25 -04:00