Skip to content

Remove nested archetypes #40794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 22 commits into from
Jan 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
2a90cd1
Eliminate and simplify some uses of NestedArchetypeType.
DougGregor Jan 8, 2022
c5c1347
Remove ArchetypeType::getKnownNestedTypes().
DougGregor Jan 8, 2022
183cf58
Sink the generic environment of an archetype down into ArchetypeType.
DougGregor Jan 10, 2022
1a563d4
Make the creation of generic environments for opaque archetype eager.
DougGregor Jan 11, 2022
c8b7181
Always store a generic environment in a nested archetype.
DougGregor Jan 11, 2022
9b4d804
Remove unnecessary uses of `ArchetypeType::getParent()`.
DougGregor Jan 11, 2022
2974f54
Reimplement ArchetypeType::getParent() in terms of interface type + e…
DougGregor Jan 11, 2022
590331d
Moving nested archetype storage into the generic environment.
DougGregor Jan 11, 2022
3b8e9df
Use the generic signature to find nested types by name.
DougGregor Jan 11, 2022
8df65e7
Remove unnecessary uses of `NestedArchetypeType`.
DougGregor Jan 11, 2022
0ffd11c
RequirementMachine: New GenericSignature::isValidTypeInContext() query
slavapestov Jan 11, 2022
2dbaab9
Adopt GenericSignature::isValidTypeInContext for nested archetypes
DougGregor Jan 12, 2022
8595ebf
Rework opaque archetype mangling to be representation agnostic.
DougGregor Jan 12, 2022
6ae6ab9
Make opaque type archetypes root- and nested-type agnostic
DougGregor Jan 12, 2022
50fd5b5
Add ArchetypeType::isRoot() and use it instead of implicit "root" checks
DougGregor Jan 12, 2022
ac4d26d
Generalize (Primary|Sequence)ArchetypeType to arbitrary interface types.
DougGregor Jan 12, 2022
b30c5b8
Eliminate OpaqueTypeArchetypeType::getOrdinal(), which shouldn't be used
DougGregor Jan 13, 2022
34506bf
Rework OpenedArchetypeType to generalize over interface types.
DougGregor Jan 14, 2022
ca2c44d
Make GenericEnvironment::addMapping private.
DougGregor Jan 14, 2022
96fdbe1
Check root archetypes in a few more places.
DougGregor Jan 14, 2022
452ecca
Remove NestedArchetypeType.
DougGregor Jan 14, 2022
b1d5302
Fix opaque type archetype emission for nested archetypes
DougGregor Jan 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions include/swift/AST/ASTMangler.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,11 @@ class ASTMangler : public Mangler {
ModuleDecl *fromModule);
void appendImplFunctionType(SILFunctionType *fn, GenericSignature sig,
const ValueDecl *forDecl = nullptr);
void appendOpaqueTypeArchetype(ArchetypeType *archetype,
OpaqueTypeDecl *opaqueDecl,
SubstitutionMap subs,
GenericSignature sig,
const ValueDecl *forDecl);

void appendContextOf(const ValueDecl *decl);

Expand Down
38 changes: 30 additions & 8 deletions include/swift/AST/GenericEnvironment.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "swift/AST/GenericSignature.h"
#include "swift/Basic/Compiler.h"
#include "swift/Basic/Debug.h"
#include "swift/Basic/UUID.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Support/ErrorHandling.h"
#include "llvm/Support/TrailingObjects.h"
Expand Down Expand Up @@ -50,6 +51,12 @@ class QueryInterfaceTypeSubstitutions {
Type operator()(SubstitutableType *type) const;
};

/// Extra data in a generic environment for an opened existentiak.
struct OpenedGenericEnvironmentData {
Type existential;
UUID uuid;
};

