fmease / lushui

The reference compiler of the Lushui programming language
Apache License 2.0
7 stars 0 forks source link

Restructure the HIR to use indices for nested declarations #44

Open fmease opened 4 years ago

fmease commented 4 years ago

Instead of having hir::Declarations inside hir::{Module, Data}, use HIRIndex/HIRIdentifier and store all declarations linearly in CrateScope. This would make iterating over declarations easier. We can and should then also store the parent for each declaration. This would get rid of our Index/Environment "hack" in the typer (and resolver(?)) we currently require in some cases for handling constructors and need some data from the parent data declaration — in the new system, we can simply look up the parent by HIRIndex (plus some "downcasting"). Maybe this would also allow us to throw out the typer::Registration system by just having a list of those indices. I don't know.

This might also help finding unused declarations, implementing privacy and printing relative paths but maybe it does not but only if we also do this change to lowered_ast::Declaration b.c. the resolver needs it. I dunno.