Commit Graph

17532 Commits

Author SHA1 Message Date
hkalbasi
f4c52b40bd fix bug in labeled for loop desugaring 2023-06-01 17:51:53 +03:30
bors
bafa6c4ee5 Auto merge of #14935 - Veykril:sysroot-dedup, r=Veykril
fix: Don't duplicate sysroot crates in rustc workspace

Since we handle `library` as the sysroot source directly in the rustc workspace, we now duplicate the crates there, once as sysroot and once as just plain workspace crate. This causes a variety of issues for `vec!` macros and similar that emit `$crate` tokens across crates.
2023-05-31 13:50:53 +00:00
Lukas Wirth
ecb8616870 fix: Don't duplicate sysroot crates in rustc workspace 2023-05-31 15:37:35 +02:00
bors
526507fe22 Auto merge of #14888 - lunacookies:multi-qos, r=Veykril
Prioritize threads affected by user typing

To this end I’ve introduced a new custom thread pool type which can spawn threads using each QoS class. This way we can run latency-sensitive requests under one QoS class and everything else under another QoS class. The implementation is very similar to that of the `threadpool` crate (which is currently used by rust-analyzer) but with unused functionality stripped out.

I’ll have to rebase on master once #14859 is merged but I think everything else is alright :D
2023-05-31 10:23:19 +00:00
bors
d2b3caa5b5 Auto merge of #14929 - Veykril:hover-hex, r=Veykril
Add render configs for memory layout hovers

Closes https://github.com/rust-lang/rust-analyzer/issues/14918
2023-05-30 16:47:41 +00:00
Lukas Wirth
3c862507b9 Add render configs for memory layout hovers 2023-05-30 18:36:06 +02:00
bors
e33c0b4b5e Auto merge of #14842 - alibektas:internal/ast-make-improve, r=Veykril
Improve ast::make

Add `ty_alias` and make `impl_trait` , `fn` and `impl_` have more coverage.
2023-05-30 16:09:46 +00:00
bors
76d86502f7 Auto merge of #14912 - Veykril:cargo-alltargets, r=Veykril
Don't add --all-targets to runnables for no-std crates

Fixes https://github.com/rust-lang/rust-analyzer/issues/14155
2023-05-30 12:34:28 +00:00
bors
be446c6fd7 Auto merge of #14905 - Veykril:hover-hex, r=Veykril
feat: Render niches on hover
2023-05-30 12:19:51 +00:00
bors
e8dbb8e2e0 Auto merge of #14911 - Veykril:config-cfg, r=Veykril
Allow setting cfgs

Fixes https://github.com/rust-lang/rust-analyzer/issues/14365
2023-05-30 12:00:14 +00:00
Lukas Wirth
1275adc200 Don't leak rustc Layout in hir layer 2023-05-30 13:54:30 +02:00
Lukas Wirth
3514f2f2ab Render niches on hover 2023-05-30 13:49:43 +02:00
bors
51c3ab5b85 Auto merge of #14920 - lowr:fix/overhaul-named-struct-to-tuple-struct, r=Veykril
Fix edits for `convert_named_struct_to_tuple_struct`

Two fixes:
- When replacing syntax nodes, macro files weren't taken into account. Edits were simply made for `node.syntax().text_range()`, which would be wrong range when `node` is inside a macro file.
- We do ancestor node traversal for every struct name reference to find record expressions/patterns to edit, but we didn't verify that expressions/patterns do actually refer to the struct we're operating on.

Best reviewed one commit at a time.

