Skip to content

Commit 1d70540

Browse files
RedBeard0531MongoDB Bot
authored and
MongoDB Bot
committed
SERVER-98435 remove duplicate(ish) reported usages for method calls (#35325)
GitOrigin-RevId: 6034c17ff3abe111020011311c1f334de26846d7
1 parent 8692faa commit 1d70540

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

modules_poc/mod_scanner.py

+19
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,10 @@ def pretty_location(loc: clang.SourceLocation | clang.Cursor):
550550
# location, but have an extent. Use the start of the extent instead.
551551
extent_start = loc.extent.start # type: clang.SourceLocation
552552
loc = extent_start
553+
# NOTE: not using normpath_for_file() here because we don't want to convert
554+
# bazel-out/blah/src/mongo/beep to src/mongo/beep. All paths output by pretty_location
555+
# should be relative to the repo root. This is important for the browser to be able to
556+
# load the file. We still want to use os.path.normpath to fix up foo/bar/../baz to foo/baz.
553557
name = os.path.normpath(loc.file.name) if loc.file else "<unknown>"
554558
# return f"{name}({loc.line},{loc.column})" # MSVC format
555559
return f"{name}:{loc.line}:{loc.column}" # gcc format
@@ -743,6 +747,21 @@ def find_usages(mod: str, c: Cursor):
743747
assert not ref.location.file or mod_for_file(ref.location.file) is None
744748
return
745749

750+
if c.kind == CursorKind.CALL_EXPR and c.referenced.kind != CursorKind.CONSTRUCTOR:
751+
# For a call expression like a.b(c) or a::b(c) the whole thing is considered a reference of
752+
# a.b, but unfortunately the reported location is that of a, while we'd really want it to be
753+
# that of b. This was frequently resulting in two usage locations being reported for each
754+
# method call. Luckily, in most cases, the first child of the call expression (or one of its
755+
# transitive children) is the sub-expression a.b, which has a reference to b with the right
756+
# location. So we can safely ignore the call expression and rely on the post-order traversal
757+
# already adding a relevant used_from reference for this expression. The one exception is
758+
# that for constructor calls, the child refers to the *type* a::b, rather than the specific
759+
# constructor a::b::b() chosen, so we still need to add this location (even if not ideal) to
760+
# ensure that we mark the constructor's usage. I ran this with an assert to check that this
761+
# doesn't cause us to lose any usages, but it is too slow to keep (O(n^2) for n calls to a
762+
# method in a TU, causing some TUs to take several minutes).
763+
return
764+
746765
if is_local_decl(ref):
747766
return
748767

0 commit comments

Comments
 (0)