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
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.
| Language | Checked against | Call edges | Disagreements | How much of the referee’s answer is an edge |
|---|---|---|---|---|
| Go | go/types | 64,579 | 0 | 93% to 98% of the true static calls to the repository’s functions, on six repositories |
| Rust | rust-analyzer | 19,218 | 1, in a file rust-analyzer treats as compiled out | 73% to 96% of the definitions it finds, on five repositories |
| Python | jedi | 5,731 | 0 | 71% to 93% of the definitions it finds, on four repositories |
| TypeScript, JavaScript | the TypeScript compiler | 2,316 | 0 | 95.7% to 100% of the functions it finds, on three repositories |
| C | clang | 14,206 | 0 | 99.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.
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.
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.
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.
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.
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.