mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Previously SILModule contained two different pathways for the deserializer to send notifications that it had created functions: 1. A list of function pointers that were called when a function's body was deserialized. This was added recently so that access enforcement elimination is run on newly deserialized SIL code if we have already eliminated access enforcement from the module. 2. SILModule::SerializationCallback. This is an implementation of the full callback interface and is used by the SILModule to update linkage and other sorts of book keeping. To fix the pass manager notification infrastructure, I need to be able to send notifications to a SILPassManager when deserializing. I also need to be able to eliminate these callbacks when a SILPassManager is destroyed. These requirements are incompatible with the current two implementations since: (2) is an implementation detail of SILModule and (1) only notifies on function bodies being deserialized instead of the creation of new declarations (what the caller analysis wants). Rather than adding a third group of callbacks, this commit refactors the infrastructure in such a way that all of these use cases can use one implementation. This is done by: 1. Lifting the interface of SerializedSILLoader::Callback into a base notification protocol for deserialization called DeserializationNotificationHandlerBase and its base no-op implementation into an implementation of the aforementioned protocol: DeserializationNotificationHandler. 2. Changing SILModule::SerializationCallback to implement DeserializationNotificationHandler. 3. Creating a class called FunctionBodyDeserializationNotificationHandler that takes in a function pointer and uses that to just override the didDeserializeFunctionBody. This eliminates the need for the specific function body deserialization list. 4. Replacing the state associated with the two other pathways with a single DeserializationNotificationHandlerSet class that contains a set of DeserializationNotificationHandler and chains notifications to them. This set implements DeserializationNotificationHandlerBase so we know that its implementation will always be in sync with DeserializationNotificationHandler. rdar://42301529
114 lines
3.6 KiB
C++
114 lines
3.6 KiB
C++
//===--- SerializedSILLoader.h - Handle SIL section in modules --*- C++ -*-===//
|
|
//
|
|
// This source file is part of the Swift.org open source project
|
|
//
|
|
// Copyright (c) 2014 - 2017 Apple Inc. and the Swift project authors
|
|
// Licensed under Apache License v2.0 with Runtime Library Exception
|
|
//
|
|
// See https://swift.org/LICENSE.txt for license information
|
|
// See https://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
|
|
//
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
#ifndef SWIFT_SERIALIZATION_SILLOADER_H
|
|
#define SWIFT_SERIALIZATION_SILLOADER_H
|
|
|
|
#include "swift/AST/Decl.h"
|
|
#include "swift/AST/Identifier.h"
|
|
#include "swift/SIL/Notifications.h"
|
|
#include "swift/SIL/SILDeclRef.h"
|
|
#include "swift/SIL/SILLinkage.h"
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace swift {
|
|
class ASTContext;
|
|
class FileUnit;
|
|
class ModuleDecl;
|
|
class SILDeserializer;
|
|
class SILFunction;
|
|
class SILGlobalVariable;
|
|
class SILModule;
|
|
class SILVTable;
|
|
class SILWitnessTable;
|
|
class SILDefaultWitnessTable;
|
|
|
|
/// Maintains a list of SILDeserializer, one for each serialized modules
|
|
/// in ASTContext. It provides lookupSILFunction that will perform lookup
|
|
/// on each SILDeserializer.
|
|
class SerializedSILLoader {
|
|
private:
|
|
std::vector<std::unique_ptr<SILDeserializer>> LoadedSILSections;
|
|
|
|
explicit SerializedSILLoader(
|
|
ASTContext &ctx, SILModule *SILMod,
|
|
DeserializationNotificationHandlerSet *callbacks);
|
|
|
|
public:
|
|
/// Create a new loader.
|
|
///
|
|
/// \param callbacks - not owned by the loader
|
|
static std::unique_ptr<SerializedSILLoader>
|
|
create(ASTContext &ctx, SILModule *SILMod,
|
|
DeserializationNotificationHandlerSet *callbacks) {
|
|
return std::unique_ptr<SerializedSILLoader>(
|
|
new SerializedSILLoader(ctx, SILMod, callbacks));
|
|
}
|
|
~SerializedSILLoader();
|
|
|
|
SILFunction *lookupSILFunction(SILFunction *Callee);
|
|
SILFunction *
|
|
lookupSILFunction(StringRef Name, bool declarationOnly = false,
|
|
Optional<SILLinkage> linkage = None);
|
|
bool hasSILFunction(StringRef Name, Optional<SILLinkage> linkage = None);
|
|
SILVTable *lookupVTable(Identifier Name);
|
|
SILVTable *lookupVTable(const ClassDecl *C) {
|
|
return lookupVTable(C->getName());
|
|
}
|
|
SILWitnessTable *lookupWitnessTable(SILWitnessTable *C);
|
|
SILDefaultWitnessTable *lookupDefaultWitnessTable(SILDefaultWitnessTable *C);
|
|
|
|
/// Invalidate the cached entries for deserialized SILFunctions.
|
|
void invalidateCaches();
|
|
|
|
bool invalidateFunction(SILFunction *F);
|
|
|
|
/// Deserialize all SILFunctions, VTables, and WitnessTables in all
|
|
/// SILModules.
|
|
void getAll();
|
|
|
|
/// Deserialize all SILFunctions, VTables, and WitnessTables for
|
|
/// a given Module.
|
|
///
|
|
/// If PrimaryFile is nullptr, all definitions are brought in with
|
|
/// definition linkage.
|
|
///
|
|
/// Otherwise, definitions not in the primary file are brought in
|
|
/// with external linkage.
|
|
void getAllForModule(Identifier Mod, FileUnit *PrimaryFile);
|
|
|
|
/// Deserialize all SILFunctions in all SILModules.
|
|
void getAllSILFunctions();
|
|
|
|
/// Deserialize all VTables in all SILModules.
|
|
void getAllVTables();
|
|
|
|
/// Deserialize all WitnessTables in all SILModules.
|
|
void getAllWitnessTables();
|
|
|
|
/// Deserialize all DefaultWitnessTables in all SILModules.
|
|
void getAllDefaultWitnessTables();
|
|
|
|
/// Deserialize all Properties in all SILModules.
|
|
void getAllProperties();
|
|
|
|
SerializedSILLoader(const SerializedSILLoader &) = delete;
|
|
SerializedSILLoader(SerializedSILLoader &&) = delete;
|
|
SerializedSILLoader &operator=(const SerializedSILLoader &) = delete;
|
|
SerializedSILLoader &operator=(SerializedSILLoader &&) = delete;
|
|
};
|
|
|
|
} // end namespace swift
|
|
|
|
#endif
|