Skip to content

Commit ebac209

Browse files
committed
Unified: Add explicit rules for unsupported nodes
Adds rules for each of the node types that we currently do not support. This means if the fallback clause actually fires, then we've encountered a truly new node type (or something that shouldn't have been translated, like a token). In this case, we now emit an error message (but this does not affect extraction -- it'll succeed with an `unhandled_node` in the output).
1 parent d802fe2 commit ebac209

1 file changed

Lines changed: 55 additions & 15 deletions

File tree

  • unified/extractor/src/languages/swift

‎unified/extractor/src/languages/swift/swift.rs‎

Lines changed: 55 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
129129
vec![
130130
// ---- Top-level ----
131131
// These rules translate the swift-syntax AST (camelCase kind names),
132-
// produced by the sibling `adapter` module from the `swift-syntax-parse`
133-
// binary's JSON. Anything unmatched falls through to the
134-
// `unsupported_node` fallback at the end.
132+
// produced by the sibling `adapter` module from swift-syntax JSON.
133+
// Known kinds without dedicated rules become `unsupported_node`;
134+
// genuinely unknown kinds become `unhandled_node`.
135135
//
136136
// `sourceFile` holds its top-level statements in an (elided)
137137
// `statements` collection; each element is a `codeBlockItem` wrapping
@@ -1383,18 +1383,58 @@ fn translation_rules() -> Vec<Rule<SwiftContext>> {
13831383
name_node: (identifier #{name})
13841384
bound: {bound})
13851385
),
1386-
// ---- Fallbacks ----
1387-
// Bare `_` (rather than `(_)`) so this matches both named nodes
1388-
// and unnamed tokens. Any unnamed token that escapes the
1389-
// input-schema-specific rules (e.g. captured operators in
1390-
// `additive_expression op: @op`) has its auto-translated value
1391-
// replaced with an `unsupported_node` whose source range is
1392-
// inherited from the original token, so `#{op}` still reads the
1393-
// original text.
1394-
rule!(
1395-
_
1396-
=>
1397-
(unsupported_node)
1386+
// ---- Explicitly unsupported roots ----
1387+
// These kinds can reach translation independently, but we do not
1388+
// currently map them to the unified AST. Syntax nested inside one of
1389+
// these roots is discarded with its parent and needs no separate rule.
1390+
rule!((actorDecl) => (unsupported_node)),
1391+
rule!((attributedType) => (unsupported_node)),
1392+
rule!((borrowExpr) => (unsupported_node)),
1393+
rule!((classRestrictionType) => (unsupported_node)),
1394+
rule!((compositionType) => (unsupported_node)),
1395+
rule!((consumeExpr) => (unsupported_node)),
1396+
rule!((copyExpr) => (unsupported_node)),
1397+
rule!((deferStmt) => (unsupported_node)),
1398+
rule!((discardStmt) => (unsupported_node)),
1399+
rule!((fallThroughStmt) => (unsupported_node)),
1400+
rule!((ifConfigDecl) => (unsupported_node)),
1401+
rule!((implicitlyUnwrappedOptionalType) => (unsupported_node)),
1402+
rule!((inOutExpr) => (unsupported_node)),
1403+
rule!((inlineArrayType) => (unsupported_node)),
1404+
rule!((keyPathExpr) => (unsupported_node)),
1405+
rule!((macroDecl) => (unsupported_node)),
1406+
rule!((metatypeType) => (unsupported_node)),
1407+
rule!((namedOpaqueReturnType) => (unsupported_node)),
1408+
rule!((operatorDecl) => (unsupported_node)),
1409+
rule!((packElementExpr) => (unsupported_node)),
1410+
rule!((packElementType) => (unsupported_node)),
1411+
rule!((packExpansionExpr) => (unsupported_node)),
1412+
rule!((packExpansionType) => (unsupported_node)),
1413+
rule!((postfixIfConfigExpr) => (unsupported_node)),
1414+
rule!((postfixOperatorExpr) => (unsupported_node)),
1415+
rule!((poundSourceLocation) => (unsupported_node)),
1416+
rule!((precedenceGroupDecl) => (unsupported_node)),
1417+
rule!((someOrAnyType) => (unsupported_node)),
1418+
rule!((subscriptDecl) => (unsupported_node)),
1419+
rule!((suppressedType) => (unsupported_node)),
1420+
rule!((typeExpr) => (unsupported_node)),
1421+
rule!((unsafeExpr) => (unsupported_node)),
1422+
rule!((yieldStmt) => (unsupported_node)),
1423+
// Anything reaching this final generic handler has neither a
1424+
// dedicated rule nor an explicit unsupported entry.
1425+
rule!(
1426+
_ @@node
1427+
=>
1428+
unhandled_node {
1429+
let input = ctx.ast.get_node(node).expect("matched node must exist");
1430+
tracing::error!(
1431+
target: "unified_extractor",
1432+
node_kind = input.kind_name(),
1433+
source_range = ?input.source_range(),
1434+
"Unhandled Swift syntax node reached translation"
1435+
);
1436+
tree!((unhandled_node))
1437+
}
13981438
),
13991439
]
14001440
}

0 commit comments

Comments
 (0)