-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Ensure that SourceFiles always have a backing buffer in the SourceManager #76512
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
Ensure that SourceFiles always have a backing buffer in the SourceManager #76512
Conversation
…butes When rendering a swift_attr attribute for parsing, we were creating both the backing buffer and a source file, but not providing the buffer's ID to the source file, so we couldn't find the source code again. Fix that. While here, also register the source file with the module, so we can find the source file again based on location.
…ager The "buffer ID" in a SourceFile, which is used to find the source file's contents in the SourceManager, has always been optional. However, the effectively every SourceFile actually does have a buffer ID, and the vast majority of accesses to this information dereference the optional without checking. Update the handful of call sites that provided `nullopt` as the buffer ID to provide a proper buffer instead. These were mostly unit tests and testing programs, with a few places that passed a never-empty optional through to the SourceFile constructor. Then, remove optionality from the representation and accessors. It is now the case that every SourceFile has a buffer ID, simplying a bunch of code.
@swift-ci please smoke test |
@swift-ci please test source compatibility |
ParsingOptions parsingOpts, bool isPrimary) | ||
: FileUnit(FileUnitKind::Source, M), BufferID(bufferID ? *bufferID : -1), | ||
: FileUnit(FileUnitKind::Source, M), BufferID(bufferID), | ||
ParsingOpts(parsingOpts), IsPrimary(isPrimary), Kind(K) { | ||
M.getASTContext().addDestructorCleanup(*this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this assert that the buffer ID isn't ~0
or is that now valid (if... very unlikely to be encountered in the wild)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea!
-1 was once used as a sentinel value for "no buffer"; make sure it doesn't persist anywhere.
@swift-ci please test |
@swift-ci please smoke test |
@swift-ci please smoke test |
The "buffer ID" in a SourceFile, which is used to find the source file's contents in the SourceManager, has always been optional. However, the effectively every SourceFile actually does have a buffer ID, and the vast majority of accesses to this information dereference the optional without checking.
Update the handful of call sites that provided
nullopt
as the buffer ID to provide a proper buffer instead. These were mostly unit tests and testing programs, with a few places that passed a never-empty optional through to the SourceFile constructor. The code that created a source buffer to parse Cswift_attr
attributes also failed to pass that source buffer through.Then, remove optionality from the representation and accessors. It is now the case that every SourceFile has a buffer ID, simplying a bunch of code.