Clean up serializer class#1353
Conversation
|
CMAKE-FORMAT TEST - PASSED |
|
CLANG-FORMAT TEST - PASSED |
|
Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
fbbd165 to
3d23134
Compare
|
CLANG-FORMAT TEST - FAILED (on last commit): |
|
CMAKE-FORMAT TEST - PASSED |
|
Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
3d23134 to
982c11e
Compare
|
CLANG-FORMAT TEST - PASSED |
|
CMAKE-FORMAT TEST - PASSED |
982c11e to
9d06c0e
Compare
|
CLANG-FORMAT TEST - PASSED |
|
CMAKE-FORMAT TEST - PASSED |
9d06c0e to
b079687
Compare
|
CLANG-FORMAT TEST - PASSED |
|
CMAKE-FORMAT TEST - PASSED |
|
Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
4e9707b to
af341cc
Compare
|
CLANG-FORMAT TEST - PASSED |
|
CMAKE-FORMAT TEST - PASSED |
|
Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
|
For |
|
CLANG-FORMAT TEST - PASSED |
|
CMAKE-FORMAT TEST - PASSED |
|
Status Flag 'Pre-Test Inspection' - - This Pull Request Requires Inspection... The code must be inspected by a member of the Team before Testing/Merging |
|
Status Flag 'Pre-Test Inspection' - SUCCESS: The last commit to this Pull Request has been INSPECTED by label AT: PRE-TEST INSPECTED! Autotester is Removing Label; this inspection will remain valid until a new commit to source branch is performed. |
|
Status Flag 'Pull Request AutoTester' - Testing Jenkins Projects: Pull Request Auto Testing STARTING (click to expand)Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements_MR-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements_MT-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-core_Make-Dist
Build InformationTest Name: SST__AutotestGen2_NewFW_OSX-14-XC15-ARM2_OMPI-4.1.6_PY3.10_sst-elements
Using Repos:
Pull Request Author: leekillough |
|
Status Flag 'Pull Request AutoTester' - Jenkins Testing: all Jobs PASSED Pull Request Auto Testing has PASSED (click to expand)Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements_MR-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-elements_MT-2
Build InformationTest Name: SST__AutotestGen2_NewFW_sst-test_OMPI-4.1.4_PY3.6_sst-core_Make-Dist
Build InformationTest Name: SST__AutotestGen2_NewFW_OSX-14-XC15-ARM2_OMPI-4.1.6_PY3.10_sst-elements
|
|
Status Flag 'Pre-Merge Inspection' - SUCCESS: The last commit to this Pull Request has been INSPECTED AND APPROVED by [ feldergast ]! |
|
Status Flag 'Pull Request AutoTester' - Pull Request MUST BE MERGED MANUALLY BY Project Team - This Repo does not support Automerge |
This PR cleans up the
serializerclass:The current mode is controlled by a
std::variant<pvt::ser_sizer, pvt::ser_packer, pvt::ser_unpacker, pvt::ser_mapper> ser_member, each variant of which holds all data necessary for the current mode.The variants have indices of
SIZER,PACK,UNPACK, andMAP, and the current mode is the one returned byser_.index().The serializer data for a mode is accessed like
std::get<UNPACK>(ser_), whereser_is thestd::variantmember.Since their names are shorter, and they already existed, the accessors
sizer(),packer(),unpacker()andmapper()are used everywhere, and they callstd:get<MODE>(ser_). What was previouslysizer_is nowsizer().If a method is called which is not valid for the current mode, a
std::bad_variant_accessexception is thrown. Thiserror checking is automatically provided by
std::get<MODE>(std::variant).All pointer tracking data structures, such as
ser_pointer_setandser_pointer_map, have been moved topvt::sizer,pvt::ser_packer,pvt::ser_unpacker, andpvt:ser_mapper, so that they are private to each mode, and are automatically initialized/destroyed when the mode changes, without requiring explicit initialization or destruction/clearing in theserializerclass. This was motivated bystd::shared_ptrtracking requiring additional tracking containers, and requiring different ones for different serialization modes.set_mode()is marked deprecated, because it was not very useful, was not used anywhere in Core or Elements, and in the new code, we cannot change the mode without changing and initializing the new variant.set_mode()will still change the mode, but the variant of the new mode will be default-initialized, which meanspvt::ser_packerwill have amax_sizeof 0, etc. There was no way in the old interface to changemax_sizeexceptstart_packing(), and if you changed modes, some of the settings could be uninitialized or have bad data from the old mode. Now switching modes is clean, and data for each mode is clearly separated.reset()is not used anywhere either, and is marked deprecated.If it is not important that we keepset_mode()andreset(), I vote to remove them immediately.start_sizing(),start_packing(),start_unpacking(), andstart_mapping()change the active mode, andinitialize the mode's data structures by calling the variant's constructor.
The
.init()methods of thepvt::serializers have been replaced by constructors. For example,In this example,
start_unpacking()changes the mode toUNPACK, automatically calling the destructors of any data in the previous mode, and callspvt::ser_unpacker's constructor withbufferandsizearguments, instead ofseparately calling an
.init()method.pvt::ser_packerandpvt::ser_unpacker, which are derived fromser_buffer_accessor, use C++11 inherited constructors so that thepvt::ser_packer(buffer, size)andpvt::ser_unpacker(buffer, size)constructors are automatically created, and pass their arguments to the inheritedser_buffer_accessorconstructor.Non-templated serialization functions which aren't very short were moved from
serializer.htoserializer.cc.To avoid having to overload
sizer(),packer(),unpacker()andmapper()withconstversions in addition to their non-const versions,consthas been removed from thesize()method, which was the only method which usedconston*this. Since almost all uses ofsize()will beser.size()whereseris a non-constreference to aserializer(all cases in Core and Elements so far), this will not cause a problem. Only if you hadconst serializer& serand needed to callser.size()would aconstmethod ofsize()be needed. If this is not acceptable, we can either duplicate the accessors withconstversions, or we can changesize()to not use the accessors but to usestd::get<>(ser_)directly. I like the accessors as being a single place where the variants are extracted, and they replace names likesizer_withsizer(),packer_withpacker(), etc.check_pointer_pack()was split intocheck_pointer_pack()andcheck_pointer_sizer(), and thestd::setwas moved fromserializerintopvt::ser_sizerandpvt::ser_packer, so thatSIZEandPACKmodes have their own pointer tracking sets, and the rightcheck_pointer_*for the current mode is called.The maps used in mapping mode and unpacking mode were moved to
pvt::ser_mapperandpvt::ser_unpacker, and although the map has the same declaration in both, the way the map is used is totally different in unpacking and mapping mode. Best to separate them.The new code is 40+ lines shorter and much cleaner. Adding serialization of
std::shared_ptrandstd::unique_ptrwill be simpler since now the tracking data is separately in each mode'spvt::class, and is cleanly initialized/destroyed when switching modes.Edit 6/10:
EMPTYhas been added as the default serializer mode.std::monostatetype has been added as the defaultEMPTYtype of thestd::variant.sizer(),packer(),unpacker()ormapper()during a different mode thanSIZER,PACK,UNPACKorMAP, respectively, causes a runtime error.set_mode()andreset()methods have been removed.finalize()method has been added which, right now, simply sets the mode toEMPTYand destroys any state object of the old mode. Later it might be changed to do more, such as considering the current mode and doing something special for it, such as finalization of mapping mode.SIZERmode is sometimes used to clear the old state; however,SIZERmode has its own state (astd::setwhich is empty on construction). An explicitEMPTYmode separate from other modes is preferable.EMPTYnot being listed inswitchcases,EMPTYhas been defined outside of theenum.pvt::ser_packerfunctions defined inserializer.cchave been moved to a new fileimpl/packer.cc.pvt::ser_unpackerfunctions defined inserializer.cchave been moved to a new fileimpl/unpacker.ccser_buf_accessorhas been made much simpler, with a single methodbuf_next(size)which returns the buffer address and advances it bysize, making sure that it does not overflow. This simplifies the multiple methods which were used before, such as special methods forstd::string.