Add imports of enclosing scopes. (#3575)

Namespaces are copied, which means also adding their name to the
underlying instruction. It happened not to be done previously; the name
was only in name lookup.

Since the only import supported right now is the default import,
functionality is limited; in the future I'll need to deal with namespace
vs package conflicts.

Tests of namespace imports are under "namespace" -- I figured this would
be best for scaling as more instructions get support.

This also improves some debugging-related output that I was trying to
use while trying to build the support.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
Jon Ross-Perkins
2024-01-10 17:36:50 +00:00
committed by GitHub
co-authored by Richard Smith
parent 848d4d7ec0
commit cad4605dad
309 changed files with 965 additions and 453 deletions
+3 -3
View File
@@ -25,10 +25,10 @@ auto HandleAnyBindingPattern(Context& context, Parse::NodeId parse_node,
auto make_bind_name = [&, name_node = name_node, name_id = name_id](
SemIR::TypeId type_id,
SemIR::InstId value_id) -> SemIR::Inst {
// TODO: Set the correct enclosing_scope_id.
// TODO: Eventually the name will need to support associations with other
// scopes, but right now we don't support qualified names here.
auto bind_name_id = context.bind_names().Add(
{.name_id = name_id,
.enclosing_scope_id = SemIR::NameScopeId::Invalid});
{.name_id = name_id, .enclosing_scope_id = context.current_scope_id()});
if (is_generic) {
// TODO: Create a `BindTemplateName` instead inside a `template` pattern.
return SemIR::BindSymbolicName{name_node, type_id, bind_name_id,