Stream: t-compiler/wg-rls-2.0

Topic: How is parsing and analyzing after an edit done?


osa1 (Apr 30 2020 at 20:31, on Zulip):

I'm trying to understand how rust-analyzer updates the AST after an edit, and re-run or update analyses. I'm guessing it takes an incremental approach and doesn't re-run everything from scratch, but I'm not sure where to look for how this is implemented. Given an edit (say I turn a normal function into an async function by adding the keyword "async") how does rust-analyzer updates the AST, analysis results etc.? Which files/modules should I be looking at?

Thanks!

matklad (Apr 30 2020 at 20:32, on Zulip):

The entry point here is RootDatabase::apply_change (change.rs)

matklad (Apr 30 2020 at 20:32, on Zulip):

Though, that method is rather boring -- mostly is says "ok, now this file has this content"

matklad (Apr 30 2020 at 20:33, on Zulip):

Figuring out which caches need to be invalidates is the job of salsa: https://github.com/salsa-rs/salsa

osa1 (Apr 30 2020 at 21:48, on Zulip):

Thanks! I'm trying to find where does re-parsing happen (after a set_file_text_with_durability). Presumely salsa calls rust-analyzer at some point, right? Which rust-analyzer function does it call with the new file contents?

matklad (May 01 2020 at 09:04, on Zulip):

That would be SourceDatabase::parse function, defined in ra_db/lib.rs

osa1 (May 01 2020 at 09:37, on Zulip):

Thanks! Where do I look for generation of red tree from a green tree?

matklad (May 01 2020 at 09:47, on Zulip):

That would to rowan crate

matklad (May 01 2020 at 09:47, on Zulip):

https://github.com/rust-analyzer/rowan/tree/master/src

matklad (May 01 2020 at 09:47, on Zulip):

green is green, cursor is red, violets are blue, naming is hard

osa1 (May 01 2020 at 10:26, on Zulip):

What is the reason for InternId to have type NonZeroU32 instead of u32 ? Optimizations?

matklad (May 01 2020 at 10:32, on Zulip):

Yup, so that Option<InternId> takes 32 bits

Last update: Oct 28 2020 at 18:00UTC