[LLVMdev] Requirements for the EH representation

Charllls Alquarra charlesneedspace at yahoo.com.ar
Thu May 5 22:50:11 PDT 2011


On Apr 13, 2011, at 21:43 CDT, John McCall wrote: 

> And it's okay to have limited goals!   I personally don't;  I think we
> should aim to get the IR design good enough to support crazy resumptive
> languages with crazy custom unwinding schemes.  But I need to know what
> range of problems we're willing to consider solving before I can usefully
> weigh different solutions.

I will dare a comment on this topic well over my head, so my answer will probably only reflect my ignorance on the deepness of the subject, however, in any case i hope to get some clarification of my concepts

let me say more before i go into the idea on this post: I've used coroutines a lot in my c++ programming, and certainly when you work a lot of time with a hammer, everything starts looking like a nail.

However, it has always seemed to me that exception handling (at least on c++) is just a particular syntax of a subset of coroutine semantics:

void f() { throw 1; }
void h();

void g() {
 try {
   f();
 } catch (...) {
   h();
 }
}

assumming a hypothetical Coroutine object that supports manual cleanup of the stack allocated objects, the code above is semantically equivalent to:

struct CoroutineStack {
 Coroutine* context;
 CoroutineStack* next;
}
Coroutine* currentContext;
CoroutineStack * nextCatchContextLink;
void f () { currentContext->yieldTo( nextCatchContextLink->context ); }
void h();

void g() {
  Coroutine tryContext( [&] => { f(); } );
  Coroutine catchContext( [&] => { h(); } );
  //define a new link to store current catch context
  // which points to outer stack contexts in this same stack
 CoroutineStack catchContextLink;
  catchContextLink.context = &catchContext;
  catchContextLink.next = nextCatchContextLink;
  nextCatchContextLink = & catchContextLink; 
  tryContext();     
}

in the case a rethrow happens in the catch context, the code in the catch needs to change slightly;  

 Coroutine catchContext( [&] => { h(); nextCatchContextLink = nextCatchContextLink ->next; } );


I don't know much about DWARF and other EH schemes, and i really can't say what can do a personality or a landing pad that you can't express with coroutine semantics, so forgive me if the above makes large oversights orits just Plain Silly.

does this make sense?





More information about the llvm-dev mailing list