Parser/Sema/SILGen changes for @_dynamicReplacement(for:)

Dynamic replacements are currently written in extensions as

extension ExtendedType {
  @_dynamicReplacement(for: replacedFun())
  func replacement() { }
}

The runtime implementation allows an implementation in the future where
dynamic replacements are gather in a scope and can be dynamically
enabled and disabled.

For example:

dynamic_extension_scope CollectionOfReplacements {
  extension ExtentedType {
    func replacedFun() {}
  }

  extension ExtentedType2 {
    func replacedFun() {}
  }
}

CollectionOfReplacements.enable()
CollectionOfReplacements.disable()
This commit is contained in:
Arnold Schwaighofer
2018-11-05 09:53:40 -08:00
parent 52c1903e54
commit b102c7f6b4
35 changed files with 1264 additions and 205 deletions

View File

@@ -2541,6 +2541,30 @@ ModuleFile::getDeclCheckedImpl(DeclID DID) {
break;
}
case decls_block::DynamicReplacement_DECL_ATTR: {
bool isImplicit;
uint64_t numArgs;
ArrayRef<uint64_t> rawPieceIDs;
DeclID replacedFunID;
serialization::decls_block::DynamicReplacementDeclAttrLayout::
readRecord(scratch, isImplicit, replacedFunID, numArgs, rawPieceIDs);
auto replacedFunDecl = getDeclChecked(replacedFunID);
if (!replacedFunDecl)
return replacedFunDecl.takeError();
auto baseName = getDeclBaseName(rawPieceIDs[0]);
SmallVector<Identifier, 4> pieces;
for (auto pieceID : rawPieceIDs.slice(1))
pieces.push_back(getIdentifier(pieceID));
assert(numArgs != 0);
assert(!isImplicit && "Need to update for implicit");
Attr = DynamicReplacementAttr::create(
ctx, DeclName(ctx, baseName, ArrayRef<Identifier>(pieces)),
cast<AbstractFunctionDecl>(*replacedFunDecl));
break;
}
#define SIMPLE_DECL_ATTR(NAME, CLASS, ...) \
case decls_block::CLASS##_DECL_ATTR: { \
bool isImplicit; \