Commit graph

143 commits

Author SHA1 Message Date
Lukas Wirth
b795128dde Use hir::GenericParam in ide_db::Definition instead of relisting all 3 2021-01-10 12:33:47 +01:00
bors[bot]
1a29934c37
Merge #7145
7145: Proper handling $crate Take 2 [DO NOT MERGE] r=edwin0cheng a=edwin0cheng

Similar to previous PR (#7133) , but improved the following things :

1. Instead of storing the whole `ExpansionInfo`, we store a similar but stripped version `HygieneInfo`.
2. Instread of storing the `SyntaxNode` (because every token we are interested are IDENT), we store the `TextRange` only.
3. Because of 2, we now can put it in Salsa.
4. And most important improvement: Instead of computing the whole frames every single time, we compute it recursively through salsa: (Such that in the best scenario, we only need to compute the first layer of frame)

```rust
        let def_site = db.hygiene_frame(info.def.file_id);
        let call_site = db.hygiene_frame(info.arg.file_id);

        HygieneFrame { expansion: Some(info), local_inner, krate, call_site, def_site }
```

The overall speed compared to previous PR is much faster (65s vs 45s) :
```
[WITH old PR]
Database loaded 644.86ms, 284mi
Crates in this dir: 36
Total modules found: 576
Total declarations: 11153
Total functions: 8715
Item Collection: 15.78s, 91562mi
Total expressions: 240721
Expressions of unknown type: 2635 (1%)
Expressions of partially unknown type: 2064 (0%)
Type mismatches: 865
Inference: 49.84s, 250747mi
Total: 65.62s, 342310mi
rust-analyzer -q analysis-stats .  66.72s user 0.57s system 99% cpu 1:07.40 total

[WITH this PR]
Database loaded 665.83ms, 284mi
Crates in this dir: 36
Total modules found: 577
Total declarations: 11188
Total functions: 8743
Item Collection: 15.28s, 84919mi
Total expressions: 241229
Expressions of unknown type: 2637 (1%)
Expressions of partially unknown type: 2064 (0%)
Type mismatches: 868
Inference: 30.15s, 135293mi
Total: 45.43s, 220213mi   
rust-analyzer -q analysis-stats .  46.26s user 0.74s system 99% cpu 47.294 total
```

*HOWEVER*,  it is still a perf regression (35s vs 45s):
```
[WITHOUT this PR]
Database loaded 657.42ms, 284mi
Crates in this dir: 36
Total modules found: 577
Total declarations: 11177
Total functions: 8735
Item Collection: 12.87s, 72407mi
Total expressions: 239380
Expressions of unknown type: 2643 (1%)
Expressions of partially unknown type: 2064 (0%)
Type mismatches: 868
Inference: 22.88s, 97889mi
Total: 35.74s, 170297mi
rust-analyzer -q analysis-stats .  36.71s user 0.63s system 99% cpu 37.498 total
```



Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-01-08 03:57:11 +00:00
Phil Ellison
b2dbe6e43a Add fix to wrap return expression in Some 2021-01-07 19:01:33 +00:00
Edwin Cheng
76f2b9d2ef Proper handling $crate Take 2 2021-01-07 13:08:32 +08:00
Aleksey Kladov
f9707cde68 Rename expr -> tail_expr 2021-01-05 15:51:13 +03:00
Arnaud
052404565e Remove RetType 2021-01-04 20:34:23 +01:00
Arnaud
2f0969b873 Document hir::Function::ret_type
This adds documentation for the newly added function. It might be a bit too
detailed, but I like it that way :)
2021-01-04 19:14:44 +01:00
Arnaud
a6dc7cf36d Make it possible to retrieve hir::Function's return type
This is done by adding a `ret_type` method to `hir::Function`.
I followed `assoc_fn_params` convention by creating a new `RetType` type,
that contains the actual return type accessible via a `ty` method.
2021-01-04 19:14:44 +01:00
Lukas Wirth
54b9b03ca2 Show GotoTypeAction for TypeParam 2021-01-04 15:54:45 +01:00
Lukas Wirth
bd47e140b6 Show GotoTypeAction for ConstParam 2021-01-04 15:19:09 +01:00
Lukas Wirth
47900dd3bc Impl hovering for TypeParams 2021-01-04 12:24:47 +01:00
bors[bot]
1cc73d60bb
Merge #7068
7068: Add VSCode command to view the hir of a function body r=theotherphil a=theotherphil

Will fix https://github.com/rust-analyzer/rust-analyzer/issues/7061. Very rough initial version just to work out where I needed to wire everything up.

@matklad would you be happy merging a hir visualiser of some kind? If so, do you have any thoughts on what you'd like it show, and how?

