Rename semantics InvalidType to Error (#2975)

Following up on zygoloid's request [on
#2940](https://github.com/carbon-language/carbon-lang/pull/2940#discussion_r1253522564)
This commit is contained in:
Jon Ross-Perkins
2023-07-06 22:30:56 +00:00
committed by GitHub
parent ea982ad2c8
commit bc84f109fe
28 changed files with 60 additions and 58 deletions
+1 -1
View File
@@ -17,7 +17,7 @@
// CHECK:STDOUT: ]
// CHECK:STDOUT: nodes: [
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: nodeTypeType, type: typeTypeType},
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: nodeError, type: typeError},
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: nodeBoolType, type: typeTypeType},
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: nodeIntegerType, type: typeTypeType},
// CHECK:STDOUT: {kind: CrossReference, arg0: ir0, arg1: nodeFloatingPointType, type: typeTypeType},
@@ -40,9 +40,11 @@
// This has a deliberately self-referential type.
CARBON_SEMANTICS_BUILTIN_KIND(TypeType, "Type")
// Used when a SemanticNode has an invalid type, which should then be ignored
// for future type checking.
CARBON_SEMANTICS_BUILTIN_KIND(InvalidType, "<unknown>")
// Used when a semantic error has been detected, and a SemanticNodeId is still
// required. For example, when there is a type checking issue, this will be used
// in the type_id. It's typically used as a cue that semantic checking doesn't
// need to issue further diagnostics.
CARBON_SEMANTICS_BUILTIN_KIND(Error, "<error>")
// -----------------------------------------------------------------------------
// TODO: Below types are all placeholders. While the above may last, the below
+10 -10
View File
@@ -33,10 +33,10 @@ SemanticsContext::SemanticsContext(const TokenizedBuffer& tokens,
params_or_args_stack_("params_or_args_stack_", semantics_ir, vlog_stream),
args_type_info_stack_("args_type_info_stack_", semantics_ir,
vlog_stream) {
// Inserts the "Invalid" and "Type" types as "used types" so that
// Inserts the "Error" and "Type" types as "used types" so that
// canonicalization can skip them. We don't emit either for lowering.
canonical_types_.insert(
{SemanticsNodeId::BuiltinInvalidType, SemanticsTypeId::InvalidType});
{SemanticsNodeId::BuiltinError, SemanticsTypeId::Error});
canonical_types_.insert(
{SemanticsNodeId::BuiltinTypeType, SemanticsTypeId::TypeType});
}
@@ -142,7 +142,7 @@ auto SemanticsContext::LookupName(ParseTree::Node parse_node,
emitter_->Emit(parse_node, NameNotFound,
semantics_ir_->GetString(name_id));
}
return SemanticsNodeId::BuiltinInvalidType;
return SemanticsNodeId::BuiltinError;
}
CARBON_CHECK(!it->second.empty())
<< "Should have been erased: " << semantics_ir_->GetString(name_id);
@@ -157,7 +157,7 @@ auto SemanticsContext::LookupName(ParseTree::Node parse_node,
emitter_->Emit(parse_node, NameNotFound,
semantics_ir_->GetString(name_id));
}
return SemanticsNodeId::BuiltinInvalidType;
return SemanticsNodeId::BuiltinError;
}
return it->second;
@@ -360,7 +360,7 @@ auto SemanticsContext::ApplyDeclarationNameQualifier(
auto resolved_node_id = LookupName(name_context.parse_node, name_id,
name_context.target_scope_id,
/*print_diagnostics=*/false);
if (resolved_node_id == SemanticsNodeId::BuiltinInvalidType) {
if (resolved_node_id == SemanticsNodeId::BuiltinError) {
// Invalid indicates an unresolved node. Store it and return.
name_context.state = DeclarationNameContext::State::Unresolved;
name_context.unresolved_name_id = name_id;
@@ -479,20 +479,20 @@ auto SemanticsContext::ImplicitAsImpl(SemanticsNodeId value_id,
-> ImplicitAsKind {
// Start by making sure both sides are valid. If any part is invalid, the
// result is invalid and we shouldn't error.
if (value_id == SemanticsNodeId::BuiltinInvalidType) {
if (value_id == SemanticsNodeId::BuiltinError) {
// If the value is invalid, we can't do much, but do "succeed".
return ImplicitAsKind::Identical;
}
auto value = semantics_ir_->GetNode(value_id);
auto value_type_id = value.type_id();
if (value_type_id == SemanticsTypeId::InvalidType) {
if (value_type_id == SemanticsTypeId::Error) {
return ImplicitAsKind::Identical;
}
if (as_type_id == SemanticsTypeId::InvalidType) {
if (as_type_id == SemanticsTypeId::Error) {
// Although the target type is invalid, this still changes the value.
if (output_value_id != nullptr) {
*output_value_id = SemanticsNodeId::BuiltinInvalidType;
*output_value_id = SemanticsNodeId::BuiltinError;
}
return ImplicitAsKind::Compatible;
}
@@ -519,7 +519,7 @@ auto SemanticsContext::ImplicitAsImpl(SemanticsNodeId value_id,
// TODO: Handle ImplicitAs for compatible structs and tuples.
if (output_value_id != nullptr) {
*output_value_id = SemanticsNodeId::BuiltinInvalidType;
*output_value_id = SemanticsNodeId::BuiltinError;
}
return ImplicitAsKind::Incompatible;
}
+1 -1
View File
@@ -210,7 +210,7 @@ class SemanticsContext {
-> bool;
// Runs ImplicitAsImpl for a situation where a cast is required, returning the
// updated `value_id`. Prints a diagnostic and returns an InvalidType if
// updated `value_id`. Prints a diagnostic and returns an Error if
// unsupported.
auto ImplicitAsRequired(ParseTree::Node parse_node, SemanticsNodeId value_id,
SemanticsTypeId as_type_id) -> SemanticsNodeId;
+1 -1
View File
@@ -238,7 +238,7 @@ auto SemanticsHandleMemberAccessExpression(SemanticsContext& context,
}
// Should only be reached on error.
context.node_stack().Push(parse_node, SemanticsNodeId::BuiltinInvalidType);
context.node_stack().Push(parse_node, SemanticsNodeId::BuiltinError);
return true;
}
@@ -32,7 +32,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::BuiltinInvalidType);
context.node_stack().Push(parse_node, SemanticsNodeId::BuiltinError);
return true;
}
+7 -7
View File
@@ -17,14 +17,14 @@ auto SemanticsIR::MakeBuiltinIR() -> SemanticsIR {
SemanticsIR semantics_ir(/*builtin_ir=*/nullptr);
semantics_ir.nodes_.reserve(SemanticsBuiltinKind::ValidCount);
// InvalidType uses a self-referential type so that it's not accidentally
// treated as a normal type. Every other builtin is a type, including the
// Error uses a self-referential type so that it's not accidentally treated as
// a normal type. Every other builtin is a type, including the
// self-referential TypeType.
#define CARBON_SEMANTICS_BUILTIN_KIND(Name, ...) \
semantics_ir.nodes_.push_back(SemanticsNode::Builtin::Make( \
SemanticsBuiltinKind::Name, \
SemanticsBuiltinKind::Name == SemanticsBuiltinKind::InvalidType \
? SemanticsTypeId::InvalidType \
#define CARBON_SEMANTICS_BUILTIN_KIND(Name, ...) \
semantics_ir.nodes_.push_back(SemanticsNode::Builtin::Make( \
SemanticsBuiltinKind::Name, \
SemanticsBuiltinKind::Name == SemanticsBuiltinKind::Error \
? SemanticsTypeId::Error \
: SemanticsTypeId::TypeType));
#include "toolchain/semantics/semantics_builtin_kind.def"
+4 -4
View File
@@ -225,11 +225,11 @@ class SemanticsIR {
return type_id;
}
// Gets the node ID for a type. This doesn't handle TypeType or InvalidType in
// Gets the node ID for a type. This doesn't handle TypeType or Error in
// order to avoid a check; callers that need that should use
// GetTypeAllowBuiltinTypes.
auto GetType(SemanticsTypeId type_id) const -> SemanticsNodeId {
// Double-check it's not called with TypeType or InvalidType.
// Double-check it's not called with TypeType or Error.
CARBON_CHECK(type_id.index >= 0)
<< "Invalid argument for GetType: " << type_id;
return types_[type_id.index];
@@ -239,8 +239,8 @@ class SemanticsIR {
-> SemanticsNodeId {
if (type_id == SemanticsTypeId::TypeType) {
return SemanticsNodeId::BuiltinTypeType;
} else if (type_id == SemanticsTypeId::InvalidType) {
return SemanticsNodeId::BuiltinInvalidType;
} else if (type_id == SemanticsTypeId::Error) {
return SemanticsNodeId::BuiltinError;
} else {
return GetType(type_id);
}
+5 -5
View File
@@ -168,8 +168,8 @@ struct SemanticsTypeId : public IndexBase {
// The builtin TypeType.
static const SemanticsTypeId TypeType;
// The builtin InvalidType.
static const SemanticsTypeId InvalidType;
// The builtin Error.
static const SemanticsTypeId Error;
// An explicitly invalid ID.
static const SemanticsTypeId Invalid;
@@ -179,8 +179,8 @@ struct SemanticsTypeId : public IndexBase {
out << "type";
if (index == TypeType.index) {
out << "TypeType";
} else if (index == InvalidType.index) {
out << "InvalidType";
} else if (index == Error.index) {
out << "Error";
} else {
IndexBase::Print(out);
}
@@ -189,7 +189,7 @@ struct SemanticsTypeId : public IndexBase {
constexpr SemanticsTypeId SemanticsTypeId::TypeType =
SemanticsTypeId(SemanticsTypeId::InvalidIndex - 2);
constexpr SemanticsTypeId SemanticsTypeId::InvalidType =
constexpr SemanticsTypeId SemanticsTypeId::Error =
SemanticsTypeId(SemanticsTypeId::InvalidIndex - 1);
constexpr SemanticsTypeId SemanticsTypeId::Invalid =
SemanticsTypeId(SemanticsTypeId::InvalidIndex);
@@ -23,7 +23,7 @@
// CHECK:STDOUT: {kind: BindName, arg0: str0, arg1: node+0, type: type0},
// CHECK:STDOUT: {kind: VarStorage, type: type0},
// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node+2, type: type0},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -31,7 +31,7 @@
// CHECK:STDOUT: {kind: VarStorage, type: type2},
// CHECK:STDOUT: {kind: BindName, arg0: str2, arg1: node+4, type: type2},
// CHECK:STDOUT: {kind: Call, arg0: block0, arg1: function0, type: type0},
// CHECK:STDOUT: {kind: Assign, arg0: node+4, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+4, arg1: nodeError, type: typeError},
// CHECK:STDOUT: {kind: Return},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
+1 -1
View File
@@ -33,7 +33,7 @@
// CHECK:STDOUT: {kind: Assign, arg0: node+5, arg1: node+7, type: type1},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+5, type: type1},
// CHECK:STDOUT: {kind: Branch, arg0: block6},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -24,8 +24,8 @@
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: function0},
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int0, type: type0},
// CHECK:STDOUT: {kind: RealLiteral, arg0: real0, type: type1},
// CHECK:STDOUT: {kind: BinaryOperatorAdd, arg0: nodeInvalidType, arg1: node+2, type: typeInvalidType},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+3, type: typeInvalidType},
// CHECK:STDOUT: {kind: BinaryOperatorAdd, arg0: nodeError, arg1: node+2, type: typeError},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+3, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -25,10 +25,10 @@
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: function0},
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int0, type: type0},
// CHECK:STDOUT: {kind: RealLiteral, arg0: real0, type: type1},
// CHECK:STDOUT: {kind: BinaryOperatorAdd, arg0: nodeInvalidType, arg1: node+2, type: typeInvalidType},
// CHECK:STDOUT: {kind: BinaryOperatorAdd, arg0: nodeError, arg1: node+2, type: typeError},
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int1, type: type0},
// CHECK:STDOUT: {kind: BinaryOperatorAdd, arg0: node+3, arg1: node+4, type: typeInvalidType},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+5, type: typeInvalidType},
// CHECK:STDOUT: {kind: BinaryOperatorAdd, arg0: node+3, arg1: node+4, type: typeError},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: node+5, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -22,7 +22,7 @@
// CHECK:STDOUT: nodes: [
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: function0},
// CHECK:STDOUT: {kind: RealLiteral, arg0: real0, type: type1},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: ReturnExpression, arg0: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -26,7 +26,7 @@
// CHECK:STDOUT: {kind: BindName, arg0: str0, arg1: node+2, type: type1},
// CHECK:STDOUT: {kind: StructType, arg0: block0, type: typeTypeType},
// CHECK:STDOUT: {kind: StructValue, arg0: block0, type: type2},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -30,7 +30,7 @@
// CHECK:STDOUT: {kind: StubReference, arg0: node+4, type: type1},
// CHECK:STDOUT: {kind: StructType, arg0: block2, type: typeTypeType},
// CHECK:STDOUT: {kind: StructValue, arg0: block3, type: type2},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -31,7 +31,7 @@
// CHECK:STDOUT: {kind: StubReference, arg0: node+4, type: type0},
// CHECK:STDOUT: {kind: StructType, arg0: block3, type: typeTypeType},
// CHECK:STDOUT: {kind: StructValue, arg0: block4, type: type2},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -32,7 +32,7 @@
// CHECK:STDOUT: {kind: StubReference, arg0: node+4, type: type2},
// CHECK:STDOUT: {kind: StructType, arg0: block3, type: typeTypeType},
// CHECK:STDOUT: {kind: StructValue, arg0: block4, type: type3},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -34,7 +34,7 @@
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: node+7, type: type1},
// CHECK:STDOUT: {kind: VarStorage, type: type2},
// CHECK:STDOUT: {kind: BindName, arg0: str2, arg1: node+9, type: type2},
// CHECK:STDOUT: {kind: Assign, arg0: node+9, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+9, arg1: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -33,7 +33,7 @@
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: node+7, type: type1},
// CHECK:STDOUT: {kind: VarStorage, type: type0},
// CHECK:STDOUT: {kind: BindName, arg0: str2, arg1: node+9, type: type0},
// CHECK:STDOUT: {kind: Assign, arg0: node+9, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+9, arg1: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -32,7 +32,7 @@
// CHECK:STDOUT: {kind: StubReference, arg0: node+5, type: type0},
// CHECK:STDOUT: {kind: StructType, arg0: block3, type: typeTypeType},
// CHECK:STDOUT: {kind: StructValue, arg0: block4, type: type2},
// CHECK:STDOUT: {kind: Assign, arg0: node+3, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+3, arg1: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -24,7 +24,7 @@
// CHECK:STDOUT: {kind: VarStorage, type: type1},
// CHECK:STDOUT: {kind: BindName, arg0: str0, arg1: node+2, type: type1},
// CHECK:STDOUT: {kind: StructTypeField, arg0: str1, type: type0},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -25,8 +25,8 @@
// CHECK:STDOUT: {kind: StubReference, arg0: node+0, type: type0},
// CHECK:STDOUT: {kind: StructType, arg0: block2, type: typeTypeType},
// CHECK:STDOUT: {kind: StructValue, arg0: block3, type: type1},
// CHECK:STDOUT: {kind: VarStorage, type: typeInvalidType},
// CHECK:STDOUT: {kind: BindName, arg0: str0, arg1: node+5, type: typeInvalidType},
// CHECK:STDOUT: {kind: VarStorage, type: typeError},
// CHECK:STDOUT: {kind: BindName, arg0: str0, arg1: node+5, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -26,7 +26,7 @@
// CHECK:STDOUT: {kind: VarStorage, type: type1},
// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node+1, type: type1},
// CHECK:STDOUT: {kind: RealLiteral, arg0: real0, type: type2},
// CHECK:STDOUT: {kind: Assign, arg0: node+1, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+1, arg1: nodeError, type: typeError},
// CHECK:STDOUT: {kind: Return},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
@@ -23,7 +23,7 @@
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: function0},
// CHECK:STDOUT: {kind: VarStorage, type: type1},
// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node+1, type: type1},
// CHECK:STDOUT: {kind: Assign, arg0: node+1, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+1, arg1: nodeError, type: typeError},
// CHECK:STDOUT: {kind: Return},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
@@ -27,7 +27,7 @@
// CHECK:STDOUT: {kind: Return},
// CHECK:STDOUT: {kind: VarStorage, type: type1},
// CHECK:STDOUT: {kind: BindName, arg0: str2, arg1: node+4, type: type1},
// CHECK:STDOUT: {kind: Assign, arg0: node+4, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+4, arg1: nodeError, type: typeError},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [
// CHECK:STDOUT: [
@@ -24,10 +24,10 @@
// CHECK:STDOUT: nodes: [
// CHECK:STDOUT: {kind: FunctionDeclaration, arg0: function0},
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int0, type: type1},
// CHECK:STDOUT: {kind: VarStorage, type: typeInvalidType},
// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node+2, type: typeInvalidType},
// CHECK:STDOUT: {kind: VarStorage, type: typeError},
// CHECK:STDOUT: {kind: BindName, arg0: str1, arg1: node+2, type: typeError},
// CHECK:STDOUT: {kind: IntegerLiteral, arg0: int1, type: type1},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeInvalidType, type: typeInvalidType},
// CHECK:STDOUT: {kind: Assign, arg0: node+2, arg1: nodeError, type: typeError},
// CHECK:STDOUT: {kind: Return},
// CHECK:STDOUT: ]
// CHECK:STDOUT: node_blocks: [