Skip to content

Conversation

rintaro
Copy link
Member

@rintaro rintaro commented Aug 26, 2024

Types:

  • SyntaxLayout<T>: represents the layout of the T syntax layout type
  • SyntaxLayoutProperty: represents an element in SyntaxLayout. like AnyKeyPath
  • ConcreteSyntaxProperty<Base, Value>: represent a typed property. like KeyPath<Root, Value>

API:

  • _LeafSyntaxNodeProtocol.syntaxKind to get the syntax kind from the meta type.
  • _LayoutSyntaxNodeProtocol protocol for non-collection leaf syntax nodes
  • _LayoutSyntaxNodeProtocol.layout to get the layout (SyntaxLayout<Self>)

Usage:

func usage(node: some SyntaxProtocol) { node.propertyInParent == FuncDeclSyntax.layout[.funcKeyword] }

This is faster than keyPathInParent and comparing KeyPath. Combined with #2842, BasicFormat performs 30% faster

@rintaro rintaro force-pushed the syntaxlayout branch 2 times, most recently from a8678db to 0ae17dc Compare September 10, 2024 13:46
@rintaro
Copy link
Member Author

rintaro commented Sep 10, 2024

@swift-ci Please test

@rintaro rintaro marked this pull request as ready for review September 10, 2024 14:38
@rintaro
Copy link
Member Author

rintaro commented Sep 10, 2024

@swift-ci Please test

@rintaro rintaro force-pushed the syntaxlayout branch 6 times, most recently from 23f65e3 to 341f740 Compare January 21, 2025 17:17
This replaces most use case of `keyPathInParent` and `SyntaxNodeStructure.layout`. Since getting and comparing `KeyPath` is not trivial, `keyPathInParent` were suffered from performance issue, Newly introduced `SyntaxProtocol.propertyInParent` is trivial, and comparing it with a SyntaxLayoutProperty is also trivial.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

1 participant