Skip to content

Commit

Permalink
complete migration to TypeInfo
Browse files Browse the repository at this point in the history
Summary:
There are two type predicates in the Hack schema.

The legacy, deprecated, `type`, and the most recent `TypeInfo`.

`TypeInfo` contains the pretty-printed type, but also xrefs relative to that string. Codehub uses it to generate go-to-def links the API doc page.

Not all definitions contain a TypeInfo field yet. This diff updates the schema to add it everywhere.

Motivation:
 - consistency
 - if we want to index the Hack type AST, it'll be simpler to add a new field in TypeInfo, which is now available everywhere (see linked task)

Reviewed By: pepeiborra, donsbot

Differential Revision: D62471296

fbshipit-source-id: 17bf41cab000600d294058b9a3c4293c4504ecd2
  • Loading branch information
Philippe Bidinger authored and facebook-github-bot committed Sep 13, 2024
1 parent 4046373 commit 5d1f21a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 22 deletions.
2 changes: 1 addition & 1 deletion glean/glass/Glean/Glass/Pretty/Hack.hs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ toReifyKind Hack.ReifyKind_Erased = Erased
toReifyKind (Hack.ReifyKind__UNKNOWN _) = Erased

toConstraint :: Hack.Constraint -> Constraint
toConstraint (Hack.Constraint kind ty) =
toConstraint (Hack.Constraint kind ty _typeInfo) =
Constraint (toConstraintKind kind) (toType $ Just ty)

