Commit Graph

158 Commits

Author SHA1 Message Date
Slava Pestov
7e36060331 AST: Remove VarDecl::getOpenedElementEnvironment() 2024-05-10 17:21:17 -04:00
Slava Pestov
305e79644b AST: Rewrite GenericEnvironment::mapElementTypeIntoPackContext()
We don't need to build a DenseMap here. More importantly, this
changes the logic to avoid calling mapTypeOutOfContext() on
element archetypes, instead doing the mapping directly.
2024-05-10 17:21:17 -04:00
Slava Pestov
8d3064532c AST: Use hasPrimaryArchetype() in a few places 2024-05-10 17:21:17 -04:00
Slava Pestov
5c46e06aaf Sema: Remove isInterfaceTypeNoncopyable() 2024-02-29 18:13:28 -05: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
Sima Nerush
0b167b55b1 [ConstraintSystem] Cache pack element generic environments associated withfor-in loops over parameter packs to apply in getPackElementEnvironment. 2024-01-27 00:12:33 -08:00
Sima Nerush
62d86701c1 [AST] Use interface type to obtain the depth of parameter pack's element type. 2024-01-26 18:48:35 -08:00
Slava Pestov
e6253b282a AST: Re-implement mapPackTypeIntoElementContext() in terms of mapContextualPackTypeIntoElementContext() 2023-07-12 18:02:14 -04:00
Slava Pestov
b011215474 AST: Use transformTypeParameterPacks() in mapContextualPackTypeIntoElementContext() 2023-07-12 18:02:14 -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
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
Holly Borla
d6fe62542a [GenericEnvironment] Don't apply outer context substitutions before
type.subst in mapTypeIntoContext.

The outer context substitutions are already applied when invoking
QueryInterfaceTypeSubstitutions. Applying the context substitutions
before subst also causes problems because QueryInterfaceTypeSubstitutions
will return a null type if given an archetype, which manifested with
opened pack element environments.
2023-06-12 23:07:21 -07:00
Slava Pestov
be218f5e16 AST: Use PackElementType to model references to pack elements of outer expansions 2023-06-06 14:18:37 -04:00
John McCall
7a8d8b4997 Fix the mapping of pack types into opened element environments.
First, we need this to work on both lowered and unlowered types,
so Type::subst is problematic: it'll assert if it sees a type
like SILFunctionType.  In this case, the substitution is simple
enough that that's never a problem, but Type::subst doesn't know
that, and the assertion is generally a good one.

Second, we need this to not recurse into nested pack expansions.

Third, we need this to not mess around with any existing element
archetypes we might see in the type, so mapping in and out of
context is not really okay.

Fortunately, because we're mapping between structures (pack and
element archetypes) that are guaranteed to have the same
constraints, this transformation is really easy and we can just
do it with transformRec.
2023-03-15 17:45:55 -04:00
John McCall
48ccef7cde [NFC] Store the list of opened pack parameters as a flat array in
opened generic environments

Finding these is very hot for these environments, so doing it once
is a pretty nice win in both speed and code complexity.

I'm not actually using this yet.
2023-03-15 17:27:04 -04:00
John McCall
09018a8981 [NFC] Store interface shape types in opened element environments 2023-03-15 17:25:04 -04:00
John McCall
dc477a0fd2 Merge pull request #64167 from rjmccall/variadic-results
Implement the caller side of return types containing variadic packs
2023-03-07 11:20:46 -05:00
John McCall
6c066502a2 Add an API to map contextual types from the pack to element environment
I'm not really convinced that the existing implementation here is
correct in general; it might work for the type checker's use cases,
but I don't think we can rely on not seeing opened element archetypes
from other expansions in the type we're processing here.  But we can
at least tread water while offering a more convenient API.
2023-03-07 03:15:31 -05:00
John McCall
db4b16e3dd [WIP] Always use PackTypes as the substitutions for type parameter packs
This simplifies the representation and allows clients to handle fewer
cases.  It also removes an ambiguity in the representation which could
lead us to have two canonical types for the same type.

This is definitely not working yet, but I'm not making progress on
it quickly enough to unblock what we need to unblock; it'll have to
be fixed in parallel.
2023-03-06 17:08:35 -08: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
John McCall
68df7e80b1 [NFC] Move this helper for opening pack expansions into the AST 2023-02-24 15:02:09 -05:00
Nate Chandler
502bbd01e7 [GenericEnvironment] API to iterate pack element
The function `forEachPackElementBinding` found "interesting"
GenericTypeParamTypes, transformed each, and called back.  Here the work
of finding such "interesting" types is pulled out into a separate
function `forEachPackElementGenericTypeParam` through which
`forEachPackElementBinding` now factors.
2023-02-16 14:11:05 -08:00
John McCall
c491d25d06 Fix printing and implement parsing of opened element archetypes in SIL
Also, fix a couple places that were checking for opened existentials
to check for any local archetype.
2023-01-31 19:54:31 -05:00
John McCall
e536e4913d Make the API for iterating packs in an opened environment callback-based
This is generally easier for clients to work with.
2023-01-11 03:11:30 -05:00
Holly Borla
2d893d23bf [GenericEnvironment] For opened pack element environments, only include element type
parameters whose originating packs are in a given shape equivalence class.
2023-01-08 12:59:08 -08:00
Holly Borla
bdab953f64 [GenericEnvironment] Handle parameter packs in opened element signatures in
getOrCreateArchetypeFromInterfaceType.

