[libSyntax] Make the ByteTree format forwards-compatible

This commit is contained in:
Alex Hoppen
2018-07-26 17:10:34 -07:00
parent e09e86a9fe
commit 34a89d45e2
6 changed files with 124 additions and 26 deletions

View File

@@ -156,6 +156,15 @@ SerializeAsByteTree("serialize-byte-tree",
"serialized in the ByteTree format instead "
"of JSON."));
static llvm::cl::opt<bool>
AddByteTreeFields("add-bytetree-fields",
llvm::cl::desc("If specified, further fields will be added "
"to the syntax tree if it is serialized as a "
"ByteTree. This is to test forward "
"compatibility with future versions of "
"SwiftSyntax that might add more fields to "
"syntax nodes."));
static llvm::cl::opt<bool>
IncrementalSerialization("incremental-serialization",
llvm::cl::desc("If specified, the serialized syntax "
@@ -724,6 +733,9 @@ int doSerializeRawTree(const char *MainExecutablePath,
llvm::BinaryStreamWriter Writer(Stream);
std::map<void *, void *> UserInfo;
UserInfo[swift::byteTree::UserInfoKeyReusedNodeIds] = &ReusedNodeIds;
if (options::AddByteTreeFields) {
UserInfo[swift::byteTree::UserInfoKeyAddInvalidFields] = (void *)true;
}
swift::byteTree::ByteTreeWriter::write(/*ProtocolVersion=*/1, Writer,
*Root, UserInfo);
auto OutputBufferOrError = llvm::FileOutputBuffer::create(