Stream: t-compiler/rust-analyzer

Topic: Something stalls in the type inference?


matklad (Mar 29 2021 at 18:43, on Zulip):

I am seeing the following in the profilere output when typing at the top level in apply_change.rs:

 2183ms - handle_semantic_tokens_full_delta
     2183ms - highlight
         2090ms - infer:wait @ per_query_memory_usage
             2090ms - infer_query
                    2ms - crate_def_map:wait (17088 calls)
                    0ms - generic_params_query (1 calls)
                 2088ms - ???
matklad (Mar 29 2021 at 18:44, on Zulip):

Anyone has ideas about what that 2 semonds of ??? might be doing?

Laurențiu (Mar 29 2021 at 18:45, on Zulip):

What's per_query_memory_usage doing there?

matklad (Mar 29 2021 at 18:47, on Zulip):

hm, I suspect that might actually be the ansewer? Thanks for reading the paster text to me, @Laurențiu !

matklad (Mar 29 2021 at 18:47, on Zulip):

I suspect it just expands the macros

matklad (Mar 29 2021 at 19:03, on Zulip):

Wait, no, this is infer, it happens after expand

Laurențiu (Mar 29 2021 at 19:11, on Zulip):

Did you run the memory usage command?

matklad (Mar 29 2021 at 19:18, on Zulip):

No, I am typing in the file that implements this command

matklad (Mar 29 2021 at 19:22, on Zulip):

Will come back to this tomorrow, unless someone from other timezone beats me to it. This is as far as I've gone:

image.png

Laurențiu (Mar 29 2021 at 19:25, on Zulip):

matklad said:

No, I am typing in the file that implements this command

Oh, right

Jonas Schievink [he/him] (Mar 29 2021 at 19:56, on Zulip):

I've definitely seen this function take a while before, yeah

matklad (Mar 29 2021 at 20:08, on Zulip):

The big issue is not the time per se, but the fact that the works seems uncancellable

matklad (Mar 29 2021 at 20:10, on Zulip):

On the positeve side, thacking this made me realize that our existing profile calls can be used to decect missing cancellation: https://github.com/rust-analyzer/rust-analyzer/pull/8244

Jonas Schievink [he/him] (Mar 29 2021 at 20:17, on Zulip):

yeah, saw that PR, really nice trick!

matklad (Mar 30 2021 at 14:28, on Zulip):

stand-alone repro: https://github.com/rust-analyzer/rust-analyzer/issues/8263

matklad (Mar 30 2021 at 14:32, on Zulip):

@Florian Diebold do you want to look into that?

Florian Diebold (Mar 30 2021 at 15:19, on Zulip):

hmm. that's one of those functions that will be mostly replaced with a Chalk equivalent

Florian Diebold (Mar 30 2021 at 15:21, on Zulip):

so I wouldn't want to put much time into that right now

matklad (Mar 30 2021 at 15:23, on Zulip):

Makes sense. I looked into this a bit more, looks like the loop in

    fn resolve_obligations_as_possible(&mut self) {
        let obligations = mem::replace(&mut self.obligations, Vec::new());
        for obligation in obligations {

is queadratic for this particular case

matklad (Mar 30 2021 at 15:23, on Zulip):

We accumulate 500 obligations or so

Florian Diebold (Mar 30 2021 at 15:23, on Zulip):

ok, that's not so great and will not be impacted by the Chalk move

Jonas Schievink [he/him] (Mar 30 2021 at 15:24, on Zulip):

rustc solves this with the obligation forest data structure

Florian Diebold (Mar 30 2021 at 15:24, on Zulip):

I guess it's a few obligations for each of those macro calls? the problem might be that we don't manage to solve any of them

Florian Diebold (Mar 30 2021 at 15:26, on Zulip):

but also, if nothing changes we should be able to reuse a cached solution, if we're not then something may be wrong with that as well

matklad (Mar 30 2021 at 15:27, on Zulip):

Another bit: a lot of paths in that function are unresolved.

matklad (Mar 30 2021 at 15:27, on Zulip):

So we might hit some bad case around unknown type?

Florian Diebold (Mar 30 2021 at 16:10, on Zulip):

yes, probably

matklad (Mar 30 2021 at 17:19, on Zulip):

Also, the thing reproduces if run "expand macros recursively" and manually paste the output (removing noisy format! calls mnaually), so this is unrelated to macros

Florian Diebold (Apr 01 2021 at 19:51, on Zulip):

rust-analyzer#8285

Florian Diebold (Apr 01 2021 at 19:52, on Zulip):

but yeah that's a lot of obligations that we never manage to solve

Last update: Jul 26 2021 at 13:45UTC