Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I'll contribute another solution, used in the Go compiler: build a big map from AST node -> typeinfo. This approach is very flexible (e.g. you can add more maps later without changing the AST struct), but, like Nullable, it's not correct-by-construction -- and worse, you "just have to know" that this map exists and how to access/update it. Seems to be working ok for them, though!


This is also the natural solution when you're using Datalog to compute with the AST: Datalog operates on relations/tables, so associating types to AST nodes can be accomplished using a table with two columns: One for the ID representing an AST node, and one for the type associated to the AST node. I've recently written about this approach in the series starting here: https://www.mbid.me/posts/type-checking-with-eqlog-parsing/


Yeah this is what MyPy does internally too

You just have a big dict of types, which are keyed by the AST node

It seemed a bit weird to me, but certainly works. I guess I usually use dicts that are keyed by value and not by address of the instance




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: