Commit graph

119 commits

Author SHA1 Message Date
bors[bot]
31ed164161
Merge #8134
8134: Correct the paths of submodules from the include! macro r=edwin0cheng a=sticnarf

This PR should fix #7846. It mostly follows the instructions from @edwin0cheng in that issue.

Co-authored-by: Yilin Chen <sticnarf@gmail.com>
2021-03-21 17:57:45 +00:00
Yilin Chen
3bb9efb6b7
use the included file as the source of expanded include macro
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
2021-03-21 23:02:01 +08:00
Matthias Krüger
8a67116857 use strip_prefix() instead of starts_with and slicing (clippy::manual_strip) 2021-03-21 12:38:21 +01:00
Matthias Krüger
3d9b3a8575 remove more redundant clones (clippy::redundant_clone()) 2021-03-21 12:10:39 +01:00
Jonas Schievink
93aeb16eb2 Return Either from MacroDefId::ast_id 2021-03-19 19:56:13 +01:00
Jonas Schievink
54c78c96db Rename derive-specific APIs 2021-03-19 14:23:13 +01:00
Jonas Schievink
c05a1a6e37 Store an AstId for procedural macros 2021-03-18 16:11:18 +01:00
Jonas Schievink
b84efbaacf Make MacroDefId's AstId mandatory when possible 2021-03-18 15:37:14 +01:00
Jonas Schievink
4cf36545e6 Create AstId for builtin_derive macro in tests 2021-03-18 15:14:52 +01:00
Jonas Schievink
5f80364ede Improve diagnostic when including nonexistent file 2021-03-17 21:56:09 +01:00
bors[bot]
f7fbea509f
Merge #8063
8063: couple clippy::complexity fixes r=matklad a=matthiaskrgr

avoid redundant `.into()` calls to convert T into identical T (`let x: String = String::from("hello").into();`)
use `if let Some(x)` instead of `.is_some()` + `.unwrap()`
don't clone Copy types
remove redundant wrapped ?s:  `Some(Some(3)?)` can just be `Some(3)`
use `.map(|x| y)` instead of `and_then(|x| Some(y)` on `Option`s

Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
2021-03-17 08:12:34 +00:00
bors[bot]
6fcb5d772f
Merge #8048
8048: Fix missing unresolved macro diagnostic in function body r=edwin0cheng a=brandondong

This was an issue I found while working on https://github.com/rust-analyzer/rust-analyzer/pull/7970.

**Reproduction:**
1. Call a non-existent macro in a function body.
```
fn main() {
  foo!();
}
```
2. No diagnostics are raised. An unresolved-macro-call diagnostic is expected.
3. If the macro call is instead outside of the function body, this works as expected.

I believe this worked previously and regressed in https://github.com/rust-analyzer/rust-analyzer/pull/7805.

**Behavior prior to https://github.com/rust-analyzer/rust-analyzer/pull/7805:**
- The unresolved-macro-call diagnostic did not exist. Instead, a macro-error diagnostic would be raised with the text "could not resolve macro [path]".
- This was implemented by adding an error to the error sink (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8L657).
- The error was propagated through 1a82af3527/crates/hir_def/src/body.rs (L123) eventually reaching 1a82af3527/crates/hir_def/src/body/lower.rs (L569).

**Behavior after:**
- Instead of writing to the error sink, an UnresolvedMacro error is now returned (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8R631).
- The parent caller throws away the error as its function signature is `Option<MacroCallId>` (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8R604).
- We instead now reach the warn condition (1a82af3527/crates/hir_def/src/body.rs (L124)) and no diagnostics are created in 1a82af3527/crates/hir_def/src/body/lower.rs (L575).

**Fix:**
- Make sure to propagate the UnresolvedMacro error. Report the error using the new unresolved-macro-call diagnostic.


