I’m trying to get a prototype together that uses rustc to typecheck an expr very fast (I’m aiming for <100ms). This is to help the ide tools initiative (+ my racer project).
By dynamically stripping the input text as it is loaded into rustc I was able to get typecking down to sub-second (Some more info here [1]). Unfortunately I think getting the time down significantly below this will require some caching of typeck’d HIR and side tables.
The approach I’m considering is to load and typecheck a skeleton ast of just type signatures (no function bodies), and then somehow just load and typeck individual function bodies on demand. It’s not clear to me the best way to achieve this, but it looks like I would need to modify all the stages to be able to process an Item rather than a full Crate.
Can anybody with rustc experience suggest if there’s a hack or shortcut I’m missing? Maybe there’s some way I could create a dummy crate to process just the function, but using the side-tables from the other crate?
Any suggestions or pointers would be much appreciated!
I think you’ll have to give much more details about what you’re thinking/how to achieve it, because (a) there’s no way to stop immediately after coherence checking, and (b) it doesn’t obviously (to me at least) solve the fundamental problem of caching/reusing previous computation.
Sorry, I had to be AFK after I posted this. Actually, you may also want to also do wf+item-type checking (in a different thread and tcx?), not only coherence checking. This can be done by modifying rustc_typeck::check::check_item_bodies (or its caller, rustc_typeck::check_crate) to e.g. run a server instead of a visitor.
Hi @arielb1, @huon, Yes parsing, expansion and resolution are a big part of the problem. I need to do some more experimenting here and I haven’t had much spare time with the keyboard over the last few days (kids are off school this week!).
I was wondering about parsing a crate with only the target Item in it plus parent modules e.g.
mod1 { mod2 {
fn myfunction() {...}
} }
and then somehow expanding + resolving using the session from the previously processed skeleton crate. I’ll try and find some time to experiment over the weekend.
Ask @nrc to help you with parsing+expansion. Resolution should be relatively easy - find a way to reuse the Resolver from rustc_resolve - but expansion is ugly. Maybe for a prototype just erase all macros, or hardcode some important ones (e.g. try!).