Skip to content

Commit

Permalink
hardcode enum member methods
Browse files Browse the repository at this point in the history
Summary:
enum classes inherit from these member functions https://www.internalfb.com/code/symbol/fbsource/php/HH/BuiltinEnum

> Under the hood, an enum Foo will extend BuiltinEnum<Foo>.

These relations aren't captured in Glean at the moment. We could get them from [here](https://www.internalfb.com/code/fbsource/[537c193db6f8]/fbcode/hphp/hack/src/typing/write_symbol_info/file_info.ml?lines=114)  but they've been filtered out for saving space/indexing time.

As a quick fix, I propose to hardcode them it in the schema to unblock itsnauman who requested this. I think they want to use "codemarkup.hack.HackEnumInheritedMembers" but I also added the inheritance relations in the codemarkup inheritance predicates.

Reviewed By: itsnauman

Differential Revision: D55808239

fbshipit-source-id: 0292ea515244c10b4d441e71ea6112c75cf77152
  • Loading branch information
Philippe Bidinger authored and facebook-github-bot committed Apr 9, 2024
1 parent 990ad18 commit 615c489
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"@generated": null,
"hack.ClassDefinition.6": 4,
"hack.ContainerParent.6": 11,
"hack.EnumDeclaration.6": 5,
"hack.InterfaceDefinition.6": 3,
"hack.MethodDefinition.6": 1,
"hack.MethodOverrides.6": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"@generated": null,
"hack.ContainerParent.6": 11,
"hack.DeclarationSpan.6": 23,
"hack.EnumDeclaration.6": 5,
"hack.MethodOverrides.6": 1
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"hack.ClassDefinition.6": 4,
"hack.ContainerParent.6": 11,
"hack.DeclarationSpan.6": 21,
"hack.EnumDeclaration.6": 5,
"hack.InterfaceDefinition.6": 3,
"hack.MethodDefinition.6": 1,
"hack.MethodOverrides.6": 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"@generated": null,
"hack.ContainerParent.6": 11,
"hack.DeclarationSpan.6": 23,
"hack.EnumDeclaration.6": 5,
"hack.MethodOverrides.6": 1
}
32 changes: 29 additions & 3 deletions glean/schema/source/codemarkup.hack.angle
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ predicate HackContainsParentEntity :
)

# parent contains child
# Enums inherits from HH\builtinEnum
predicate HackContainsChildEntity :
{
parent: code.hack.Entity,
Expand Down Expand Up @@ -364,8 +365,15 @@ predicate HackExtendsChildEntity :
) |
(
hack.MethodOverridden{base=P, derived=C};
{method=P}=Parent;
{method=C}=Child
{ method = P } = Parent;
{ method = C } = Child
) |
( { container =
{ class_ =
{ name = { name = "BuiltinEnum", namespace_ = { just = { name = "HH" } } } }
}
} = Parent;
{ container = { enum_ = _ } } = Child
)

# child extends parent
Expand All @@ -382,7 +390,25 @@ predicate HackExtendsParentEntity :
hack.MethodOverrides { derived=C, base=P };
{ method = C } = Child;
{ method = P } = Parent
)
) | (
{ container = { enum_ = _ } } = Child;
{ container =
{ class_ =
{ name = { name = "BuiltinEnum", namespace_ = { just = { name = "HH" } } } }
}
} = Parent
)

# All method in HH\builtinEnum which are inherited by enum types
predicate HackEnumInheritedMembers :
{
member_ : hack.MethodDeclaration
} { member_ = Md } where
hack.ClassDefinition {
declaration = { name = { name = "BuiltinEnum", namespace_ = {just = { name = "HH" } } } },
members = Ms
};
{ method = Md } = Ms[..]

# Inherited parents but drop those with "HideFromDocs" annotations
# Used to reduce the search space to "interesting" containers only
Expand Down

0 comments on commit 615c489

Please sign in to comment.