Co-authored-by: Brandon <brandondong604@hotmail.com>
2021-03-17 07:20:28 +00:00
Brandon
a79b5673e8 Follow established ErrorEmitted pattern 2021-03-16 23:31:14 -07:00
Matthias Krüger
64b91393b8 remove uselessly wrapped ?s. (clippy::meedless_question_mark
let x = Some(3);

let y = Some(x?);
can just be:
let y = x
2021-03-17 02:19:40 +01:00
Matthias Krüger
048dad8c2e don't clone types that are copy (clippy::clone_on_copy) 2021-03-17 01:56:31 +01:00
Aleksey Kladov
f5a81ec468 Upgrade rowan
Notably, new rowan comes with support for mutable syntax trees.
2021-03-16 16:10:49 +03:00
Edwin Cheng
8e07b23b84 Fix macro expansion for statements w/o semicolon 2021-03-16 13:44:50 +08:00
Chetan Khilosiya
0c2d4a8a77 7709: Updated the implementation.
The get function from impl method is updated.
and now same method used to get len and is_empty function.
2021-03-15 22:48:50 +05:30
Matthias Krüger
cad617bba0 some clippy::performance fixes
use vec![] instead of Vec::new() +  push()
avoid redundant clones
use chars instead of &str for single char patterns in ends_with() and starts_with()
allocate some Vecs with capacity to avoid unneccessary resizing
2021-03-15 10:19:59 +01:00
bors[bot]
fe4a94fff3
Merge #7994
7994: Speed up mbe matching in heavy recursive cases r=edwin0cheng a=edwin0cheng

In some cases (e.g.  #4186), mbe matching is very slow due to a lot of copy and allocation for bindings, this PR try to solve this problem by introduce a semi "link-list" approach for bindings building.

I used this [test case](https://github.com/weiznich/minimal_example_for_rust_81262) (for `features(32-column-tables)`) to run following command to benchmark:
```
time rust-analyzer analysis-stats  --load-output-dirs ./ 
```

Before this PR : 2 mins
After this PR: 3 seconds.

However, for 64-column-tables cases, we still need 4 mins to complete. 

I will try to investigate in the following weeks.

bors r+




Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-13 13:04:45 +00:00
Edwin Cheng
f1350dd93c add expand log 2021-03-13 20:14:21 +08:00
Jonas Schievink
bc4ecb199b Use expect-test for builtin macro/derive tests 2021-03-10 21:05:02 +01:00
Jonas Schievink
2b8674b37e Implement builtin cfg! macro 2021-03-10 19:43:03 +01:00
Aleksey Kladov
842d8ad9c8 Compilation speed 2021-03-09 22:30:58 +03:00
Edwin Cheng
30402beeb2 Fix assert split exprs on comma 2021-02-28 20:46:24 +08:00
Edwin Cheng
f5bf1a9650 Fix builtin macros split exprs on comma 2021-02-28 13:06:17 +08:00
Matt Hall
a28e862825 Address further review comments
* Use known names for iter/iter_mut method (simplifies checking if the
  method exists
* Extract code to check assist with fixtures to function
2021-02-24 19:23:12 +00:00
Lukas Wirth
2887426da0 Revert "Replace usage of ast::NameOrNameRef with ast::NameLike"
This reverts commit e1dbf43cf8.
2021-02-17 15:00:44 +01:00
Lukas Wirth
e1dbf43cf8 Replace usage of ast::NameOrNameRef with ast::NameLike 2021-02-17 14:02:34 +01:00
Aleksey Kladov
181590412e add more counts 2021-01-27 12:16:24 +03:00
Laurențiu Nicola
4e92681aba Disallow non-boolean literals in concat! 2021-01-25 13:31:03 +02:00
Laurențiu Nicola
ee8c678870 Unquote strings and handle boolean literals in concat! 2021-01-25 13:02:57 +02:00
Phil Ellison
8c7ccdc29d Identify methods using functions ids rather than string names 2021-01-23 07:40:25 +00:00
bors[bot]
e62533c3ec
Merge #7359
7359: ItemTree: store a mapping from blocks to inner items r=jonas-schievink a=jonas-schievink

To do name resolution within block expressions, we need to know which inner items are located inside each block expression. This adds such a mapping to `ItemTree`, replacing the previous one, which was seemingly unused other than to access all the inner items.

This also assigns `AstId`s to block expressions, which is needed to store the mapping in salsa.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-01-20 16:09:22 +00:00
Aleksey Kladov
46b4f89c92 . 2021-01-20 01:56:11 +03:00
Aleksey Kladov
cd21b0e9c1 ⬆️ rowan 2021-01-19 22:11:42 +03:00
Jonas Schievink
52fe50a97b Record FileAstIds for block expressiosn
Every block expression may contain inner items, so we need to be able
to refer to any block expression and use it as a salsa key.
2021-01-19 19:49:19 +01:00
Jonas Schievink
2d799cf5e0 shrink_to_fit TokenMap's backing storage 2021-01-18 18:40:06 +01:00
bors[bot]
9eb37fbdeb
Merge #7292
7292: Swap assert_eq_text\!(expected, actual) r=matklad a=u5surf

Fixes #7283 

Swap assert_eq_text parameters in the order (expected, actual)

Co-authored-by: yugo-horie <u5.horie@gmail.com>
2021-01-18 10:12:54 +00:00
Aleksey Kladov
1c8feac01f ⬆️ arena 2021-01-17 11:43:04 +03:00
bors[bot]
f5f011ba71
Merge #7304
7304: Depend on local copy of la-arena instead of crates.io’s r=lnicola a=arzg

This addresses [this comment](https://github.com/rust-analyzer/rust-analyzer/pull/7276#issuecomment-760909936). #7275 and #7276 should start compiling if this is merged.

Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
2021-01-17 07:05:44 +00:00
Aramis Razzaghipour
709034d123
Depend on local copy of la-arena instead of crates.io’s 2021-01-17 17:52:57 +11:00
Aleksey Kladov
b38414c7f4 When building an item-tree, keep fewer nodes in memory 2021-01-16 23:07:28 +03:00
yugo-horie
f273995a25 Swap assert_eq_text\!(expected, actual) 2021-01-16 13:30:26 +09:00
Aleksey Kladov
6dbba4d75d Remove useless wrapper 2021-01-15 20:15:33 +03:00
Aleksey Kladov
4c4e54ac8a prepare to publish el libro de arena 2021-01-14 19:06:02 +03:00
Vincent Esche
21f8239ac8 Fixed typos in code comments 2021-01-09 15:41:29 +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
Kevaundray Wedderburn
72b9a4fbd3 Change <|> to $0 - Rebase 2021-01-07 12:09:23 +00:00