Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
SerializeLoc: serialize basic decl source location information to .swiftsourceinfo file #27464
After setting up the .swiftsourceinfo file, this patch starts to actually serialize and de-serialize source locations for declaration. The binary format of .swiftsourceinfo currently contains these three records:
BasicDeclLocs: a hash table mapping from a USR ID to a list of basic source locations. The USR id could be retrieved from the following DeclUSRs record using an actual decl USR. The basic source locations include a file ID and the results from Decl::getLoc(), ValueDecl::getNameLoc(), Decl::getStartLoc() and Decl::getEndLoc(). The file ID could be used to retrieve the actual file name from the following SourceFilePaths record. Each location is encoded as a line:column pair.
DeclUSRS: a hash table mapping from USR to a USR ID used by location records.
SourceFilePaths: a hash table mapping from a file ID to actual file name.
BasicDeclLocs should be sufficient for most diagnostic cases. If additional source locations are needed, we could always add new source location records without breaking the backward compatibility. When de-serializing the source location from a module-imported decl, we calculate its USR, retrieve the USR ID from the DeclUSRS record, and use the USR ID to look up the basic location list in the BasicDeclLocs record.
For more details about .swiftsourceinfo file: https://forums.swift.org/t/proposal-emitting-source-information-file-during-compilation
brentdax left a comment
I'm not going to pretend I had the attention span to read every line in detail, but it looked alright in my skim. If there's something specific you want me to examine more minutely, please let me know.
… in .swiftsourceinfo file For .swiftdoc file, we don't expose doc-comments for underscored symbols. But this seems to be an unnecessary constraint on .swiftsourceinfo file since we put these symbols in .swiftinterface files anyway.
After this change, we only use one single hash table for USR to USR id mapping. The basic source locations are an array of fixed length records that could be retrieved by using the USR id since each USR id is guaranteed to be associated with one basic location entry. The source file paths are refactored to a blob of 0-terminated strings. Decl locations use offset in this blob to refer to the source file path where the decl was defined.
…/Project This directory should be excluded during installation since the content is only used for local development. swiftsourceinfo file is currently emitted to this directory.
I think that this may have caused a regression on Windows: https://dev.azure.com/compnerd/windows-swift/_build/results?buildId=11097&view=logs&j=b9e62f99-1a98-5ed7-01d2-f4794231ed79&t=6116924f-95b5-5652-9734-6b3f0d96ecae&l=922