Skip to content
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

Introduce move-inhibiting version of KJ_DISALLOW_COPY #236

Merged
merged 4 commits into from
Dec 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ rules_foreign_cc_dependencies()

http_archive(
name = "capnp-cpp",
sha256 = "523f41d27e7ae7aed2b176a63fc759a5dac095d93bf508d2d52ad4f75083d31b",
strip_prefix = "capnproto-capnproto-5dffa41/c++",
sha256 = "4a642173569caf4869150d6ec08e40644158b5148f485979bbf15244c4f09df2",
strip_prefix = "capnproto-capnproto-6a1dcb8/c++",
type = "tgz",
urls = ["https://github.com/capnproto/capnproto/tarball/5dffa41c2c63c7ce79a00059d5f93de5ca1eb4f0"],
urls = ["https://github.com/capnproto/capnproto/tarball/6a1dcb8e4b2864b95e4be43ed6314f5334d457fa"],
)

http_archive(
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/html-rewriter.c++
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public:
kj::ArrayPtr<const char> encoding,
kj::Own<WritableStreamSink> inner,
CompatibilityFlags::Reader featureFlags);
KJ_DISALLOW_COPY(Rewriter);
KJ_DISALLOW_COPY_AND_MOVE(Rewriter);

// WritableStreamSink implementation. The input body pumpTo() operation calls these.
kj::Promise<void> write(const void* buffer, size_t size) override;
Expand Down
4 changes: 2 additions & 2 deletions src/workerd/api/html-rewriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class HTMLRewriter: public jsg::Object {

explicit HTMLRewriter();
~HTMLRewriter() noexcept(false);
KJ_DISALLOW_COPY(HTMLRewriter);
KJ_DISALLOW_COPY_AND_MOVE(HTMLRewriter);

static jsg::Ref<HTMLRewriter> constructor();

Expand Down Expand Up @@ -230,7 +230,7 @@ class Element final: public HTMLRewriter::Token {
private:
struct Impl {
Impl(CType& element, Rewriter&);
KJ_DISALLOW_COPY(Impl);
KJ_DISALLOW_COPY_AND_MOVE(Impl);
~Impl() noexcept(false);

CType& element;
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/api/streams/compression.c++
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public:
}
}

KJ_DISALLOW_COPY(Context);
KJ_DISALLOW_COPY_AND_MOVE(Context);

void setInput(const void* in, size_t size) {
ctx.next_in = const_cast<byte*>(reinterpret_cast<const byte*>(in));
Expand Down
4 changes: 1 addition & 3 deletions src/workerd/api/streams/internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,7 @@ class ReadableStreamInternalController: public ReadableStreamController {
explicit ReadableStreamInternalController(Readable readable)
: state(kj::mv(readable)) {}

KJ_DISALLOW_COPY(ReadableStreamInternalController);
ReadableStreamInternalController(ReadableStreamInternalController&& other) = delete;
ReadableStreamInternalController& operator=(ReadableStreamInternalController&& other) = delete;
KJ_DISALLOW_COPY_AND_MOVE(ReadableStreamInternalController);

~ReadableStreamInternalController() noexcept(false) override;

Expand Down
6 changes: 2 additions & 4 deletions src/workerd/api/streams/queue.h
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ class ConsumerImpl final {
~UpdateBackpressureScope() noexcept(false) {
queue.maybeUpdateBackpressure();
}
KJ_DISALLOW_COPY(UpdateBackpressureScope);
KJ_DISALLOW_COPY_AND_MOVE(UpdateBackpressureScope);
};

using ReadRequest = typename Self::ReadRequest;
Expand Down Expand Up @@ -763,9 +763,7 @@ class ByteQueue final {
consumer(consumer),
queue(queue) {}

KJ_DISALLOW_COPY(ByobRequest);
ByobRequest(ByobRequest&&) = delete;
ByobRequest& operator=(ByobRequest&&) = delete;
KJ_DISALLOW_COPY_AND_MOVE(ByobRequest);

~ByobRequest() noexcept(false);

Expand Down
4 changes: 2 additions & 2 deletions src/workerd/api/streams/standard.c++
Original file line number Diff line number Diff line change
Expand Up @@ -1156,7 +1156,7 @@ struct ValueReadable final: public api::ValueQueue::ConsumerImpl::StateListener,
ValueReadable(jsg::Lock& js, auto owner, ValueReadable& other)
: state(KJ_ASSERT_NONNULL(other.state).cloneWithNewOwner(js, owner, this)) {}

KJ_DISALLOW_COPY(ValueReadable);
KJ_DISALLOW_COPY_AND_MOVE(ValueReadable);

void visitForGc(jsg::GcVisitor& visitor) {
visitor.visit(state);
Expand Down Expand Up @@ -1264,7 +1264,7 @@ struct ByteReadable final: public api::ByteQueue::ConsumerImpl::StateListener,
: state(KJ_ASSERT_NONNULL(other.state).cloneWithNewOwner(js, owner, this)),
autoAllocateChunkSize(other.autoAllocateChunkSize) {}

KJ_DISALLOW_COPY(ByteReadable);
KJ_DISALLOW_COPY_AND_MOVE(ByteReadable);

void visitForGc(jsg::GcVisitor& visitor) {
visitor.visit(state);
Expand Down
4 changes: 1 addition & 3 deletions src/workerd/api/streams/standard.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,9 +749,7 @@ class ReadableStreamBYOBRequest: public jsg::Object {
kj::Own<ByteQueue::ByobRequest> readRequest,
jsg::Ref<ReadableByteStreamController> controller);

KJ_DISALLOW_COPY(ReadableStreamBYOBRequest);
ReadableStreamBYOBRequest(ReadableStreamBYOBRequest&&) = delete;
ReadableStreamBYOBRequest& operator=(ReadableStreamBYOBRequest&&) = delete;
KJ_DISALLOW_COPY_AND_MOVE(ReadableStreamBYOBRequest);

kj::Maybe<int> getAtLeast();
// getAtLeast is a non-standard Workers-specific extension that specifies
Expand Down
6 changes: 3 additions & 3 deletions src/workerd/io/actor-cache.h
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ class ActorCache final: public ActorCacheInterface {
// constructor.

~Entry() noexcept(false);
KJ_DISALLOW_COPY(Entry);
KJ_DISALLOW_COPY_AND_MOVE(Entry);

kj::Maybe<ActorCache&> cache;
const Key key;
Expand Down Expand Up @@ -489,7 +489,7 @@ class ActorCache final: public ActorCacheInterface {
kj::Maybe<kj::Own<kj::PromiseFulfiller<void>>> fulfiller;
ReadCompletionChain() = default;
~ReadCompletionChain() noexcept(false);
KJ_DISALLOW_COPY(ReadCompletionChain);
KJ_DISALLOW_COPY_AND_MOVE(ReadCompletionChain);
};
kj::Own<ReadCompletionChain> readCompletionChain = kj::refcounted<ReadCompletionChain>();
// Used to implement waitForPastReads(). See that function to understand how it works...
Expand Down Expand Up @@ -736,7 +736,7 @@ class ActorCache::SharedLru {
explicit SharedLru(Options options);

~SharedLru() noexcept(false);
KJ_DISALLOW_COPY(SharedLru);
KJ_DISALLOW_COPY_AND_MOVE(SharedLru);

size_t currentSize() const { return size.load(std::memory_order_relaxed); }
// Mostly for testing.
Expand Down
6 changes: 2 additions & 4 deletions src/workerd/io/io-context.c++
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,7 @@ public:
using Iterator = Map::iterator;

TimeoutManagerImpl() = default;
KJ_DISALLOW_COPY(TimeoutManagerImpl);
TimeoutManagerImpl(TimeoutManagerImpl&&) = delete;
TimeoutManagerImpl& operator=(TimeoutManagerImpl&&) = delete;
KJ_DISALLOW_COPY_AND_MOVE(TimeoutManagerImpl);

TimeoutId setTimeout(
IoContext& context, TimeoutId::Generator& generator, TimeoutParameters params) override {
Expand Down Expand Up @@ -518,7 +516,7 @@ class IoContext::PendingEvent: public kj::Refcounted {
public:
explicit PendingEvent(IoContext& context): context(context) {}
~PendingEvent() noexcept(false);
KJ_DISALLOW_COPY(PendingEvent);
KJ_DISALLOW_COPY_AND_MOVE(PendingEvent);

IoContext& context;
};
Expand Down
8 changes: 4 additions & 4 deletions src/workerd/io/io-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ class IoContext_IncomingRequest {
kj::Own<IoChannelFactory> ioChannelFactory,
kj::Own<RequestObserver> metrics,
kj::Maybe<kj::Own<WorkerTracer>> workerTracer);
KJ_DISALLOW_COPY(IoContext_IncomingRequest);
KJ_DISALLOW_COPY_AND_MOVE(IoContext_IncomingRequest);
~IoContext_IncomingRequest() noexcept(false);

IoContext& getContext() { return *context; }
Expand Down Expand Up @@ -608,7 +608,7 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler

public:

KJ_DISALLOW_COPY(Finalizeable);
KJ_DISALLOW_COPY_AND_MOVE(Finalizeable);

#ifdef KJ_DEBUG
Finalizeable();
Expand Down Expand Up @@ -866,7 +866,7 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
class OwnedObjectList {
public:
OwnedObjectList() = default;
KJ_DISALLOW_COPY(OwnedObjectList);
KJ_DISALLOW_COPY_AND_MOVE(OwnedObjectList);
~OwnedObjectList() noexcept(false);

void link(kj::Own<OwnedObject> object);
Expand Down Expand Up @@ -918,7 +918,7 @@ class IoContext final: public kj::Refcounted, private kj::TaskSet::ErrorHandler
public:
DeleteQueuePtr(kj::Own<DeleteQueue> value)
: kj::Own<DeleteQueue>(kj::mv(value)) {}
KJ_DISALLOW_COPY(DeleteQueuePtr);
KJ_DISALLOW_COPY_AND_MOVE(DeleteQueuePtr);
~DeleteQueuePtr() noexcept(false) {
auto ptr = get();
if (ptr != nullptr) {
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/io/observer.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class IsolateObserver: public kj::AtomicRefcounted {
~LockRecord() noexcept(false) {
KJ_IF_MAYBE(l, lockTiming) l->get()->stop();
}
KJ_DISALLOW_COPY(LockRecord);
KJ_DISALLOW_COPY_AND_MOVE(LockRecord);

void locked() { KJ_IF_MAYBE(l, lockTiming) l->get()->locked(); }
void gcPrologue() { KJ_IF_MAYBE(l, lockTiming) l->get()->gcPrologue(); }
Expand Down
8 changes: 4 additions & 4 deletions src/workerd/io/trace.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Trace final : public kj::Refcounted {
explicit Trace(kj::Maybe<kj::String> stableId, kj::Maybe<kj::String> scriptName, kj::Maybe<kj::String> dispatchNamespace, kj::Array<kj::String> scriptTags);
Trace(rpc::Trace::Reader reader);
~Trace() noexcept(false);
KJ_DISALLOW_COPY(Trace);
KJ_DISALLOW_COPY_AND_MOVE(Trace);

class FetchEventInfo {
public:
Expand Down Expand Up @@ -263,7 +263,7 @@ class Tracer final : public kj::Refcounted {
explicit Tracer(kj::EntropySource& entropySource,
kj::Maybe<kj::Own<Tracer>> parent, kj::Maybe<Jaeger::SpanContext> parentSpanContext,
kj::Maybe<JaegerSpanSubmitter&> jaegerSpanSubmitter, kj::Own<void> ownJaegerSpanSubmitter);
KJ_DISALLOW_COPY(Tracer);
KJ_DISALLOW_COPY_AND_MOVE(Tracer);

kj::Own<Tracer> makeSubtracer(kj::Maybe<Jaeger::SpanContext> overrideParent);

Expand Down Expand Up @@ -433,7 +433,7 @@ class PipelineTracer final : public kj::Refcounted {
// Creates a pipeline tracer (with a possible parent).

~PipelineTracer() noexcept(false);
KJ_DISALLOW_COPY(PipelineTracer);
KJ_DISALLOW_COPY_AND_MOVE(PipelineTracer);

kj::Promise<kj::Array<kj::Own<Trace>>> onComplete();
// Returns a promise that fulfills when traces are complete. Only one such promise can
Expand Down Expand Up @@ -470,7 +470,7 @@ class WorkerTracer final : public kj::Refcounted {
explicit WorkerTracer(kj::Own<PipelineTracer> parentPipeline,
kj::Own<Trace> trace, PipelineLogLevel pipelineLogLevel);
explicit WorkerTracer(PipelineLogLevel pipelineLogLevel);
KJ_DISALLOW_COPY(WorkerTracer);
KJ_DISALLOW_COPY_AND_MOVE(WorkerTracer);

void log(kj::Date timestamp, LogLevel logLevel, kj::String message);
// Adds log line to trace. For Spectre, timestamp should only be as accurate as JS Date.now().
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/io/worker-entrypoint.c++
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class WorkerEntrypoint::ResponseSentTracker final: public kj::HttpService::Respo
public:
ResponseSentTracker(kj::HttpService::Response& inner)
: inner(inner) {}
KJ_DISALLOW_COPY(ResponseSentTracker);
KJ_DISALLOW_COPY_AND_MOVE(ResponseSentTracker);

bool isSent() const { return sent; }

Expand Down
6 changes: 3 additions & 3 deletions src/workerd/io/worker.c++
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ struct Worker::Isolate::Impl {
}
impl.currentLock = nullptr;
}
KJ_DISALLOW_COPY(Lock);
KJ_DISALLOW_COPY_AND_MOVE(Lock);

void setupContext(v8::Local<v8::Context> context) {
// Set WebAssembly.Module @@HasInstance
Expand Down Expand Up @@ -1912,7 +1912,7 @@ public:
}
}

KJ_DISALLOW_COPY(LimitedBodyWrapper);
KJ_DISALLOW_COPY_AND_MOVE(LimitedBodyWrapper);

void reset() {
this->inner = nullptr;
Expand Down Expand Up @@ -2313,7 +2313,7 @@ private:
session = nullptr;
}

KJ_DISALLOW_COPY(State);
KJ_DISALLOW_COPY_AND_MOVE(State);
};
kj::MutexGuarded<kj::Own<State>> state;
// Mutex ordering: You must lock this *before* locking the isolate.
Expand Down
14 changes: 7 additions & 7 deletions src/workerd/io/worker.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class Worker: public kj::AtomicRefcounted {
// properties to `target`.

~Worker() noexcept(false);
KJ_DISALLOW_COPY(Worker);
KJ_DISALLOW_COPY_AND_MOVE(Worker);

const Script& getScript() const { return *script; }
const Isolate& getIsolate() const;
Expand Down Expand Up @@ -142,7 +142,7 @@ class Worker: public kj::AtomicRefcounted {
~TeardownFinishedGuard() noexcept(false) {
ref.teardownFinished();
}
KJ_DISALLOW_COPY(TeardownFinishedGuard);
KJ_DISALLOW_COPY_AND_MOVE(TeardownFinishedGuard);

private:
Observer& ref;
Expand All @@ -169,7 +169,7 @@ class Worker::Script: public kj::AtomicRefcounted {

public:
~Script() noexcept(false);
KJ_DISALLOW_COPY(Script);
KJ_DISALLOW_COPY_AND_MOVE(Script);

inline kj::StringPtr getId() const { return id; }
const Isolate& getIsolate() const { return *isolate; }
Expand Down Expand Up @@ -243,7 +243,7 @@ class Worker::Isolate: public kj::AtomicRefcounted {
// inspector session to stay open across them).

~Isolate() noexcept(false);
KJ_DISALLOW_COPY(Isolate);
KJ_DISALLOW_COPY_AND_MOVE(Isolate);

const IsolateObserver& getMetrics() const { return *metrics; }

Expand Down Expand Up @@ -407,7 +407,7 @@ class Worker::Isolate: public kj::AtomicRefcounted {
: constIsolate(kj::mv(isolate)), inner(kj::mv(inner)),
contentEncodingHeaderId(contentEncodingHeaderId),
requestMetrics(kj::addRef(requestMetrics)) {}
KJ_DISALLOW_COPY(SubrequestClient);
KJ_DISALLOW_COPY_AND_MOVE(SubrequestClient);
kj::Promise<void> request(
kj::HttpMethod method, kj::StringPtr url, const kj::HttpHeaders& headers,
kj::AsyncInputStream& requestBody, kj::HttpService::Response& response) override;
Expand Down Expand Up @@ -524,7 +524,7 @@ class Worker::Lock {
};

explicit Lock(const Worker& worker, LockType lockType);
KJ_DISALLOW_COPY(Lock);
KJ_DISALLOW_COPY_AND_MOVE(Lock);
~Lock() noexcept(false);

void requireNoPermanentException();
Expand Down Expand Up @@ -720,7 +720,7 @@ class Worker::AsyncWaiter: public kj::Refcounted {
public:
AsyncWaiter(kj::Own<const Isolate> isolate);
~AsyncWaiter() noexcept;
KJ_DISALLOW_COPY(AsyncWaiter);
KJ_DISALLOW_COPY_AND_MOVE(AsyncWaiter);

private:
const kj::Executor& executor;
Expand Down
6 changes: 2 additions & 4 deletions src/workerd/jsg/jsg.h
Original file line number Diff line number Diff line change
Expand Up @@ -1031,9 +1031,7 @@ class Object: private Wrappable {
// Objects that extend from jsg::Object should never be copied or moved
// independently of their owning jsg::Ref so we explicitly delete the
// copy and move constructors and assignment operators to be safe.
KJ_DISALLOW_COPY(Object);
Object(Object&&) = delete;
Object& operator=(Object&&) = delete;
KJ_DISALLOW_COPY_AND_MOVE(Object);

// Since we explicitly delete the copy and move constructors, we have
// to explicitly declare the default constructor.
Expand Down Expand Up @@ -1555,7 +1553,7 @@ class GcVisitor {

explicit GcVisitor(Wrappable& parent, kj::Maybe<cppgc::Visitor&> cppgcVisitor)
: parent(parent), cppgcVisitor(cppgcVisitor) {}
KJ_DISALLOW_COPY(GcVisitor);
KJ_DISALLOW_COPY_AND_MOVE(GcVisitor);

friend class Wrappable;
friend class Object;
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/jsg/setup.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class IsolateBase {

explicit IsolateBase(const V8System& system, v8::Isolate::CreateParams&& createParams);
~IsolateBase() noexcept(false);
KJ_DISALLOW_COPY(IsolateBase);
KJ_DISALLOW_COPY_AND_MOVE(IsolateBase);

void dropWrappers(kj::Own<void> typeWrapperInstance);

Expand Down
2 changes: 1 addition & 1 deletion src/workerd/jsg/type-wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ class TypeWrapper: public DynamicResourceTypeMap<Self>,
MaybeWrapper<Self>(configuration) {
isolate->SetData(1, this);
}
KJ_DISALLOW_COPY(TypeWrapper);
KJ_DISALLOW_COPY_AND_MOVE(TypeWrapper);

static TypeWrapper& from(v8::Isolate* isolate) {
return *reinterpret_cast<TypeWrapper*>(isolate->GetData(1));
Expand Down
2 changes: 1 addition & 1 deletion src/workerd/util/batch-queue-test.c++
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ KJ_TEST("BatchQueue::Batch clears the pop buffer when it is destroyed") {
struct DestructionDetector {
DestructionDetector(uint& count): count(count) {}
~DestructionDetector() noexcept(false) { ++count; }
KJ_DISALLOW_COPY(DestructionDetector);
KJ_DISALLOW_COPY_AND_MOVE(DestructionDetector);
uint& count;
};

Expand Down
2 changes: 1 addition & 1 deletion src/workerd/util/canceler.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class RefcountedCanceler: public kj::Refcounted {
canceler.release();
}

KJ_DISALLOW_COPY(RefcountedCanceler);
KJ_DISALLOW_COPY_AND_MOVE(RefcountedCanceler);

template <typename T>
kj::Promise<T> wrap(kj::Promise<T> promise) {
Expand Down
Loading