Commit Graph

397 Commits

Author SHA1 Message Date
Lukas Wirth
b38d5394bb internal: Move grammar codegen into xtask 2024-03-19 10:57:53 +01:00
bors
d3eeadc242 Auto merge of #16852 - ShoyuVanilla:atpit, r=Veykril
feat: Implement ATPIT

Resolves #16584

Note: This implementation only works for ATPIT, not for TAIT.
The main hinderence that blocks the later is the defining sites of TAIT can be inner blocks like in;
```rust
type X = impl Default;

mod foo {
    fn bar() -> super::X {
        ()
    }
}
```
So, to figure out we are defining it or not, we should recursively probe for nested modules and bodies.

For ATPIT, we can just look into current body because `error[E0401]: can't use 'Self' from outer item` prevent such nested structures;

```rust
trait Foo {
    type Item;
    fn foo() -> Self::Item;
}

struct Bar;

impl Foo for Bar {
    type Item = impl Default;
    fn foo() -> Self::Item {
        fn bar() -> Self::Item {
                    ^^^^^^^^^^
                    |
                    use of `Self` from outer item
                    refer to the type directly here instead
            5
        }
        bar()
    }
}
```

But this implementation does not checks for unification of same ATPIT between different bodies, monomorphization, nor layout for similar reason. (But these can be done with lazyness if we can utilize something like "mutation of interned value" with `db`. I coundn't find such thing but I would appreciate it if such thing exists and you could let me know 😅)
2024-03-18 10:38:24 +00:00
Shoyu Vanilla
d034ab0f92 Apply reviewed suggestions 2024-03-18 18:25:41 +09:00
bors
a71a0328d8 Auto merge of #16830 - Jesse-Bakker:fix-ty-panic, r=ShoyuVanilla
Fix panic with impl trait associated types in where clause

Not sure if this is the correct fix, but the tests are green :')

Fixes #16823
2024-03-18 08:35:53 +00:00
bors
65c601fa42 Auto merge of #16863 - Nadrieril:update-pat-ana, r=Veykril
Bump dependencies and use in-tree `rustc_pattern_analysis`

One last `pattern_analysis` API change. I don't have any more planned! So we can now use the in-tree version when available.
2024-03-18 08:08:11 +00:00
Nadrieril
8d59aaf735 Use in-tree rustc_pattern_analysis 2024-03-17 14:16:30 +01:00
Nadrieril
b99618c191 Bump dependencies 2024-03-17 14:11:44 +01:00
Matthias Krüger
2a8edaa14d remove redundant clone()s 2024-03-17 14:06:21 +01:00
Shoyu Vanilla
fc53c59388 fix: typo 2024-03-16 03:53:55 +09:00
Shoyu Vanilla
d2aba91a0c feat: Implement ATPIT 2024-03-16 03:31:12 +09:00
Jesse Bakker
95828850b2 Fix panic with impl trait associated types in where clause 2024-03-13 18:02:15 +01:00
Lukas Wirth
9ba4493918 internal: Improve rooted upmapping 2024-03-12 13:46:58 +01:00
Lukas Wirth
fdc527f096 fix: Fix method resolution snapshotting receiver_ty too early 2024-03-11 15:35:06 +01:00
bors
8f8bcfc131 Auto merge of #16335 - lnicola:salsa-lz4-file-text, r=Veykril
internal: Compress file text using LZ4

I haven't tested properly, but this roughly looks like:

```
1246 MB
    59mb   4899 FileTextQuery

1008 MB
    20mb   4899 CompressedFileTextQuery
   555kb   1790 FileTextQuery
```

We might want to test on something more interesting, like `bevy`.
2024-03-11 13:43:33 +00:00
bors
2320e12541 Auto merge of #16771 - Veykril:self-param-split, r=Veykril
internal: Don't desugar self param into a pattern

Small experiment to see if this simplifies things
2024-03-11 12:45:46 +00:00
bors
a5035f4931 Auto merge of #16749 - Veykril:on-demand-validation-err, r=Veykril
internal: Some method resolution cleanups
2024-03-11 09:18:24 +00:00
bors
1069f57d8b Auto merge of #16784 - Veykril:body-invalid, r=Veykril
internal: Remove synstructure const hack support

The latest version of it no longer emits these
2024-03-11 09:05:26 +00:00
Lukas Wirth
c679482d7e Add method resolution deref inference var test 2024-03-11 10:02:03 +01:00
Lukas Wirth
458f4a2960 internal: Treat the self param as different from patterns when lowering 2024-03-11 09:46:28 +01:00
Lukas Wirth
558feeab61 internal: Remove synstructure const hack support 2024-03-11 09:44:40 +01:00
Laurențiu Nicola
aa74d57825 Merge commit '574e23ec508064613783cba3d1833a95fd9a5080' into sync-from-ra 2024-03-10 08:47:38 +02:00
Laurențiu Nicola
0f43b55e83 Stop using an Arc when setting the file text 2024-03-08 20:30:12 +02:00
Laurențiu Nicola
02b6c181dd Compress file text using lz4 in salsa 2024-03-08 20:22:08 +02:00
Laurențiu Nicola
cd2347e132 Skip match diagnostics for partially unknown types 2024-03-07 19:11:23 +02:00
bors
bbb441ec6d Auto merge of #16778 - Nadrieril:update-pat-ana, r=lnicola
Update `rustc_pattern_analysis` to 0.42.0

There was an important API change in 0.41.0, and (hopefully) a fix for https://github.com/rust-lang/rust-analyzer/issues/16774 in 0.42.0.
2024-03-07 16:22:26 +00:00
Nadrieril
e31484c108 Update the other crates too 2024-03-07 16:44:46 +01:00
Nadrieril
1b0b4220fd Update rustc_pattern_analysis to 0.42.0 2024-03-07 16:33:31 +01:00
bors
e101f24798 Auto merge of #16776 - Veykril:parse-macro-parse, r=Veykril
fix: Don't force draw a dependency edge to the real_span_map query

This can cause extra invalidations as like direct `AstIdMap` dependencies
2024-03-07 13:19:36 +00:00
Lukas Wirth
c04c0dd5ba fix: Don't force draw a dependency edge to the real_span_map query 2024-03-07 14:14:59 +01:00
bors
00f6a7aced Auto merge of #16772 - Veykril:salsa-tracing, r=Veykril
internal: Add tracing spans to macro generated database
2024-03-07 10:16:53 +00:00
Lukas Wirth
a3b6e891ea Add tracing spans to macro generated database 2024-03-06 20:19:36 +01:00
Shoyu Vanilla
a8f56112ea fix: Function argument type inference with associated type impl trait 2024-03-06 21:16:41 +09:00
roife
9cc3a9cfc2 fix: formatting 2024-03-05 19:55:31 +08:00
Lukas Wirth
d21f88883b Remove some unnecessary cloning in method_resolution 2024-03-05 12:39:27 +01:00
Lukas Wirth
593156a357 Re-use InferenceTable by snapshotting in method resolution 2024-03-05 12:39:27 +01:00
roife
96a7c6ae3c fix: mir for range pattern 2024-03-05 19:31:20 +08:00
bors
676455f911 Auto merge of #16757 - Veykril:style-lints, r=Veykril
fix: Put style lints behind disabled-by-default config

Fixes https://github.com/rust-lang/rust-analyzer/issues/16542
Fixes https://github.com/rust-lang/rust-analyzer/issues/16725
cc https://github.com/rust-lang/rust-analyzer/issues/16628

Our diagnostic infra is not yet setup for those kinds of diagnostics
2024-03-05 10:45:05 +00:00
Lukas Wirth
8844640c6f fix: Put style lints behind disabled-by-default config 2024-03-05 11:43:23 +01:00
Lukas Wirth
b20e467373 internal: Adjust a few things for trait assoc item hovers 2024-03-05 11:06:36 +01:00
bors
ce3216e0ae Auto merge of #15938 - Young-Flash:display_trait_item_when_hover, r=Veykril
feat: add hover display for trait assoc items

This PR enable preview assoc items when hover on `trait`

![image](https://github.com/rust-lang/rust-analyzer/assets/71162630/d9c3949c-33cf-4a32-aa97-3af46b28033a)

inspired by https://github.com/rust-lang/rust-analyzer/pull/15847
2024-03-05 08:26:53 +00:00
Nicholas Nethercote
49c0b33862 Change message type in bug functions.
From `impl Into<DiagnosticMessage>` to `impl Into<Cow<'static, str>>`.

Because these functions don't produce user-facing output and we don't
want their strings to be translated.
2024-03-05 17:11:42 +11:00
Lukas Wirth
4303e741de Cleanup 2024-03-04 11:10:06 +01:00
Laurențiu Nicola
80470d5ce8 Merge commit '4ef6a49b44e8aa380da7522442234bfd7a52c55e' into sync-from-ra 2024-03-03 09:17:31 +02:00
Young-Flash
dba67b46a1 update for review 2024-03-02 10:01:04 +08:00
bors
a3236be9d7 Auto merge of #16630 - ShoyuVanilla:fix-closure-kind-inference, r=Veykril
fix: Wrong closure kind deduction for closures with predicates

Completes #16472, fixes #16421

The changed closure kind deduction is mostly simlar to `rustc_hir_typeck/src/closure.rs`.
Porting closure sig deduction from it seems possible too and I'm considering doing it with another PR
2024-02-27 14:41:23 +00:00
Lukas Wirth
3a1b4c29b3 internal: Remove dead branches in method_resolutiopn::is_valid_candidate 2024-02-27 10:00:45 +01:00
Lukas Wirth
cc7fe32ba3 fix: Fix completions panicking with certain macro setups 2024-02-27 09:35:57 +01:00
bors
5fead606bc Auto merge of #16555 - davidbarsky:david/speedup-completions-by-exploiting-orphan-rules, r=Veykril
performance: Speed up Method Completions By Taking Advantage of Orphan Rules

(Continues https://github.com/rust-lang/rust-analyzer/pull/16498)

This PR speeds up method completions by doing two things without regressing `analysis-stats`[^1]:
- Filter candidate traits prior to calling `iterate_path_candidates` by relying on orphan rules (see below for a slightly more in-depth explanation). When generating completions [on `slog::Logger`](5e9e59c312/common/src/ledger.rs (L78)) in `oxidecomputer/omicron` as a test, this PR halved my completion times—it's now 454ms cold and 281ms warm. Before this PR, it was 808ms cold and 579ms warm.
- Inline some of the method candidate checks into `is_valid_method_candidate` and remove some unnecessary visibility checks. This was suggested by `@Veykril` in [this comment](https://github.com/rust-lang/rust-analyzer/pull/16498#issuecomment-1929864427).

We filter candidate traits by taking advantage of orphan rules. For additional details, I'll rely on `@WaffleLapkin's` explanation  [from Zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Trait.20Checking/near/420942417):

> A type `A` can only implements traits which
> 1. Have a blanket implementation (`impl<T> Trait for T {}`)
> 2. Have implementation for `A` (`impl Trait for A {}`)
>
> Blanket implementation can only exist in `Trait`'s crate. Implementation for `A` can only exist in `A`'s or `Trait`'s crate.

Big thanks to Waffle for its keen observation!

---

I think some additional improvements are possible:
- `for_trait_and_self_ty` seemingly does not distinguish between `&T`, `&mut T`, or `T`, resulting in seemingly irrelevant traits like `tokio::io::AsyncWrite` being being included for, e.g., `&slog::Logger`. I don't know they're being considered due to the [autoref/autoderef behavior](a02a219773/crates/hir-ty/src/method_resolution.rs (L945-L962)), but I wonder if it'd make sense to filter by mutability earlier and not consider trait implementations that require `&mut T` when we only have a `&T`.
- The method completions [spend a _lot_ of time in unification](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Trait.20Checking/near/421072356), and while there might be low-hanging fruit there, it might make more sense to wait for the new trait solver in `rustc`. I dunno.

[^1]: The filtering occurs outside of typechecking, after all.
2024-02-26 18:05:52 +00:00
David Barsky
c246a93046 completions: speed up completions by filtering non-applicable traits 2024-02-26 12:49:11 -05:00
Shoyu Vanilla
a4021f6ed5 Use lang-item instead of db lookup for FnTrait kind 2024-02-27 00:38:53 +09:00