Commit Graph

23067 Commits

Author SHA1 Message Date
OleStrohm
301b8894ea Added more consteval tests and fixed consteval result 2022-09-12 20:20:45 +01:00
OleStrohm
ad0a6bf1a3 Added consteval tests 2022-09-12 20:20:43 +01:00
OleStrohm
2f84b6e2e5 Almost there 2022-09-12 20:20:22 +01:00
OleStrohm
b63234e20b Cleaned up code 2022-09-12 20:19:49 +01:00
OleStrohm
e28046c673 Removed unnecessary TODO 2022-09-12 20:19:19 +01:00
OleStrohm
997fc46efa Implemented basic enum const eval 2022-09-12 20:19:13 +01:00
bors
f64c95600c Auto merge of #13216 - DesmondWillowbrook:move_format_string_arg, r=DesmondWillowbrook
New assist: move_format_string_arg

The name might need some improving.

```rust
fn main() {
    print!("{x + 1}");
}
```
to
```rust
fn main() {
    print!("{}"$0, x + 1);
}
```

fixes #13180

ref to #5988 for similar work

* extracted `format_like`'s parser to it's own module in `ide-db`
* reworked the parser's API to be more direct
* added assist to extract expressions in format args
2022-09-12 15:50:42 +00:00
bors
b1a4ba3e84 Auto merge of #13223 - lowr:fix/hir-proj-normalization, r=flodiebold
fix: handle lifetime variables in projection normalization

Fixes #12674

The problem is that we've been skipping the binders of normalized projections assuming they should be empty, but the assumption is unfortunately wrong. We may get back lifetime variables and should handle them before returning them as normalized projections. For those who are curious why we get those even though we treat all lifetimes as 'static, [this comment in chalk](d875af0ff1/chalk-solve/src/infer/unify.rs (L888-L908)) may be interesting.

I thought using `InferenceTable` would be cleaner than the other ways as it already has the methods for canonicalization, normalizing projection, and resolving variables, so moved goal building and trait solving logic to a new `HirDatabase` query. I made it transparent query as the query itself doesn't do much work but the eventual call to `HirDatabase::trait_solve_query()` does.
2022-09-12 14:24:57 +00:00
Ryo Yoshida
efb56160c9
fix: handle lifetime variables in projection normalization 2022-09-12 22:52:58 +09:00
bors
b54d22d96a Auto merge of #13215 - Veykril:toggle-inlay, r=Veykril
Remove the toggleInlayHints command from VSCode

Inlay hints are no longer something specifc to r-a as it has been upstreamed into the LSP, we don't have a reason to give the config for this feature special treatment in regards to toggling. There are plenty of other options out there in the VSCode marketplace to create toggle commands/hotkeys for configurations in general which I believe we should nudge people towards instead.
2022-09-12 13:45:25 +00:00
Kartavya Vashishtha
54e9324e93
Update crates/ide-assists/src/handlers/move_format_string_arg.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-09-12 05:45:11 -07:00
bors
7a704f2cc7 Auto merge of #13147 - lowr:fix/dyn-ty-inherent-methods, r=Veykril
fix: handle trait methods as inherent methods for trait-related types

Fixes #10677

When resolving methods for trait object types and placeholder types that are bounded by traits, we need to count the methods of the trait and its super traits as inherent methods. This matters because these trait methods have higher priority than the other traits' methods.

Relevant code in rustc: [`assemble_inherent_candidates_from_object()`](0631ea5d73/compiler/rustc_typeck/src/check/method/probe.rs (L783-L792)) for trait object types, [`assemble_inherent_candidates_from_param()`](0631ea5d73/compiler/rustc_typeck/src/check/method/probe.rs (L838-L847)) for placeholder types. Notice the second arg of `push_candidate()` is `is_inherent`.
2022-09-12 12:19:14 +00:00
bors
e38dfe5536 Auto merge of #13186 - enomado:master, r=Veykril
Filter imports on find-all-references

Attempt to #13184
2022-09-12 12:09:57 +00:00
bors
352a5b8625 Auto merge of #13212 - Veykril:no-std-config, r=Veykril
Add config to unconditionally prefer core imports over std

Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
2022-09-12 11:51:31 +00:00
bors
bc131422e9 Auto merge of #13222 - BorysMinaiev:master, r=flodiebold
Remove redundant 'resolve_obligations_as_possible' call

Hi! I was looking for a "good first issue" and saw this one: https://github.com/rust-lang/rust-analyzer/issues/7542. I like searching for performance improvements, so I wanted to try to find something useful there.

