Use typed parse node ids in SemIR instruction types (#3560)

This involves a number of supporting changes:
* The `parse_node;` member of instruction types may now have any type
derived from `Parse::NodeId` and is no longer required to have that
exact type.
* `Parse::Node::Invalid` is now a singleton object of a separate type
that is convertible to `Parse::NodeId` and its descendants. This
replaces the `Invalid` member of its descendants, and avoids having to
write long `NodeIdOneOf<...>` types when initializing variables to
invalid.
* `IndexBase` now allows `==` and `!=` comparisons between its derived
classes and types that are convertible to those types.
* A number of functions in the check stage have been changed to preserve
more type information instead of using `Parse::NodeId`.
* `NodeIdForKind<K>` (also known as `KId`) now has a `Kind` member so it
may be used to declare `NodeIdOneOf<T, U>` types without #including
`parse/typed_nodes.h`.
* `NodeIdForKind<K>` (also known as `KId`) may be implicitly converted
to `NodeIdOneOf<T, U>` if `T::Kind == K` or `U::Kind == K` (executing a
TODO).

Many of the `parse_node` members were not converted since they would
have required more extensive changes. They have been marked with "TODO"
comments.

---------

Co-authored-by: Richard Smith <richard@metafoo.co.uk>
This commit is contained in:
josh11b
2024-01-03 23:13:30 +00:00
committed by GitHub
co-authored by Richard Smith
parent 95746df788
commit b0da52a3d7
13 changed files with 169 additions and 83 deletions
+5 -3
View File
@@ -108,7 +108,8 @@ auto RegisterReturnedVar(Context& context, SemIR::InstId bind_id) -> void {
}
}
auto BuildReturnWithNoExpr(Context& context, Parse::NodeId parse_node) -> void {
auto BuildReturnWithNoExpr(Context& context,
Parse::ReturnStatementId parse_node) -> void {
const auto& function = GetCurrentFunction(context);
if (function.return_type_id.is_valid()) {
@@ -122,7 +123,7 @@ auto BuildReturnWithNoExpr(Context& context, Parse::NodeId parse_node) -> void {
context.AddInst(SemIR::Return{parse_node});
}
auto BuildReturnWithExpr(Context& context, Parse::NodeId parse_node,
auto BuildReturnWithExpr(Context& context, Parse::ReturnStatementId parse_node,
SemIR::InstId expr_id) -> void {
const auto& function = GetCurrentFunction(context);
auto returned_var_id = GetCurrentReturnedVar(context);
@@ -154,7 +155,8 @@ auto BuildReturnWithExpr(Context& context, Parse::NodeId parse_node,
context.AddInst(SemIR::ReturnExpr{parse_node, expr_id});
}
auto BuildReturnVar(Context& context, Parse::NodeId parse_node) -> void {
auto BuildReturnVar(Context& context, Parse::ReturnStatementId parse_node)
-> void {
const auto& function = GetCurrentFunction(context);
auto returned_var_id = GetCurrentReturnedVar(context);