Instead of special casing parameter packs for primary generic environments,
handle parameter packs in each kind of environment. For opened element
environments, a pack archetype can be produced from the outer substitutions.
2022-11-23 15:10:07 -05:00
Holly Borla
8db8b7c29a [GenericEnvironment] Add a method to retrieve the bindings from pack element
archetypes to their originating pack archetypes.
2022-11-23 12:52:54 -05:00
Holly Borla
8ec5405a30 [GenericEnvironment] Store a substitution map for the outer generic parameters
of an opened pack element generic environment.
2022-11-23 11:17:05 -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
d09ea98ba6 [GenericEnvironment] Add helper methods to map pack interface types to
element archetypes, and element interface types to pack archetypes.
2022-10-26 00:04:56 -07:00
Holly Borla
cf38d55e3a [AST] Plumb reduced shape types through local requirements into pack archetypes. 2022-10-23 11:42:46 -07:00
Slava Pestov
68514b10b5 AST: Introduce ElementArchetypeType 2022-10-21 21:55:35 -04:00
Holly Borla
c4b946195e [AST] Replace the "type sequence" terminology with "parameter pack". 2022-10-10 16:28:13 -07:00
Holly Borla
9bb837a241 [AST] Rename SequenceArchetype to PackArchetype. 2022-10-10 16:25:26 -07:00
Slava Pestov
b36f37cc72 Serialization: Preserve identity of opened generic environments
We used to create a new environment for each opened archetype, which is
incorrect when deserializing a nested type of another opened archetype.
2022-08-15 13:59:12 -04:00
Slava Pestov
7a970367fd AST: Rename GenericEnvironment::Kind::Normal to ::Primary, ::getIncomplete() to ::forPrimary() 2022-08-15 13:59:12 -04:00
Slava Pestov
87eb2cac31 AST: Don't strip bound dependent member types when forming keys in a generic environment 2022-08-15 13:59:12 -04:00
John McCall
5519749ade [NFC] Collect protocol decls, not type, in ExistentialLayout
Another thing that will be necessary for correctness with
compositions of parameterized protocols.
2022-04-11 22:15:16 -04:00
Doug Gregor
bd6f27bd55 Stop mapping opened archetypes "out of context".
These opened archetypes need to be bound within their context, so any mapping out of
the context will need to be explicit and map to newly-created generic parameters.
2022-03-11 09:27:48 -08:00
Anthony Latsis
b3ee4b0718 AST, Sema: Use the opened archetype's generic signature to determine existential member availability 2022-02-02 02:09:59 +03:00
Anthony Latsis
756bf30eeb GenericEnvironment: Don't use the existential layout's protocols to build "nested" opened archetypes 2022-02-01 23:00:55 +03:00
Doug Gregor
2bf7f36542 Don't build opaque archetypes referencing the outer environment.
When there are same-type constraints involving opaque archetype
parameters and generic parameters of the enclosing environment, a
nested type of an opaque type archetype might in fact refer to
something in the outer environment of the opaque type. Recognize this
case and perform substitutions on such types using the opaque type's
substitutions.
2022-01-19 16:26:28 -08:00
Doug Gregor
452eccab83 Remove NestedArchetypeType.
Nested archetypes are represented by their base archetype kinds (primary,
opened, or opaque type) with an interface type that is a nested type,
as represented by a DependentMemberType. This provides a more uniform
representation of archetypes throughout the frontend.
2022-01-14 21:28:21 -08:00
Doug Gregor
96fdbe18ea Check root archetypes in a few more places.
This makes more code agnostic to the presence of NestedArchetypeType.
2022-01-14 21:28:02 -08:00
Doug Gregor
34506bf316 Rework OpenedArchetypeType to generalize over interface types.
Form opened archetype types based on an interface type and existential
type, rather than assuming all OpenedArchetypeType instances only
represent the root. Sink the UUID, existential type, and actual creation
of the opened archetype into the opened generic environment, so we
consistently only create new archetype instances from the generic
environment. This slims down OpenedArchetypeType and makes it work
similarly to the other archetype kinds, as well as generalizing it
to support nested types.
Sink the existential type and UUID of an
2022-01-14 21:27:14 -08:00
Doug Gregor
ac4d26d711 Generalize (Primary|Sequence)ArchetypeType to arbitrary interface types.
As another step toward eliminating NestedArchetypeType, generalize the
representation, construction, and serialization of primary and sequence
archetypes to interface types, rather than generic parameter types.
2022-01-14 21:26:28 -08:00
Doug Gregor
590331d59f Moving nested archetype storage into the generic environment.
Instead of storing nested archetypes hierarchically in `ArchetypeType`,
store them in a map (indexed by dependent member type) on the generic
environment itself. With this, we no longer need to create archetypes
for every type along the path, because archetypes are findable via
generic environment + interface type.
2022-01-14 21:25:31 -08:00
Doug Gregor
2974f548be Reimplement ArchetypeType::getParent() in terms of interface type + environment
Rather that requiring parent archetypes to be stored at the time of
construction, map the base of the interface type through the
generic environment.
2022-01-14 21:25:31 -08:00
Doug Gregor
c8b71819d4 Always store a generic environment in a nested archetype. 2022-01-14 21:25:31 -08:00