As part of Google Summer of Code 2026, I implemented a preliminary version of qualified name lookup in swift-syntax under the mentorship of Pavel Yaskevich (@xedin). Building on Jakub Florek’s GSoC 2024 unqualified-name-lookup project, this effort exposes syntactic queries formerly confined to the Swift compiler as an easy-to-use API in the swift-syntax package. Now, swift-syntax can find definitions of types and type members, like a simplified version of an editor’s “jump to definition” function. Namely, developers of build tools, such as linters, code generators and macros, can determine which declaration a TypeSyntax refers to, or find that type’s members.
- Contributor: Filip Sakellariou (@filip-sakel)
- Mentor: Pavel Yaskevich (@xedin)
- Organization: Swift
As part of Google Summer of Code 2026, I implemented a basic version of qualified name lookup in swift-syntax. Like the GSoC 2024 unqualified-name-lookup project, this effort exposes syntactic queries formerly confined to the Swift compiler as an easy-to-use API in the swift-syntax package. Developers of build tools, such as linters, code generators and macros, can now ask swift-syntax which declaration a type reference in the user’s code refers to, or to find members of a type.
Believe it or not, the diagram below is a simplified version 😅. Here's the main idea: you give TypeQualifier some type syntax (no semantic information), and it resolves it to extended nominal types: nominal declarations and all their accessible extensions.
First, we convert the given type syntax to an array of references we can more easily look up; e.g., (Collection & MyProto).Element becomes Collection.Element and MyProto.Element. Then, we split each type reference up into the base type and its member type; in our example, the base is Collection with member type Element. Like all type syntax, Collection depends on its declaration context, so we perform unqualified type lookup to find the referenced type declaration. For now, let’s assume unqualified lookup returns a nominal declaration. If the declaration is nested within an extension, its qualified name depends on the extended type, so we have to recursively resolve that before continuing. For instance, if we don’t resolve the extended type `
| // | |
| // TaskRacing.swift | |
| // | |
| // Created by Filip Sakel on 21/6/21. | |
| // | |
| import Dispatch | |
| // MARK: - Utilities |