Annotations for actors to ease debugging #59

Neverlord opened this Issue Aug 17, 2012 · 1 comment

1 participant

CAF: C++ Actor Framework member

Right now, an actor always accepts all kinds of messages, even if its behavior is defined only for a few cases. Encoding the list of accepted messages in an actors type is not feasible, since objects are guarded by actor_ptr, which in fact uses type erasure. However, a type annotation still can be very useful. If compiled in debug mode, the actor can check each incoming message at runtime.

Annotations might look like the following example.

class foobar : public annotated_actor<event_based_actor,
                                      type_list<atom_value, int>,
                                      type_list<atom_value, double, string> > {
    foobar() {
        annotation<0>().add_guard(_x1 == atom("foo"));
        annotation<1>().add_guard(_x1 == atom("bar"));
    // ...

// ...

auto x = spawn<foobar>();

In the example above, x would have an annotated actor_ptr which then could type check passed messages using send. However, the annotations are lost as soon as x is used in messages or passed wherever an ordinary actor_ptr is expected. Still, each bug found at compile time is a bug less at runtime.

The real feature, however, is the runtime check with optional guards. Each unsupported message will raise an exception or print a stack trace to give developers are clear hint that an actor has received a message it shouldn't.

CAF: C++ Actor Framework member

Type errors can be eliminated when using typed actors. So this idea isn't worthwhile any longer.

@Neverlord Neverlord closed this Dec 9, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment