gleam icon indicating copy to clipboard operation
gleam copied to clipboard

Use memory arena for types when type checking

Open lpil opened this issue 1 year ago • 3 comments

Currently, we represent types using a nested tree structure in which nodes are reference counted. This is at times awkward to work with, not particularly well-suited to a multithreaded compilation, and potentially slower than using an arena due to the overhead of reference, counting and memory fragmentation. Use an id based memory arena instead.

It is only during type interference and checking that we need to mutate types and to have the various different kinds of type variables, so for all other parts of the compiler, we can have a different, simpler data structure with which to represent types. Related to https://github.com/gleam-lang/gleam/issues/865

lpil avatar Jun 29 '23 15:06 lpil

I'm working on it rn. Unfortunately, there are a lot of uses of Arc<Type> in the compiler's source code, so keeping up with updates on the main branch will be hard, but I will try.

abs0luty avatar Dec 04 '23 10:12 abs0luty

Thank you! I expect the main branch will be pretty quiet for a while as I'm focusing on documentation, so now is a good time.

Note one thing we'd like to do is be able to use multiple threads, so an arena where the storage can be sent to another thread such as id arena would be best.

lpil avatar Dec 04 '23 13:12 lpil

@lpil I use id_arena crate as for memory arena for patterns in exhaustive type checking, so should be fine.

abs0luty avatar Dec 04 '23 16:12 abs0luty