There are two tests in integrated_benchmarks.rs, I looked at 'integrated_highlighting_benchmark' (not the one discussed in the issue above).

Profile from that test looks like this:
```
$ RUN_SLOW_BENCHES=1 cargo test --release --package rust-analyzer --lib -- integrated_benchmarks::integrated_highlighting_benchmark --exact --nocapture
    Finished release [optimized] target(s) in 0.06s
     Running unittests src/lib.rs (target/release/deps/rust_analyzer-a80ca6bb8f877458)

running 1 test
workspace loading: 358.45ms
initial: 9.60s
change: 13.96µs
cpu profiling is disabled, uncomment `default = [ "cpu_profiler" ]` in Cargo.toml to enable.
  273ms - highlight
      143ms - infer:wait @ per_query_memory_usage
          143ms - infer_query
                0   - crate_def_map:wait (3165 calls)
                4ms - deref_by_trait (967 calls)
               96ms - resolve_obligations_as_possible (22106 calls)
                0   - trait_solve::wait (2068 calls)
       21ms - Semantics::analyze_impl (18 calls)
        0   - SourceBinder::to_module_def (20 calls)
       36ms - classify_name (19 calls)
       19ms - classify_name_ref (308 calls)
        0   - crate_def_map:wait (461 calls)
        4ms - descend_into_macros (628 calls)
        0   - generic_params_query (4 calls)
        0   - impl_data_with_diagnostics_query (1 calls)
       45ms - infer:wait (37 calls)
        0   - resolve_obligations_as_possible (2 calls)
        0   - source_file_to_def (1 calls)
        0   - trait_solve::wait (42 calls)
after change: 275.23ms
test integrated_benchmarks::integrated_highlighting_benchmark ... ok
```
22106 calls to `resolve_obligations_as_possible` seem like the main issue there.

One thing I noticed (and fixed in this PR) is that `InferenceContext::resolve_ty_shallow` first calls `resolve_obligations_as_possible`, and then calls `InferenceTable::resolve_ty_shallow`. But `InferenceTable::resolve_ty_shallow` [inside](2e9f1204ca/crates/hir-ty/src/infer/unify.rs (L372)) again calls `resolve_obligations_as_possible`.

`resolve_obligations_as_possible` inside has a while loop, which works until it can't find any helpful information. So calling this function for the second time does nothing, so one of the calls could be safely removed.

`InferenceContext::resolve_ty_shallow` is actually quite a hot place, and after fixing it, the total number of `resolve_obligations_as_possible` in this test is reduced to 15516 (from 22106). "After change" time also improves from ~270ms to ~240ms, which is not a very huge win, but still something measurable.

Same profile after PR:
```
$ RUN_SLOW_BENCHES=1 cargo test --release --package rust-analyzer --lib -- integrated_benchmarks::integrated_highlighting_benchmark --exact --nocapture
    Finished release [optimized] target(s) in 0.06s
     Running unittests src/lib.rs (target/release/deps/rust_analyzer-a80ca6bb8f877458)

running 1 test
workspace loading: 339.86ms
initial: 9.28s
change: 10.69µs
cpu profiling is disabled, uncomment `default = [ "cpu_profiler" ]` in Cargo.toml to enable.
  236ms - highlight
      110ms - infer:wait @ per_query_memory_usage
          110ms - infer_query
                0   - crate_def_map:wait (3165 calls)
                4ms - deref_by_trait (967 calls)
               64ms - resolve_obligations_as_possible (15516 calls)
                0   - trait_solve::wait (2068 calls)
       21ms - Semantics::analyze_impl (18 calls)
        0   - SourceBinder::to_module_def (20 calls)
       34ms - classify_name (19 calls)
       18ms - classify_name_ref (308 calls)
        0   - crate_def_map:wait (461 calls)
        3ms - descend_into_macros (628 calls)
        0   - generic_params_query (4 calls)
        0   - impl_data_with_diagnostics_query (1 calls)
       45ms - infer:wait (37 calls)
        0   - resolve_obligations_as_possible (2 calls)
        0   - source_file_to_def (1 calls)
        0   - trait_solve::wait (42 calls)
after change: 238.15ms
test integrated_benchmarks::integrated_highlighting_benchmark ... ok
```

The performance of this test could be further improved but at the cost of making code more complicated, so I wanted to check if such a change is desirable before sending another PR.