Fixes #13780
Fixes #14927
2023-05-30 11:45:22 +00:00
Ryo Yoshida
033e6ac57a
Verify name references more rigidly
Previously we didn't verify that record expressions/patterns that were
found did actually point to the struct we're operating on. Moreover,
when that record expressions/patterns had missing child nodes, we would
continue traversing their ancestor nodes.
2023-05-29 20:10:54 +09:00
Ryo Yoshida
ab9347542c
Consider macro files when replacing nodes 2023-05-29 19:52:31 +09:00
hkalbasi
51368793b4 MIR episode 6 2023-05-28 23:25:15 +03:30
Lukas Wirth
8bc826dd53 Add diagnostic for _ expressions (typed holes) 2023-05-28 14:55:28 +02:00
Lukas Wirth
bbd9e41606 Don't add --all-targets to runnables for no-std crates 2023-05-28 14:18:44 +02:00
Luna Razzaghipour
6b46095980
Make formatting a latency-sensitive request 2023-05-28 22:10:24 +10:00
Lukas Wirth
cea84427e0 Allow setting cfgs 2023-05-28 13:43:21 +02:00
Ryo Yoshida
0d4d1d7e3b
Implement ${count()} metavariable expression 2023-05-28 19:54:36 +09:00
Ryo Yoshida
9ebaa85d37
Split test module for metavariable expressions 2023-05-28 19:54:23 +09:00
Luna Razzaghipour
74bc2a47e0
Wrap platform-specific QoS in r-a-specific “thread intent” 2023-05-28 20:37:38 +10:00
Luna Razzaghipour
d0b001eed2
Use appropriate QoS classes throughout the codebase 2023-05-28 20:37:37 +10:00
Luna Razzaghipour
2924fd2213
Implement custom QoS-aware thread pool
This code replaces the thread pool implementation we were using
previously (from the `threadpool` crate). By making the thread pool
aware of QoS, each job spawned on the thread pool can have a different
QoS class.

This commit also replaces every QoS class used previously with Default
as a temporary measure so that each usage can be chosen deliberately.
2023-05-28 20:37:35 +10:00
bors
1b5523a8cd Auto merge of #14913 - HKalbasi:fix14844, r=HKalbasi
Evaluate `UnevalutedConst` before trait solving

cc #14844
2023-05-26 21:01:20 +00:00
hkalbasi
cd4bffdd69 Evaluate UnevalutedConst before trait solving 2023-05-27 00:28:11 +03:30
Lukas Wirth
35b208aaa7 Filter out unused cargo features from config 2023-05-26 22:16:34 +02:00
Lukas Wirth
ee8c18cb6e Fix out_dirs_check test on stable 2023-05-26 20:54:58 +02:00
bors
6bca9f2aac Auto merge of #14859 - lunacookies:qos, r=lunacookies
Specify thread types using Quality of Service API

<details>
<summary>Some background (in case you haven’t heard of QoS before)</summary>

Heterogenous multi-core CPUs are increasingly found in laptops and desktops (e.g. Alder Lake, Snapdragon 8cx Gen 3, M1). To maximize efficiency on this kind of hardware, it is important to provide the operating system with more information so threads can be scheduled on different core types appropriately.

The approach that XNU (the kernel of macOS, iOS, etc) and Windows have taken is to provide a high-level semantic API – quality of service, or QoS – which informs the OS of the program’s intent. For instance, you might specify that a thread is running a render loop for a game. This makes the OS provide this thread with as large a share of the system’s resources as possible. Specifying a thread is running an unimportant background task, on the other hand, is cause for it to be scheduled exclusively on high-efficiency cores instead of high-performance cores.

QoS APIs allows for easy configuration of many different parameters at once; for instance, setting QoS on XNU affects scheduling, timer latency, I/O priorities, and of course what core type the thread in question should run on. I don’t know any details on how QoS works on Windows, but I would guess it’s similar.

Hypothetically, taking advantage of these APIs would improve power consumption, thermals, battery life if applicable, etc.

</details>

# Relevance to rust-analyzer

From what I can tell the philosophy behind both the XNU and Windows QoS APIs is that _user interfaces should never stutter under any circumstances._ You can see this in the array of QoS classes which are available: the highest QoS class in both APIs is one intended explicitly for UI render loops.

Imagine rust-analyzer is performing CPU-intensive background work – maybe you just invoked Find Usages on `usize` or opened a large project – in this scenario the editor’s render loop should absolutely get higher priority than rust-analyzer, no matter what. You could view it in terms of “realtime-ness”: flight control software is hard realtime, audio software is soft realtime, GUIs are softer realtime, and rust-analyzer is not realtime at all. Of course, maximizing responsiveness is important, but respecting the rest of the system is more important.

# Implementation

I’ve tried my best to unify thread creation in `stdx`, where the new API I’ve introduced _requires_ specifying a QoS class. Different points along the performance/efficiency curve can make a great difference; the M1’s e-cores use around three times less power than the p-cores, so putting in this effort is worthwhile IMO.

