Commit Graph

2054 Commits

Author SHA1 Message Date
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
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
Ryo Yoshida
397c8e5148
fix: don't try determining type of token inside macro calls 2023-05-26 16:46:45 +09:00
alibektas
1222869b3e Fix #14557. Docs aliases can now be detected and used in searching for workspace symbols 2023-05-24 23:57:24 +02:00
Lukas Wirth
c7ef6c25b7 internal: Replace Display impl for Name 2023-05-24 20:55:12 +02:00
Luna Razzaghipour
ca6461c143
Add proof-of-concept QoS implementation 2023-05-20 22:29:32 +10:00
hkalbasi
92d6670f72 Consider block impls in lookup_impl_assoc_item_for_trait_ref 2023-05-20 01:11:17 +03:30
hkalbasi
60379dabfb resolve types in closure capture copy detection 2023-05-19 14:54:57 +03:30
bors
e8ae2d3976 Auto merge of #14848 - bm-w:fix/highlight-let-else-return, r=Veykril
Fix `preorder_expr` skipping the `else` block of let-else statements

Fixes exit/yield points not getting highlighted in such blocks for `highlight_related` (#14813; and possibly other bugs in features that use `preorder_expr`).
2023-05-19 07:41:46 +00:00
Bastiaan Marinus van de Weerd
5857836047
Fix preorder_expr skipping the else block of let-else statements
Fixes exit/yield points not getting highlighted in such blocks for `highlight_related` (#14813; and possibly other bugs in features that use `preorder_expr`).
2023-05-18 18:30:27 -04:00
hkalbasi
cae9660a1d Add layout info for enum variant and locals 2023-05-18 21:03:03 +03:30
hkalbasi
4adfbbfbad partially support panic message in MirEvalError 2023-05-18 18:30:49 +03:30
bors
9ce95674e8 Auto merge of #14837 - Veykril:rustc-lexer, r=Veykril
Support c string literals
2023-05-18 11:55:38 +00:00
bors
034d7c8537 Auto merge of #14787 - HKalbasi:mir2, r=HKalbasi
MIR episode 5

This PR inits drop support (it is very broken at this stage, some things are dropped multiple time, drop scopes are wrong, ...) and adds stdout support (`println!` doesn't work since its expansion is dummy, but `stdout().write(b"hello world\n")` works if you use `RA_SYSROOT_HACK`) for interpreting. There is no useful unit test that it can interpret yet, but it is a good sign that it didn't hit a major road block yet.

In MIR lowering, it adds support for slice pattern and anonymous const blocks, and some fixes so that we can evaluate `SmolStr::new_inline` in const eval. With these changes, 57 failed mir body remains.
2023-05-18 09:44:26 +00:00
bors
f9be79603a Auto merge of #14820 - HKalbasi:format-args, r=HKalbasi
Expand `format_args!` with more details
2023-05-18 09:09:06 +00:00
Lukas Wirth
4b577e2bc8 Support c string literals 2023-05-18 11:06:05 +02:00
Lukas Wirth
03fb1310c2 fix: Fix bind pat hint padding 2023-05-18 08:48:53 +02:00
bors
c06f088968 Auto merge of #14823 - Veykril:discriminant-inlays, r=Veykril
fix: Discriminant hints only render for datacarrying enums with primitive repr
2023-05-18 05:50:41 +00:00
bors
c4026bf9b9 Auto merge of #14818 - poliorcetics:type-hints-after-item, r=Veykril
fix: place type inlay hints after the item and without left-padding

**Before**:

![Type hints were placed before the item and there was left-padding that accentuaded the issue](https://github.com/rust-lang/rust-analyzer/assets/7951708/006a28e9-ed7b-4d49-a7e7-3c6da8efca79)

**After**:

![Type hints are now placed after the item and without padding since there already is `: ` in front of the type](https://github.com/rust-lang/rust-analyzer/assets/7951708/330a847f-8c59-40c7-877f-bf1aaced30e2)
2023-05-18 04:50:09 +00:00
bors
d0768aad62 Auto merge of #14812 - Veykril:highlight-trait-assoc, r=HKalbasi
feat: Highlight used trait assoc items when cursor is on trait import or trait bound
2023-05-18 01:53:30 +00:00
Lukas Wirth
c12ede8c34 fix: Discriminant hints only render for datacarrying enums with primitive repr 2023-05-16 22:15:39 +02:00
hkalbasi
a6e5a912f9 Expand format_args! with more details 2023-05-16 19:12:40 +03:30
Alexis (Poliorcetics) Bourget
22599adf9b fix: place type inlay hints after the item and without left-padding 2023-05-16 15:13:48 +02:00
Lukas Wirth
b87ee914fa feat: Highlight used trait assoc items when cursor is on trait import or trait bound 2023-05-15 20:41:35 +02:00
Lukas Wirth
ba8bcde4f5 Also render coercions for ranged type hover on closures 2023-05-15 19:45:01 +02:00
Lukas Wirth
08dc0e21af feat: Render hover actions for closure captures and sig 2023-05-15 19:35:27 +02:00
bors
1e6bd6cb0d Auto merge of #14794 - Veykril:inlay-kind-refac, r=Veykril
Restructure InlayHint, no longer derive properties from its kind

Closes https://github.com/rust-lang/rust-analyzer/issues/14595
2023-05-15 09:49:17 +00:00
bors
db8f39ce19 Auto merge of #14797 - Veykril:symbol-query, r=Veykril
fix: Fix perf regression from symbol index refactor

Should fix the regressions introduced by https://github.com/rust-lang/rust-analyzer/pull/14715 by partially rolling back the PR
2023-05-13 15:41:54 +00:00
Lukas Wirth
2e03b198ca fix: Fix perf regression from symbol index refactor 2023-05-13 17:41:09 +02:00
Lukas Wirth
8e116855f5 Add macro modifier for highlighting tokens in macro calls 2023-05-13 11:43:39 +02:00
Lukas Wirth
edd60f7b0d Simplify bind pat filtering 2023-05-13 11:02:57 +02:00
Lukas Wirth
730286b523 Restructure InlayHint, no longer derive properties from its kind 2023-05-13 10:42:26 +02:00
hkalbasi
cbcafd3539 MIR episode 5 2023-05-12 18:17:15 +03:30
Lukas Wirth
4b42acf617 Add basic support for augmentsSyntaxTokens 2023-05-10 20:48:51 +02:00
bors
aaed89ac04 Auto merge of #14763 - lnicola:dep-tree-fixes, r=lnicola
Fix manual formatting and remove duplicate command
2023-05-08 18:28:58 +00:00
Laurențiu Nicola
10637cf3e8 Fix formatting 2023-05-08 21:27:43 +03:00
Laurențiu Nicola
b632c7d322 Fix broken table 2023-05-08 21:27:35 +03:00
bors
d3ce333ec8 Auto merge of #14742 - Veykril:closure-capture-inlays, r=Veykril
feat: Closure capture inlay hints

I opted for a fictional `move(foo, &bar, &mut qux)` syntax here, disabled by default as these are not correct rust syntax and hence could cause confusion.
![image](https://user-images.githubusercontent.com/3757771/236447484-649a4ea6-ad61-496e-bad8-765a5236150e.png)
2023-05-08 09:52:29 +00:00
Lukas Wirth
4c5fd19ee5 Render places in capture inlay hints 2023-05-08 09:50:58 +02:00
bors
833d5301d1 Auto merge of #14758 - lumenian:hover-layout-config, r=HKalbasi
Add config for disabling hover memory layout data

Requested in https://github.com/rust-lang/rust-analyzer/pull/14748#issuecomment-1537190252
2023-05-07 16:22:57 +00:00
Yury Ivanou
8e1ba7fdab Fix memory layout config not working for closures 2023-05-07 19:10:01 +03:00
Yury Ivanou
4ed0fa8414 Add config for disabling hover memory layout data 2023-05-07 18:21:07 +03:00
bors
260e996140 Auto merge of #14733 - azdavis:master, r=matklad
Make line-index a lib, use nohash_hasher

These seem like they are not specific to rust-analyzer and could be pulled out to their own libraries. So I did.

https://github.com/azdavis/millet/issues/31
2023-05-06 23:37:02 +00:00
Yury Ivanou
ecc081d625 Show type alias layout on hover 2023-05-06 16:58:57 +03:00
Ariel Davis
4a1922fd1a Depend on nohash-hasher individually 2023-05-06 00:49:23 -07:00
Lukas Wirth
abcdb4bc7d Fix test fixtures 2023-05-05 14:18:27 +02:00
Lukas Wirth
8081a654da feat: Closure capture inlay hints 2023-05-05 13:38:22 +02:00
bors
0d5773e04e Auto merge of #14725 - HKalbasi:derive-impls, r=HKalbasi
Emit function bodies in expanding builtin derives

fix #14235
2023-05-04 15:01:44 +00:00