Skip to content

Only emit one copy-to-host or copy-to-accelerator compiler warning per source location, even if it has multiple host uses. #18402

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

Merged
merged 2 commits into from
Jul 31, 2018

Conversation

mhong
Copy link

@mhong mhong commented Jul 31, 2018

Resolves SR-8412.

@mhong
Copy link
Author

mhong commented Jul 31, 2018

@swift-ci please test tensorflow

@mhong mhong requested review from lattner and rxwei and removed request for lattner July 31, 2018 17:32
// DenseMap/DenseSet key type instead of SourceRange. That would require that
// the call-site translate a SILLocation / SourceRange to line and column
// numbers first.
template<> struct DenseMapInfo<SourceRange> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go in the header that defines SourceRange, and upstreamed :-)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do!

// Emit the warning on this value, if that has not been done before.
if (!copyToAccelWarningLocs.insert(loc.getSourceRange()).second)
return;

diagnose(ctx, loc.getSourceLoc(), diagID, description)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you need to unique based on the entire source range? Would it be fine to just unique based on loc.getSourceLoc() ? That would eliminate the need for template specialization entirely.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DenseMapInfo is not defined for SourceLoc either, so I might as make SourceRange work as the key type.

Compiler error for using llvm::DenseSet<SourceLoc> copyToHostWarningLocs:

/usr/local/google/home/hongm/ssd_part/git/swift-base/llvm/include/llvm/ADT/DenseMap.h:421:22: error: no member named 'getEmptyKey' in 'llvm::DenseMapInfo<swift::SourceLoc>'
    return KeyInfoT::getEmptyKey();

Copy link
Contributor

@rxwei rxwei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fix! LGTM.

// the call-site translate a SILLocation / SourceRange to line and column
// numbers first.
template<> struct DenseMapInfo<SourceRange> {
static SourceRange getEmptyKey() { return SourceRange(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider making the empty key and the tombstone key different?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Mingsheng Hong added 2 commits July 31, 2018 14:09
@mhong mhong force-pushed the warning_per_loc branch from cd374b9 to 91c8f4b Compare July 31, 2018 21:11
@mhong mhong merged commit 10fd132 into swiftlang:tensorflow Jul 31, 2018
@mhong mhong deleted the warning_per_loc branch July 31, 2018 21:12
mhong pushed a commit to mhong/swift that referenced this pull request Jul 31, 2018
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants