Improve namespace handling in imports. (#4153)

This implements a few closely related features:

- Starts merging namespaces discovered inside imports.
- Stores results of cross-package name lookup as an entry inside the
scope.
  - Note this is particularly visible with `i32`.
- Moves more of the imported instructions to the import scope.

Note this is primarily for executing the namespace TODO in check.cpp,
which is removed here.
`testdata/namespace/merging_with_indirections.carbon` tests key
behavior.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Jon Ross-Perkins
2024-07-24 19:56:17 +00:00
committed by GitHub
co-authored by Richard Smith
parent 55f3f48707
commit 7ded56ef35
455 changed files with 9570 additions and 9238 deletions
-8
View File
@@ -303,14 +303,6 @@ static auto ImportOtherPackages(Context& context, UnitInfo& unit_info,
}
// Add imports to the root block.
// TODO: Should this be importing all namespaces before anything else, including
// for imports from other packages? Otherwise, name conflict resolution
// involving something such as `fn F() -> Other.NS.A`, wherein `Other.NS`
// hasn't been imported yet (before `Other.NS` had a constant assigned), could
// result in an inconsistent scoping for `Other.NS.A` versus if it were imported
// as part of scanning `Other.NS` (after `Other.NS` had a constant assigned).
// This will probably require IRs separating out which namespaces they
// declare (or declare entities inside).
static auto InitPackageScopeAndImports(Context& context, UnitInfo& unit_info,
int total_ir_count) -> void {
// First create the constant values map for all imported IRs. We'll populate