Commit graph

379 commits

Author SHA1 Message Date
Aleksey Kladov 86720f2953 minor: drop dummy authors field 2021-07-05 14:19:41 +03:00
Aleksey Kladov c4d2671767 minor: untangle complex condition 2021-07-04 17:32:59 +03:00
Aleksey Kladov c2704bebc1 minor: better error message 2021-07-04 11:20:31 +03:00
bors[bot] 336194c09b
Merge #9476
9476: internal: overhaul codegen r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-07-03 19:26:04 +00:00
Aleksey Kladov 58d2ece88a internal: overhaul code generation
* Keep codegen adjacent to the relevant crates.
* Remove codgen deps from xtask, speeding-up from-source installation.

This regresses the release process a bit, as it now needs to run the
tests (and, by extension, compile the code).
2021-07-03 22:11:03 +03:00
Lukas Wirth d308f17a21 Inline parameters in inline_call if possible 2021-07-03 20:05:54 +02:00
Lukas Wirth 14e18bfa38 Merge the inline function/method assists into inline_call 2021-07-03 18:07:03 +02:00
Lukas Wirth 688398febc feat: Implement inline_method assist 2021-07-03 01:33:34 +02:00
Lukas Wirth 251f0c6090 replace_match_with_if_let works on more binary matches 2021-07-02 21:05:10 +02:00
bors[bot] d18cfd4467
Merge #9458
9458: minor: Remove make::match_arm_with_guard r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-01 23:47:38 +00:00
Lukas Wirth 071ac48b6c Remove make::match_arm_with_guard 2021-07-02 01:44:54 +02:00
bors[bot] cd3d633850
Merge #9455
9455: feat: Handle not let if expressions in replace_if_let_with_match r=Veykril a=Veykril

Transforms bare `if cond {}` into `_ if cond` guard patterns in the match as long as at least one `if let` is in the if chain, otherwise the assist wont be applicable.

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-07-01 23:00:50 +00:00
Lukas Wirth 8967856d78 Handle not let if expressions in replace_if_let_with_match 2021-07-02 00:58:56 +02:00
bors[bot] c8c4d73648
Merge #9437
9437: fix: Don't classify paths inside attribute TokenTrees r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-30 19:52:03 +00:00
Lukas Wirth 04f1104179 Don't classify NameRef paths inside attribute TokenTrees 2021-06-30 21:51:28 +02:00
kjeremy bf7651886e Cargo update and pull in the new rowan
This brings in the new hashbrown for better compile times.
2021-06-30 10:03:31 -04:00
Lukas Wirth 9957220dfe Fix NameRef::classify path resolution inside attributes 2021-06-28 19:07:23 +02:00
Lukas Wirth 3ce5c66ca1 Deduplicate ast expression walking logic 2021-06-27 01:11:57 +02:00
bors[bot] e2ca2325f5
Merge #9367
9367: Document perf characteristic of to_node r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-06-22 08:46:01 +00:00
Aleksey Kladov e611c6758c Document perf characteristic of to_node 2021-06-22 11:45:22 +03:00
Aleksey Kladov 099b63e7c0 feature: massively improve performance for large files
This story begins in #8384, where we added a smart test for our syntax
highting, which run the algorithm on synthetic files of varying length
in order to guesstimate if the complexity is O(N^2) or O(N)-ish.

The test turned out to be pretty effective, and flagged #9031 as a
change that makes syntax highlighting accidentally quadratic. There was
much rejoicing, for the time being.

Then, lnicola asked an ominous question[1]: "Are we sure that the time
is linear right now?"

Of course it turned out that our sophisticated non-linearity detector
*was* broken, and that our syntax highlighting *was* quadratic.

Investigating that, many brave hearts dug deeper and deeper into the
guts of rust-analyzer, only to get lost in a maze of traits delegating
to traits delegating to macros.

Eventually, matklad managed to peel off all layers of abstraction one by
one, until almost nothing was left. In fact, the issue was discovered in
the very foundation of the rust-analyzer -- in the syntax trees.

Worse, it was not a new problem, but rather a well-know, well-understood
and event (almost) well-fixed (!) performance bug.

The problem lies within `SyntaxNodePtr` type -- a light-weight "address"
of a node in a syntax tree [3]. Such pointers are used by rust-analyzer all
other the place to record relationships between IR nodes and the
original syntax.

Internally, the pointer to a syntax node is represented by node's range.
To "dereference" the pointer, you traverse the syntax tree from the
root, looking for the node with the right range. The inner loop of this
search is finding a node's child whose range contains the specified
range. This inner loop was implemented by naive linear search over all
the children. For wide trees, dereferencing a single `SyntaxNodePtr` was
linear. The problem with wide trees though is that they contain a lot of
nodes! And dereferencing pointers to all the nodes is quadratic in the
size of the file!

The solution to this problem is to speed up the children search --
rather than doing a linear lookup, we can use binary search to locate
the child with the desired interval.

Doing this optimization was one of the motivations (or rather, side
effects) of #6857. That's why `rowan` grew the useful
`child_or_token_at_range` method which does exactly this binary search.

But looks like we've never actually switch to this method? Oups.

Lesson learned: do not leave broken windows in the fundamental infra.
Otherwise, you'll have to repeatedly re-investigate the issue, by
digging from the top of the Everest down to the foundation!

[1]: https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/.60syntax_highlighting_not_quadratic.60.20failure/near/240811501
[2]: https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Syntax.20highlighting.20is.20quadratic
[3]: https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Syntax.20highlighting.20is.20quadratic/near/243412392
2021-06-21 20:14:38 +03:00
Lukas Wirth 344cb5e76a Don't insert imports outside of cfg attributed items 2021-06-18 23:56:43 +02:00
Lukas Wirth 2ee090faaf Allow to disable import insertion on single path glob imports 2021-06-18 23:11:56 +02:00
Lukas Wirth 02d25ab60d Fix parser tests for 1.53 2021-06-17 18:09:44 +02:00
Lukas Wirth cd5f4121e3 Create modules in correct directory for nested modules in move_module assist 2021-06-17 12:09:28 +02:00
Lukas Wirth 29054e02fb Highlight unsafe trait refs as unsafe only in impl blocks and definitions 2021-06-15 21:49:59 +02:00
Aleksey Kladov 067e97d149 internal: enforce no #[ignore] and no #[should_panic] 2021-06-15 16:54:43 +03:00
Maan2003 b857a5dcf0
clippy::manual_str_repeat 2021-06-13 09:37:28 +05:30
Maan2003 c9b4ac5be4
clippy::redudant_borrow 2021-06-13 09:24:16 +05:30
Aleksey Kladov 0463d76a1f internal: cross-crate cov-marks 2021-06-12 23:40:52 +03:00
Jonas Schievink 1d6eef1350 Update ungrammar 2021-06-11 18:34:30 +02:00
Lukas Wirth 31aad2528f Fix edge case for ImportGranularity guessing 2021-06-08 22:14:30 +02:00
Clemens Wasser 629e8d1ed0 Apply more clippy suggestions and update generated 2021-06-03 12:46:56 +02:00
Lukas Wirth f3dc4321c8 Account for generics in extract_struct_from_enum_variant 2021-06-02 17:44:00 +02:00
Aleksey Kladov ee51bf04be minor: remove debug print 2021-05-31 20:20:30 +03:00
bors[bot] f41b68637a
Merge #9062
9062: internal: Bump deps r=lnicola a=lnicola

Fixes #9061

bors r+

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2021-05-30 11:48:59 +00:00
Laurențiu Nicola 36567eb9be Bump deps 2021-05-30 14:48:10 +03:00
Lukas Wirth fc37e2f953 Attribute completion is context aware 2021-05-27 23:28:14 +02:00
Domantas Jadenkus 22e5194396 generate match arms with todo!() as placeholder body 2021-05-24 22:17:16 +03:00
Laurențiu Nicola b43bc61981 Bump rustc_lexer 2021-05-24 16:39:19 +03:00
Aleksey Kladov 188b0f96f9 Add more docs 2021-05-22 16:53:47 +03:00
Aleksey Kladov 47d7434dde internal: replace AstTransformer with mutable syntax trees 2021-05-22 15:27:32 +03:00
Lukas Tobias Wirth da7f1eb756 Don't compare ast::Visibility by stringifying 2021-05-20 17:45:59 +02:00
Aleksey Kladov 75a0123614 fix: don't add extra whitespace around fields
closes #8785
2021-05-17 12:45:01 +03:00
Aleksey Kladov 1859df37fd internal: use mutable syntax trees when filling fields 2021-05-16 18:10:56 +03:00
Aleksey Kladov e4a7b44e55 internal: use mutable trees when filling match arms 2021-05-16 15:10:18 +03:00
bors[bot] a57bd59f35
Merge #8813
8813: Get some more array lengths! r=lf- a=lf-

This is built on #8799 and thus contains its changes. I'll rebase it onto master when that one gets merged. It adds support for r-a understanding the length of:

* `let a: [u8; 2] = ...`
* `let a = b"aaa"`
* `let a = [0u8; 4]`

I have added support for getting the values of byte strings, which was not previously there. I am least confident in the correctness of this part and it probably needs some more tests, as we currently have only one test that exercised that part (!).

Fixes #2922.