toConstraintKind :: Hack.ConstraintKind -> ConstraintKind
Expand Down
39 changes: 20 additions & 19 deletions glean/schema/cpp/schema.h
Original file line number Diff line number Diff line change
Expand Up @@ -11389,7 +11389,7 @@ namespace Hack {

enum class TypeConstKind { Abstract, Concrete, PartiallyAbstract };

struct TypeConstDefinition : Predicate<std::tuple<Fact<TypeConstDeclaration>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<Type>>>, TypeConstKind, std::vector<Fact<UserAttribute>>>> {
struct TypeConstDefinition : Predicate<std::tuple<Fact<TypeConstDeclaration>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<Type>>>, TypeConstKind, std::vector<Fact<UserAttribute>>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<TypeInfo>>>>> {
static const char* GLEAN_name() {
return "hack.TypeConstDefinition";
}
Expand Down Expand Up @@ -11469,7 +11469,7 @@ struct QName : Predicate<std::tuple<Fact<Name>, boost::variant<Alt<0, std::tuple
}
}; // struct QName

struct PropertyDefinition : Predicate<std::tuple<Fact<PropertyDeclaration>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<Type>>>, Visibility, bool, bool, bool, std::vector<Fact<UserAttribute>>>> {
struct PropertyDefinition : Predicate<std::tuple<Fact<PropertyDeclaration>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<Type>>>, Visibility, bool, bool, bool, std::vector<Fact<UserAttribute>>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<TypeInfo>>>>> {
static const char* GLEAN_name() {
return "hack.PropertyDefinition";
}
Expand Down Expand Up @@ -11757,7 +11757,7 @@ struct GlobalNamespaceAlias : Predicate<std::tuple<Fact<Name>, Fact<NamespaceQNa
}
}; // struct GlobalNamespaceAlias

struct GlobalConstDefinition : Predicate<std::tuple<Fact<GlobalConstDeclaration>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<Type>>>, std::string>> {
struct GlobalConstDefinition : Predicate<std::tuple<Fact<GlobalConstDeclaration>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<Type>>>, std::string, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<TypeInfo>>>>> {
static const char* GLEAN_name() {
return "hack.GlobalConstDefinition";
}
Expand Down Expand Up @@ -11797,7 +11797,7 @@ struct Enumerator : Predicate<std::tuple<Fact<Name>, Fact<EnumDeclaration>>> {
}
}; // struct Enumerator

struct EnumDefinition : Predicate<std::tuple<Fact<EnumDeclaration>, Fact<Type>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<Type>>>, std::vector<Fact<Enumerator>>, std::vector<Fact<UserAttribute>>, std::vector<Fact<EnumDeclaration>>, bool, boost::variant<Alt<0, std::tuple<>>, Alt<1, ModuleMembership>>>> {
struct EnumDefinition : Predicate<std::tuple<Fact<EnumDeclaration>, Fact<Type>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<TypeInfo>>>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<Type>>>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<TypeInfo>>>, std::vector<Fact<Enumerator>>, std::vector<Fact<UserAttribute>>, std::vector<Fact<EnumDeclaration>>, bool, boost::variant<Alt<0, std::tuple<>>, Alt<1, ModuleMembership>>>> {
static const char* GLEAN_name() {
return "hack.EnumDefinition";
}
Expand Down Expand Up @@ -12622,7 +12622,7 @@ enum class ConstraintKind { As, Equal, Super };
} // namespace schema

template<> struct Repr_<facebook::glean::cpp::schema::Hack::Constraint> {
using Type = Tuple<Repr<facebook::glean::cpp::schema::Hack::ConstraintKind>, facebook::glean::cpp::schema::Hack::Type>;
using Type = Tuple<Repr<facebook::glean::cpp::schema::Hack::ConstraintKind>, facebook::glean::cpp::schema::Hack::Type, Maybe<facebook::glean::cpp::schema::Hack::TypeInfo>>;
};


Expand All @@ -12633,33 +12633,34 @@ namespace Hack {
struct Constraint {
ConstraintKind constraintKind;
Fact<Type> type;
boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<TypeInfo>>> typeInfo;

bool operator==(const Constraint& other) const {
return std::tie(constraintKind,type)
== std::tie(other.constraintKind,other.type);
return std::tie(constraintKind,type,typeInfo)
== std::tie(other.constraintKind,other.type,other.typeInfo);
}
bool operator!=(const Constraint& other) const {
return std::tie(constraintKind,type)
!= std::tie(other.constraintKind,other.type);
return std::tie(constraintKind,type,typeInfo)
!= std::tie(other.constraintKind,other.type,other.typeInfo);
}
bool operator<(const Constraint& other) const {
return std::tie(constraintKind,type)
< std::tie(other.constraintKind,other.type);
return std::tie(constraintKind,type,typeInfo)
< std::tie(other.constraintKind,other.type,other.typeInfo);
}
bool operator<=(const Constraint& other) const {
return std::tie(constraintKind,type)
<= std::tie(other.constraintKind,other.type);
return std::tie(constraintKind,type,typeInfo)
<= std::tie(other.constraintKind,other.type,other.typeInfo);
}
bool operator>(const Constraint& other) const {
return std::tie(constraintKind,type)
> std::tie(other.constraintKind,other.type);
return std::tie(constraintKind,type,typeInfo)
> std::tie(other.constraintKind,other.type,other.typeInfo);
}
bool operator>=(const Constraint& other) const {
return std::tie(constraintKind,type)
>= std::tie(other.constraintKind,other.type);
return std::tie(constraintKind,type,typeInfo)
>= std::tie(other.constraintKind,other.type,other.typeInfo);
}
void outputRepr(Output<Repr<Constraint>> out) const {
outputValue(out, std::make_tuple(constraintKind, type));
outputValue(out, std::make_tuple(constraintKind, type, typeInfo));
}
}; // struct Constraint

Expand Down Expand Up @@ -12782,7 +12783,7 @@ struct ClassDeclaration : Predicate<std::tuple<Fact<QName>>> {
}
}; // struct ClassDeclaration

struct ClassConstDefinition : Predicate<std::tuple<Fact<ClassConstDeclaration>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<Type>>>, boost::variant<Alt<0, std::tuple<>>, Alt<1, std::string>>>> {
struct ClassConstDefinition : Predicate<std::tuple<Fact<ClassConstDeclaration>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<Type>>>, boost::variant<Alt<0, std::tuple<>>, Alt<1, std::string>>, boost::variant<Alt<0, std::tuple<>>, Alt<1, Fact<TypeInfo>>>>> {
static const char* GLEAN_name() {
return "hack.ClassConstDefinition";
}
Expand Down
11 changes: 9 additions & 2 deletions glean/schema/source/hack.angle
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ type ConstraintKind = enum { As | Equal | Super }
type Constraint =
{
constraintKind : ConstraintKind,
type: Type,
type: Type, # deprecated, replaced by TypeInfo
typeInfo: maybe TypeInfo
}

type ReadonlyKind = enum { Readonly }
Expand Down Expand Up @@ -298,9 +299,11 @@ predicate TraitDefinition :
predicate EnumDefinition :
{
declaration : EnumDeclaration,
enumBase: Type,
enumBase: Type, # deprecated, replaced by TypeInfo
enumBaseTypeInfo: maybe TypeInfo,
# 'as' type; always nothing for enum classes
enumConstraint: maybe Type,
enumConstraintTypeInfo: maybe TypeInfo,
enumerators : [Enumerator],
attributes : [UserAttribute],
# uses for normal enums, and extends for enum classes
Expand Down Expand Up @@ -345,6 +348,7 @@ predicate PropertyDefinition :
isAbstract : bool,
isStatic : bool,
attributes : [UserAttribute],
typeInfo: maybe TypeInfo
}

# Definition of a Hack global (top-level) constant
Expand All @@ -353,6 +357,7 @@ predicate GlobalConstDefinition :
declaration : GlobalConstDeclaration,
type : maybe Type,
value : string,
typeInfo: maybe TypeInfo,
}

# Definition of a member constant
Expand All @@ -362,6 +367,7 @@ predicate ClassConstDefinition :
type : maybe Type,
# A none/nothing value indicates an abstract const
value : maybe string,
typeInfo: maybe TypeInfo
}

type TypeConstKind = enum { Abstract | Concrete | PartiallyAbstract }
Expand All @@ -373,6 +379,7 @@ predicate TypeConstDefinition :
type : maybe Type,
kind : TypeConstKind,
attributes : [UserAttribute],
typeInfo: maybe TypeInfo
}

# Definition of a Hack function
Expand Down

0 comments on commit 5d1f21a

Please sign in to comment.