branch: imports
Should just be able to be a HIR Pass
. Has to occur before typechecking though.
The question is whether to make this actually use ML-y modules that turn into struct definitions, or whether we want packages to just be namespaces. I'm leaning towards the latter: if we make them Real Modules then we need to a) make structs able to contain types, and b) make it so that
import foo
actually instantiates foo and any generic type params it may need. That's pretty heckin' wonky, so I think we should make this feature strictly stay related to namespaces, since that's honestly what everyone wants it to be. I've never experienced anyone who actually seriously said "I wishimport foo from bar
involved type metaprogramming". We know a lot more about code reuse now than we did in the 1980's.I'm calling our namespaces "packages" for the moment, because "namespaces" is too long and "modules" is overloaded. See https://todo.sr.ht/~icefox/garnet/46 .
Currently this has zero relation to separate compilation. All imports are mooshed together into a single big whack of IR and compiled all at once, the same way Rust compiles individual crates. This is not really how I want things to work in the end, but is ok for now.
The
imports
branch has a fairly lame minimal implementation of this, commit8ecded7551ff
. It just mooshes all imported modules together and turns all global names into fully-qualified ones. What it does not do is actually go through the actual code and turn all local names into fully-qualified ones, or have any actually good name mangling (just uses_
as a package separator). But improving it would involve either duplicating or refactoring the name-resolution and predecl pass already part oftypeck.rs
, and I don't feel like that right now, so here we are.Something this branch does reveal is that we want an
Ir
to contain the package name and file name, which is useful for diagnostics anyway. So that settles that at least.