Skip to content

Commit

Permalink
Introduce HeapSize()
Browse files Browse the repository at this point in the history
This PR adds the possibility to determine for a chain of
eventuals the maximum amount of heap memory that needs to
get allocated.
  • Loading branch information
ArthurBandaryk committed Aug 31, 2022
1 parent a4a3d01 commit a803f92
Show file tree
Hide file tree
Showing 43 changed files with 433 additions and 6 deletions.
5 changes: 5 additions & 0 deletions eventuals/catch.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "eventuals/terminal.h"
#include "eventuals/then.h"
#include "eventuals/type-traits.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -174,6 +175,10 @@ struct _Catch final {
// the handler.
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

std::tuple<CatchHandlers_...> catch_handlers_;

Interrupt* interrupt_ = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions eventuals/closure.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "eventuals/compose.h"
#include "eventuals/interrupt.h"
#include "eventuals/type-erased-stream.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -63,6 +64,10 @@ struct _Closure final {
return *continuation_;
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

F_ f_;

Interrupt* interrupt_ = nullptr;
Expand Down
9 changes: 9 additions & 0 deletions eventuals/concurrent-ordered.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "eventuals/map.h"
#include "eventuals/stream.h"
#include "eventuals/terminal.h"
#include "stout/bytes.h"

/////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -94,6 +95,10 @@ struct _ReorderAdaptor final {
upstream_->Done();
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

TypeErasedStream* upstream_ = nullptr;

std::map<int, std::deque<Value_>> buffer_;
Expand Down Expand Up @@ -208,6 +213,10 @@ struct _ConcurrentOrderedAdaptor final {
upstream_->Done();
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

bool ended_ = false;

std::optional<int> index_;
Expand Down
5 changes: 5 additions & 0 deletions eventuals/concurrent.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "eventuals/terminal.h"
#include "eventuals/then.h"
#include "eventuals/until.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -705,6 +706,10 @@ struct _Concurrent final {
handler_->Install();
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

Adaptor<F_, Arg_> adaptor_;

TypeErasedStream* stream_ = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions eventuals/conditional.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "eventuals/then.h" // For '_Then::Adaptor'.
#include "eventuals/type-traits.h" // For 'type_identity'.
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -78,6 +79,10 @@ struct _Conditional {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

Condition_ condition_;
Then_ then_;
Else_ else_;
Expand Down
5 changes: 5 additions & 0 deletions eventuals/do-all.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "eventuals/compose.h"
#include "eventuals/scheduler.h"
#include "eventuals/terminal.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -285,6 +286,10 @@ struct _DoAll final {
handler_->Install();
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

// NOTE: need to destruct the fibers LAST since they have a
// Scheduler::Context which may get borrowed in 'adaptor_' and
// it's continuations so those need to be destructed first.
Expand Down
5 changes: 5 additions & 0 deletions eventuals/eventual.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "eventuals/interrupt.h"
#include "eventuals/scheduler.h"
#include "eventuals/undefined.h"
#include "stout/bytes.h"

// TODO(benh): catch exceptions from 'start', 'fail', 'stop', etc.

Expand Down Expand Up @@ -170,6 +171,10 @@ struct _Eventual {
return adaptor_;
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

Context_ context_;
Start_ start_;
Fail_ fail_;
Expand Down
5 changes: 5 additions & 0 deletions eventuals/expected.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "eventuals/compose.h"
#include "eventuals/eventual.h"
#include "stout/bytes.h"
#include "tl/expected.hpp"

////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -102,6 +103,10 @@ class expected : public tl::expected<Value_, Error_> {
.template k<Value_>(std::move(k));
}

Bytes StaticHeapSize() {
return Bytes(0);
}

using tl::expected<Value_, Error_>::expected;

template <typename Downstream>
Expand Down
5 changes: 5 additions & 0 deletions eventuals/filter.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "eventuals/stream.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -46,6 +47,10 @@ struct _Filter final {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

F_ f_;

TypeErasedStream* stream_ = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions eventuals/finally.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "eventuals/expected.h"
#include "eventuals/terminal.h" // For 'StoppedException'.
#include "eventuals/then.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -41,6 +42,10 @@ struct _Finally final {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

K_ k_;
};

Expand Down
5 changes: 5 additions & 0 deletions eventuals/flat-map.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "eventuals/stream.h"
#include "eventuals/terminal.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -129,6 +130,10 @@ struct _FlatMap final {
});
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

F_ f_;

TypeErasedStream* outer_ = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions eventuals/head.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "eventuals/stream.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -45,6 +46,10 @@ struct _Head final {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

std::optional<Arg_> arg_;

TypeErasedStream* stream_ = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions eventuals/if.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "eventuals/eventual.h"
#include "eventuals/then.h" // For '_Then::Adaptor'.
#include "eventuals/type-traits.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -57,6 +58,10 @@ struct _If final {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

bool condition_;
YesE_ yes_;
NoE_ no_;
Expand Down
13 changes: 13 additions & 0 deletions eventuals/lock.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "eventuals/stream.h"
#include "eventuals/then.h"
#include "eventuals/undefined.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -456,6 +457,10 @@ struct _Acquire final {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

Lock* lock_;
Lock::Waiter waiter_;
std::optional<
Expand Down Expand Up @@ -548,6 +553,10 @@ struct _Release final {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

Lock* lock_;

// NOTE: we store 'k_' as the _last_ member so it will be
Expand Down Expand Up @@ -776,6 +785,10 @@ struct _Wait final {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

Lock* lock_;
F_ f_;

Expand Down
5 changes: 5 additions & 0 deletions eventuals/loop.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "eventuals/stream.h"
#include "eventuals/type-traits.h"
#include "eventuals/undefined.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -216,6 +217,10 @@ struct _Loop final {
return adaptor_;
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

Context_ context_;
Begin_ begin_;
Body_ body_;
Expand Down
5 changes: 5 additions & 0 deletions eventuals/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "eventuals/compose.h" // For 'HasValueFrom'.
#include "eventuals/stream.h"
#include "eventuals/then.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -78,6 +79,10 @@ struct _Map final {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

E_ e_;

using Adapted_ = decltype(std::declval<E_>().template k<Arg_>(
Expand Down
5 changes: 5 additions & 0 deletions eventuals/on-begin.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "eventuals/eventual.h"
#include "eventuals/stream.h"
#include "eventuals/then.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -89,6 +90,10 @@ struct _OnBegin final {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

E_ e_;

Interrupt* interrupt_ = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions eventuals/on-ended.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "eventuals/eventual.h"
#include "eventuals/stream.h"
#include "eventuals/then.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -92,6 +93,10 @@ struct _OnEnded final {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

E_ e_;

Interrupt* interrupt_ = nullptr;
Expand Down
5 changes: 5 additions & 0 deletions eventuals/raise.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "eventuals/interrupt.h"
#include "eventuals/type-traits.h"
#include "stout/bytes.h"

////////////////////////////////////////////////////////////////////////

Expand Down Expand Up @@ -36,6 +37,10 @@ struct _Raise final {
k_.Register(interrupt);
}

Bytes StaticHeapSize() {
return Bytes(0) + k_.StaticHeapSize();
}

T_ t_;

// NOTE: we store 'k_' as the _last_ member so it will be
Expand Down
Loading

0 comments on commit a803f92

Please sign in to comment.