Drop fn destroy support (#6136)

`fn destroy` is being removed per decision on #6124. It seems like the
relevant decision will result in no more keyword-based function names,
so this is removing all related support.
This commit is contained in:
Jon Ross-Perkins
2025-09-25 21:56:48 +00:00
committed by GitHub
parent 5b34054341
commit 705c95d6e0
18 changed files with 160 additions and 701 deletions
@@ -55,13 +55,6 @@ auto HandleDeclNameAndParams(Context& context) -> void {
return;
}
if (auto keyword = context.ConsumeIf(Lex::TokenKind::Destroy)) {
HandleName(context, state, *keyword, NodeKind::KeywordNameNotBeforeParams,
NodeKind::KeywordNameQualifierWithoutParams,
NodeKind::KeywordNameBeforeParams);
return;
}
Lex::TokenIndex token = *context.position();
if (context.tokens().GetKind(token) == Lex::TokenKind::FileEnd) {
// The end of file is an unhelpful diagnostic location. Instead, use the
@@ -100,11 +93,10 @@ auto HandleDeclNameAndParamsAfterParams(Context& context) -> void {
auto state = context.PopState();
if (auto period = context.ConsumeIf(Lex::TokenKind::Period)) {
auto start_kind = context.tree().node_kind(NodeId(state.subtree_start));
auto node_kind = start_kind == NodeKind::IdentifierNameBeforeParams
? NodeKind::IdentifierNameQualifierWithParams
: NodeKind::KeywordNameQualifierWithParams;
context.AddNode(node_kind, *period, state.has_error);
CARBON_CHECK(context.tree().node_kind(NodeId(state.subtree_start)) ==
NodeKind::IdentifierNameBeforeParams);
context.AddNode(NodeKind::IdentifierNameQualifierWithParams, *period,
state.has_error);
context.PushState(StateKind::DeclNameAndParams);
}
}
-5
View File
@@ -98,9 +98,6 @@ CARBON_PARSE_NODE_KIND(EmptyDecl)
CARBON_PARSE_NODE_KIND(IdentifierNameNotBeforeParams)
CARBON_PARSE_NODE_KIND(IdentifierNameBeforeParams)
CARBON_PARSE_NODE_KIND(KeywordNameNotBeforeParams)
CARBON_PARSE_NODE_KIND(KeywordNameBeforeParams)
CARBON_PARSE_NODE_KIND(IdentifierNameExpr)
CARBON_PARSE_NODE_KIND(SelfValueName)
@@ -133,8 +130,6 @@ CARBON_PARSE_NODE_KIND(InlineImportBody)
CARBON_PARSE_NODE_KIND(IdentifierNameQualifierWithParams)
CARBON_PARSE_NODE_KIND(IdentifierNameQualifierWithoutParams)
CARBON_PARSE_NODE_KIND(KeywordNameQualifierWithParams)
CARBON_PARSE_NODE_KIND(KeywordNameQualifierWithoutParams)
CARBON_PARSE_NODE_KIND(ExportIntroducer)
CARBON_PARSE_NODE_KIND(ExportDecl)
-86
View File
@@ -36,26 +36,6 @@ fn foo(a: i32, b: i32);
fn foo() -> u32;
// --- keyword.carbon
fn destroy() {}
// --- keyword_no_params.carbon
fn destroy {}
// --- keyword_in_qualified.carbon
fn MyClass.destroy() {}
// --- keyword_decl_qualified_no_params.carbon
fn destroy.Foo() {}
// --- keyword_decl_qualified_with_params.carbon
fn destroy[self: Self]().Foo() {}
// --- impl_fn.carbon
override fn F();
@@ -276,72 +256,6 @@ fn (a tokens c d e f g h i j k l m n o p q r s t u v w x y z);
// CHECK:STDOUT: {kind: 'FunctionDecl', text: ';', subtree_size: 7},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDOUT: - filename: keyword.carbon
// CHECK:STDOUT: parse_tree: [
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'KeywordNameBeforeParams', text: 'destroy'},
// CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
// CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
// CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 5},
// CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 6},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDOUT: - filename: keyword_no_params.carbon
// CHECK:STDOUT: parse_tree: [
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'KeywordNameNotBeforeParams', text: 'destroy'},
// CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 3},
// CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 4},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDOUT: - filename: keyword_in_qualified.carbon
// CHECK:STDOUT: parse_tree: [
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'IdentifierNameNotBeforeParams', text: 'MyClass'},
// CHECK:STDOUT: {kind: 'IdentifierNameQualifierWithoutParams', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'KeywordNameBeforeParams', text: 'destroy'},
// CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
// CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
// CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 7},
// CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 8},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDOUT: - filename: keyword_decl_qualified_no_params.carbon
// CHECK:STDOUT: parse_tree: [
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'KeywordNameNotBeforeParams', text: 'destroy'},
// CHECK:STDOUT: {kind: 'KeywordNameQualifierWithoutParams', text: '.', subtree_size: 2},
// CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'Foo'},
// CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
// CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
// CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 7},
// CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 8},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDOUT: - filename: keyword_decl_qualified_with_params.carbon
// CHECK:STDOUT: parse_tree: [
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
// CHECK:STDOUT: {kind: 'FunctionIntroducer', text: 'fn'},
// CHECK:STDOUT: {kind: 'KeywordNameBeforeParams', text: 'destroy'},
// CHECK:STDOUT: {kind: 'ImplicitParamListStart', text: '['},
// CHECK:STDOUT: {kind: 'SelfValueName', text: 'self'},
// CHECK:STDOUT: {kind: 'SelfTypeNameExpr', text: 'Self'},
// CHECK:STDOUT: {kind: 'LetBindingPattern', text: ':', subtree_size: 3},
// CHECK:STDOUT: {kind: 'ImplicitParamList', text: ']', subtree_size: 5},
// CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
// CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
// CHECK:STDOUT: {kind: 'KeywordNameQualifierWithParams', text: '.', subtree_size: 9},
// CHECK:STDOUT: {kind: 'IdentifierNameBeforeParams', text: 'Foo'},
// CHECK:STDOUT: {kind: 'ExplicitParamListStart', text: '('},
// CHECK:STDOUT: {kind: 'ExplicitParamList', text: ')', subtree_size: 2},
// CHECK:STDOUT: {kind: 'FunctionDefinitionStart', text: '{', subtree_size: 14},
// CHECK:STDOUT: {kind: 'FunctionDefinition', text: '}', subtree_size: 15},
// CHECK:STDOUT: {kind: 'FileEnd', text: ''},
// CHECK:STDOUT: ]
// CHECK:STDOUT: - filename: impl_fn.carbon
// CHECK:STDOUT: parse_tree: [
// CHECK:STDOUT: {kind: 'FileStart', text: ''},
+2 -26
View File
@@ -132,18 +132,12 @@ using EmptyDecl =
using IdentifierNameBeforeParams =
LeafNode<NodeKind::IdentifierNameBeforeParams, Lex::IdentifierTokenIndex,
NodeCategory::MemberName | NodeCategory::NonExprName>;
using KeywordNameBeforeParams =
LeafNode<NodeKind::KeywordNameBeforeParams, Lex::TokenIndex,
NodeCategory::MemberName | NodeCategory::NonExprName>;
// A name in a non-expression context, such as a declaration, that is known
// to not be followed by parameters.
using IdentifierNameNotBeforeParams =
LeafNode<NodeKind::IdentifierNameNotBeforeParams, Lex::IdentifierTokenIndex,
NodeCategory::MemberName | NodeCategory::NonExprName>;
using KeywordNameNotBeforeParams =
LeafNode<NodeKind::KeywordNameNotBeforeParams, Lex::TokenIndex,
NodeCategory::MemberName | NodeCategory::NonExprName>;
// A name in an expression context.
using IdentifierNameExpr =
@@ -184,15 +178,6 @@ struct IdentifierNameQualifierWithParams {
std::optional<ExplicitParamListId> params;
Lex::PeriodTokenIndex token;
};
struct KeywordNameQualifierWithParams {
static constexpr auto Kind = NodeKind::KeywordNameQualifierWithParams.Define(
{.bracketed_by = KeywordNameBeforeParams::Kind});
KeywordNameBeforeParamsId name;
std::optional<ImplicitParamListId> implicit_params;
std::optional<ExplicitParamListId> params;
Lex::PeriodTokenIndex token;
};
// A name qualifier without parameters, such as `A.`.
struct IdentifierNameQualifierWithoutParams {
@@ -203,21 +188,12 @@ struct IdentifierNameQualifierWithoutParams {
IdentifierNameNotBeforeParamsId name;
Lex::PeriodTokenIndex token;
};
struct KeywordNameQualifierWithoutParams {
static constexpr auto Kind =
NodeKind::KeywordNameQualifierWithoutParams.Define(
{.bracketed_by = KeywordNameNotBeforeParams::Kind});
KeywordNameNotBeforeParamsId name;
Lex::PeriodTokenIndex token;
};
// A complete name in a declaration: `A.C(T:! type).F(n: i32)`.
// Note that this includes the parameters of the entity itself.
struct DeclName {
llvm::SmallVector<NodeIdOneOf<
IdentifierNameQualifierWithParams, IdentifierNameQualifierWithoutParams,
KeywordNameQualifierWithParams, KeywordNameQualifierWithoutParams>>
llvm::SmallVector<NodeIdOneOf<IdentifierNameQualifierWithParams,
IdentifierNameQualifierWithoutParams>>
qualifiers;
AnyNonExprNameId name;
std::optional<ImplicitParamListId> implicit_params;
+2 -2
View File
@@ -293,8 +293,8 @@ NodeIdForKind error: wrong kind IdentifierNameBeforeParams, expected ImplicitPar
Optional [^:]*: missing
NodeIdInCategory NonExprName: kind IdentifierNameBeforeParams consumed
Vector: begin
NodeIdOneOf IdentifierNameQualifierWithParams or IdentifierNameQualifierWithoutParams or KeywordNameQualifierWithParams or KeywordNameQualifierWithoutParams: IdentifierNameQualifierWithoutParams consumed
NodeIdOneOf error: wrong kind AbstractModifier, expected IdentifierNameQualifierWithParams or IdentifierNameQualifierWithoutParams or KeywordNameQualifierWithParams or KeywordNameQualifierWithoutParams
NodeIdOneOf IdentifierNameQualifierWithParams or IdentifierNameQualifierWithoutParams: IdentifierNameQualifierWithoutParams consumed
NodeIdOneOf error: wrong kind AbstractModifier, expected IdentifierNameQualifierWithParams or IdentifierNameQualifierWithoutParams
Vector: end
Aggregate [^:]*: success
Vector: begin