Skip to content

[IDE] Pass a SourceRange instead of a CharSourceRange in SemaAnnotator::passReference #81975

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 5, 2025

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented Jun 4, 2025

Most SemaAnnotators don’t actually care about the char source range. Instead, they only care about the start location of the reference, which is also included in SourceRange. Computing a CharSourceRange from a SourceRange is kind of expensive because it needs to start a new lexer.

To avoid this overhead, pass SourceRange to SemaAnnotator::passReference and related functions and let the clients compute the CharSourceRange when needed.

This reduces the overhead of index-while-building by about 10%.

@ahoppen
Copy link
Member Author

ahoppen commented Jun 4, 2025

@swift-ci Please smoke test

…otator::passReference`

Most `SemaAnnotator`s don’t actually care about the char source range. Instead, they only care about the start location of the reference, which is also included in `SourceRange`. Computing a `CharSourceRange` from a `SourceRange` is kind of expensive because it needs to start a new lexer.

To avoid this overhead, pass `SourceRange` to `SemaAnnotator::passReference` and related functions and let the clients compute the `CharSourceRange` when needed.

This reduces the overhead of index-while-building by about 10%.
@ahoppen ahoppen force-pushed the sema-annotate-source-range branch from cd19463 to c6c40de Compare June 4, 2025 16:04
@ahoppen
Copy link
Member Author

ahoppen commented Jun 4, 2025

@swift-ci Please smoke test

assert(Range.getByteLength() > 3);
assert(Range.str().starts_with("`_") ||
Range.str().starts_with("`$"));
CharSourceRange CharRange = Lexer::getCharSourceRangeFromSourceRange(
Copy link
Contributor

Choose a reason for hiding this comment

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

Does VD not have its name?

if (SeenDecls.insert(D).second)
tryDemangleDecl(D, Range, /*isRef=*/true);
tryDemangleDecl(D, CharRange, /*isRef=*/true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't really matter since this is swift-ide-test, but looks like tryDemangleDecl only uses the range to get the name again 🤷

@ahoppen ahoppen merged commit 021cdd4 into swiftlang:main Jun 5, 2025
3 checks passed
@ahoppen ahoppen deleted the sema-annotate-source-range branch June 5, 2025 11:49
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