News for hackers. Stuff that matters.
Re:Flattening ASTs (and Other Compiler Data Structures) by chubot on Sunday July 02, 2023 @11:36AM (#36562435)
Yes totally, I keep seeing people mention these arena / flattened tree and graph structures, without mentioning memory safety.

And also weird claims that arenas solve memory safety problems in C, when it's equally likely (depending on the program) that they CAUSE dangling pointers, use-after-free, etc.

The same issue comes up in slightly different ways in both C/C++ and Rust

---

My comment on this post from 2 months ago:

https://old.reddit.com/r/ProgrammingLanguages/comments/1350d...

Summary: the upsides are very real, but we should mention the downsides too:

- Arenas punt on memory safety; Ownership can be nontrivial (a bunch of examples)

- Mutation, and appending to list/vectors are complications

- Pointer representations are more friendly to debuggers

My wiki page is linked at the bottom of this article (which I appreciate because it actually has code and measurements!)

https://github.com/oilshell/oil/wiki/Compact-AST-Representat...

Re:Flattening ASTs (and Other Compiler Data Structures) by kazinator on Sunday July 02, 2023 @12:36PM (#36563078)
* * *
Re:Flattening ASTs (and Other Compiler Data Structures) by chubot on Monday July 03, 2023 @12:28PM (#36575259)
Yes, I mentioned the same issue a few days ago -- arenas break ASAN/Valgrind, and those are the BEST tools to ensure memory safety:

https://news.ycombinator.com/item?id=36427264

In response to a claim about arena-based allocators and memory safety

Re:Flattening ASTs (and Other Compiler Data Structures) by kazinator on Monday July 03, 2023 @01:19PM (#36576063)
Maybe Valgrind has an API now to attach a backtrace to a custom allocation out of an arena. I haven't touched that in years. I did the initial Valgrind integration in 2009 and just maintained it with changes to the gc.

I see this in the current manual:

VALGRIND_MALLOCLIKE_BLOCK:

If your program manages its own memory instead of using the standard malloc / new / new[], tools that track information about heap blocks will not do nearly as good a job. For example, Memcheck won't detect nearly as many errors, and the error messages won't be as informative. To improve this situation, use this macro just after your custom allocator allocates some new memory. See the comments in valgrind.h for information on how to use it.

I can't remember whether I saw this before; i.e. is this something existing that had not been useful, or is it something new. I will look into it.

It does look like it should be attacking the same problem: that the errors aren't detected well or nearly as informative in blocks carved out of larger block by custom allocators.

Re:Flattening ASTs (and Other Compiler Data Structures) by kazinator on Tuesday July 04, 2023 @07:37PM (#36593864)
* * *