Skip to content
Peter Styk HPC & AI Platform Engineer

Project · A tool

OntoSys: a code repository as a graph you can query

OntoSys reads Go, Rust, Python, TypeScript, JavaScript and C with real parsers and records every function, class and import: where it is, what it calls, who calls it, and how complex it is. The result is RDF, so a repository can be explored, queried and compared release against release.

  • v0.15 the current release
  • 6 languages, each parsed with its own grammar
  • 106,050 call edges checked, 1 disagreement

Source and install on GitHubSpecialist readers, and their referees

requests 2.33.1 rewrote the function _parse_content_type_header. Two functions call it directly: get_encoding_from_headers, and the test test__parse_content_type_header, which changed in the same release. Two calls away are build_response, get_unicode_from_response and the test test_get_encoding_from_headers, which also changed. Three calls away is send, in the adapters module.
What one change reachesDownload SVG

What it answers

Who calls this, what a change reaches, what the comments promise

Explore

ontosys init reads the code into .ontosys/; ontosys serve opens it in a browser.

Ask

ontosys query takes SPARQL: who calls this function, which functions branch most.

Compare

ontosys diff and ontosys impact show what changed between two checkouts, entity by entity, and which callers each change reaches.

Check

ontosys claims checks what doc comments promise against the code.

Specialist readers

Five readers for six languages, each with its own referee

No general reader stands in for six languages. Each language is parsed with its own grammar into its own syntax tree, and each reader has its own rules for which function a call reaches; TypeScript and JavaScript share one reader. Those rules are then checked, on real projects, against the tool that language’s own community trusts. A call edge points at one function, or it is not drawn: where the source leaves the target open, the possible targets are recorded as candidates.

LanguageChecked againstCall edgesDisagreementsHow much of the referee’s answer is an edge
Gogo/types64,579093% to 98% of the true static calls to the repository’s functions, on six repositories
Rustrust-analyzer19,2181, in a file rust-analyzer treats as compiled out73% to 96% of the definitions it finds, on five repositories
Pythonjedi5,731071% to 93% of the definitions it finds, on four repositories
TypeScript, JavaScriptthe TypeScript compiler2,316095.7% to 100% of the functions it finds, on three repositories
Cclang14,206099.5% and 100% of the certain edges, on Redis and Lua

Nearly every call that is not an edge is kept as a candidate. The figures are the ones OntoSys v0.15 publishes in its README and reference.

Types and members

Every declared field, class attribute and interface member is a node with its declared type and its doc comment, and when its type is declared in the repository, it links to that declaration. Against go/types: all 5,420 Go fields that name a type the repository declares are linked. Against rust-analyzer: 907 links, none wrong. Against jedi: 331 links, none wrong.

What Go needs

The comment groups above a declaration’s doc are kept, each file links to its go.mod, and a type written over several lines is stated on one, as Go writes it: the text of 34 API interfaces matches an independent extractor exactly.

What C needs

The C reader follows includes and records the macros it rewrote to read the code. Headers that only C++, CUDA or HIP sources include are counted as not read, instead of being misread as C.

Complexity

Branching, nesting and loops for each function, and growth estimates that carry their evidence.

How it works

One build, five steps, one sorted graph

The same source, read by the same OntoSys version, gives the same bytes, so a graph can be kept, hashed and compared.

A build in five steps. Files: a checkout, minus what git ignores. Read: each language parsed with its own grammar into a syntax tree. Resolve: calls, language by language, as an edge to one function or as the candidates it may be. Measure: complexity and growth estimates. Write: one sorted graph, the same bytes for the same source and the same OntoSys version. The explorer, SPARQL queries, an export for an RDF store, and the comparison of two versions all read that graph.
From a checkout to a graphDownload SVG

What it writes

What the graph states

A project has files; a file declares types and imports; a function belongs to its file, an implementation or a trait, and calls other functions. The picture draws what v0.15 writes, and nothing it does not.

The main kinds in the graph and how they are joined. A project has files. A file declares structs, traits, implementations, enums and imports. A struct has fields, and a field points to the struct or trait its type names. A function belongs to its file, an implementation or a trait; it has parameters and calls other functions. Where the source leaves a call open, the function calls an external symbol that lists the candidate functions.
What the graph statesDownload SVG

Release against release

What changed, and who it reaches

Two checkouts are each built into a graph, and the graphs are compared. An identity carries no line numbers, so code that only moved is not reported as a change.

Two checkouts, requests 2.33.0 and 2.33.1, are each built into a graph. Diff lists what changed, entity by entity: five functions differ. Impact follows the callers of each changed function: _parse_content_type_header has two callers one call away, three more two calls away and one three calls away; two of them are tests changed in the same release. Claims checks what doc comments promise.
Two versions, comparedDownload SVG

In the browser

Who calls a function, and what it calls

ontosys serve opens the graph in a browser. Search for a function and draw its callers on one side and what it calls on the other; with --compare, changed entities are ringed and the panel shows what changed in each. A call the source leaves open, such as a method on a value whose type it does not state, is drawn apart from the calls settled to one function.

Session.request in requests 2.33.1. Ten functions call it: the seven HTTP-verb methods delete, get, head, options, patch, post and put, and three tests. It calls four functions of requests: Request.__init__, merge_environment_settings, prepare_request and send. Two more calls, to an update method and an upper method, could not be settled to one function.
Who calls a function, and what it callsDownload SVG
The function _parse_content_type_header in src/requests/utils.py, as the explorer reports its change from requests 2.33.0. The kind of change is implementation: the body changed; the signature and the calls did not. Cognitive complexity went from 6 to 4, deepest nesting from 3 to 2, statements from 15 to 12. Its definition hash changed, and its doc comment gained two full stops.
What changed in one functionDownload SVG

Both pictures are redrawn from the explorer’s own views of requests 2.33.1.

Versions 0.14 and 0.15

Faster on large repositories, and a build that says what it is doing

Apart from C++ headers no longer being read as C, neither release changed what a graph states. They changed how long it takes to state it, and how much a build tells you while it runs.

Python · v0.1448 sto build a 7,300-file Python repository that took 9 min 13 s before. The graph it writes is the same, byte for byte.
Rust · v0.1549 sfor a 2,078-file Rust workspace whose modules re-export each other. Before, it had not finished after 15 minutes.
C++ headers · v0.1518 times fewerC error nodes on a Python and C++ framework: 304,149 before, 16,926 after, now that C++ headers are not read as C.

A build journal

Each phase’s time and peak memory, progress every ten seconds, and the name of any function still being resolved after ten. A build that seems stuck says where.

Sorted on every core

The graph is sorted in parallel, with the same bytes: on a graph of 6.8 million statements the sort went from 16 seconds to 8.

A survey of a machine

ontosys survey reads every .ontosys/ folder below a directory and reports how each repository has moved. It never writes to a repository.

From OntoSys’s changelog, which leaves the repositories unnamed.

Works with

The graph, kept in PostgreSQL

OntoSys reads the code into RDF; pgRDF holds the graph inside PostgreSQL, judges it by shapes and answers SPARQL across it.

pgRDF

Other projects

Where else the study goes

All research