Co-authored-by: Jade <software@lfcode.ca>
2021-05-16 01:53:12 +00:00
Lukas Wirth 4b5b54279a Attach comments to ast::Impl 2021-05-15 17:32:28 +02:00
Aleksey Kladov 883dd1568f internal: use more mutable APIs 2021-05-14 20:00:35 +03:00
Aleksey Kladov cea589b3b5 internal: rewrite assoc item manipulaion to use mutable trees 2021-05-14 18:47:08 +03:00
Aleksey Kladov 73123a7550 internal: remove SyntaxRewriter 2021-05-14 16:40:11 +03:00
Aleksey Kladov 873717190d internal: remove more of the SyntaxRewriter 2021-05-14 16:28:59 +03:00
Aleksey Kladov 0650f77dd9 internal: remove one more immutable tree 2021-05-14 16:19:27 +03:00
Aleksey Kladov ad0648dc95 Cleanup imports 2021-05-13 13:44:47 +03:00
Jade 73023c0299 Support length for ByteStrings
I am not confident that my added byte string parsing is right.
2021-05-12 21:22:46 -07:00
Aleksey Kladov bf26e13cd2 simplify 2021-05-10 15:25:56 +03:00
Aleksey Kladov 4f3c0adc5a internal: introduce ast::make::ext module with common shortcuts
There's a tension between keeping a well-architectured minimal
orthogonal set of constructs, and providing convenience functions.
Relieve this pressure by introducing an dedicated module for
non-orthogonal shortcuts.

This is inspired by the django.shortcuts module which serves a similar
purpose architecturally.
2021-05-09 19:55:43 +03:00
Aleksey Kladov 680a0d54e4 internal: fix make API 2021-05-09 19:22:33 +03:00
Aleksey Kladov 5342800147 internal: rewrite **Repalce impl Trait** assist to mutable syntax trees 2021-05-09 18:20:37 +03:00
Aleksey Kladov d9c9f6dc2c cleanups 2021-05-09 17:58:03 +03:00
Aleksey Kladov 8a7904127d minor: remove dead code 2021-05-08 23:28:36 +03:00
Aleksey Kladov 1755b57e1a internal: pull_assignment_up uses mutable trees 2021-05-08 23:11:42 +03:00
Aleksey Kladov 880ddddfe6 dead code 2021-05-08 20:02:48 +03:00
Aleksey Kladov 1fdc9d8e9e internal: remove one more syntax rewriter 2021-05-08 14:47:14 +03:00
Jonas Schievink e2b664e9fd fix: use raw idents in make::name{_ref} with keywords 2021-05-07 17:22:54 +02:00
Dawer 0a156c80af Hide implementation details of TokenText 2021-05-06 10:07:06 +05:00
Dawer d9b4ac8128 Clean up 2021-05-06 10:07:06 +05:00
Dawer d7e169fe55 Borrow text from nodes of immutable syntax trees 2021-05-06 10:07:06 +05:00
Dawer dc4fa504ea Adapt to a new rowan borrowing node API. 2021-05-06 10:06:52 +05:00
Dawer 52143f389f Update to rowan 0.13.0-pre.5 2021-05-06 10:04:39 +05:00
Jonas Schievink cb8632d87c Parse const param defaults 2021-04-29 03:07:53 +02:00
Jonas Schievink caee3a2eeb Correctly parse negated literals as const args 2021-04-29 02:27:55 +02:00
Lukas Wirth 050c69c19d Split out merge_imports module from helpers::insert_use 2021-04-24 13:31:43 +02:00
bors[bot] 5cbde9f531
Merge #8591 #8638
8591: Remove SyntaxRewriter usage in insert_use in favor of mutable syntax trees r=matklad a=Veykril

Unfortunately changing `insert_use` to not use `SyntaxRewriter` creates a lot of changes since so much relies on that. But on the other hand this should be the biggest usage of `SyntaxRewriter` I believe.

8638: Remove SyntaxRewriter::from_fn r=Veykril a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-04-23 16:49:08 +00:00
Lukas Wirth e6e4417bbb Remove SyntaxRewriter::from_fn 2021-04-23 18:36:43 +02:00
bors[bot] 85bab7539a
Merge #8317
8317: Convert tuple struct to named struct assist r=Veykril a=unexge

Closes https://github.com/rust-analyzer/rust-analyzer/issues/8192

Co-authored-by: unexge <unexge@gmail.com>
2021-04-23 13:37:48 +00:00
Laurențiu Nicola e50ca6b067 Bump rustc_lexer 2021-04-21 19:19:27 +03:00
Comonad 09147c3303 Add support for fill match arms of boolean values
- Add support for boolean inside tuple
2021-04-21 19:33:45 +08:00
Lukas Wirth 3f7a086b4f Parse outer atttributes for RecordPatField 2021-04-21 11:08:15 +02:00
Lukas Wirth fa20a5064b Remove SyntaxRewriter usage in insert_use in favor of ted 2021-04-20 02:09:12 +02:00
bors[bot] 6877e6e4da
Merge #8578
8578: fix: false positive about inner attrs in docs r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-04-19 14:37:54 +00:00
Aleksey Kladov 5f89a60f1a fix: false positive about inner attrs in docs
closes #8541
2021-04-19 17:11:49 +03:00
bors[bot] e7a8977358
Merge #8524 #8527
8524: Fix extract function with partial block selection r=matklad a=brandondong

**Reproduction:**
```rust
fn foo() {
    let n = 1;
    let mut v = $0n * n;$0
    v += 1;
}
```
1. Select the snippet ($0) and use the "Extract into function" assist.
2. Extracted function is incorrect and does not compile:
```rust
fn foo() {
    let n = 1;
    let mut v = fun_name(n);
    v += 1;
}

fn fun_name(n: i32) {}
```
3. Omitting the ending semicolon from the selection fixes the extracted function:
```rust
fn fun_name(n: i32) -> i32 {
    n * n
}
```

**Cause:**
- When `extraction_target` uses a block extraction (semicolon case) instead of an expression extraction (no semicolon case), the user selection is directly used as the TextRange.
- However, the existing function extraction logic for blocks requires that the TextRange spans from start to end of complete statements to work correctly.
- For example:
```rust
fn foo() {
    let m = 2;
    let n = 1;
    let mut v = m $0* n;
    let mut w = 3;$0
    v += 1;
    w += 1;
}
```
produces
```rust
fn foo() {
    let m = 2;
    let n = 1;
    let mut v = m let mut w = fun_name(n);
    v += 1;
    w += 1;
}

fn fun_name(n: i32) -> i32 {
    let mut w = 3;
    w
}
```
- The user selected TextRange is directly replaced by the function call which is now in the middle of another statement. The extracted function body only contains statements that were fully covered by the TextRange and so the `* n` code is deleted. The logic for calculating variable usage and outlived variables for the function parameters and return type respectively search within the TextRange and so do not include `m` or `v`.

**Fix:**
- Only extract full statements when using block extraction. If a user selected part of a statement, extract that full statement.

8527: Switch introduce_named_lifetime assist to use mutable syntax tree  r=matklad a=iDawer

This extends `GenericParamsOwnerEdit` trait with `get_or_create_generic_param_list` method

Co-authored-by: Brandon <brandondong604@hotmail.com>
Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-04-19 13:09:18 +00:00
cynecx cf3b4f1e20 hir_ty: Expand macros at type position 2021-04-17 16:24:56 +02:00
Bernhard Schuster 3b7753d257
nail rowan version down
The different pre versions include breaking changes, which cause build failures for the users.
2021-04-17 09:31:54 +02:00
Dawer 8965be3d0e Fill match arms for a tuple of a single enum. 2021-04-16 17:22:11 +05:00
Dawer cedbf2e1c5 Finish GenericParamsOwnerEdit impls 2021-04-15 15:57:45 +05:00
Dawer 144afa55a6 Switch introduce_named_lifetime assist to use mutable syntax tree 2021-04-15 01:56:19 +05:00
kjeremy 761a81822a Update crates 2021-04-07 11:39:33 -04:00
kjeremy b246f57fad Use arrayvec 0.7 to avoid perf regression in 0.6.1
See: https://github.com/bluss/arrayvec/issues/182
2021-04-05 12:58:35 -04:00
unexge 8d4be829e0 Add convert tuple struct to named struct assist 2021-04-04 20:52:43 +03:00
Edwin Cheng eedadd7024 Add support for doc on hover for macro 2.0 2021-03-27 14:57:11 +08:00
Edwin Cheng a193666361 Basic Support Macro 2.0 2021-03-27 13:44:54 +08:00
Aleksey Kladov 1bbac9053d Add TokenText 2021-03-26 21:33:45 +03:00
cynecx 5ff3299dd6 syntax: return owned string instead of leaking string 2021-03-26 18:30:59 +01:00
Laurențiu Nicola bc5c86543b Use more std::array::IntoIter 2021-03-25 21:06:48 +02:00
Laurențiu Nicola 9787bddac5 Use arrayvec 0.6 2021-03-25 21:03:20 +02:00
Aleksey Kladov e33959a888 Simplify code
changelog: skip
2021-03-23 19:41:15 +03:00
Aleksey Kladov 9cbf09ec4f rewrite merge use trees assist to use muatable syntax trees
changelog internal
2021-03-22 20:47:46 +03:00
Aleksey Kladov 48b534ceb8 ⬆️ rowan 2021-03-22 20:26:59 +03:00