mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Merge remote-tracking branch 'origin/master' into master-next
This commit is contained in:
@@ -1065,6 +1065,7 @@ static uint8_t getRawStableDefaultArgumentKind(swift::DefaultArgumentKind kind)
|
||||
CASE(Inherited)
|
||||
CASE(Column)
|
||||
CASE(File)
|
||||
CASE(FilePath)
|
||||
CASE(Line)
|
||||
CASE(Function)
|
||||
CASE(DSOHandle)
|
||||
@@ -1996,6 +1997,18 @@ static uint8_t getRawStableVarDeclIntroducer(swift::VarDecl::Introducer intr) {
|
||||
llvm_unreachable("bad variable decl introducer kind");
|
||||
}
|
||||
|
||||
/// Translate from the AST derivative function kind enum to the Serialization
|
||||
/// enum values, which are guaranteed to be stable.
|
||||
static uint8_t getRawStableAutoDiffDerivativeFunctionKind(
|
||||
swift::AutoDiffDerivativeFunctionKind kind) {
|
||||
switch (kind) {
|
||||
case swift::AutoDiffDerivativeFunctionKind::JVP:
|
||||
return uint8_t(serialization::AutoDiffDerivativeFunctionKind::JVP); case swift::AutoDiffDerivativeFunctionKind::VJP:
|
||||
return uint8_t(serialization::AutoDiffDerivativeFunctionKind::VJP);
|
||||
}
|
||||
llvm_unreachable("bad derivative function kind");
|
||||
}
|
||||
|
||||
/// Returns true if the declaration of \p decl depends on \p problemContext
|
||||
/// based on lexical nesting.
|
||||
///
|
||||
@@ -2069,7 +2082,7 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
|
||||
didVerifyAttrs = true;
|
||||
}
|
||||
|
||||
void writeDeclAttribute(const DeclAttribute *DA) {
|
||||
void writeDeclAttribute(const Decl *D, const DeclAttribute *DA) {
|
||||
using namespace decls_block;
|
||||
|
||||
// Completely ignore attributes that aren't serialized.
|
||||
@@ -2180,6 +2193,22 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
|
||||
return;
|
||||
}
|
||||
|
||||
case DAK_OriginallyDefinedIn: {
|
||||
auto *theAttr = cast<OriginallyDefinedInAttr>(DA);
|
||||
ENCODE_VER_TUPLE(Moved, llvm::Optional<llvm::VersionTuple>(theAttr->MovedVersion));
|
||||
auto abbrCode = S.DeclTypeAbbrCodes[OriginallyDefinedInDeclAttrLayout::Code];
|
||||
llvm::SmallString<32> blob;
|
||||
blob.append(theAttr->OriginalModuleName.str());
|
||||
blob.push_back('\0');
|
||||
OriginallyDefinedInDeclAttrLayout::emitRecord(
|
||||
S.Out, S.ScratchRecord, abbrCode,
|
||||
theAttr->isImplicit(),
|
||||
LIST_VER_TUPLE_PIECES(Moved),
|
||||
static_cast<unsigned>(theAttr->Platform),
|
||||
blob);
|
||||
return;
|
||||
}
|
||||
|
||||
case DAK_Available: {
|
||||
auto *theAttr = cast<AvailableAttr>(DA);
|
||||
ENCODE_VER_TUPLE(Introduced, theAttr->Introduced)
|
||||
@@ -2245,10 +2274,11 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
|
||||
pieces.push_back(S.addDeclBaseNameRef(replacedFun.getBaseName()));
|
||||
for (auto argName : replacedFun.getArgumentNames())
|
||||
pieces.push_back(S.addDeclBaseNameRef(argName));
|
||||
assert(theAttr->getReplacedFunction());
|
||||
auto *afd = cast<ValueDecl>(D)->getDynamicallyReplacedDecl();
|
||||
assert(afd && "Missing replaced decl!");
|
||||
DynamicReplacementDeclAttrLayout::emitRecord(
|
||||
S.Out, S.ScratchRecord, abbrCode, false, /*implicit flag*/
|
||||
S.addDeclRef(theAttr->getReplacedFunction()), pieces.size(), pieces);
|
||||
S.addDeclRef(afd), pieces.size(), pieces);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -2290,12 +2320,12 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
|
||||
vjpRef = S.addDeclRef(vjpFunction);
|
||||
|
||||
auto paramIndices = attr->getParameterIndices();
|
||||
// TODO(TF-837): Implement `@differentiable` attribute serialization.
|
||||
// Blocked by TF-828: `@differentiable` attribute type-checking, which
|
||||
// resolves parameter indices (`IndexSubset *`).
|
||||
// NOTE(TF-836): `@differentiable` attribute serialization is blocked by
|
||||
// `@differentiable` attribute type-checking (TF-828), which resolves
|
||||
// parameter indices (`IndexSubset *`).
|
||||
if (!paramIndices)
|
||||
return;
|
||||
assert(paramIndices && "Checked parameter indices must be resolved");
|
||||
assert(paramIndices && "Parameter indices must be resolved");
|
||||
SmallVector<bool, 4> indices;
|
||||
for (unsigned i : range(paramIndices->getCapacity()))
|
||||
indices.push_back(paramIndices->contains(i));
|
||||
@@ -2307,6 +2337,33 @@ class Serializer::DeclSerializer : public DeclVisitor<DeclSerializer> {
|
||||
indices);
|
||||
return;
|
||||
}
|
||||
|
||||
case DAK_Derivative: {
|
||||
auto abbrCode = S.DeclTypeAbbrCodes[DerivativeDeclAttrLayout::Code];
|
||||
auto *attr = cast<DerivativeAttr>(DA);
|
||||
assert(attr->getOriginalFunction() &&
|
||||
"`@derivative` attribute should have original declaration set "
|
||||
"during construction or parsing");
|
||||
auto origName = attr->getOriginalFunctionName().Name.getBaseName();
|
||||
IdentifierID origNameId = S.addDeclBaseNameRef(origName);
|
||||
DeclID origDeclID = S.addDeclRef(attr->getOriginalFunction());
|
||||
auto derivativeKind =
|
||||
getRawStableAutoDiffDerivativeFunctionKind(attr->getDerivativeKind());
|
||||
auto paramIndices = attr->getParameterIndices();
|
||||
// NOTE(TF-837): `@derivative` attribute serialization is blocked by
|
||||
// `@derivative` attribute type-checking (TF-829), which resolves
|
||||
// parameter indices (`IndexSubset *`).
|
||||
if (!paramIndices)
|
||||
return;
|
||||
assert(paramIndices && "Parameter indices must be resolved");
|
||||
SmallVector<bool, 4> indices;
|
||||
for (unsigned i : range(paramIndices->getCapacity()))
|
||||
indices.push_back(paramIndices->contains(i));
|
||||
DerivativeDeclAttrLayout::emitRecord(
|
||||
S.Out, S.ScratchRecord, abbrCode, attr->isImplicit(), origNameId,
|
||||
origDeclID, derivativeKind, indices);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2657,7 +2714,7 @@ public:
|
||||
void visit(const Decl *D) {
|
||||
// Emit attributes (if any).
|
||||
for (auto Attr : D->getAttrs())
|
||||
writeDeclAttribute(Attr);
|
||||
writeDeclAttribute(D, Attr);
|
||||
|
||||
if (auto *value = dyn_cast<ValueDecl>(D))
|
||||
writeDiscriminatorsIfNeeded(value);
|
||||
@@ -3942,6 +3999,8 @@ public:
|
||||
|
||||
void visitFunctionType(const FunctionType *fnTy) {
|
||||
using namespace decls_block;
|
||||
|
||||
// FIXME: [clang-function-type-serialization] Serialize the clang type here
|
||||
unsigned abbrCode = S.DeclTypeAbbrCodes[FunctionTypeLayout::Code];
|
||||
FunctionTypeLayout::emitRecord(S.Out, S.ScratchRecord, abbrCode,
|
||||
S.addTypeRef(fnTy->getResult()),
|
||||
|
||||
Reference in New Issue
Block a user