Add support for 'package' in expressions. (#3445)

This creates a namespace for `package` scope.

It looks like names of class_decls in namespaces lead to an unexpected
instref. This is already true, as best as I can tell. I'm not sure if
there's a preferred approach to address that, so I've left a TODO for
now.
This commit is contained in:
Jon Ross-Perkins
2023-12-04 21:05:41 +00:00
committed by GitHub
parent 1c4a35c76b
commit 30155dbb72
262 changed files with 721 additions and 129 deletions
+12 -2
View File
@@ -13,6 +13,7 @@
#include "toolchain/parse/tree.h"
#include "toolchain/parse/tree_node_location_translator.h"
#include "toolchain/sem_ir/file.h"
#include "toolchain/sem_ir/typed_insts.h"
namespace Carbon::Check {
@@ -120,9 +121,18 @@ static auto CheckParseTree(const SemIR::File& builtin_ir, UnitInfo& unit_info,
PrettyStackTraceFunction context_dumper(
[&](llvm::raw_ostream& output) { context.PrintForStackDump(output); });
// Add a block for the Parse::Tree.
// Add a block for the file.
context.inst_block_stack().Push();
context.PushScope();
// Define the package scope, with an instruction for `package` expressions to
// reference.
auto package_scope = context.name_scopes().Add();
auto package_inst = context.AddInst(SemIR::Namespace{
Parse::NodeId::Invalid,
context.GetBuiltinType(SemIR::BuiltinKind::NamespaceType),
package_scope});
CARBON_CHECK(package_inst == SemIR::InstId::PackageNamespace);
context.PushScope(SemIR::InstId::Invalid, package_scope);
AddImports(context, unit_info);