ajtulloch / roogle

Rust API search engine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Roogle

This is a modification of Hoogle to allow searching Rust type signatures.

See https://github.com/ajtulloch/rust/tree/roogle for the RustDoc modifications necessary.

Approach

RustDoc generates JSON type signatures for method/functions invocations, of the form in Haskell

data Type = TApp Type [Type] -- a list of types, first one being the constructor
          | TLit String -- bound variables, Maybe, ":", "(,)", "(,,)" (tuple)
          | TVar String -- unbound variables, "a"
          | TFun [Type]

or in Rust,

pub enum HType {
    App(Box<HType>, Vec<Box<HType>>),
    Lit(String),
    Var(String),
    Fun(Vec<Box<HType>>)
}

For example,

fn lookup<T>(x: Vec<T>, y: int) -> Option<T>

has the Hoogle type

TFun [TApp 
      (TLit "(,)") 
        [TApp (TLit "Vec") [TVar "T"], 
        (TLit "int")],
      TApp (TLit "Option") [TVar "T"]]

Note that this does not capture the full generality of Rust’s type system (e.g. we ignore mutability, references, lifetime annotations). Thus when searching we don’t distinguish between cases like:

fn function_1(x: &int, y: &int) -> int
fn function_2(x: int, y: int) -> &int

These are generated by RustDoc in the course of the usual HTML generation approach, and Roogle parses these JSON files to construct it’s type database.

Once Roogle has the type signatures, we can use the existing sophisticated type-search infrastructure to search for types (see http://community.haskell.org/~ndm/hoogle/ and links therein for more detail).

Currently Implemented

  • Free Function
  • Method Implementations

Usage

First, generate the documentation hoogle.json files from RustDoc. (in $RUSTDIR$)

make docs

Next, parse the JSON files and generate the Roogle databases. (in $HOOGLE_DIR$)

cabal build
dist/build/hoogle/hoogle rustdoc $(find $RUSTDIR/doc -iname 'hoogle.json')

Finally, send some queries to Roogle,

∴ dist/build/hoogle/hoogle search "Path -> Path" | head -n8
"Loading database: ./rust.hoo"
Warning: Unknown type Path
clone :: Path -> Path
dir_path :: Path -> Path
make_absolute :: Path -> IoResult Path
readlink :: Path -> IoResult Path
realpath :: Path -> IoResult Path
make_non_verbatim :: Path -> Option Path
tulloch at tulloch-mbp in ~/src/hoogle (roogle)
∴ dist/build/hoogle/hoogle search "(AtomicBool) -> bool" | head -n5
"Loading database: ./rust.hoo"
Warning: Unknown type AtomicBool
load :: AtomicBool -> Ordering -> bool
compare_and_swap :: AtomicBool -> (,) bool bool Ordering -> bool
fetch_and :: AtomicBool -> (bool, Ordering) -> bool

You can also use the web interface, by calling

dist/build/hoogle/hoogle server --port 8080

and navigating to http://localhost:8080. For example,

http://i.imgur.com/mdiCh9R.png

About

Rust API search engine


Languages

Language:Haskell 86.9%Language:TeX 5.8%Language:JavaScript 4.0%Language:CSS 1.8%Language:C 0.8%Language:Shell 0.5%Language:Emacs Lisp 0.2%