Page MenuHomePhabricator

[clang][Basic] Make SourceLocation usable as key in hash maps, NFCI
ClosedPublic

Authored by miyuki on Oct 19 2020, 11:31 AM.

Details

Summary

This change creates a DenseMapInfo trait specialization for the
SourceLocation class. The empty key, the tombstone key, and the hash
function are identical to DenseMapInfo<unsigned>, because we already
have hash maps that use raw the representation of SourceLocation as
a key.

The update of existing DenseMaps containing raw representation of
SourceLocations will be done in a follow-up patch. As an example
the patch makes use of the new trait in one instance:
clang-tidy/google/UpgradeGoogletestCaseCheck.{h,cpp}

Diff Detail

Event Timeline

miyuki created this revision.Oct 19 2020, 11:31 AM
Herald added a project: Restricted Project. · View Herald TranscriptOct 19 2020, 11:31 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
miyuki requested review of this revision.Oct 19 2020, 11:31 AM
dexonsmith requested changes to this revision.Oct 19 2020, 2:20 PM

We don't usually add code without any current users. I suggest either adding a small unit test proving SourceLocation can now be used as a DenseMap key (probably preferred) or converting one DenseMap over so that it at least has one use.

This revision now requires changes to proceed.Oct 19 2020, 2:20 PM
miyuki updated this revision to Diff 299340.Oct 20 2020, 5:11 AM
miyuki edited the summary of this revision. (Show Details)

Added an example of usage.

This revision is now accepted and ready to land.Oct 20 2020, 5:52 AM
miyuki added a comment.EditedOct 20 2020, 7:52 AM

The test failure is unrelated (see D89463)

This revision was landed with ongoing or failed builds.Oct 20 2020, 7:53 AM
This revision was automatically updated to reflect the committed changes.