Skip to content

Expose read-only AST Node traversal API and internal classifiers#11

Open
sewerynplazuk wants to merge 1 commit into
oozoofrog:mainfrom
sewerynplazuk:support-node-traversal
Open

Expose read-only AST Node traversal API and internal classifiers#11
sewerynplazuk wants to merge 1 commit into
oozoofrog:mainfrom
sewerynplazuk:support-node-traversal

Conversation

@sewerynplazuk
Copy link
Copy Markdown

@sewerynplazuk sewerynplazuk commented May 4, 2026

This PR enables downstream tools to traverse the demangled AST to find the nominal owners of symbols. Currently, they have to manually duplicate compiler logic to guess what constitutes a "context" or "function attribute," which may break between Swift releases.

The changes are straightforward and don't add any new logic or maintenance burden to upstream. Please let me know if this is acceptable, as it does enforce some sort of public contract.

}

var isMacroExpandion: Bool {
public var isMacroExpansion: Bool {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed typo.

@oozoofrog
Copy link
Copy Markdown
Owner

oozoofrog commented May 10, 2026

Thanks for the follow-up to #9, @sewerynplazuk — and nice catch on the isMacroExpandionisMacroExpansion typo.

One concern before merging: exposing classifiers like isContext / isFunctionAttr makes their membership part of our public contract — and that membership tracks Swift compiler changes (e.g. .IsolatedDeallocator, .DefaultOverride were added recently). Same signature, drifting behavior across Swift releases — a subtle semver promise.

What if we exposed the goal directly instead?

public extension String {
    /// The nominal type or module that owns the demangled symbol.
    var nominalOwner: SymbolOwner? { get }
}

Internally it would reuse your classifiers but keep them internal — same pattern as the existing String.symbolKind. (If even that feels too much, var nominalChain: [String]? is the strict subset.)

Two questions to size this right:

  1. Could you share a short snippet of the current call site? If nominalOwner would replace it cleanly, easy call.
  2. Just the owner, or also adjacent info (type signatures, requirements, macro expansions)? If it's more than owners, your PR's shape may actually be the right one.

The String.node introduction looks worth keeping either way. Thanks for pushing this forward!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants