Refactor and Break Down TypeSerializer

This class is a perennial source of bugs when we add new type nodes because there is no signal when you forget to update it since it's just comparing record IDs in the switch. Break this class down and add new macros that enforce structural checks and require exhaustiveness at compile time.

This TYPE_LAYOUT(...) macro replaces the usual \c BCRecordLayout coding structure by enforcing structural checks for the definition of deserialization members. If you forget to define a TYPE_LAYOUT(...) for a TYPE(...) there will be a gnarly SFINAE error pointing at it in DeclTypeRecordNodes.def.

This macro pairs with \c DESERIALIZE_TYPE(...) in Deserialization.cpp such that if you forget \c DESERIALIZE_TYPE(...) you will come up with a linker error.
This commit is contained in:
Robert Widmann
2022-05-11 04:13:49 -07:00
parent f3870767b4
commit 28abcbbea9
3 changed files with 1092 additions and 1091 deletions

View File

@@ -56,6 +56,9 @@ class ModuleFile
friend class TypeDeserializer;
friend class SILDeserializer;
friend class ProtocolConformanceDeserializer;
template <serialization::decls_block::detail::TypeRecords TypeRecord>
friend class serialization::decls_block::detail::TypeRecordDispatch;
friend struct serialization::decls_block::detail::function_deserializer;
using Status = serialization::Status;
using TypeID = serialization::TypeID;
using ProtocolConformanceID = serialization::ProtocolConformanceID;