Stream: t-compiler/rust-analyzer

Topic: Are functionIds unique per Crate?


kev (Jan 01 2021 at 20:11, on Zulip):

Hi,

I noticed that ModuleId was defined as:

pub struct ModuleId {
    pub krate: CrateId,
    pub local_id: LocalModuleId,
}

and FunctionId was

pub struct FunctionId(salsa::InternId);

In this method: https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_def/src/item_scope.rs#L357

I think we are able to get the CrateID from just the FunctionID, does this mean that FunctionId's are unique across crates? And it is only true while Crates are processed sequentially?

Florian Diebold (Jan 01 2021 at 20:12, on Zulip):

FunctionIds are unique globally

kev (Jan 01 2021 at 20:13, on Zulip):

Florian Diebold said:

FunctionIds are unique globally

Ah so if you wanted to process the dependencies for a crate in parallel, this would need to change? Or you would maybe have a LocalFunctionId and FunctionId like ModuleId?

kev (Jan 01 2021 at 20:13, on Zulip):

Or maybe it will always be this way?

Florian Diebold (Jan 01 2021 at 20:14, on Zulip):

why would it need to change?

kev (Jan 01 2021 at 20:14, on Zulip):

Florian Diebold said:

why would it need to change?

I thought it was a blocker for processing dependencies in parallel?

kev (Jan 01 2021 at 20:16, on Zulip):

Hmm or maybe that would not matter for incremental compilation as much, as it would only help on the first compilation

Florian Diebold (Jan 01 2021 at 20:16, on Zulip):

I don't see why it would be a blocker for that. FunctionIds aren't guaranteed to be in any kind of sequential order

Florian Diebold (Jan 01 2021 at 20:17, on Zulip):

they are interned IDs referring to the location of the function, i.e. the ID of the container plus the index in the container

Florian Diebold (Jan 01 2021 at 20:18, on Zulip):

the interning is synchronized, but it's very fast

kev (Jan 01 2021 at 20:18, on Zulip):

Florian Diebold said:

I don't see why it would be a blocker for that. FunctionIds aren't guaranteed to be in any kind of sequential order

Oh my thought process was that if the FunctionID is unique globally, then you cannot process two crates at the same time. Because then you may not have the functionIds be synchronised.

Hmm can you see where my logic fails?

kev (Jan 01 2021 at 20:20, on Zulip):

Florian Diebold said:

the interning is synchronized, but it's very fast

Oh, so the processing of dependencies will be parallel, but the IDs will be given out by the Interner which will guarantee that each Crate gets a unique FunctionID? And this would not be a bottleneck because the internet is fast?

Florian Diebold (Jan 01 2021 at 20:20, on Zulip):

yes

kev (Jan 01 2021 at 20:21, on Zulip):

Okay got it, thanks for explaining!

kev (Jan 01 2021 at 20:28, on Zulip):

kev said:

Hmm or maybe that would not matter for incremental compilation as much, as it would only help on the first compilation

What I said here is not entirely true when I think it through, because external dependencies once downloaded would not change but if you are in a workspace then I think parallel processing would help since all crates in the workspace have an _equal_ chance of being changed.

Last update: Jul 24 2021 at 20:30UTC