[SwiftLexicalLookup] Preliminary Qualified-Lookup API#3346
[SwiftLexicalLookup] Preliminary Qualified-Lookup API#3346filip-sakel wants to merge 11 commits into
Conversation
| /// | ||
| /// We use ``DeclName`` because it strips away low-level information, such as a | ||
| /// node's trivia, leaving us with a `Hashable` name that we can use in lookup. | ||
| @_spi(_QualifiedLookup) public indirect enum DeclName: Hashable, CustomDebugStringConvertible { |
There was a problem hiding this comment.
Same here probably, this is more of a compiler naming, we should consider DeclarationName.
xedin
left a comment
There was a problem hiding this comment.
Overall LGTM! I think some of the naming choices should be made more swift-syntax canonical instead of trying to match what the compiler is doing.
|
I noticed swift-syntax itself is slightly inconsistent with So, IIUC, we want to change:
Also, are there any special considerations for the breaking change in the unqualified API from |
|
Maybe we make Arguments an inner type of DeclarationNameReference? |
The problem is that both For now, I think any of these options works; let me know what you prefer. |
|
@swift-ci please test |
|
@swift-ci please test |
|
@swift-ci please test |
|
@swift-ci please test |
The initial code following this discussion to implement qualified name lookup for GSoC 2026.
This PR adds support for looking up the members of a group declaration —nominal type, protocol, or extension— through the
DeclGroupSyntax.findDirectMembersmethod. It can optionally filter by aDeclNameRefname orMemberKindkind. Further, providing aConfiguredRegionsinstance, resolves#ifdeclarations. The method returns an array ofValueDeclSyntax, a new currency type.Value declarations are analogous to the compiler’s
ValueDecl: they are syntax nodes with a name that can evaluate to a value. They provide useful properties, such asdeclName: DeclNamewhich we try to match ourDeclNameRefagainst, along withisStaticandisTypeDeclwhich help filter forMemberKind. You’ll note that not all value declarations are actual declarations. The two exceptions are identifier patterns (expected to appear in a variable declaration) and enum elements (inside enum case declarations). Regardless, we assume nothing about the syntax tree. We provide detailed enough errors for users to understand the causes for failure and potentially diagnose user errors in the syntax tree.Design Rationale
You’ll notice that
DeclNameandDeclNameRefare more explicit than their compiler equivalents. As I explained in my last forum post, my rationale was that being forced to consider all cases ultimately reduces logic bugs. Of course, I’m open to revising this API.MemberKindis implemented in terms of mutually exclusive flags. For instance, there’s no built-inincludeStaticflag. It is instead a composition ofincludeNonTypeStaticandincludeTypes. This design streamlines filtering and modifying member kind. (For instance, when performing lookup on a metatype, we can easily and correctly restrict the member kind to look at only static declarations through the.onlyStaticmethod)As for testing, I added extensive tests for value declarations since they form the backbone of result filtering. Also, I added an assertion API that helps us test
findDirectMembesresults more concisely and intuitively.Open Questions / Future Work
callAsFunctiongets a special declaration name, perhaps we could do the same for:dynamicallyCall(withArguments:),dynamicallyCall(withKeywordArguments:), andsubscript(dynamicMember:).@abiand@_implements