mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
[Serialization] Add a "nested types" lookup table for partial modules.
There's a class of errors in Serialization called "circularity issues", where declaration A in file A.swift depends on declaration B in file B.swift, and B also depends on A. In some cases we can manage to type-check each of these files individually due to the laziness of 'validateDecl', but then fail to merge the "partial modules" generated from A.swift and B.swift to form a single swiftmodule for the library (because deserialization is a little less lazy for some things). A common case of this is when at least one of the declarations is nested, in which case a lookup to find that declaration needs to load all the members of the parent type. This gets even worse when the nested type is defined in an extension. This commit sidesteps that issue specifically for nested types by creating a top-level, per-file table of nested types in the "partial modules". When a type is in the same module, we can then look it up /without/ importing all other members of the parent type. The long-term solution is to allow accessing any members of a type without having to load them all, something we should support not just for module-merging while building a single target but when reading from imported modules as well. This should improve both compile time and memory usage, though I'm not sure to what extent. (Unfortunately, too many things still depend on the whole members list being loaded.) Because this is a new code path, I put in a switch to turn it off: frontend flag -disable-serialization-nested-type-lookup-table https://bugs.swift.org/browse/SR-3707 (and possibly others)
This commit is contained in:
@@ -316,6 +316,10 @@ private:
|
||||
using SerializedLocalDeclTable =
|
||||
llvm::OnDiskIterableChainedHashTable<LocalDeclTableInfo>;
|
||||
|
||||
class NestedTypeDeclsTableInfo;
|
||||
using SerializedNestedTypeDeclsTable =
|
||||
llvm::OnDiskIterableChainedHashTable<NestedTypeDeclsTableInfo>;
|
||||
|
||||
std::unique_ptr<SerializedDeclTable> TopLevelDecls;
|
||||
std::unique_ptr<SerializedDeclTable> OperatorDecls;
|
||||
std::unique_ptr<SerializedDeclTable> PrecedenceGroupDecls;
|
||||
@@ -323,6 +327,7 @@ private:
|
||||
std::unique_ptr<SerializedDeclTable> ClassMembersByName;
|
||||
std::unique_ptr<SerializedDeclTable> OperatorMethodDecls;
|
||||
std::unique_ptr<SerializedLocalDeclTable> LocalTypeDecls;
|
||||
std::unique_ptr<SerializedNestedTypeDeclsTable> NestedTypeDecls;
|
||||
|
||||
class ObjCMethodTableInfo;
|
||||
using SerializedObjCMethodTable =
|
||||
@@ -441,6 +446,11 @@ private:
|
||||
std::unique_ptr<ModuleFile::SerializedObjCMethodTable>
|
||||
readObjCMethodTable(ArrayRef<uint64_t> fields, StringRef blobData);
|
||||
|
||||
/// Read an on-disk local decl hash table stored in
|
||||
/// index_block::NestedTypeDeclsLayout format.
|
||||
std::unique_ptr<SerializedNestedTypeDeclsTable>
|
||||
readNestedTypeDeclsTable(ArrayRef<uint64_t> fields, StringRef blobData);
|
||||
|
||||
/// Reads the index block, which contains global tables.
|
||||
///
|
||||
/// Returns false if there was an error.
|
||||
@@ -580,6 +590,10 @@ public:
|
||||
/// Searches the module's local type decls for the given mangled name.
|
||||
TypeDecl *lookupLocalType(StringRef MangledName);
|
||||
|
||||
/// Searches the module's nested type decls table for the given member of
|
||||
/// the given type.
|
||||
TypeDecl *lookupNestedType(Identifier name, const ValueDecl *parent);
|
||||
|
||||
/// Searches the module's operators for one with the given name and fixity.
|
||||
///
|
||||
/// If none is found, returns null.
|
||||
|
||||
Reference in New Issue
Block a user