On Wed, 09 Oct 2013 22:30:05 +0200, Adam D. Ruppe wrote: > On Wednesday, 9 October 2013 at 20:10:40 UTC, Justin Whear wrote: >> Related to the latter, it would be really nice to be able to prove that >> a section of code makes no heap allocations/GC collections. > > As a quick temporary thing, how about gc_throw_on_next(); ? > > That'd just set a thread local flag that gc_malloc checks and if it is > set, immediately resets it and throws an AllocAssertError. My thought is > this could be quickly and easily implemented pending a better solution > and in the mean time can be used in unit tests to help check this stuff.
So user-code would look like this? // Set up code, GC is fine here ... // Entering critical loop (which may run for months at a time) debug GC.throw_on_next(true); while (true) { ... } // Tear-down code, GC is fine here // (though unnecessary as the process is about to exit) debug GC.throw_on_next(false); ... Something like this would make testing simpler and is probably much more feasible than deep static analysis.