`resolve_obligations_as_possible` is actually called a lot of times even when no new information was provided. As I understand, `resolve_obligations_as_possible` could do something useful only if some variables/values were unified since the last check. We can store a boolean variable inside `InferenceTable`, which indicates if `try_unify` was called after last `resolve_obligations_as_possible`. If it wasn't called, we can safely not call `resolve_obligations_as_possible` again.

I tested this change locally, and it reduces the number of `resolve_obligations_as_possible` to several thousand (it is not shown in the profile anymore, so don't know the exact number), and the total time is reduced to ~180ms. Here is a generated profile:
```
$ RUN_SLOW_BENCHES=1 cargo test --release --package rust-analyzer --lib -- integrated_benchmarks::integrated_highlighting_benchmark --exact --nocapture
    Finished release [optimized] target(s) in 0.06s
     Running unittests src/lib.rs (target/release/deps/rust_analyzer-a80ca6bb8f877458)

running 1 test
workspace loading: 349.92ms
initial: 8.56s
change: 11.32µs
cpu profiling is disabled, uncomment `default = [ "cpu_profiler" ]` in Cargo.toml to enable.
  175ms - highlight
       21ms - Semantics::analyze_impl (18 calls)
        0   - SourceBinder::to_module_def (20 calls)
       33ms - classify_name (19 calls)
       17ms - classify_name_ref (308 calls)
        0   - crate_def_map:wait (461 calls)
        3ms - descend_into_macros (628 calls)
        0   - generic_params_query (4 calls)
        0   - impl_data_with_diagnostics_query (1 calls)
       97ms - infer:wait (38 calls)
        0   - resolve_obligations_as_possible (2 calls)
        0   - source_file_to_def (1 calls)
        0   - trait_solve::wait (42 calls)
after change: 177.04ms
test integrated_benchmarks::integrated_highlighting_benchmark ... ok
```
Let me know if adding a new bool field seems like a reasonable tradeoff, so I can send a PR.
2022-09-12 11:30:24 +00:00
Borys Minaiev
32603baac3 Remove redundant 'resolve_obligations_as_possible' call 2022-09-12 11:03:44 +01:00
bors
2e9f1204ca Auto merge of #13214 - SpencerSharkey:ubuntu-container-build, r=lnicola
Build release artifact against older Glibc

When GitHub [deprecated Ubuntu 18.04](https://github.blog/changelog/2022-08-09-github-actions-the-ubuntu-18-04-actions-runner-image-is-being-deprecated-and-will-be-removed-by-12-1-22/) runners, rust-analyzer was forced to bump runners to 20.04 which includes an updated Glib. This renders RA incompatible with the still popular Ubuntu 18.04 and other slightly older distro versions.

Until a deprecation plan is announced on RA's side, I propose binaries shall be built against older glibc to maintain compatibility.

This PR changes the Release CI workflow to build the `linux-x64/x86_64-unknown-linux-gnu` release in an Ubuntu 18.04 container.

Fixes #13081 and #13085
2022-09-11 11:34:25 +00:00
Spencer
73d759955f
use rustup minimal profile and add curl retries 2022-09-10 23:43:33 -07:00
Spencer
ae57150d0d
add rustup bin to path 2022-09-10 23:29:15 -07:00
Spencer
dd65588c51
install rustup directly 2022-09-10 23:25:30 -07:00
Kartavya Vashishtha
fb5ae9906b
suggest ExtractRefactor if no expressions found
Added `Ident` variant to arg enum.
2022-09-11 10:39:25 +05:30
Spencer
b843b8801d
revert conditional logic for apt update step 2022-09-10 18:10:56 -07:00
Kartavya Vashishtha
a5cbee4d11
remove false positive 2022-09-10 21:04:25 +05:30
Kartavya Vashishtha
cc7200891b
new lint: move_format_string_arg
The name might need some improving.

extract format_like's parser to it's own module in ide-db

reworked the parser's API to be more direct

added assist to extract expressions in format args
2022-09-10 20:13:46 +05:30
Kartavya Vashishtha
2584d48508
wip 2022-09-10 20:13:46 +05:30
Lukas Wirth
9c97997af9 Remove the toggleInlayHints command from VSCode
Inlay hints are no longer something specifc to r-a as it has been
upstreamed into the LSP, we don't have a reason to give the config
for this feature special treatment in regards to toggling. There are
plenty of other options out there in the VSCode marketplace to create
toggle commands/hotkeys for configurations in general which I believe
we should nudge people towards instead.
2022-09-10 11:50:55 +02:00
Spencer Sharkey
54fe5b7fc2 use ubuntu 18.04 container for release 2022-09-09 21:23:02 -07:00
Lukas Wirth
7d19971666 Add config to unconditionally prefer core imports over std
Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
2022-09-09 20:04:56 +02:00
Stanislav
f7f4792f4f fixes 2022-09-09 20:58:06 +03:00
bors
b7e8b9a6b8 Auto merge of #13207 - randomicon00:semicol#13196, r=lnicola
fix: add semicolon completion to mod

fixes #13196

`@Veykril` The tests are passing. I added one specifically for this case.
2022-09-09 04:15:20 +00:00
Stanislav
773f9b38e3 fix. round 4 2022-09-09 01:19:34 +03:00
Peh
bd3feea8bc fix: removed swap file 2022-09-08 22:44:10 +01:00
Peh
c7fefd5223 fix: add semicolon completion to mod 2022-09-08 22:37:31 +01:00
Stanislav
ab0b64b26c fix comment round 3 2022-09-08 22:55:04 +03:00
Stanislav
0240294759 fix comment round 2 2022-09-08 22:47:39 +03:00
Stanislav
1764c42518 fix comment 2022-09-08 22:36:36 +03:00
bors
4e1a3da8f2 Auto merge of #13158 - jonas-schievink:inlayhint-links, r=jonas-schievink
feat: make clicking a closing brace inlay hint go to the opening brace
2022-09-08 16:38:40 +00:00
Jonas Schievink
c4eadab016
Update crates/rust-analyzer/src/to_proto.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-09-08 18:33:53 +02:00
Jonas Schievink
064c9ef9e2 Make clicking closing brace hint go to the opening brace 2022-09-08 17:25:28 +02:00
Stanislav
9f6553e1d6 add config for import filtering 2022-09-08 01:53:20 +03:00
bors
6909556435 Auto merge of #13200 - P1n3appl3:sysroot, r=Veykril
Use proc-macro-srv from sysroot in rust-project.json workspaces

This was discussed [on zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/.60sysroot.60.20vs.20.60sysroot_src.60.20for.20.60rust-project.2Ejson.60.3F/near/293023920), basically in `rust-project.json` workspaces RA doesn't respect the `sysroot` setting when picking which `proc-macro-srv` to launch, and this causes abi mismatches in practice.

This is the simple fix that `@Veykril` suggested, and I've verified that it works on Fuchsia by inspecting the cmdline with `pgrep rust-analyzer | xargs ps -fp` to check that it's using the `proc-macro-srv` from our prebuilts which matches the `sysroot` specified in our `rust-project.json`.

Can this be merged as is, or do we need to add tests that exercise this?
2022-09-07 09:36:03 +00:00
Joseph Ryan
5d126a18b4 Use proc-macro-srv from sysroot in rust-project.json 2022-09-06 18:27:17 -07:00
Stanislav
eba54c2fc9 pretty solition works 2022-09-07 04:09:25 +03:00
Stanislav
92d54f9b30 typo and draft 2022-09-07 03:24:55 +03:00
Stanislav
bd0eeb3f04
Update crates/ide/src/references.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-09-07 03:01:06 +03:00
bors
6dfd8aebdf Auto merge of #13192 - lowr:fix/dyn-sort-all-bounds, r=Veykril
fix: sort all bounds on trait object types

Fixes #13181

#12793 allowed different ordering of trait bounds in trait object types but failed to account for the ordering of projection bounds. I opted for sorting all the bounds at once rather than splitting them into `SmallVec`s so it's easier to do the same thing for other bounds when we have them.
2022-09-05 11:24:54 +00:00
bors
5be2e6574d Auto merge of #13185 - ChayimFriedman2:insert-ws-in-static-const-macro, r=Veykril
fix: Insert whitespaces into static & const bodies if they are expanded from macro on hover

Partially fixes #13143.

To resolve the other part we need to expand macros in unevaluated static & const bodies, and I'm not sure we want to. If for example it includes a call to `assert!()`, expanding it will lead to worse hover.
2022-09-05 11:10:40 +00:00
bors
4790916876 Auto merge of #13139 - Austaras:enum, r=Veykril
Suggest struct when completing enum

closes #13107
2022-09-05 10:59:38 +00:00
bors
a1c26530ec Auto merge of #13091 - ice1k:hey, r=Veykril
Remove type alias definition on inline

Fix #13079
2022-09-05 10:49:19 +00:00
Ryo Yoshida
265c75c53f
fix: sort all bounds on trait object types 2022-09-05 19:13:32 +09:00