add "ac" (arc+cow) types, initially as wrappers around qt types #48228
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Long term we want to move off of Qt, and this will mean replacing all use of Qt types with either C++ standard library types or wrapped Rust types. For example, we could imagine replacing
QString
withstd::string
. These two types don't work exactly the same way though, and porting the entire codebase to types with different APIs and behaviors would be a lot of work as well as error prone. To simplify the porting process, I propose we substitute the Qt types with our own internal types that provide identical APIs and behaviors. Only the type names would be different. This should make the substitution process fairly safe.To start out, this PR adds types
AcString
andAcByteArray
as drop-in substitutes forQString
andQByteArray
, and uses them inQZmq::Socket
. The "Ac" stands for atomic reference count & copy on write, which is the main special behavior provided by these (and most) Qt types. Initially, the implementations are simply wrappers around the Qt types. For example,AcString
has a single privateQString
member that it forwards to. Later on, we could change it to wrap an ARC'd COW'd standard C++ or Rust string instead.The substitute types are also cheaply convertible to/from Qt types, so they can be introduced gradually with minimal/zero overhead. For example, a
QString
can be converted to anAcString
and back without deep copying. The memory layouts of the types are also statically asserted as identical (similar to Rust's#[repr(transparent)]
), to enable converting between collections without copying. For example,QList<QByteArray> &
can be casted toQList<AcByteArray> &
. It's a little scary looking but I think it is safe. Not sure if portable, but hopefully.Plan: