rust/crates
bors[bot] f7f9757b6b
Merge #2396
2396: Switch to variant-granularity field type inference r=flodiebold a=matklad

r? @flodiebold 

Previously, we had a `ty` query for each field. This PR switcthes to a query per struct, which returns an `ArenaMap` with `Ty`s. 

I don't know which approach is better. What is bugging me about the original approach is that, if we do all queries on the "leaf" defs, in practice we get a ton of queries which repeatedly reach into the parent definition to compute module, resolver, etc. This *seems* wasteful (but I don't think this is really what causes any perf problems for us). 

At the same time, I've been looking at Kotlin, and they seem to use the general pattern of analyzing the *parent* definition, and storing info about children into a `BindingContext`. 

I don't really which way is preferable. I think I want to try this approach, where query granularity generally mirrors the data granularity. The primary motivation for me here is probably just hope that we can avoid adding a ton of helpers to a `StructField`, and maybe in general avoid the need to switch to a global `StructField`, using `LocalStructFieldId` most of the time internally. 

For external API (ie, for `ra_ide_api`), I think we should continue with fine-grained `StructField::ty` approach, which internally fetches the table for the whole struct and indexes into it.

In terms of actual memory savings, the results are as follows:

```
This PR:
   142kb FieldTypesQuery (deps)
    38kb FieldTypesQuery

Status Quo:
   208kb TypeForFieldQuery (deps)
    18kb TypeForFieldQuery
```

Note how the table itself occupies more than twice as much space! I don't have an explanation for this: a plausible hypothesis is that single-field structs are very common and for them the table is a pessimisation. 

THere's noticiable wallclock time difference.

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2019-11-24 21:45:26 +00:00
..
ra_arena Switch to variant-granularity field type inference 2019-11-25 00:12:36 +03:00
ra_assists Merge #2343 2019-11-24 08:32:07 +00:00
ra_batch Fix panic in batch analysis 2019-11-24 12:06:00 +03:00
ra_cfg Disable doctests 2019-11-17 18:35:05 +03:00
ra_cli Simplify 2019-11-24 20:53:42 +03:00
ra_db Pull macro up 2019-11-24 14:13:51 +03:00
ra_fmt fix 2190; add test for "replace if let with match" 2019-11-20 19:01:06 +01:00
ra_hir Switch to variant-granularity field type inference 2019-11-25 00:12:36 +03:00
ra_hir_def Merge #2396 2019-11-24 21:45:26 +00:00
ra_hir_expand Use macro for all the things 2019-11-23 22:48:34 +08:00
ra_ide_api Switch to variant-granularity field type inference 2019-11-25 00:12:36 +03:00
ra_lsp_server Ban println in lsp_server 2019-11-22 10:46:56 +03:00
ra_mbe Fixed mbe trival subtree 2019-11-22 01:02:07 +08:00
ra_parser Disable doctests 2019-11-17 18:35:05 +03:00
ra_prof Disable doctests 2019-11-17 18:35:05 +03:00
ra_project_model Merge #2381 2019-11-24 15:59:47 +00:00
ra_syntax Merge #2343 2019-11-24 08:32:07 +00:00
ra_text_edit Disable doctests 2019-11-17 18:35:05 +03:00
ra_tt Disable doctests 2019-11-17 18:35:05 +03:00
ra_vfs_glob Disable doctests 2019-11-17 18:35:05 +03:00
test_utils Disable doctests 2019-11-17 18:35:05 +03:00