-
Notifications
You must be signed in to change notification settings - Fork 440
[SourceLocation] Extract and rework line tables #2900
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
Conversation
e430317
to
3848831
Compare
@swift-ci Please test |
@swift-ci Please test |
3848831
to
74765fd
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
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.
Nice
public var fileName: String | ||
/// Line number offset from the physical line number. | ||
public var lineOffset: Int | ||
/// The position of the filename literal. |
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.
Could you elaborate what fileNamePosition
is, maybe with an example? It’s not immediately clear to me.
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.
For example, for #sourceLocation(file: "input", line: 12)
, fileNamePosition
is the position of "input"
. This is needed by the compiler to diagnose them later in the compiler. See https://github.com/swiftlang/swift/blob/50175c7e41120facbea67fc57af810e15f646675/test/ASTGen/sourcelocation.swift#L28-L39
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.
Would you mind adding a comment for that?
|
||
extension SortedArray: Sendable where Element: Sendable {} | ||
|
||
/// Represent a virtual file region in the source file. |
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.
Could you give an example what virtual files are used for here? Does #sourceLocation
create a virtual file or are virtual files for macro expansions etc.?
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.
VirtualFile
corresponds to swift::SourceManager::VirtualFile
This will be used for populating swift::SourceManager
's table see swiftlang/swift#77721
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.
I think a doc comment would be helpful for this.
74765fd
to
1250cfd
Compare
@swift-ci Please test |
@swift-ci Please smoke test |
* `computeLines` now produces newly introducded 'SourceLineTable'. * `SourceLineTable` is factored out line tables and `#sourceLocation` directive info, extracted from `SourceLocationConverter`. * `forEachLineLength` is now `forEachEndOfLine` which emits the absolute position of each end-of-line, instead of the line length, because the caller can easily derive the start-of-line position (i.e. the last end-of-line). * `#sourceLocation` info are now handled differently. Specifically, while traversing the syntax tree, it only collects the raw syntax, then post-process those info to produce the newly introduced `VirtualFile`. `VirtualFile` is a type that have enough infomation for `swift::SourceMamanger` in the compiler. Post-processing is needed because we want the start position of the _next_ line of the end of `#sourceLocation` directive, which might still not available when the first pass sees the directive. * In the future, the compiler shoud only use `SourceLineTable` instead of `SourceLocationConverter` as `swift::SourceManager` already know the file name and the whole source buffer.
1250cfd
to
42cff3a
Compare
@swift-ci Please test |
@swift-ci Please test Windows |
@swift-ci Please test |
computeLines
now produces newly introducded 'SourceLineTable'.SourceLineTable
is factored out line tables and#sourceLocation
directive info, extracted fromSourceLocationConverter
.forEachLineLength
is nowforEachEndOfLine
which emits the absolute position of each end-of-line, instead of the line length, because the caller can easily derive the start-of-line position (i.e. the last end-of-line).#sourceLocation
info are now handled differently. Specifically, while traversing the syntax tree, it only collects the raw syntax, then post-process those info to produce the newly introducedVirtualFile
.VirtualFile
is a type that have enough infomation forswift::SourceMamanger
in the compiler. Post-processing is needed because we want the start position of the next line of the end of#sourceLocation
directive, which might still not available when the first pass sees the directive.SourceLineTable
instead ofSourceLocationConverter
asswift::SourceManager
already know the file name and the whole source buffer.No significant performance change by this.
before:
after