-
Notifications
You must be signed in to change notification settings - Fork 440
Make SourceLocation and related types Hashable #254
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
It seems natural to be able to compare ranges for equality. Currently this requires declaring manual `Equatable` conformance in libraries that use SwiftSyntax, which is error-prone.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Build failed |
@swift-ci please test |
Please feel free to merge when you see fit, I don't have commit access here. |
@@ -43,7 +43,7 @@ struct ComputedLocation: Codable, CustomDebugStringConvertible { | |||
} | |||
|
|||
/// Represents a source location in a Swift file. | |||
public struct SourceLocation: Codable, CustomDebugStringConvertible { | |||
public struct SourceLocation: Hashable, Codable, CustomDebugStringConvertible { |
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.
Just to be clear: Should two SourceLocation
s be different if one has a ComputedLocation
and the other does not? After all, they still refer to the same location in the source code.
I’m not 100% sure on this, but I’m leaning towards making the identity of SourceLocation
be purely based on the value of offset
. What do you think, @MaxDesiatov?
CC: @akyrtzi
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.
In my opinion they shouldn't be equal since line
, column
, and file
will return different results for them. The one without a ComputedLocation
could refer to a different file altogether, as file
is inferred from compLoc
.
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.
That’s a good point. I didn’t consider file
. With that in mind, I’m fine with keeping the implementation as-is.
It seems natural to be able to compare source locations for equality, or to add locations to a
Set
or use them as keys in dictionaries. Currently this requires declaring manualHashable
conformance in libraries that use SwiftSyntax, which is error-prone.