/// Describes the mapping between archetypes and interface types for the
/// generic parameters of a DeclContext.
///
Expand All @@ -60,7 +67,8 @@ class QueryInterfaceTypeSubstitutions {
///
class alignas(1 << DeclAlignInBits) GenericEnvironment final
: private llvm::TrailingObjects<
GenericEnvironment, OpaqueTypeDecl *, SubstitutionMap, Type> {
GenericEnvironment, OpaqueTypeDecl *, SubstitutionMap,
OpenedGenericEnvironmentData, Type> {
public:
enum class Kind {
/// A normal generic environment, determined only by its generic
Expand All @@ -72,16 +80,20 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
Opaque,
};

class NestedTypeStorage;

private:
mutable llvm::PointerIntPair<GenericSignature, 2, Kind> SignatureAndKind{
GenericSignature(), Kind::Normal};
NestedTypeStorage *nestedTypeStorage = nullptr;

friend TrailingObjects;
friend OpaqueTypeArchetypeType;

size_t numTrailingObjects(OverloadToken<OpaqueTypeDecl *>) const;
size_t numTrailingObjects(OverloadToken<SubstitutionMap>) const;
size_t numTrailingObjects(OverloadToken<Type>) const;
size_t numTrailingObjects(OverloadToken<OpenedGenericEnvironmentData>) const;

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

explicit GenericEnvironment(GenericSignature signature, Kind kind);
/// Get the nested type storage, allocating it if required.
NestedTypeStorage &getOrCreateNestedTypeStorage();

explicit GenericEnvironment(GenericSignature signature);
explicit GenericEnvironment(
GenericSignature signature, Type existential, UUID uuid);
explicit GenericEnvironment(
GenericSignature signature, OpaqueTypeDecl *opaque, SubstitutionMap subs);

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

Type getOrCreateArchetypeFromInterfaceType(Type depType);

/// Add a mapping of a generic parameter to a specific type (which may be
/// an archetype)
void addMapping(GenericParamKey key, Type contextType);

/// Retrieve the mapping for the given generic parameter, if present.
///
/// This is only useful when lazily populating a generic environment.
Expand All @@ -116,6 +137,12 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final

TypeArrayView<GenericTypeParamType> getGenericParams() const;

/// Retrieve the existential type for an opened existential environment.
Type getOpenedExistentialType() const;

/// Retrieve the UUID for an opened existential environment.
UUID getOpenedExistentialUUID() const;

/// Retrieve the opaque type declaration for a generic environment describing
/// opaque types.
OpaqueTypeDecl *getOpaqueTypeDecl() const;
Expand All @@ -130,18 +157,13 @@ class alignas(1 << DeclAlignInBits) GenericEnvironment final
GenericEnvironment *getIncomplete(GenericSignature signature);

/// Create a new generic environment for an opened existential.
static GenericEnvironment *forOpenedExistential(
GenericSignature signature, const OpenedArchetypeType *type);
static GenericEnvironment *forOpenedExistential(Type existential, UUID uuid);

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

/// Add a mapping of a generic parameter to a specific type (which may be
/// an archetype)
void addMapping(GenericParamKey key, Type contextType);

/// Make vanilla new/delete illegal.
void *operator new(size_t Bytes) = delete;
void operator delete(void *Data) = delete;
Expand Down
2 changes: 2 additions & 0 deletions include/swift/AST/GenericSignature.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,6 +390,8 @@ class alignas(1 << TypeAlignInBits) GenericSignatureImpl final

bool isCanonicalTypeInContext(Type type) const;

bool isValidTypeInContext(Type type) const;

/// Retrieve the conformance access path used to extract the conformance of
/// interface \c type to the given \c protocol.
///
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/TypeNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ ABSTRACT_TYPE(Substitutable, Type)
ALWAYS_CANONICAL_TYPE(PrimaryArchetype, ArchetypeType)
ALWAYS_CANONICAL_TYPE(OpaqueTypeArchetype, ArchetypeType)
ALWAYS_CANONICAL_TYPE(OpenedArchetype, ArchetypeType)
ALWAYS_CANONICAL_TYPE(NestedArchetype, ArchetypeType)
ALWAYS_CANONICAL_TYPE(SequenceArchetype, ArchetypeType)
TYPE_RANGE(Archetype, PrimaryArchetype, SequenceArchetype)
TYPE(GenericTypeParam, SubstitutableType)
Expand Down
Loading