Commit Graph

17995 Commits

Author SHA1 Message Date
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
bors[bot]
f06ddbea6a
Merge #9080
9080: Improve completion of cfg attributes r=JamieCunliffe a=JamieCunliffe

This will close #5398 and it also adds some completion for cfg options.

Co-authored-by: Jamie Cunliffe <Jamie.Cunliffe@outlook.com>
2021-06-21 17:05:21 +00:00
Jamie Cunliffe
ae823aa23f Move features into potential_cfg_options 2021-06-21 17:54:05 +01:00
Jamie Cunliffe
284483b347 Improve completion of cfg attributes
The completion of cfg will look at the enabled cfg keys when
performing completion.

It will also look crate features when completing a feature cfg
option. A fixed list of known values for some cfg options are
provided.

For unknown keys it will look at the enabled values for that cfg key,
which means that completion will only show enabled options for those.
2021-06-21 17:47:00 +01:00
bors[bot]
1b05dbba39
Merge #9359
9359: internal: Update vscode-languageclient r=kjeremy a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
2021-06-21 15:49:02 +00:00
kjeremy
b88019c610 Update vscode-languageclient 2021-06-21 11:39:13 -04:00
bors[bot]
56e61bdfea
Merge #9165
9165: Apply some clippy suggestions r=matklad a=clemenswasser



Co-authored-by: Clemens Wasser <clemens.wasser@gmail.com>
2021-06-21 15:11:21 +00:00
Clemens Wasser
47747cd412 Apply some clippy suggestions 2021-06-21 16:40:21 +02:00
bors[bot]
25bf451c84
Merge #9264
9264: feat: Make documentation on hover configurable r=Veykril a=Veykril

This also implements deprecation support for config options as this renames `hoverActions_linksInHover` to `hover_linksInHover`.

Fixes #9232

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-21 14:15:49 +00:00
Lukas Wirth
43098d99ae Remove deprecation support in config 2021-06-21 16:15:25 +02:00
bors[bot]
5567b8a632
Merge #9314
9314: Fix extract_function with await r=sasurau4 a=sasurau4

Fix #9287 

Co-authored-by: Daiki Ihara <sasurau4@gmail.com>
2021-06-21 13:59:29 +00:00
Daiki Ihara
873aa904f2 Fix var name 2021-06-21 22:47:39 +09:00
bors[bot]
b48aba0090
Merge #9227
9227: Add a config setting to disable the 'test' cfg in specified crates r=matklad a=lf-

If you are opening libcore from rust-lang/rust as opposed to e.g.
goto definition from some other crate which would use the sysroot
instance of libcore, a `#![cfg(not(test))]` would previously have made
all the code excluded from the module tree, breaking the editor
experience.

Core does not need to ever be edited with `#[cfg(test)]` enabled,
as the tests are in another crate.

This PR puts in a slight hack that checks for the crate name "core" and
turns off `#[cfg(test)]` for that crate.

Fixes #9203 
Fixes #9226 

Co-authored-by: Jade <software@lfcode.ca>
2021-06-21 13:41:27 +00:00
bors[bot]
4402f2b280
Merge #9357
9357: fix: Update sysroot crates r=jonas-schievink a=jonas-schievink

Removes `rtstartup`, since that's not a Cargo crate (its files are compiled into object files and linked alongside the stdlib).

Adds  `std_detect`.

Part of https://github.com/rust-analyzer/rust-analyzer/issues/9352 (doesn't fix it since std_detect is full of `cfg_if!`)

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-06-21 13:27:57 +00:00
Jonas Schievink
9e306909db Update sysroot crates 2021-06-21 15:26:26 +02:00
bors[bot]
c69f762f26
Merge #9356
9356: internal: Move out and regroup more completion tests r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-21 13:15:12 +00:00
Lukas Wirth
0729913525 Various keyword completion fixes 2021-06-21 15:14:28 +02:00
Lukas Wirth
b9d85f55b7 Move out completion type position tests 2021-06-21 15:00:53 +02:00
bors[bot]
488c9ef9c0
Merge #9355
9355: Don't insert `}` when typing `{` in string r=jonas-schievink a=jonas-schievink

Checks that the token at the cursor is `L_CURLY`.

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/9351

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-06-21 13:00:02 +00:00
Jonas Schievink
8d2a33da05 Don't insert } when typing { in string 2021-06-21 14:54:49 +02:00
bors[bot]
f26dcb25f7
Merge #9347
9347: add note about passing cfg(debug_assertions) r=matklad a=rezural

add note about passing cfg(debug_assertions) to rustc on build. The server will not spin on start  without this arcane hack

