On Tue, Mar 15, 2011 at 2:17 PM, Rafael Avila de Espindola <[email protected]> wrote: > Sorry for bringing even harder questions, but this also got me thinking > about one of the nice features of C/C++: the ability to represent not only > cycles, but arbitrary memory layout. Is there a plan to implement something > similar in rust?
There's no reason arbitrary memory layout can't be done safely -- not to toot my own group's horn here, but Habit[0][1][2] has features to look at if you're interested in that. > > For example, if I implement a JS interpreter or JIT in C/C++, I can give its > data structures any layout that is appropriate for the JS implementation. > If, for example, a garbage collector is used for the JS objects they don't > need a reference count, but I can still get a pointer to it from the C++ > code. > > I am sure this is not safe in general, but it would be sad to have to go > back to C/C++ for any unsafe operation. > > An example that is probably closer to the issues we will have after > bootstrap: can rust's garbage collector be written in rust? > In general, you can't implement a garbage collector in a typed language, because re-using memory for a value of a different type is inherently unsafe. There are fancy type systems that can get around that, but probably nothing that's likely to be in Rust... unless the typestate system could be used for that? [0] http://hasp.cs.pdx.edu/habit-report-Nov2010.pdf [1] Iavor Diatchki and Mark Jones, "Strongly Typed Memory Areas: Programming Systems-Level Data Structures in a Functional Language" http://web.cecs.pdx.edu/~mpj/pubs/bytedata.html [2] Iavor Diatchki, Mark Jones, and Rebekah Leslie, "High-level Views on Low-level Representations" http://web.cecs.pdx.edu/~mpj/pubs/bitdata.html Cheers, Tim -- Tim Chevalier * http://cs.pdx.edu/~tjc/ * Often in error, never in doubt "an intelligent person fights for lost causes,realizing that others are merely effects" -- E.E. Cummings _______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
