-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Make swift::SourceLoc and swift::SourceRange usable as a key type for DenseSet/DenseMap. #18417
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
One use case is using DenseSet to manage a set of source locations, so that we emit at most one compiler diagnostic per location (see swiftlang#18402).
@lattner Who would you suggest we loop in for review? Thanks. |
include/swift/Basic/SourceLoc.h
Outdated
template <typename T> struct DenseMapInfo; | ||
|
||
template <> struct DenseMapInfo<swift::SourceRange> { | ||
static swift::SourceRange getEmptyKey() { return swift::SourceRange(); } |
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'd suggest changing this to:
SMLoc::getFromPointer(DenseMapInfo<const char *>::getEmptyKey())))
for consistency.
I can review it, LGTM. |
I do think you should use SourceLoc for your original test case, though. No reason to store twice as many pointers. |
@jrose-apple, I tried out a simple example like: public func test() {
var a = 1.0
a += 2.0
} In the SIL code, I find that the insts that read the old e.g. I saw these two insts:
vs
The former reads the old So it'd be safer to store the loc pair. We don't expect to generate a lot of sends/recvs warnings, but if performance ever becomes a concern, we can revisit this (e.g. maybe just warn on the first K occurrences globally, or within each function.) |
@swift-ci please test |
I mean, even the range isn't unique per instruction, because of implicit expressions, or just AST-level expressions that take more than one instruction. You could also have unrelated diagnostics at the same location. |
…te can decide whether to use a map key based on SourceLoc or SourceRange.
@jrose-apple Based on the feedback, I added DenseMapInfo specialization for SourceLoc as well. Once we downstream this patch into tensorflow branch, I can change the callsite to use SourceLoc as the key. Please let me know if there are more comments. Thank you! |
@swift-ci please test |
Build failed |
Build failed |
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.
This seems reasonable to me!
Thank you @jrose-apple! I'll attempt a merge. |
@swift-ci please test and merge |
1 similar comment
@swift-ci please test and merge |
One use case is using DenseSet to manage a set of source locations, so that we
emit at most one compiler diagnostic per location (see
#18402).