On Tue, Jul 30, 2013 at 2:56 PM, David Jeske <[email protected]> wrote:
> On Tue, Jul 30, 2013 at 2:30 PM, Jonathan S. Shapiro <[email protected]>wrote: > >> I think it's also useful to add a notion of region-based "borrowed" >> references. A borrowed reference is guaranteed not to be the last reference >> to an object. >> > > I don't understand what you mean here, can you clarify? > > Since I'm assuming GC is running on all regions at all times, all box > references are real and traced. Like in standard CLR, all ref (interior > pointers) are "borrowed" and rely on the guarantee that a specific pointer > to the box outlives the ref. > > Is that the "borrowed" what you're talking about above? > Almost. In the course of keyboarding a previous email, I realized that REF pointers actually want to have region annotations. This allows them to be used much more flexibly than strict FIFO order permits. The defining characteristic of a REF pointer is that it is guaranteed to go out of scope before its initializer goes out of scope. Proving that requirement is a regions problem that happens to be trivially satisfied by the FIFO rule, but that's not good enough (e.g.) to allow borrowed pointers to serve as return values. Most pointers residing in region j < k that name an object in region k are actually borrowed pointers. This can cease to be true if some root pointer in region k is overwritten such that the object is now referenced only from region j. Borrowed pointers therefore require a stronger check, but I think that augmenting them with region-based lifespans makes them more flexible. > > >> There are a bunch of cases where interior pointers cannot be returned >> safely unless you have a region-based type system. In languages that >> require memory safety, the usual workarounds are (1) return a dynamically >> allocated copy, or (b) add indirection in the original data type so that >> you can share substructure. >> > > I'll go read the Cyclone paper. In the meantime, how do regions help you > here? Because GC is running all the time, a region held on a higher > stack-frame does not make any guarantees about liveliness of a particular > box in the region. We have to put the specific box on the stack to borrow a > ref/interior pointer. > I'm doing this from memory, so I'll likely get it wrong, but... Consider strpos(), where you want to return an interior pointer to a C-style string. A region system lets you say that the liveness of the returned pointer has to match the liveness of the argument. Absent that, a memory-safe language is required to allocate a new string.
_______________________________________________ bitc-dev mailing list [email protected] http://www.coyotos.org/mailman/listinfo/bitc-dev