It’s worth mentioning that Linux does not [yet](https://youtu.be/RfgPWpTwTQo) have a QoS API. Maybe translating QoS into regular thread priorities would be acceptable? From what I can tell the only scheduling-related code in rust-analyzer is Windows-specific, so ignoring QoS entirely on Linux shouldn’t cause any new issues. Also, I haven’t implemented support for the Windows QoS APIs because I don’t have a Windows machine to test on, and because I’m completely unfamiliar with Windows APIs :)

I noticed that rust-analyzer handles some requests on the main thread (using `.on_sync()`) and others on a threadpool (using `.on()`). I think it would make sense to run the main thread at the User Initiated QoS and the threadpool at Utility, but only if all requests that are caused by typing use `.on_sync()` and all that don’t use `.on()`. I don’t understand how the `.on_sync()`/`.on()` split that’s currently present was chosen, so I’ve let this code be for the moment. Let me know if changing this to what I proposed makes any sense.

To avoid having to change everything back in case I’ve misunderstood something, I’ve left all threads at the Utility QoS for now. Of course, this isn’t what I hope the code will look like in the end, but I figured I have to start somewhere :P

# References

<ul>

<li><a href="https://developer.apple.com/library/archive/documentation/Performance/Conceptual/power_efficiency_guidelines_osx/PrioritizeWorkAtTheTaskLevel.html">Apple documentation related to QoS</a></li>
<li><a href="67e155c940/include/pthread/qos.h">pthread API for setting QoS on XNU</a></li>
<li><a href="https://learn.microsoft.com/en-us/windows/win32/procthread/quality-of-service">Windows’s QoS classes</a></li>
<li>
<details>
<summary>Full documentation of XNU QoS classes. This documentation is only available as a huge not-very-readable comment in a header file, so I’ve reformatted it and put it here for reference.</summary>
<ul>
<li><p><strong><code>QOS_CLASS_USER_INTERACTIVE</code>: A QOS class which indicates work performed by this thread is interactive with the user.</strong></p><p>Such work is requested to run at high priority relative to other work on the system. Specifying this QOS class is a request to run with nearly all available system CPU and I/O bandwidth even under contention. This is not an energy-efficient QOS class to use for large tasks. The use of this QOS class should be limited to critical interaction with the user such as handling events on the main event loop, view drawing, animation, etc.</p></li>
<li><p><strong><code>QOS_CLASS_USER_INITIATED</code>: A QOS class which indicates work performed by this thread was initiated by the user and that the user is likely waiting for the results.</strong></p><p>Such work is requested to run at a priority below critical user-interactive work, but relatively higher than other work on the system. This is not an energy-efficient QOS class to use for large tasks. Its use should be limited to operations of short enough duration that the user is unlikely to switch tasks while waiting for the results. Typical user-initiated work will have progress indicated by the display of placeholder content or modal user interface.</p></li>
<li><p><strong><code>QOS_CLASS_DEFAULT</code>: A default QOS class used by the system in cases where more specific QOS class information is not available.</strong></p><p>Such work is requested to run at a priority below critical user-interactive and user-initiated work, but relatively higher than utility and background tasks. Threads created by <code>pthread_create()</code> without an attribute specifying a QOS class will default to <code>QOS_CLASS_DEFAULT</code>. This QOS class value is not intended to be used as a work classification, it should only be set when propagating or restoring QOS class values provided by the system.</p></li>
<li><p><strong><code>QOS_CLASS_UTILITY</code>: A QOS class which indicates work performed by this thread may or may not be initiated by the user and that the user is unlikely to be immediately waiting for the results.</strong></p><p>Such work is requested to run at a priority below critical user-interactive and user-initiated work, but relatively higher than low-level system maintenance tasks. The use of this QOS class indicates the work should be run in an energy and thermally-efficient manner. The progress of utility work may or may not be indicated to the user, but the effect of such work is user-visible.</p></li>
<li><p><strong><code>QOS_CLASS_BACKGROUND</code>: A QOS class which indicates work performed by this thread was not initiated by the user and that the user may be unaware of the results.</strong></p><p>Such work is requested to run at a priority below other work. The use of this QOS class indicates the work should be run in the most energy and thermally-efficient manner.</p></li>
<li><p><strong><code>QOS_CLASS_UNSPECIFIED</code>: A QOS class value which indicates the absence or removal of QOS class information.</strong></p><p>As an API return value, may indicate that threads or pthread attributes were configured with legacy API incompatible or in conflict with the QOS class system.</p></li>
</ul>
</details>
</li>

</ul>
2023-05-26 15:48:22 +00:00
Lukas Wirth
be9cc0baae Render size, align and offset hover values in hex 2023-05-26 16:41:45 +02:00
Lukas Wirth
f876adf617 Report flycheck errors via status 2023-05-26 15:37:41 +02:00
Lukas Wirth
a2b59b110f Report config errors via status 2023-05-26 15:26:03 +02:00
Lukas Wirth
79fe11ced3 Shuffle some things around 2023-05-26 15:09:19 +02:00
bors
e963846656 Auto merge of #14816 - justahero:gh-14626, r=Veykril
feat: Assist to replace generic with impl trait

This adds a new assist named "Replace named generic with impl". It is the inverse operation to the existing "Replace impl trait with generic" assist.

It allows to refactor the following statement:

```rust
//      👇 cursor
fn new<T$0: ToString>(input: T) -> Self {}
```

to be transformed into:

```rust
fn new(input: impl ToString) -> Self {}
```

* adds new helper function `impl_trait_type` to create AST node
* add method to remove an existing generic param type from param list

Closes #14626
2023-05-26 12:03:44 +00:00
Sebastian Ziebell
e78df83e2f Integrate feedback
* pass in existing `Semantics` object to function
* pass in `Definition` for param type
* refactor iterator to use `flatten`
2023-05-26 13:43:12 +02:00
bors
8589a2d843 Auto merge of #14849 - alibektas:14557n, r=Veykril
enhancement : using doc aliases to search workspace symbols  ( fixes #14557 )

Doc aliases are now visible among symbols and can be used for searching.
2023-05-26 11:30:40 +00:00
Ali Bektas
d49924dc6e Choose & over ref, make nav target's name more intuitive. 2023-05-26 13:24:44 +02:00
Sebastian Ziebell
ce1c85317f Check param is not referenced in function
This checks the type param is referenced neither in the function body
nor as a return type.

* add tests
2023-05-26 13:24:29 +02:00
Sebastian Ziebell
95f59668e6 Fix removal of generic param from list
This removes an existing generic param from the `GenericParamList`. It
also considers to remove the extra colon & whitespace to the previous
sibling.

* change order to get all param types first and mark them as mutable
  before the first edit happens
* add helper function to remove a generic parameter
* fix test output
2023-05-26 13:13:15 +02:00
Sebastian Ziebell
59f8827a6f Implement assist to replace named generic with impl
This adds a new assist named "replace named generic with impl" to move
the generic param type from the generic param list into the function
signature.

```rust
fn new<T: ToString>(input: T) -> Self {}
```

becomes

```rust
fn new(input: impl ToString) -> Self {}
```

The first step is to determine if the assist can be applied, there has
to be a match between generic trait param & function paramter types.

* replace function parameter type(s) with impl
* add new `impl_trait_type` function to generate the new trait bounds with `impl` keyword  for use in the
  function signature
2023-05-26 13:13:11 +02:00
bors
2fd9260472 Auto merge of #14897 - HKalbasi:dev, r=HKalbasi
Insert type vars in function arguments

follow up #14891
2023-05-26 10:56:39 +00:00
hkalbasi
c21d09f3cc insert type vars in function arguments 2023-05-26 14:26:13 +03:30
Ryo Yoshida
397c8e5148
fix: don't try determining type of token inside macro calls 2023-05-26 16:46:45 +09:00
Wilfred Hughes
5b0e170683 Allow users to override the .scip output file path
Previously, rust-analyzer would write to the file index.scip
unconditionally.
2023-05-25 16:54:31 -07:00
hkalbasi
780349bdaf fix need-mut false positive in closure capture of match scrutinee 2023-05-26 02:08:37 +03:30
hkalbasi
7ef185d65e evaluate UnevaluatedConst in unify 2023-05-25 19:37:20 +03:30
bors
efd3094aba Auto merge of #14890 - HKalbasi:dev, r=HKalbasi
use `::core` instead of `$crate` in `option_env!`

fix #14885
2023-05-25 15:19:18 +00:00
hkalbasi
b0f17668f7 use ::core instead of $crate in option_env! 2023-05-25 18:46:34 +03:30
Lukas Wirth
e3dfcf2eb2 Add context to overly long loop message 2023-05-25 16:20:28 +02:00