Split Semantics into Check and SemIR namespaces (#3138)

Splits IR files into SemIR, and logic files into Check. These will be
split into separate directories as part of a later move; the namespaces
are being done first in order to vet the switch, and hopefully make
conflicts a little easier to manage due to the substantial renames.

A lot of this is just automated removal of Semantics prefixes from
names, adding namespace references where needed. A few special-cases
are:

- SemanticsIR -> SemIR::File
- A few things were discussed, like Unit, CompileUnit, or CompiledUnit.
Unit was too vague for chandlerc, and I thought CompileUnit might lead
to incorrect inferences (CompilationUnit would be more precise, but
typically written as SemIR::CompilationUnit which is pretty long). File
seemed to be a short name that we could agree on.
- SemanticsIRFormatter -> SemIR::Formatter
- FormatSemanticsIR -> SemIR::FormatFile
- SemanticsFileTest -> CheckFileTest
- It remains in the Testing namespace, where just "FileTest" might be
too broad a name.
- SemanticsDeclarationNameStack::Context ->
Check::DeclarationNameStack::NameContext
  - This avoids a Check::Context name shadowing.

Changes check_internal.h to include ostream.h to improve finding of
Print/operator<< (otherwise it didn't compile).

This is part of #3070
This commit is contained in:
Jon Ross-Perkins
2023-08-23 22:51:23 +00:00
committed by GitHub
parent b2db2ca7cf
commit 67da700dd5
53 changed files with 1337 additions and 1466 deletions
@@ -5,10 +5,10 @@
#include "toolchain/semantics/semantics_context.h"
#include "toolchain/semantics/semantics_node.h"
namespace Carbon {
namespace Carbon::Check {
auto SemanticsHandleCallExpression(SemanticsContext& context,
ParseTree::Node parse_node) -> bool {
auto HandleCallExpression(Context& context, ParseTree::Node parse_node)
-> bool {
auto refs_id = context.ParamOrArgEnd(
/*for_args=*/true, ParseNodeKind::CallExpressionStart);
@@ -17,7 +17,7 @@ auto SemanticsHandleCallExpression(SemanticsContext& context,
context.node_stack()
.PopWithParseNode<ParseNodeKind::CallExpressionStart>();
auto name_node = context.semantics_ir().GetNode(name_id);
if (name_node.kind() != SemanticsNodeKind::FunctionDeclaration) {
if (name_node.kind() != SemIR::NodeKind::FunctionDeclaration) {
// TODO: Work on error.
context.TODO(parse_node, "Not a callable name");
context.node_stack().Push(parse_node, name_id);
@@ -33,7 +33,7 @@ auto SemanticsHandleCallExpression(SemanticsContext& context,
if (!context.ImplicitAsForArgs(refs_id, name_node.parse_node(),
callable.param_refs_id, &diagnostic)) {
diagnostic.Emit();
context.node_stack().Push(parse_node, SemanticsNodeId::BuiltinError);
context.node_stack().Push(parse_node, SemIR::NodeId::BuiltinError);
return true;
}
@@ -42,32 +42,31 @@ auto SemanticsHandleCallExpression(SemanticsContext& context,
/*diagnostic=*/nullptr));
// TODO: Propagate return types from callable.
SemanticsTypeId type_id = callable.return_type_id;
SemIR::TypeId type_id = callable.return_type_id;
// For functions with an implicit return type, set the return type to empty
// tuple type.
if (type_id == SemanticsTypeId::Invalid) {
if (type_id == SemIR::TypeId::Invalid) {
type_id = context.CanonicalizeTupleType(call_expr_parse_node, {});
}
auto call_node_id = context.AddNode(SemanticsNode::Call::Make(
auto call_node_id = context.AddNode(SemIR::Node::Call::Make(
call_expr_parse_node, type_id, refs_id, function_id));
context.node_stack().Push(parse_node, call_node_id);
return true;
}
auto SemanticsHandleCallExpressionComma(SemanticsContext& context,
ParseTree::Node /*parse_node*/)
auto HandleCallExpressionComma(Context& context, ParseTree::Node /*parse_node*/)
-> bool {
context.ParamOrArgComma(/*for_args=*/true);
return true;
}
auto SemanticsHandleCallExpressionStart(SemanticsContext& context,
ParseTree::Node parse_node) -> bool {
auto HandleCallExpressionStart(Context& context, ParseTree::Node parse_node)
-> bool {
auto name_id = context.node_stack().PopExpression();
context.node_stack().Push(parse_node, name_id);
context.ParamOrArgStart();
return true;
}
} // namespace Carbon
} // namespace Carbon::Check