Skip to content

[Serialization] Drop GenericEnvironmentID for GenericSignatureID #26862

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 1 commit into from
Aug 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion include/swift/Serialization/DeclTypeRecordNodes.def
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ OTHER(GENERIC_SIGNATURE, 231)
TRAILING_INFO(GENERIC_REQUIREMENT)
TRAILING_INFO(LAYOUT_REQUIREMENT)
// 234 is unused
OTHER(SIL_GENERIC_ENVIRONMENT, 235)
OTHER(SIL_GENERIC_SIGNATURE, 235)
OTHER(SUBSTITUTION_MAP, 236)

OTHER(LOCAL_DISCRIMINATOR, 237)
Expand Down
32 changes: 18 additions & 14 deletions include/swift/Serialization/ModuleFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,14 +210,13 @@ class ModuleFile
return Value.template get<serialization::BitOffset>();
}

template <typename Derived>
Serialized &operator=(Derived deserialized) {
Serialized &operator=(T deserialized) {
assert(!isComplete() || ImplTy(deserialized) == Value);
Value = deserialized;
return *this;
}

void unsafeOverwrite(T t) {
void uncheckedOverwrite(T t) {
Value = t;
}
};
Expand Down Expand Up @@ -317,11 +316,17 @@ class ModuleFile
/// Types referenced by this module.
MutableArrayRef<Serialized<Type>> Types;

/// Generic signatures referenced by this module.
MutableArrayRef<Serialized<GenericSignature *>> GenericSignatures;
using GenericSignatureOrEnvironment =
llvm::PointerUnion<GenericSignature *, GenericEnvironment *>;

/// Generic environments referenced by this module.
MutableArrayRef<Serialized<GenericEnvironment *>> GenericEnvironments;
/// Generic signatures and environments referenced by this module.
///
/// Technically only the GenericSignatures are encoded, but storing the
/// environment here too allows caching them.
// FIXME: That caching should be done at the AST level; it's not specific to
// Serialization.
MutableArrayRef<Serialized<GenericSignatureOrEnvironment>>
GenericSignaturesAndEnvironments;

/// Substitution maps referenced by this module.
MutableArrayRef<Serialized<SubstitutionMap>> SubstitutionMaps;
Expand Down Expand Up @@ -560,9 +565,8 @@ class ModuleFile

/// Set up a (potentially lazy) generic environment for the given type,
/// function or extension.
void configureGenericEnvironment(
GenericContext *genericDecl,
serialization::GenericEnvironmentID envID);
void configureGenericEnvironment(GenericContext *genericDecl,
serialization::GenericSignatureID envID);

/// Populates the protocol's default witness table.
///
Expand Down Expand Up @@ -879,14 +883,14 @@ class ModuleFile
/// \param wantEnvironment If true, always return the full generic
/// environment. Otherwise, only return the generic environment if it's
/// already been constructed, and the signature in other cases.
llvm::PointerUnion<GenericSignature *, GenericEnvironment *>
getGenericSignatureOrEnvironment(serialization::GenericEnvironmentID ID,
GenericSignatureOrEnvironment
getGenericSignatureOrEnvironment(serialization::GenericSignatureID ID,
bool wantEnvironment = false);

/// Returns the generic environment for the given ID, deserializing it if
/// needed.
GenericEnvironment *getGenericEnvironment(
serialization::GenericEnvironmentID ID);
GenericEnvironment *
getGenericEnvironment(serialization::GenericSignatureID ID);

/// Returns the substitution map for the given ID, deserializing it if
/// needed.
Expand Down
38 changes: 16 additions & 22 deletions include/swift/Serialization/ModuleFormat.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const uint16_t SWIFTMODULE_VERSION_MAJOR = 0;
/// describe what change you made. The content of this comment isn't important;
/// it just ensures a conflict if two people change the module format.
/// Don't worry about adhering to the 80-column limit for this line.
const uint16_t SWIFTMODULE_VERSION_MINOR = 515; // remove DeclContext indirection
const uint16_t SWIFTMODULE_VERSION_MINOR = 516; // encode GenericSignature and GenericEnvironment together

using DeclIDField = BCFixed<31>;

Expand Down Expand Up @@ -129,11 +129,6 @@ using NormalConformanceIDField = DeclIDField;
using GenericSignatureID = DeclID;
using GenericSignatureIDField = DeclIDField;

// GenericEnvironmentID must be the same as DeclID because it is stored in the
// same way.
using GenericEnvironmentID = DeclID;
using GenericEnvironmentIDField = DeclIDField;

// SubstitutionMapID must be the same as DeclID because it is stored in the
// same way.
using SubstitutionMapID = DeclID;
Expand Down Expand Up @@ -843,7 +838,7 @@ namespace decls_block {

using PrimaryArchetypeTypeLayout = BCRecordLayout<
PRIMARY_ARCHETYPE_TYPE,
GenericEnvironmentIDField, // generic environment
GenericSignatureIDField, // generic environment
BCVBR<4>, // generic type parameter depth
BCVBR<4> // index + 1, or zero if we have a generic type parameter decl
>;
Expand Down Expand Up @@ -963,7 +958,7 @@ namespace decls_block {
TypeIDField, // underlying type
TypeIDField, // interface type (no longer used)
BCFixed<1>, // implicit flag
GenericEnvironmentIDField, // generic environment
GenericSignatureIDField, // generic environment
AccessLevelField, // access level
BCArray<TypeIDField> // dependency types
// Trailed by generic parameters (if any).
Expand Down Expand Up @@ -992,7 +987,7 @@ namespace decls_block {
DeclContextIDField, // context decl
BCFixed<1>, // implicit flag
BCFixed<1>, // isObjC
GenericEnvironmentIDField, // generic environment
GenericSignatureIDField, // generic environment
AccessLevelField, // access level
BCVBR<4>, // number of conformances
BCVBR<4>, // number of inherited types
Expand All @@ -1007,7 +1002,7 @@ namespace decls_block {
DeclContextIDField, // context decl
BCFixed<1>, // implicit flag
BCFixed<1>, // isObjC
GenericEnvironmentIDField, // generic environment
GenericSignatureIDField, // generic environment
TypeIDField, // raw type
AccessLevelField, // access level
BCVBR<4>, // number of conformances
Expand All @@ -1024,7 +1019,7 @@ namespace decls_block {
BCFixed<1>, // implicit?
BCFixed<1>, // explicitly objc?
BCFixed<1>, // inherits convenience initializers from its superclass?
GenericEnvironmentIDField, // generic environment
GenericSignatureIDField, // generic environment
TypeIDField, // superclass
AccessLevelField, // access level
BCVBR<4>, // number of conformances
Expand Down Expand Up @@ -1066,7 +1061,7 @@ namespace decls_block {
BCFixed<1>, // stub implementation?
BCFixed<1>, // throws?
CtorInitializerKindField, // initializer kind
GenericEnvironmentIDField, // generic environment
GenericSignatureIDField, // generic environment
DeclIDField, // overridden decl
AccessLevelField, // access level
BCFixed<1>, // requires a new vtable slot
Expand Down Expand Up @@ -1134,7 +1129,7 @@ namespace decls_block {
SelfAccessKindField, // self access kind
BCFixed<1>, // has forced static dispatch?
BCFixed<1>, // throws?
GenericEnvironmentIDField, // generic environment
GenericSignatureIDField, // generic environment
TypeIDField, // result interface type
BCFixed<1>, // IUO result?
DeclIDField, // operator decl
Expand All @@ -1160,7 +1155,7 @@ namespace decls_block {
DeclIDField, // naming decl
GenericSignatureIDField, // interface generic signature
TypeIDField, // interface type for opaque type
GenericEnvironmentIDField, // generic environment
GenericSignatureIDField, // generic environment
SubstitutionMapIDField // optional substitution map for underlying type
// trailed by generic parameters
>;
Expand All @@ -1176,7 +1171,7 @@ namespace decls_block {
SelfAccessKindField, // self access kind
BCFixed<1>, // has forced static dispatch?
BCFixed<1>, // throws?
GenericEnvironmentIDField, // generic environment
GenericSignatureIDField, // generic environment
TypeIDField, // result interface type
BCFixed<1>, // IUO result?
DeclIDField, // overridden function
Expand Down Expand Up @@ -1263,7 +1258,7 @@ namespace decls_block {
WriteImplKindField, // write implementation
ReadWriteImplKindField, // read-write implementation
AccessorCountField, // number of accessors
GenericEnvironmentIDField, // generic environment
GenericSignatureIDField, // generic environment
TypeIDField, // element interface type
BCFixed<1>, // IUO element?
DeclIDField, // overridden decl
Expand All @@ -1286,7 +1281,7 @@ namespace decls_block {
TypeIDField, // base type
DeclContextIDField, // context decl
BCFixed<1>, // implicit flag
GenericEnvironmentIDField, // generic environment
GenericSignatureIDField, // generic environment
BCVBR<4>, // # of protocol conformances
BCVBR<4>, // number of inherited types
BCArray<TypeIDField> // inherited types, followed by TypeID dependencies
Expand All @@ -1299,7 +1294,7 @@ namespace decls_block {
DeclContextIDField, // context decl
BCFixed<1>, // implicit?
BCFixed<1>, // objc?
GenericEnvironmentIDField // generic environment
GenericSignatureIDField // generic environment
// This record is trailed by its inlinable body text
>;

Expand Down Expand Up @@ -1379,8 +1374,8 @@ namespace decls_block {
// Conformances trail the record.
>;

using SILGenericEnvironmentLayout = BCRecordLayout<
SIL_GENERIC_ENVIRONMENT,
using SILGenericSignatureLayout = BCRecordLayout<
SIL_GENERIC_SIGNATURE,
BCArray<TypeIDField> // (generic parameter name, sugared interface
// type) pairs
>;
Expand Down Expand Up @@ -1780,7 +1775,7 @@ namespace index_block {
LOCAL_DECL_CONTEXT_OFFSETS,
LOCAL_TYPE_DECLS,
OPAQUE_RETURN_TYPE_DECLS,
GENERIC_ENVIRONMENT_OFFSETS,
GENERIC_SIGNATURE_OFFSETS,
NORMAL_CONFORMANCE_OFFSETS,
SIL_LAYOUT_OFFSETS,

Expand All @@ -1790,7 +1785,6 @@ namespace index_block {

ORDERED_TOP_LEVEL_DECLS,

GENERIC_SIGNATURE_OFFSETS,
SUBSTITUTION_MAP_OFFSETS,
LastRecordKind = SUBSTITUTION_MAP_OFFSETS,
};
Expand Down
Loading