Skip to content

[AST] make ASTContext RawComment cache aware of serialization #36829

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 4 commits into from
Apr 9, 2021

Conversation

QuietMisdreavus
Copy link
Contributor

Resolves rdar://76162972

In situations where different parts of the codebase want to load raw comments, there's an ordering constraint between sections that don't want to load .swiftsourceinfo files (for performance reasons) and those that do (for completeness reasons). If a code with the former constraint loads the raw comment first, code with the latter constraint won't know to reload the comment to get all the information available. This caused a situation where emitting symbol graphs while compiling in batch mode (after #36270) would cause doc comments to lose their source-range information.

This PR adds a boolean to the RawComment cache in the ASTContext. This indicates whether the RawComment in question came from a RawDocCommentAttr or .swiftsourceinfo file. The existing SerializedOK flag then compares against the boolean from the cache to determine whether to discard the cached comment information and attempt to load the comment anyway. If SerializedOK is false, then the cached comment is used every time. If SerializedOK is true, then the cached comment will be used only if it came from the above situations.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please test

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please build toolchain macOS platform

/// This is some func.
public func someFunc() {}

// CHECK: range
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it worth checking the location here in case "range" is added as a key somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The problem is that the symbol graphs that come from the compiler are not formatted, so (as far as i know) there’s no easy way to check for a given line range without looking for the entire {“start”:4,”end”:15} sequence all at once. is there a way to pretty print JSON in a test, or should i just throw the whole sequence into a check condition?

@swift-ci
Copy link
Contributor

swift-ci commented Apr 9, 2021

Build failed
Swift Test Linux Platform
Git Sha - d24a2f5

@swift-ci
Copy link
Contributor

swift-ci commented Apr 9, 2021

macOS Toolchain
Download Toolchain
Git Sha - d24a2f5

Install command
tar -zxf swift-PR-36829-938-osx.tar.gz --directory ~/

@QuietMisdreavus
Copy link
Contributor Author

Linux test failed on Swift/LLDB tests? Going to try again, in case it was a fluke...

@swift-ci Please test Linux platform

@QuietMisdreavus
Copy link
Contributor Author

I've updated the test based on @bnbarham's comments.

@swift-ci Please smoke test

@swift-ci
Copy link
Contributor

swift-ci commented Apr 9, 2021

Build failed
Swift Test Linux Platform
Git Sha - d24a2f5

@QuietMisdreavus
Copy link
Contributor Author

Looks like the test i added in #36785 is flakier than anticipated. I'll fix it in this PR.

@QuietMisdreavus QuietMisdreavus force-pushed the QuietMisdreavus/serialize-aware-cache branch from 4d7aef0 to 34d8995 Compare April 9, 2021 17:40
@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

@QuietMisdreavus QuietMisdreavus force-pushed the QuietMisdreavus/serialize-aware-cache branch from 34d8995 to 2745247 Compare April 9, 2021 18:40
@QuietMisdreavus
Copy link
Contributor Author

The SymbolGraph/verbose test was disabled in #36844, so since i'm fixing it here, i'm also re-enabling it.

@swift-ci Please smoke test

@QuietMisdreavus QuietMisdreavus merged commit 51b71c7 into main Apr 9, 2021
@QuietMisdreavus QuietMisdreavus deleted the QuietMisdreavus/serialize-aware-cache branch April 9, 2021 21:58
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.

3 participants