Skip to content

SYSTEM Cited by 1 source

Angle (Glean query language)

Angle is the declarative logic-based language used for both schemas and queries in Meta's Glean code-indexing system. "Angle is an anagram of Glean, and means 'to fish'" (Source: sources/2025-01-01-meta-indexing-code-at-scale-with-glean).

Model

Angle is built around three primitives:

  • Predicate"roughly equivalent to a table in SQL". Defined as a record type with named fields.
  • Fact — an instance of a predicate; "roughly equivalent to rows in SQL".
  • Derived predicate — a predicate computed from other predicates via logic rules; derivation can happen "on-the-fly at query time or ahead of time." This is the schema-level mechanism for defining views (see patterns/language-neutral-schema-abstraction).

Schema example

From the post, the C++ schema fragment:

predicate FunctionDeclaration {
  name : string,
  namespace : string,
  location : Source
}

Defining a schema "is just like writing a set of type definitions." Each language Glean indexes has its own schema; non-language data can also be schema'd.

Query example

Find folly::parseJson:

FunctionDeclaration { name = "parseJson", namespace = "folly" }

Angle queries are prefix-indexed over field order declared in the predicate. "To query efficiently you specify a prefix of the fields… Glean can return results for this query in about a millisecond" for a name + namespace lookup.

More complex queries compose predicates. Example from the post: find "all classes that inherit from a class called exception and have a method called what that overrides a method in a base class." Results stream incrementally ("because there might be a lot of results we can fetch the results incrementally from the query server"), with "first results in a few milliseconds."

Derived predicates

Derivation lets Angle "abstract over language-specific data and provide a language-neutral view of the data. This means that we don't have to compromise between having detailed language-specific data or a lowest-common-denominator language-neutral view; we can have both."

The mechanism is analogous to SQL views: define a predicate whose facts are derived from rules over other predicates. A cross-language query (e.g. "all declarations in this file") hits a derived predicate that unions / projects over each language's native fact shape. Derivation is the architectural load-bearing piece that makes Glean's "we don't pick a data model for you" bet viable without forcing clients to learn each language's schema.

Derivation also powers incremental indexing

The transitive closure needed to compute the fanout of a set of changes is itself expressible as an Angle query — for C++, "the fanout is calculated by finding all the files that #include one of the changed files, and then repeating that query until there are no more files to find." This is a fixpoint computation over derived predicates, not a hand-written graph-traversal in the indexing driver.

Positioning vs similar languages

The post does not name a prior-art language, but Angle is recognisably in the Datalog / logic-programming lineage: declarative, bottom-up, supports transitive closures, first-order predicate logic. Trade-off: expressive power + automatic derivation comes at the cost of a non-SQL learning curve for schema authors.

Seen in

Last updated · 319 distilled / 1,201 read