I've spent very little time on this thus far, so I'm fine with throwing away the contents of this PR, but I want to avoid taking the time to make this more polished/interactive/useful only to discover that no-one else has any interest in this functionality.

![image](https://user-images.githubusercontent.com/1974256/103236081-bb58f700-493b-11eb-9d12-55ae1b870f8f.png)


Co-authored-by: Phil Ellison <phil.j.ellison@gmail.com>
2021-01-03 09:03:15 +00:00
bors[bot]
520b8a5a4d
Merge #7115
7115: Migrate HasSource::source to return Option r=matklad a=nick96

I've made a start on fixing #6913 based on the provided work plan, migrating `HasSource::source` to return an `Option`. The simple cases are migrated but there are a few that I'm unsure exactly how they should be handled:

- Logging the processing of functions in `AnalysisStatsCmd::run`: In verbose mode it includes the path to the module containing the function and the syntax range. I've handled this with an if-let but would it be better to blow up here with `expect`? I'm not 100% on the code paths but if we're processing a function definition then the source should exist.

I've handled `source()` in all code paths as `None` being a valid return value but are there some cases where we should just blow up? Also, all I've done is bubble up the returned `None`s, there may be some places where we can recover and still provide something.

Co-authored-by: Nick Spain <nicholas.spain@stileeducation.com>
Co-authored-by: Nick Spain <nicholas.spain96@gmail.com>
2021-01-03 08:56:17 +00:00
Phil Ellison
ee7c3f79e2 Use stdx::format_to instead of writeln 2021-01-03 08:54:33 +00:00
Lukas Wirth
68336fdb61 Implement HasAttrs for Type-, Const- and LifetimeParam 2021-01-02 12:11:46 +01:00
Nick Spain
40cd6cdf67 Fix ConstParam HasSource impl and implement TryToNav not Nav 2021-01-02 22:11:25 +11:00
Nick Spain
887028fcf5 Remove old_source now we've fully migrated
Fixes #6913
2021-01-02 21:53:52 +11:00
Nick Spain
c936e4b86f source_old -> source for cases that can be handled by simple bubbling 2021-01-02 21:53:52 +11:00
Nick Spain
14d0db0759 HasSource::source_old -> HasSource::source for places where proc-macros were special cased
In #6901 some special case handling for proc-macros was introduced to
prevent panicing as they have no AST. Now the new HasSource::source
method is used that returns an option.

Generally this was a pretty trivial change, the only thing of much
interest is that `hir::MacroDef` now implements `TryToNav` not `ToNav`
as this allows us to handle `HasSource::source` now returning an option.
2021-01-02 21:53:52 +11:00
Nick Spain
ea4708c444 Mark HasSource::source_old as deprecated but allow at all call sites 2021-01-02 21:53:51 +11:00
Nick Spain
2de2b1eca3 Implement new HasSource::source for all implementors of HasSource 2021-01-02 21:53:51 +11:00
Nick Spain
27cadcd531 HasSource::source -> HasSource::source_old
To start migrating HasSource::source to return an Option.
2021-01-02 21:53:51 +11:00
Lukas Wirth
ec448ca4b3 Impl HasAttrs for GenericParam 2021-01-02 00:44:59 +01:00
Phil Ellison
db53db8046 Address review suggestion, fix tidy tests 2021-01-01 19:25:18 +00:00
bors[bot]
0e5fe47153
Merge #7080
7080: Implement ConstParams for HIR r=Veykril a=Veykril

r? @flodiebold 

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-01 13:45:10 +00:00
Lukas Wirth
0acdb73076 Add ConstParams to the HIR 2021-01-01 10:06:42 +01:00
kjeremy
dc1396eec7 Update crates 2020-12-30 10:39:50 -05:00
Phil Ellison
077592a12f Initial implementation of view-hir command 2020-12-28 18:29:58 +00:00
bors[bot]
06320015af
Merge #7021
7021: Track labels in the HIR r=matklad a=Veykril

Groundwork for #6966

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-24 12:04:28 +00:00
Lukas Wirth
262b9c3982 Track labels in the HIR 2020-12-24 12:49:40 +01:00
unexge
bfae2634b4 Prevent multiple incorrect case diagnostics in functions 2020-12-23 22:18:31 +03:00
bors[bot]
4a2f60cb7b
Merge #6964
6964: Add full pattern completions for Struct and Variant patterns r=matklad a=Veykril


Just gonna call it full pattern completion as pattern completion is already implemented in a sense by showing idents in pattern position. What this does is basically complete struct and variant patterns where applicable(function params, let statements and refutable pattern locations).

This does not replace just completing the corresponding idents of the structs and variants, instead two completions are shown for these, a completion for the ident itself and a completion for the pattern(if the pattern make sense to be used that is). I figured in some cases one would rather type out the pattern manually if it has a lot of fields but you only care about one since this completion would cause one more work in the end since you would have to delete all the extra matched fields again.

These completions are tagged as `CompletionKind::Snippet`, not sure if that is the right one here.
<details>
  <summary>some gifs</summary>

![dx2lxgzhj3](https://user-images.githubusercontent.com/3757771/102719967-6987ef80-42f1-11eb-8ae0-8aff53777860.gif)
![EP2E7sJLkB](https://user-images.githubusercontent.com/3757771/102785777-c7264580-439e-11eb-8a64-f142e19fb65b.gif)
![JMNHHWknr9](https://user-images.githubusercontent.com/3757771/102785796-d1e0da80-439e-11eb-934b-218ada31b51c.gif)
</details>

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-22 18:03:51 +00:00
Lukas Wirth
b184bfad7a Add completions for patterns 2020-12-20 18:19:23 +01:00
bors[bot]
eefbae7ed4
Merge #6921
6921: Higher-ranked trait bounds for where clauses r=flodiebold a=Veykril

There is a slight problem with this which is also noted in a FIXME now but `LifetimeParameters` of these ForLifetime where clauses allocate the lifetimes in the corresponding arena as if they were lifetimes of the item itself and not just the clause they belong to. I wasn't entirely sure what I could do about this but given nothing really uses lifetimes like that currently I figured it might be fine? Open to suggestions for that problem.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-20 11:47:01 +00:00
Aleksey Kladov
f6ed16674c Align code_model name with ungrammar 2020-12-20 10:05:24 +03:00
bors[bot]
f4929fa9cc
Merge #6901
6901: Temp fixes panic caused by no ast for proc-macro r=maklad a=edwin0cheng

There are some panic when hover/goto definition for proc-macro. It is because in current design, we don't have `ast-node` for proc-macro and then it trigger [this](479d1f7eec/crates/hir/src/has_source.rs (L116)) line to panic.

This PR is a temp fix for all of these similar to bd4c352831/crates/completion/src/render/macro_.rs (L42)

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-12-18 02:30:51 +00:00
Edwin Cheng
60a3785ac2 Temp fixes panic caused by no ast for proc-macro 2020-12-18 10:26:17 +08:00
Aleksey Kladov
30216880c4 Minor API cleanup 2020-12-17 20:14:13 +03:00
Jonas Schievink
9231821c03 Make Attrs::from_attrs_owner private 2020-12-17 15:45:26 +01:00
Lukas Wirth
c8c58d81ec Remove obsolete FIXME 2020-12-17 13:40:11 +01:00
Aleksey Kladov
2ae31e34b1 Rename ImplDef -> Impl
We used to have `Def` suffix for all symbols, but we moved off from
that. `FunctionDef` isn't better than `Function`. Looks like we've
forgot to change `Impl` though!
2020-12-17 14:36:15 +03:00
Jonas Schievink
6615fda695 decl_check: don't pass db around so often 2020-12-17 01:19:56 +01:00
Jonas Schievink
21b68a328c Remove module_lang_items
It isn't used anywhere except in `crate_lang_items`. Remove it to
slightly reduce memory usage and simplify the code.
2020-12-17 00:26:01 +01:00
bors[bot]
067067a6c1
Merge #6896
6896: Node-ify lifetimes r=jonas-schievink a=Veykril

Let's see if this passes the tests 🤞 

Depends on https://github.com/rust-analyzer/ungrammar/pull/15

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-16 17:08:03 +00:00
bors[bot]
63bbdb31e5
Merge #6897
6897: Basic support for macros 2.0 r=jonas-schievink a=jonas-schievink

This adds support for (built-in-only) macros 2.0, and removes some hacks used for builtin derives, which are declared via macros 2.0 in libcore.

First steps for https://github.com/rust-analyzer/rust-analyzer/issues/2248.

Blocked on https://github.com/rust-analyzer/ungrammar/pull/16.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-12-16 16:52:46 +00:00
Lukas Wirth
dd496223f5 Node-ify lifetimes 2020-12-16 14:16:09 +01:00
Jonas Schievink
b238ddd21a Make macro def krate mandatory
Refactors builtin derive support to go through proper name resolution
2020-12-15 20:33:05 +01:00
Jonas Schievink
c31c3246a8 Basic support for decl macros 2.0 2020-12-15 18:43:34 +01:00
bors[bot]
eb9ba457b0
Merge #6879
6879: Change HasChildSource::ChildId assoc item to generic param r=matklad a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-15 17:22:03 +00:00
Lukas Wirth
2c67a4abe4 Change HasChildSource::ChildId assoc item to generic param 2020-12-15 18:21:01 +01:00