Skip to content

Commit

Permalink
Replace the NodeKind StructFieldUnknown with InvalidParse. (carbon-la…
Browse files Browse the repository at this point in the history
…nguage#3482)

StructFieldUnknown was used previously for invalid parses. But we have
added other, more common ways of talking about those; so this is
removing the special-case.
  • Loading branch information
jonmeow committed Dec 12, 2023
1 parent 032c0e0 commit 6cc5dc7
Show file tree
Hide file tree
Showing 19 changed files with 22 additions and 29 deletions.
5 changes: 0 additions & 5 deletions toolchain/check/handle_struct.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ auto HandleStructFieldType(Context& context, Parse::NodeId parse_node) -> bool {
return true;
}

auto HandleStructFieldUnknown(Context& context, Parse::NodeId parse_node)
-> bool {
return context.TODO(parse_node, "HandleStructFieldUnknown");
}

auto HandleStructFieldValue(Context& context, Parse::NodeId parse_node)
-> bool {
auto value_inst_id = context.node_stack().PopExpr();
Expand Down
4 changes: 2 additions & 2 deletions toolchain/parse/handle_brace_expr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ static auto HandleBraceExprParamFinish(Context& context, NodeKind node_kind,
auto state = context.PopState();

if (state.has_error) {
context.AddLeafNode(NodeKind::StructFieldUnknown, state.token,
context.AddLeafNode(NodeKind::InvalidParse, state.token,
/*has_error=*/true);
} else {
context.AddNode(node_kind, state.token, state.subtree_start,
Expand All @@ -172,7 +172,7 @@ auto HandleBraceExprParamFinishAsValue(Context& context) -> void {
}

auto HandleBraceExprParamFinishAsUnknown(Context& context) -> void {
HandleBraceExprParamFinish(context, NodeKind::StructFieldUnknown,
HandleBraceExprParamFinish(context, NodeKind::InvalidParse,
State::BraceExprParamAsUnknown);
}

Expand Down
4 changes: 1 addition & 3 deletions toolchain/parse/node_kind.def
Original file line number Diff line number Diff line change
Expand Up @@ -613,16 +613,14 @@ CARBON_PARSE_NODE_KIND_CHILD_COUNT(IfExprElse, 3,
// may repeat with StructComma as a separator.
//
// When a valid StructFieldType or StructFieldValue cannot be formed, elements
// may be replaced by StructFieldUnknown, which may have a preceding sibling
// may be replaced by InvalidParse, which may have a preceding sibling
// StructFieldDesignator if one was successfully parsed.
CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructLiteralOrStructTypeLiteralStart, 0,
CARBON_TOKEN(OpenCurlyBrace))
CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldDesignator, 1,
CARBON_TOKEN(Period))
CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldValue, 2, CARBON_TOKEN(Equal))
CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldType, 2, CARBON_TOKEN(Colon))
CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructFieldUnknown, 0,
CARBON_IF_ERROR(CARBON_ANY_TOKEN))
CARBON_PARSE_NODE_KIND_CHILD_COUNT(StructComma, 0, CARBON_TOKEN(Comma))
CARBON_PARSE_NODE_KIND_BRACKET(StructLiteral,
StructLiteralOrStructTypeLiteralStart,
Expand Down
2 changes: 1 addition & 1 deletion toolchain/parse/testdata/struct/fail_comma_only.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var x: {,} = {};
// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'x'},
// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: ',', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: ',', has_error: yes},
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 4},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 6},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var x: {.a: i32,,} = {};
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
// CHECK:STDOUT: {kind: 'StructFieldType', text: ':', subtree_size: 4},
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: ',', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: ',', has_error: yes},
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 9},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 11},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var x: {.a = 0,,} = {};
// CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
// CHECK:STDOUT: {kind: 'StructFieldValue', text: '=', subtree_size: 4},
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: ',', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: ',', has_error: yes},
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 9},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 11},
Expand Down
2 changes: 1 addition & 1 deletion toolchain/parse/testdata/struct/fail_dot_only.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var x: {.} = {};
// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'},
// CHECK:STDOUT: {kind: 'IdentifierName', text: '}', has_error: yes},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 5},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 7},
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var x: {."hello": i32, .y: i32} = {};
// CHECK:STDOUT: {kind: 'IdentifierName', text: '"hello"', has_error: yes},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'IntTypeLiteral', text: 'i32'},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: ':', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: ':', has_error: yes},
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'y'},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var x: {."hello" = 0, .y = 4} = {};
// CHECK:STDOUT: {kind: 'IdentifierName', text: '"hello"', has_error: yes},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '=', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: '=', has_error: yes},
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'y'},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var x: {a:} = {};
// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'x'},
// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: 'a', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: 'a', has_error: yes},
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 3},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 5},
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var x: {a=} = {};
// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'x'},
// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: 'a', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: 'a', has_error: yes},
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 3},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 5},
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var x: {a} = {};
// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'x'},
// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: 'a', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: 'a', has_error: yes},
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 3},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 5},
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
Expand Down
2 changes: 1 addition & 1 deletion toolchain/parse/testdata/struct/fail_missing_type.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var x: {.a:} = {};
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'InvalidParse', text: '}', has_error: yes},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: ':', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: ':', has_error: yes},
// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 6},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 8},
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
Expand Down
2 changes: 1 addition & 1 deletion toolchain/parse/testdata/struct/fail_missing_value.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var x: {.a=} = {};
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'InvalidParse', text: '}', has_error: yes},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '=', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: '=', has_error: yes},
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 6},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 8},
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var x: {.a: i32, .b = 0} = {};
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'b'},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 10},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 12},
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var x: {.a = 0, b: i32} = {};
// CHECK:STDOUT: {kind: 'IntLiteral', text: '0'},
// CHECK:STDOUT: {kind: 'StructFieldValue', text: '=', subtree_size: 4},
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: 'b', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: 'b', has_error: yes},
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 8},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 10},
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
Expand Down
8 changes: 4 additions & 4 deletions toolchain/parse/testdata/struct/fail_mix_with_unknown.carbon
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ var x: i32 = {.a: i32, .b, .c = 1};
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'b'},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'c'},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 14},
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 20},
// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
Expand All @@ -56,11 +56,11 @@ var x: i32 = {.a: i32, .b, .c = 1};
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'b'},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'StructComma', text: ','},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'c'},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'StructTypeLiteral', text: '}', subtree_size: 14},
// CHECK:STDOUT: {kind: 'VariableDecl', text: ';', subtree_size: 20},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ var x: {.a} = {};
// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'a'},
// CHECK:STDOUT: {kind: 'StructFieldDesignator', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: '.', has_error: yes},
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 5},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 7},
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var x: {i32} = {};
// CHECK:STDOUT: {kind: 'VariableIntroducer', text: 'var'},
// CHECK:STDOUT: {kind: 'IdentifierName', text: 'x'},
// CHECK:STDOUT: {kind: 'StructLiteralOrStructTypeLiteralStart', text: '{'},
// CHECK:STDOUT: {kind: 'StructFieldUnknown', text: 'i32', has_error: yes},
// CHECK:STDOUT: {kind: 'InvalidParse', text: 'i32', has_error: yes},
// CHECK:STDOUT: {kind: 'StructLiteral', text: '}', subtree_size: 3},
// CHECK:STDOUT: {kind: 'BindingPattern', text: ':', subtree_size: 5},
// CHECK:STDOUT: {kind: 'VariableInitializer', text: '='},
Expand Down

0 comments on commit 6cc5dc7

Please sign in to comment.