~icefox/garnetc#13: 
Make imports work

branch: imports

Should just be able to be a HIR Pass. Has to occur before typechecking though.

Status
REPORTED
Submitter
~icefox
Assigned to
No-one
Submitted
1 year, 8 months ago
Updated
1 year, 7 months ago
Labels
T-TODO

~icefox 1 year, 7 months ago

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 wish import 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, commit 8ecded7551ff. 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 of typeck.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.

Register here or Log in to comment, or comment via email.