MiraclePtr: Rewrite dawn/wire (linux)
1. Run the clang rewriter:
./tools/clang/rewrite_raw_ptr_fields/rewrite.sh
2. Add manually the missing AllowPtrArithmetic and DanglingUntriaged.
3. Split the patch
This is step 6 of using MiraclePtr in third_party/dawn project:
https://docs.google.com/document/d/1wz45t0alQthsIU9P7_rQcfQyqnrBMXzrOjSzdQo-V-A/edit#heading=h.vn4i6wy373x7
Bug: chromium:1464560
Change-Id: I8b84213aed990acf144638f6c38139db03d82431
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/165504
Commit-Queue: Arthur Sonzogni <arthursonzogni@chromium.org>
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Auto-Submit: Arthur Sonzogni <arthursonzogni@chromium.org>
diff --git a/src/dawn/wire/BUILD.gn b/src/dawn/wire/BUILD.gn
index 1fd51cb..e294cdb 100644
--- a/src/dawn/wire/BUILD.gn
+++ b/src/dawn/wire/BUILD.gn
@@ -30,7 +30,7 @@
import("${dawn_root}/generator/dawn_generator.gni")
import("${dawn_root}/scripts/dawn_component.gni")
-# Public dawn wire headers so they can be publically visible for dependencies of
+# Public dawn wire headers so they can be publicly visible for dependencies of
# dawn/wire
source_set("headers") {
public_deps = [ "${dawn_root}/include/dawn:headers" ]
@@ -151,5 +151,6 @@
public_deps = [
":abseil",
":headers",
+ "${dawn_root}/src/dawn/partition_alloc:raw_ptr",
]
}
diff --git a/src/dawn/wire/BufferConsumer.h b/src/dawn/wire/BufferConsumer.h
index 4435505..ab596f6 100644
--- a/src/dawn/wire/BufferConsumer.h
+++ b/src/dawn/wire/BufferConsumer.h
@@ -33,6 +33,7 @@
#include "dawn/common/Constants.h"
#include "dawn/common/Math.h"
#include "dawn/wire/WireResult.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire {
@@ -73,7 +74,7 @@
WireResult Peek(T** data);
private:
- BufferT* mBuffer;
+ raw_ptr<BufferT, AllowPtrArithmetic> mBuffer;
size_t mSize;
};
diff --git a/src/dawn/wire/BufferConsumer_impl.h b/src/dawn/wire/BufferConsumer_impl.h
index b1f94ba..fc6bc92 100644
--- a/src/dawn/wire/BufferConsumer_impl.h
+++ b/src/dawn/wire/BufferConsumer_impl.h
@@ -42,7 +42,7 @@
return WireResult::FatalError;
}
- *data = reinterpret_cast<T*>(mBuffer);
+ *data = reinterpret_cast<T*>(mBuffer.get());
return WireResult::Success;
}
@@ -54,7 +54,7 @@
return WireResult::FatalError;
}
- *data = reinterpret_cast<T*>(mBuffer);
+ *data = reinterpret_cast<T*>(mBuffer.get());
mBuffer += kSize;
mSize -= kSize;
return WireResult::Success;
@@ -71,7 +71,7 @@
return WireResult::FatalError;
}
- *data = reinterpret_cast<T*>(mBuffer);
+ *data = reinterpret_cast<T*>(mBuffer.get());
mBuffer += *size;
mSize -= *size;
return WireResult::Success;
diff --git a/src/dawn/wire/CMakeLists.txt b/src/dawn/wire/CMakeLists.txt
index bf709e0..22c81b8 100644
--- a/src/dawn/wire/CMakeLists.txt
+++ b/src/dawn/wire/CMakeLists.txt
@@ -107,8 +107,14 @@
"server/ServerShaderModule.cpp"
)
target_link_libraries(dawn_wire
- PUBLIC dawn_headers
- PRIVATE dawn_common dawn_internal_config absl_flat_hash_map absl_flat_hash_set
+ PUBLIC
+ dawn_headers
+ PRIVATE
+ absl_flat_hash_map
+ absl_flat_hash_set
+ dawn_common
+ dawn_internal_config
+ partition_alloc
)
install_if_enabled(dawn_wire)
diff --git a/src/dawn/wire/ChunkedCommandSerializer.h b/src/dawn/wire/ChunkedCommandSerializer.h
index 6b4edc6..655bec8 100644
--- a/src/dawn/wire/ChunkedCommandSerializer.h
+++ b/src/dawn/wire/ChunkedCommandSerializer.h
@@ -40,6 +40,7 @@
#include "dawn/common/Math.h"
#include "dawn/wire/Wire.h"
#include "dawn/wire/WireCmd_autogen.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire {
@@ -143,7 +144,7 @@
void SerializeChunkedCommand(const char* allocatedBuffer, size_t remainingSize);
- CommandSerializer* mSerializer;
+ raw_ptr<CommandSerializer> mSerializer;
size_t mMaxAllocationSize;
};
diff --git a/src/dawn/wire/WireDeserializeAllocator.h b/src/dawn/wire/WireDeserializeAllocator.h
index fe7fe83..08e992f 100644
--- a/src/dawn/wire/WireDeserializeAllocator.h
+++ b/src/dawn/wire/WireDeserializeAllocator.h
@@ -31,6 +31,7 @@
#include <vector>
#include "dawn/wire/WireCmd_autogen.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire {
// A really really simple implementation of the DeserializeAllocator. It's main feature
@@ -47,7 +48,8 @@
private:
size_t mRemainingSize = 0;
- char* mCurrentBuffer = nullptr;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire.
+ raw_ptr<char, AllowPtrArithmetic | DanglingUntriaged> mCurrentBuffer = nullptr;
char mStaticBuffer[2048];
std::vector<char*> mAllocations;
};
diff --git a/src/dawn/wire/client/Adapter.h b/src/dawn/wire/client/Adapter.h
index dd88635..b625698 100644
--- a/src/dawn/wire/client/Adapter.h
+++ b/src/dawn/wire/client/Adapter.h
@@ -36,6 +36,7 @@
#include "dawn/wire/client/LimitsAndFeatures.h"
#include "dawn/wire/client/ObjectBase.h"
#include "dawn/wire/client/RequestTracker.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire::client {
@@ -76,7 +77,8 @@
struct RequestDeviceData {
WGPURequestDeviceCallback callback = nullptr;
ObjectId deviceObjectId;
- void* userdata = nullptr;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire.
+ raw_ptr<void, DanglingUntriaged> userdata = nullptr;
};
RequestTracker<RequestDeviceData> mRequestDeviceRequests;
};
diff --git a/src/dawn/wire/client/Buffer.cpp b/src/dawn/wire/client/Buffer.cpp
index d5e44c8..4dcf340 100644
--- a/src/dawn/wire/client/Buffer.cpp
+++ b/src/dawn/wire/client/Buffer.cpp
@@ -36,6 +36,7 @@
#include "dawn/wire/client/Client.h"
#include "dawn/wire/client/Device.h"
#include "dawn/wire/client/EventManager.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire::client {
namespace {
@@ -98,7 +99,8 @@
}
WGPUBufferMapCallback mCallback;
- void* mUserdata;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire.
+ raw_ptr<void, DanglingUntriaged> mUserdata;
std::optional<WGPUBufferMapAsyncStatus> mStatus;
diff --git a/src/dawn/wire/client/Buffer.h b/src/dawn/wire/client/Buffer.h
index f86c918..1c52d57 100644
--- a/src/dawn/wire/client/Buffer.h
+++ b/src/dawn/wire/client/Buffer.h
@@ -37,6 +37,7 @@
#include "dawn/webgpu.h"
#include "dawn/wire/WireClient.h"
#include "dawn/wire/client/ObjectBase.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire::client {
@@ -124,7 +125,8 @@
std::unique_ptr<MemoryTransferService::WriteHandle> mWriteHandle = nullptr;
bool mDestructWriteHandleOnUnmap = false;
- void* mMappedData = nullptr;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire.
+ raw_ptr<void, DanglingUntriaged> mMappedData = nullptr;
size_t mMapOffset = 0;
size_t mMapSize = 0;
};
diff --git a/src/dawn/wire/client/Client.h b/src/dawn/wire/client/Client.h
index a4a82c1..05ffd10 100644
--- a/src/dawn/wire/client/Client.h
+++ b/src/dawn/wire/client/Client.h
@@ -43,6 +43,7 @@
#include "dawn/wire/client/ClientBase_autogen.h"
#include "dawn/wire/client/EventManager.h"
#include "dawn/wire/client/ObjectStore.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire::client {
@@ -120,7 +121,8 @@
ChunkedCommandSerializer mSerializer;
WireDeserializeAllocator mWireCommandAllocator;
PerObjectType<ObjectStore> mObjectStores;
- MemoryTransferService* mMemoryTransferService = nullptr;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire.
+ raw_ptr<MemoryTransferService, DanglingUntriaged> mMemoryTransferService = nullptr;
std::unique_ptr<MemoryTransferService> mOwnedMemoryTransferService = nullptr;
PerObjectType<LinkedList<ObjectBase>> mObjects;
// Map of instance object handles to a corresponding event manager. Note that for now because we
diff --git a/src/dawn/wire/client/ClientMemoryTransferService_mock.h b/src/dawn/wire/client/ClientMemoryTransferService_mock.h
index 876c83e..ad5a389 100644
--- a/src/dawn/wire/client/ClientMemoryTransferService_mock.h
+++ b/src/dawn/wire/client/ClientMemoryTransferService_mock.h
@@ -32,6 +32,7 @@
#include "dawn/wire/WireClient.h"
#include "dawn/wire/client/Client.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire::client {
@@ -51,7 +52,7 @@
size_t size) override;
private:
- MockMemoryTransferService* mService;
+ raw_ptr<MockMemoryTransferService> mService;
};
class MockWriteHandle : public WriteHandle {
@@ -66,7 +67,7 @@
void SerializeDataUpdate(void* serializePointer, size_t offset, size_t size) override;
private:
- MockMemoryTransferService* mService;
+ raw_ptr<MockMemoryTransferService> mService;
};
MockMemoryTransferService();
diff --git a/src/dawn/wire/client/Device.h b/src/dawn/wire/client/Device.h
index 12aca84..6d17a55 100644
--- a/src/dawn/wire/client/Device.h
+++ b/src/dawn/wire/client/Device.h
@@ -37,6 +37,7 @@
#include "dawn/wire/client/LimitsAndFeatures.h"
#include "dawn/wire/client/ObjectBase.h"
#include "dawn/wire/client/RequestTracker.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire::client {
@@ -90,14 +91,16 @@
LimitsAndFeatures mLimitsAndFeatures;
struct ErrorScopeData {
WGPUErrorCallback callback = nullptr;
- void* userdata = nullptr;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire.
+ raw_ptr<void, DanglingUntriaged> userdata = nullptr;
};
RequestTracker<ErrorScopeData> mErrorScopes;
struct CreatePipelineAsyncRequest {
WGPUCreateComputePipelineAsyncCallback createComputePipelineAsyncCallback = nullptr;
WGPUCreateRenderPipelineAsyncCallback createRenderPipelineAsyncCallback = nullptr;
- void* userdata = nullptr;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire:
+ raw_ptr<void, DanglingUntriaged> userdata = nullptr;
ObjectId pipelineObjectID;
};
RequestTracker<CreatePipelineAsyncRequest> mCreatePipelineAsyncRequests;
@@ -106,11 +109,14 @@
WGPUDeviceLostCallback mDeviceLostCallback = nullptr;
WGPULoggingCallback mLoggingCallback = nullptr;
bool mDidRunLostCallback = false;
- void* mErrorUserdata = nullptr;
- void* mDeviceLostUserdata = nullptr;
- void* mLoggingUserdata = nullptr;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire:
+ raw_ptr<void, DanglingUntriaged> mErrorUserdata = nullptr;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire:
+ raw_ptr<void, DanglingUntriaged> mDeviceLostUserdata = nullptr;
+ raw_ptr<void> mLoggingUserdata = nullptr;
- Queue* mQueue = nullptr;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire:
+ raw_ptr<Queue, DanglingUntriaged> mQueue = nullptr;
std::shared_ptr<bool> mIsAlive;
};
diff --git a/src/dawn/wire/client/EventManager.h b/src/dawn/wire/client/EventManager.h
index 478c7ac..6577f9e 100644
--- a/src/dawn/wire/client/EventManager.h
+++ b/src/dawn/wire/client/EventManager.h
@@ -39,6 +39,7 @@
#include "dawn/common/NonCopyable.h"
#include "dawn/webgpu.h"
#include "dawn/wire/WireResult.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire::client {
diff --git a/src/dawn/wire/client/Instance.cpp b/src/dawn/wire/client/Instance.cpp
index db7907d..e67fc83 100644
--- a/src/dawn/wire/client/Instance.cpp
+++ b/src/dawn/wire/client/Instance.cpp
@@ -35,6 +35,7 @@
#include "dawn/common/WGSLFeatureMapping.h"
#include "dawn/wire/client/Client.h"
#include "dawn/wire/client/EventManager.h"
+#include "partition_alloc/pointers/raw_ptr.h"
#include "tint/lang/wgsl/features/language_feature.h"
#include "tint/lang/wgsl/features/status.h"
@@ -80,7 +81,7 @@
if (mStatus != WGPURequestAdapterStatus_Success && mAdapter != nullptr) {
// If there was an error, we may need to reclaim the adapter allocation, otherwise the
// adapter is returned to the user who owns it.
- mAdapter->GetClient()->Free(mAdapter);
+ mAdapter->GetClient()->Free(mAdapter.get());
mAdapter = nullptr;
}
if (mCallback) {
@@ -89,7 +90,8 @@
}
WGPURequestAdapterCallback mCallback;
- void* mUserdata;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire.
+ raw_ptr<void, DanglingUntriaged> mUserdata;
// Note that the message is optional because we want to return nullptr when it wasn't set
// instead of a pointer to an empty string.
@@ -100,7 +102,8 @@
// throughout the duration of a RequestAdapterEvent because the Event essentially takes
// ownership of it until either an error occurs at which point the Event cleans it up, or it
// returns the adapter to the user who then takes ownership as the Event goes away.
- Adapter* mAdapter = nullptr;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire.
+ raw_ptr<Adapter, DanglingUntriaged> mAdapter = nullptr;
};
WGPUWGSLFeatureName ToWGPUFeature(tint::wgsl::LanguageFeature f) {
diff --git a/src/dawn/wire/client/ObjectBase.h b/src/dawn/wire/client/ObjectBase.h
index 8c90683..889c956 100644
--- a/src/dawn/wire/client/ObjectBase.h
+++ b/src/dawn/wire/client/ObjectBase.h
@@ -29,6 +29,7 @@
#define SRC_DAWN_WIRE_CLIENT_OBJECTBASE_H_
#include "dawn/webgpu.h"
+#include "partition_alloc/pointers/raw_ptr.h"
#include "dawn/common/LinkedList.h"
#include "dawn/wire/ObjectHandle.h"
@@ -39,7 +40,7 @@
class Client;
struct ObjectBaseParams {
- Client* client;
+ raw_ptr<Client> client;
ObjectHandle handle;
};
@@ -69,7 +70,7 @@
uint32_t GetRefcount() const { return mRefcount; }
private:
- Client* const mClient;
+ const raw_ptr<Client> mClient;
const ObjectHandle mHandle;
uint32_t mRefcount;
};
diff --git a/src/dawn/wire/client/Queue.cpp b/src/dawn/wire/client/Queue.cpp
index eee8a00..5337853 100644
--- a/src/dawn/wire/client/Queue.cpp
+++ b/src/dawn/wire/client/Queue.cpp
@@ -32,6 +32,7 @@
#include "dawn/wire/client/Client.h"
#include "dawn/wire/client/EventManager.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire::client {
namespace {
@@ -60,7 +61,8 @@
}
WGPUQueueWorkDoneCallback mCallback;
- void* mUserdata;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire.
+ raw_ptr<void, DanglingUntriaged> mUserdata;
WGPUQueueWorkDoneStatus mStatus = WGPUQueueWorkDoneStatus_Success;
};
diff --git a/src/dawn/wire/client/ShaderModule.h b/src/dawn/wire/client/ShaderModule.h
index 65125fe..ea7437e 100644
--- a/src/dawn/wire/client/ShaderModule.h
+++ b/src/dawn/wire/client/ShaderModule.h
@@ -29,6 +29,7 @@
#define SRC_DAWN_WIRE_CLIENT_SHADERMODULE_H_
#include "dawn/webgpu.h"
+#include "partition_alloc/pointers/raw_ptr.h"
#include "dawn/wire/client/ObjectBase.h"
#include "dawn/wire/client/RequestTracker.h"
@@ -51,7 +52,8 @@
struct CompilationInfoRequest {
WGPUCompilationInfoCallback callback = nullptr;
- void* userdata = nullptr;
+ // TODO(https://crbug.com/dawn/2345): Investigate `DanglingUntriaged` in dawn/wire.
+ raw_ptr<void, DanglingUntriaged> userdata = nullptr;
};
RequestTracker<CompilationInfoRequest> mCompilationInfoRequests;
};
diff --git a/src/dawn/wire/server/ObjectStorage.h b/src/dawn/wire/server/ObjectStorage.h
index 13b5705..797499a 100644
--- a/src/dawn/wire/server/ObjectStorage.h
+++ b/src/dawn/wire/server/ObjectStorage.h
@@ -37,6 +37,7 @@
#include "absl/container/flat_hash_set.h"
#include "dawn/wire/WireCmd_autogen.h"
#include "dawn/wire/WireServer.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire::server {
@@ -75,7 +76,7 @@
};
struct DeviceInfo {
- Server* server;
+ raw_ptr<Server> server;
ObjectHandle self;
};
@@ -90,7 +91,7 @@
template <typename T>
struct Known {
ObjectId id;
- ObjectData<T>* data;
+ raw_ptr<ObjectData<T>> data;
const ObjectData<T>* operator->() const {
DAWN_ASSERT(data != nullptr);
diff --git a/src/dawn/wire/server/Server.h b/src/dawn/wire/server/Server.h
index 5f21a51..96f1523 100644
--- a/src/dawn/wire/server/Server.h
+++ b/src/dawn/wire/server/Server.h
@@ -33,6 +33,7 @@
#include "dawn/wire/ChunkedCommandSerializer.h"
#include "dawn/wire/server/ServerBase_autogen.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire::server {
@@ -64,7 +65,7 @@
//
// void Server::MyCallbackHandler(MyUserdata* userdata, Other args) { }
struct CallbackUserdata {
- Server* const server;
+ const raw_ptr<Server> server;
std::weak_ptr<bool> const serverIsAlive;
CallbackUserdata() = delete;
@@ -243,7 +244,7 @@
ChunkedCommandSerializer mSerializer;
DawnProcTable mProcs;
std::unique_ptr<MemoryTransferService> mOwnedMemoryTransferService = nullptr;
- MemoryTransferService* mMemoryTransferService = nullptr;
+ raw_ptr<MemoryTransferService> mMemoryTransferService = nullptr;
std::shared_ptr<bool> mIsAlive;
};
diff --git a/src/dawn/wire/server/ServerMemoryTransferService_mock.h b/src/dawn/wire/server/ServerMemoryTransferService_mock.h
index 1519347..e96b64b 100644
--- a/src/dawn/wire/server/ServerMemoryTransferService_mock.h
+++ b/src/dawn/wire/server/ServerMemoryTransferService_mock.h
@@ -32,6 +32,7 @@
#include "dawn/wire/WireServer.h"
#include "dawn/wire/server/Server.h"
+#include "partition_alloc/pointers/raw_ptr.h"
namespace dawn::wire::server {
@@ -49,7 +50,7 @@
void* serializePointer) override;
private:
- MockMemoryTransferService* mService;
+ raw_ptr<MockMemoryTransferService> mService;
};
class MockWriteHandle : public WriteHandle {
@@ -65,7 +66,7 @@
const uint32_t* GetData() const;
private:
- MockMemoryTransferService* mService;
+ raw_ptr<MockMemoryTransferService> mService;
};
MockMemoryTransferService();