Commit Graph

51 Commits

Author SHA1 Message Date
Hamish Knight
edca7c85ad Adopt ABORT throughout the compiler
Convert a bunch of places where we're dumping to stderr and calling
`abort` over to using `ABORT` such that the message gets printed to
the pretty stack trace. This ensures it gets picked up by
CrashReporter.
2025-05-19 20:55:01 +01:00
Slava Pestov
fe31c61b14 AST: Remove stray assert
A pack archetype from an outer expansion here is treated as a scalar.
2025-05-15 12:22:21 -04:00
Anthony Latsis
7793f638d5 [NFC] AST: Consolidate some repeated DependentMemberType logic in Type methods 2024-12-20 02:47:29 +00:00
Alejandro Alonso
f4f60f4344 Remove Value requirement Add GenericTypeParamKind 2024-09-04 15:13:43 -07:00
Slava Pestov
52ce02eb96 AST: Remove ArchetypeType::getRoot() 2024-08-30 15:24:00 -04:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Hamish Knight
05615fa0e4 NFC: Rename TypeWalker's SkipChildren to SkipNode
For consistency with ASTWalker.
2024-02-05 15:27:25 +00:00
Slava Pestov
5d58a634ad Sema: Clean up openType() and openUnboundGenericType()
Fixes:
- rdar://112785081
- https://github.com/apple/swift/issues/67906
- https://github.com/apple/swift/issues/68160
2024-01-09 15:23:42 -05:00
Pavel Yaskevich
14cf3c3fd7 [AST] NFC: Teach getExpandedGenericArgs to handle partially resolved parameter packs
A temporary fix to make it possible to debug expressions
with partially resolved variadic generic types. The issue stems
from the fact that `BoundGenericType` is allowed to have pack
parameters directly represented by type variables, as soon as
that is no longer the case this check should be removed.
2023-08-14 17:06:40 -07:00
Holly Borla
79c4cfbf8b [NFC] Replace a few calls to TypeBase::isParameterPack() with isRootParameterPack(). 2023-07-20 15:29:53 -07:00
Holly Borla
7b586d20cc [Type Resolution] Only allow each applied directly to a type parameter pack. 2023-07-20 15:29:53 -07:00
Sophia Poirier
8173c721eb [ConstraintSystem] remove TupleType::isSingleUnlabeledPackExpansion in favor of constraints::getPatternTypeOfSingleUnlabeledPackExpansionTuple 2023-07-19 15:10:40 -07:00
Slava Pestov
d0202a7081 AST: Implement Type::transformTypeParameterPacks() 2023-07-12 18:02:14 -04:00
Slava Pestov
cfd0414be2 AST: Simplify TypeBase::getTypeParameterPacks()
Type deletes operator== so this no longer compiles on the next branch.
No idea why it worked before. We could use isEqual() instead but in fact
none of the callers care about uniqueness so let's do the simple thing
that is guaranteed to work.
2023-07-10 10:58:19 -04:00
Slava Pestov
8afff61699 AST: Replace TypeArrayView<GenericTypeParamType> with ArrayRef<GenericTypeParamType *>
This basically undoes 3da6fe9c0d, which in hindsight was wrong.

There were no other usages of TypeArrayView anywhere else except for
GenericSignature::getGenericParams(), and it was almost never what
you want, so callers had to convert back and forth to an ArrayRef.
Remove it.
2023-06-29 19:23:44 -04:00
Erik Eckstein
6b1697eb06 use new llvm::Optional APIs to fix deprecation warnings 2023-06-28 14:28:38 +02: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
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