Skip to content

Commit

Permalink
Use set for the collection of xrefs in a file
Browse files Browse the repository at this point in the history
Summary:
The collection of xrefs in a file is really a set since it's unordered. We've had problems in the past when the Hack indexer was non-deterministic and would produce different arrays in different runs. That's currently not a problem, but using sets here is the right thing to do.

This should be a no-op.

Reviewed By: simonmar

Differential Revision: D67763122

fbshipit-source-id: 1b4b94a632edce3546b5095fe1ce137172cebab5
  • Loading branch information
Josef Svenningsson authored and facebook-github-bot committed Jan 9, 2025
1 parent f3292e6 commit cd71ec4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion glean/schema/cpp/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -13292,7 +13292,7 @@ struct XRef {
}
}; // struct XRef

struct FileXRefs : Predicate<std::tuple<Fact<facebook::glean::cpp::schema::Src::File>, std::vector<XRef>>> {
struct FileXRefs : Predicate<std::tuple<Fact<facebook::glean::cpp::schema::Src::File>, std::set<XRef>>> {
static const char* GLEAN_name() {
return "hack.FileXRefs";
}
Expand Down
8 changes: 4 additions & 4 deletions glean/schema/source/codemarkup.hack.angle
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ predicate HackFileEntityXRefLocations:
}
{ File, { Location, { span = Src } }, { decl = D } } where
hack.FileXRefs { file = File, xrefs = XRefs };
hack.XRef { target = { declaration = D }, ranges = Uses } = XRefs[..];
hack.XRef { target = { declaration = D }, ranges = Uses } = elements XRefs;
hack.DeclarationName D -> (hack.Name TargetName);
hack.DeclarationLocation { declaration = D, file = TargetFile, span = TargetSpan };
Location = codemarkup.types.Location { TargetName, TargetFile, { span = TargetSpan }, nothing };
Expand All @@ -56,7 +56,7 @@ predicate HackFileEntityXRefSpans:
}
{ File, Src, { decl = D } } where
hack.FileXRefs { file = File, xrefs = XRefs };
hack.XRef { target = { declaration = D }, ranges = Uses } = XRefs[..];
hack.XRef { target = { declaration = D }, ranges = Uses } = elements XRefs;
Sources = prim.relToAbsByteSpans Uses;
Src = Sources[..]

Expand Down Expand Up @@ -889,13 +889,13 @@ predicate ConvertCalleeForFileCall :
{ occurrence = {method = {name = N} } } = O;
hack.FileXRefs { File, XRefs };
# Look for resolved occurrences with the same method name in the call
{ target = {declaration = D }, ranges = Uses } = XRefs[..];
{ target = {declaration = D }, ranges = Uses } = elements XRefs;
{ method = { name = N } } = D;
Sources = prim.relToAbsByteSpans Uses;
S = Sources[..];
src.ByteSpanContains { Span, S };
# Match them with the unresolved occurrence
{ target = O, ranges = OUses } = XRefs[..];
{ target = O, ranges = OUses } = elements XRefs;
OSources = prim.relToAbsByteSpans OUses;
S = OSources[..];
{ just = { hack = { decl = D } } } = CodeCallee ) |
Expand Down
4 changes: 2 additions & 2 deletions glean/schema/source/hack.angle
Original file line number Diff line number Diff line change
Expand Up @@ -498,7 +498,7 @@ type XRef =
predicate FileXRefs :
{
file : src.File,
xrefs : [XRef],
xrefs : set XRef,
}

# Context-free information about an expression argument
Expand Down Expand Up @@ -541,7 +541,7 @@ predicate TargetUses :
stored
{ T, File, Uses } where
hack.FileXRefs { file = File, xrefs = XRefs };
hack.XRef { target = T, ranges = Uses } = XRefs[..]
hack.XRef { target = T, ranges = Uses } = elements XRefs

# A version of 'TargetUses' with the bytespans converted from relative to
# absolute offset format for convenience.
Expand Down

0 comments on commit cd71ec4

Please sign in to comment.