Skip to content

add "ac" (arc+cow) types, initially as wrappers around qt types #48228

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

jkarneges
Copy link
Member

@jkarneges jkarneges commented May 15, 2025

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 with std::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 and AcByteArray as drop-in substitutes for QString and QByteArray, and uses them in QZmq::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 private QString 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 an AcString 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 to QList<AcByteArray> &. It's a little scary looking but I think it is safe. Not sure if portable, but hopefully.

Plan:

  1. Provide substitute types with identical APIs that wrap Qt types, along with cheap conversions to/from Qt types. Gradually update the codebase to use these types.
  2. Once the whole codebase is using the substitute types, remove any conversion functions to confirm elimination of Qt types.
  3. Replace the implementations of the substitute types to be based on non-Qt types.
  4. Remove the Qt library as a dependency of the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant