Skip to content

Commit dd2cec5

Browse files
authored
Merge pull request #40794 from DougGregor/remove-nested-archetypes
2 parents 8b08972 + b1d5302 commit dd2cec5

35 files changed

+534
-725
lines changed

include/swift/AST/ASTMangler.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,11 @@ class ASTMangler : public Mangler {
365365
ModuleDecl *fromModule);
366366
void appendImplFunctionType(SILFunctionType *fn, GenericSignature sig,
367367
const ValueDecl *forDecl = nullptr);
368+
void appendOpaqueTypeArchetype(ArchetypeType *archetype,
369+
OpaqueTypeDecl *opaqueDecl,
370+
SubstitutionMap subs,
371+
GenericSignature sig,
372+
const ValueDecl *forDecl);
368373

369374
void appendContextOf(const ValueDecl *decl);
370375

include/swift/AST/GenericEnvironment.h

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "swift/AST/GenericSignature.h"
2424
#include "swift/Basic/Compiler.h"
2525
#include "swift/Basic/Debug.h"
26+
#include "swift/Basic/UUID.h"
2627
#include "llvm/ADT/ArrayRef.h"
2728
#include "llvm/Support/ErrorHandling.h"
2829
#include "llvm/Support/TrailingObjects.h"
@@ -50,6 +51,12 @@ class QueryInterfaceTypeSubstitutions {
5051
Type operator()(SubstitutableType *type) const;
5152
};
5253

54+
/// Extra data in a generic environment for an opened existentiak.
55+
struct OpenedGenericEnvironmentData {
56+
Type existential;
57+
UUID uuid;
58+
};
59+
5360
/// Describes the mapping between archetypes and interface types for the
5461
/// generic parameters of a DeclContext.
5562
///
@@ -60,7 +67,8 @@ class QueryInterfaceTypeSubstitutions {
6067
///
6168
class alignas(1 << DeclAlignInBits) GenericEnvironment final
6269
: private llvm::TrailingObjects<
63-
GenericEnvironment, OpaqueTypeDecl *, SubstitutionMap, Type> {
70+
GenericEnvironment, OpaqueTypeDecl *, SubstitutionMap,
71+
OpenedGenericEnvironmentData, Type> {
6472
public:
6573
enum class Kind {
6674
/// A normal generic environment, determined only by its generic
@@ -72,16 +80,20 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
7280
Opaque,
7381
};
7482

83+
class NestedTypeStorage;
84+
7585
private:
7686
mutable llvm::PointerIntPair<GenericSignature, 2, Kind> SignatureAndKind{
7787
GenericSignature(), Kind::Normal};
88+
NestedTypeStorage *nestedTypeStorage = nullptr;
7889

7990
friend TrailingObjects;
8091
friend OpaqueTypeArchetypeType;
8192

8293
size_t numTrailingObjects(OverloadToken<OpaqueTypeDecl *>) const;
8394
size_t numTrailingObjects(OverloadToken<SubstitutionMap>) const;
8495
size_t numTrailingObjects(OverloadToken<Type>) const;
96+
size_t numTrailingObjects(OverloadToken<OpenedGenericEnvironmentData>) const;
8597

8698
/// Retrieve the array containing the context types associated with the
8799
/// generic parameters, stored in parallel with the generic parameters of the
@@ -93,7 +105,12 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
93105
/// generic signature.
94106
ArrayRef<Type> getContextTypes() const;
95107

96-
explicit GenericEnvironment(GenericSignature signature, Kind kind);
108+
/// Get the nested type storage, allocating it if required.
109+
NestedTypeStorage &getOrCreateNestedTypeStorage();
110+
111+
explicit GenericEnvironment(GenericSignature signature);
112+
explicit GenericEnvironment(
113+
GenericSignature signature, Type existential, UUID uuid);
97114
explicit GenericEnvironment(
98115
GenericSignature signature, OpaqueTypeDecl *opaque, SubstitutionMap subs);
99116

@@ -102,6 +119,10 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
102119

103120
Type getOrCreateArchetypeFromInterfaceType(Type depType);
104121

122+
/// Add a mapping of a generic parameter to a specific type (which may be
123+
/// an archetype)
124+
void addMapping(GenericParamKey key, Type contextType);
125+
105126
/// Retrieve the mapping for the given generic parameter, if present.
106127
///
107128
/// This is only useful when lazily populating a generic environment.
@@ -116,6 +137,12 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
116137

117138
TypeArrayView<GenericTypeParamType> getGenericParams() const;
118139

140+
/// Retrieve the existential type for an opened existential environment.
141+
Type getOpenedExistentialType() const;
142+
143+
/// Retrieve the UUID for an opened existential environment.
144+
UUID getOpenedExistentialUUID() const;
145+
119146
/// Retrieve the opaque type declaration for a generic environment describing
120147
/// opaque types.
121148
OpaqueTypeDecl *getOpaqueTypeDecl() const;
@@ -130,18 +157,13 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
130157
GenericEnvironment *getIncomplete(GenericSignature signature);
131158

132159
/// Create a new generic environment for an opened existential.
133-
static GenericEnvironment *forOpenedExistential(
134-
GenericSignature signature, const OpenedArchetypeType *type);
160+
static GenericEnvironment *forOpenedExistential(Type existential, UUID uuid);
135161

136162
/// Create a new generic environment for an opaque type with the given set of
137163
/// outer substitutions.
138164
static GenericEnvironment *forOpaqueType(
139165
OpaqueTypeDecl *opaque, SubstitutionMap subs, AllocationArena arena);
140166

141-
/// Add a mapping of a generic parameter to a specific type (which may be
142-
/// an archetype)
143-
void addMapping(GenericParamKey key, Type contextType);
144-
145167
/// Make vanilla new/delete illegal.
146168
void *operator new(size_t Bytes) = delete;
147169
void operator delete(void *Data) = delete;

include/swift/AST/GenericSignature.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,8 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final
390390

391391
bool isCanonicalTypeInContext(Type type) const;
392392

393+
bool isValidTypeInContext(Type type) const;
394+
393395
/// Retrieve the conformance access path used to extract the conformance of
394396
/// interface \c type to the given \c protocol.
395397
///

include/swift/AST/TypeNodes.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ ABSTRACT_TYPE(Substitutable, Type)
147147
ALWAYS_CANONICAL_TYPE(PrimaryArchetype, ArchetypeType)
148148
ALWAYS_CANONICAL_TYPE(OpaqueTypeArchetype, ArchetypeType)
149149
ALWAYS_CANONICAL_TYPE(OpenedArchetype, ArchetypeType)
150-
ALWAYS_CANONICAL_TYPE(NestedArchetype, ArchetypeType)
151150
ALWAYS_CANONICAL_TYPE(SequenceArchetype, ArchetypeType)
152151
TYPE_RANGE(Archetype, PrimaryArchetype, SequenceArchetype)
153152
TYPE(GenericTypeParam, SubstitutableType)

0 commit comments

Comments
 (0)