Co-authored-by: rezural <69941255+rezural@users.noreply.github.com>
2021-06-21 12:52:08 +00:00
Lukas Wirth
f835279b3a Move out completion pattern tests 2021-06-21 13:48:25 +02:00
Daiki Ihara
7a04f72220 Fix pointed out 2021-06-21 18:42:25 +09:00
Daiki Ihara
cd1ef8de18 Fix extract_function with await 2021-06-21 18:31:53 +09:00
rezural
baa060a994 output to log file if RA_LOG_FILE is defined in environment 2021-06-21 09:33:57 +10:00
bors[bot]
3898387f3b
Merge #9346
9346: Refactor / clean up hir_ty tests r=flodiebold a=flodiebold

Notable changes:
 - unify `check_types` and `check_mismatches` into `check`, which supports both kinds of annotations (`check_types` still exists because I didn't want to change all the annotations, but uses the same implementation)
 - because of that, `check_types` now fails on any type mismatches; also annotations always have to hit the exact range
 - there's also `check_no_mismatches` for when we explicitly just want to check that there are no type mismatches without giving any annotations (`check` will fail without annotations)
 - test annotations can now be overlapping (they point to the nearest line that has actual code in that range):
```
// ^^^^ annotation
//    ^^^^^^^^^ another annotation
```

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2021-06-20 17:38:27 +00:00
Florian Diebold
a1120b6879 Fix benchmark_include_macro 2021-06-20 19:37:45 +02:00
Florian Diebold
78419779f1 More cleanups, use check for display_source_code tests 2021-06-20 19:12:06 +02:00
Florian Diebold
0219b145ea Clean up coercion tests 2021-06-20 19:12:06 +02:00
Florian Diebold
d340f28a81 test_utils: Make overlapping annotations possible 2021-06-20 19:12:06 +02:00
Florian Diebold
04fbdce426 Unify check_mismatches and check_types 2021-06-20 19:12:06 +02:00
Florian Diebold
679bb21633 Add coverage mark for block local impls 2021-06-20 19:12:06 +02:00
bors[bot]
8cc2b710db
Merge #9345
9345: fix: don't add duplicate `&` during completion r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-06-20 16:38:46 +00:00
Aleksey Kladov
9a3eae8755 fix: don't add duplicate & during completion 2021-06-20 19:37:58 +03:00
bors[bot]
f1097c2d26
Merge #9344
9344: fix: rename works when invoked on a reference r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-06-20 14:08:19 +00:00
Aleksey Kladov
cbb1979c19 fix: rename works when invoked on a reference 2021-06-20 17:07:55 +03:00
bors[bot]
3843bd02a0
Merge #9328
9328: internal: Update deps r=lnicola a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
2021-06-20 03:22:13 +00:00
rezural
530ee4ff8a
add note about passing cfg(debug_assertions)
add note about passing cfg(debug_assertions) to rustc on build. The server will not spin without this arcane hack
2021-06-20 11:23:20 +10:00
bors[bot]
9d60d75e14
Merge #9339
9339: minor: Cleanup insert_use tests r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-06-19 20:33:54 +00:00
Lukas Wirth
2113c46797 Cleanup insert_use tests 2021-06-19 22:33:29 +02:00
bors[bot]
c2aa7782d6
Merge #9338
9338: minor: use minicore r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-06-19 09:18:34 +00:00
Milo
044e21ae08 remove num_format 2021-06-19 10:14:15 +01:00
Aleksey Kladov
7df6852b6e minor: use minicore 2021-06-19 12:03:59 +03:00
Milo
673933e2f7 update crate and deps section 2021-06-19 09:44:11 +01:00
Jade
8b77e2692c Implement a config override for the default #[cfg(test)] in cargo crates
Fixes crates which vanish when the 'test' cfg atom is set.

Fix #7243.
Fix #9203.
Fix #7225.
2021-06-19 01:09:19 -07:00
Jade
1f6abb7fba Fix libcore not being included in rust-lang/rust module tree
If you are opening libcore from rust-lang/rust as opposed to e.g.
goto definition from some other crate which would use the sysroot
instance of libcore, a `#![cfg(not(test))]` would previously have made
all the code excluded from the module tree, breaking the editor
experience.

This puts in a slight hack that checks for the crate name "core" and
turns off `#[cfg(test)]`.
2021-06-19 01:09:19 -07:00
Milo
d8209e6378 fmt 2021-06-19 08:12:58 +01:00
Milo
664cc8c754 use num_format 2021-06-19 08:12:46 +01:00
Milo
d2f7e0fea4 clean up some wording 2021-06-19 07:51:44 +01:00
Milo
08ec80c093 remove incorrect double blank new lines 2021-06-18 23:34:00 +01:00