[move-only] Add the ability to specify a deinit at the SIL level for a move only type.

Specifically, we get an additional table like thing called sil_moveonlydeinit. It looks as follows:

sil_moveonlydeinit TYPE {
  @FUNC_NAME
}

It always has a single entry.
This commit is contained in:
Michael Gottesman
2022-09-16 11:53:17 -07:00
parent 182df6e80d
commit c54acc83e2
24 changed files with 561 additions and 22 deletions

View File

@@ -11,15 +11,18 @@
//===----------------------------------------------------------------------===//
#define DEBUG_TYPE "sil-module"
#include "swift/SIL/SILModule.h"
#include "Linker.h"
#include "swift/AST/ASTMangler.h"
#include "swift/AST/Decl.h"
#include "swift/AST/GenericEnvironment.h"
#include "swift/AST/ProtocolConformance.h"
#include "swift/ClangImporter/ClangModule.h"
#include "swift/SIL/FormalLinkage.h"
#include "swift/SIL/Notifications.h"
#include "swift/SIL/SILDebugScope.h"
#include "swift/SIL/SILMoveOnlyDeinit.h"
#include "swift/SIL/SILRemarkStreamer.h"
#include "swift/SIL/SILValue.h"
#include "swift/SIL/SILVisitor.h"
@@ -131,6 +134,9 @@ SILModule::~SILModule() {
for (auto vt : vtables)
vt->~SILVTable();
for (auto deinit : moveOnlyDeinits)
deinit->~SILMoveOnlyDeinit();
// Drop everything functions in this module reference.
//
// This is necessary since the functions may reference each other. We don't
@@ -519,6 +525,29 @@ SILVTable *SILModule::lookUpVTable(const ClassDecl *C,
return Vtbl;
}
SILMoveOnlyDeinit *SILModule::lookUpMoveOnlyDeinit(const NominalTypeDecl *C,
bool deserializeLazily) {
if (!C)
return nullptr;
// First try to look up R from the lookup table.
auto iter = MoveOnlyDeinitMap.find(C);
if (iter != MoveOnlyDeinitMap.end())
return iter->second;
if (!deserializeLazily)
return nullptr;
// If that fails, try to deserialize it. If that fails, return nullptr.
auto *tbl = getSILLoader()->lookupMoveOnlyDeinit(C);
if (!tbl)
return nullptr;
// If we succeeded, map C -> VTbl in the table and return VTbl.
MoveOnlyDeinitMap[C] = tbl;
return tbl;
}
SerializedSILLoader *SILModule::getSILLoader() {
// If the SILLoader is null, create it.
if (!SILLoader)
@@ -627,6 +656,20 @@ lookUpFunctionInVTable(ClassDecl *Class, SILDeclRef Member) {
return nullptr;
}
SILFunction *
SILModule::lookUpMoveOnlyDeinitFunction(const NominalTypeDecl *nomDecl) {
assert(nomDecl->isMoveOnly());
auto *tbl = lookUpMoveOnlyDeinit(nomDecl);
// Bail, if the lookup of VTable fails.
if (!tbl) {
return nullptr;
}
return tbl->getImplementation();
}
SILDifferentiabilityWitness *
SILModule::lookUpDifferentiabilityWitness(StringRef name) {
auto it = DifferentiabilityWitnessMap.find(name);