Commit graph

843 commits

Author SHA1 Message Date
Lukas Wirth
d085ade631 Remove dead test code 2024-03-14 16:24:51 +01:00
Lukas Wirth
d2f8eae2ec feat: Support macro calls in eager macros for IDE features 2024-03-14 15:40:35 +01:00
Lukas Wirth
9767156a29 Simplify 2024-03-13 20:02:21 +01:00
Lukas Wirth
abe3177445 Shrink MacroCallLoc 2024-03-13 18:05:27 +01:00
bors
a2e274142f Auto merge of #16819 - Veykril:span-upmapping, r=Veykril
internal: Improve rooted upmapping

cc https://github.com/rust-lang/rust-analyzer/issues/16235
2024-03-12 12:58:52 +00:00
Lukas Wirth
9ba4493918 internal: Improve rooted upmapping 2024-03-12 13:46:58 +01:00
bors
d3e6fea315 Auto merge of #16789 - wyatt-herkamp:cfg_attr, r=Veykril
cfg Attribute Stripping for Proc Macro Expansion

This will attempt to process cfg attributes and cfg_attr attributes for proc macro expansion.
![image](https://github.com/rust-lang/rust-analyzer/assets/11785959/b85ef203-14a5-44c9-9b67-59a65a5f2d96)

Closes #8434 , #11657, and #13904
2024-03-12 10:19:19 +00:00
Wyatt Herkamp
447de3d788 Review Updates and added tests. 2024-03-11 11:05:59 -04: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
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
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
Lukas Wirth
09b9a921a8 fix: Don't invalid body query results when generating desugared names 2024-03-07 15:03:16 +01: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
Lukas Wirth
a3b6e891ea Add tracing spans to macro generated database 2024-03-06 20:19:36 +01:00
roife
ece18fecfa fix: resolve sub-patterns inside range pattern 2024-03-05 19:31:20 +08:00
Lukas Wirth
c3c9f5ffe1 internal: Compute syntax validation errors on demand 2024-03-04 12:06:15 +01:00
Lukas Wirth
4303e741de Cleanup 2024-03-04 11:10:06 +01:00
Lukas Wirth
efd76ecff1 Move AstIdMap infra to the span crate 2024-03-01 15:39:44 +01:00
Lukas Wirth
91554e0ae7 fix: Fix modules in blocks not resolving in ide layer 2024-02-26 14:54:47 +01:00
Lukas Wirth
d93096ecc0 internal: Fetch toolchain and datalayout for DetachedFiles 2024-02-20 10:40:39 +01:00
bors
2223b4fa71 Auto merge of #13112 - lowr:patch/auto-trait-bounds, r=Veykril
Setup infra for handling auto trait bounds disabled due to perf problems

This patch updates some of the partially-implemented functions of `ChalkContext as RustIrDatabase`, namely `adt_datum()` and `impl_provided_for()`. With those, we can now correctly work with auto trait bounds and distinguish methods based on them.

Resolves #7856 (the second code; the first one is resolved by #13074)

**IMPORTANT**: I don't think we want to merge this until #7637 is resolved. Currently this patch introduces A LOT of unknown types and type mismtaches as shown below. This is because we cannot resolve items like `hashbrown::HashMap` in `std` modules, leading to auto trait bounds on them and their dependents unprovable.

|crate (from `rustc-perf@c52ee6` except for r-a)|e3dc5a588f07d6f1d3a0f33051d4af26190abe9e|HEAD of this branch|
|---|---|---|
|rust-analyzer @ e3dc5a588f |exprs: 417528, ??ty: 907 (0%), ?ty: 114 (0%), !ty: 1|exprs: 417528, ??ty: 1704 (0%), ?ty: 403 (0%), !ty: 20|
|ripgrep|exprs: 62120, ??ty: 2 (0%), ?ty: 0 (0%), !ty: 0|exprs: 62120, ??ty: 132 (0%), ?ty: 58 (0%), !ty: 11|
|webrender/webrender|exprs: 94355, ??ty: 49 (0%), ?ty: 16 (0%), !ty: 2|exprs: 94355, ??ty: 429 (0%), ?ty: 130 (0%), !ty: 7|
|diesel|exprs: 132591, ??ty: 401 (0%), ?ty: 5129 (3%), !ty: 31|exprs: 132591, ??ty: 401 (0%), ?ty: 5129 (3%), !ty: 31|
2024-02-19 16:45:59 +00:00
Laurențiu Nicola
6b17dba68c Merge commit 'ac998a74b3c8ff4b81c3eeb9a18811d4cc76226d' into sync-from-ra 2024-02-18 09:41:20 +02:00
Lukas Wirth
9d18e197bc Filter out {unknown} types in adt_datum_quqery 2024-02-14 14:10:54 +01:00
bors
cf8733353d Auto merge of #16540 - Veykril:macro-arg, r=Veykril
internal: macro_arg query always returns a TokenTree
2024-02-12 16:32:40 +00:00
Lukas Wirth
2fa57d90bc internal: macro_arg query always returns a TokenTree 2024-02-12 17:19:41 +01:00
bors
818c30c311 Auto merge of #16092 - kilpkonn:term_search_1, r=Veykril
feat: Introduce term search to rust-analyzer

# Introduce term search to `rust-analyzer`
_I've marked this as draft as there might be some shortcomings, please point them out so I can fix them. Otherwise I think it is kind of ready as I think I'll rather introduce extra functionality in follow up PRs._

Term search (or I guess expression search for rust) is a technique to generate code by basically making the types match.
Consider the following program
```rust
fn wrap(arg: i32) -> Option<i32> {
    todo!();
}
```
From the types of values in scope and constructors of `Option`, we can produce the expected result of wrapping the argument in `Option`

Dependently typed languages such as `Idris2` and `Agda` have similar tools to help with proofs, but this can be also used in everyday development as a "auto-complete".

# Demo videos

https://github.com/rust-lang/rust-analyzer/assets/19900308/7b68a1b7-7dba-4e31-9221-6c7485e77d88

https://github.com/rust-lang/rust-analyzer/assets/19900308/0fae530a-aabb-4b28-af71-e19f8d3d64b2

# What does it currently do
- It works well with locals, free functions, type constructors and non-static impl methods that take items by value.
- Works with functions/methods that take shared references, but not with unique references (very conservative).
- Can handle projections to struct fields (eg. `foo.bar.baz`) but this might me more conservative than it has to be to avoid conflicting with borrow checker
- Should create only valid programs (no type / borrow checking errors). Tested with `rust-analyzer analysis-stats /path/to/ripgrep/Cargo.toml --run-term-search --validate-term-search` (basically running `cargo check` on all of the generated programs and only error seems to be due to type inference which is more of issue of testing method.

# Performace / fitness
```txt
ripgrep (latest)
Tail Expr syntactic hits: 130/1692 (7%)
Tail Exprs found: 523/1692 (30%)
Term search avg time: 9ms
Term search:         15.64s, 97ginstr, 8mb

rust-analyzer (on this branch)
Tail Expr syntactic hits: 804/13860 (5%)
Tail Exprs found: 6757/13860 (48%)
Term search avg time: 78ms
Term search:         1088.23s, 6765ginstr, 98mb
```
Highly generic code seems to blow up the search space so currently the amount of generics allowed is functions/methods is limited down to 0 (1 didn't give much improvement and 2 is already like 0.5+s search time)

# Plans for the future (not in this PR)
- ``~~Add impl methods that do not take `self` type (should be quite straight forward)~~ Done
- Be smarter (aka less restrictive) about borrow checking - this seems quite hard but since the current approach is rather naive I think some easy improvement is available.
- ``~~See if it works as a autocomplete while typing~~ Done

_Feel free to ask questions / point of shortcoming either here or on Zulip, I'll be happy to address them. I'm doing this as part of my MSc thesis so I'll be working on it till summer anyway 😄_
2024-02-12 14:47:12 +00:00
bors
47b4dd7273 Auto merge of #15923 - tamasfe:feat/better-ignored-macros2, r=Veykril
feat: ignored and disabled macro expansion

Supersedes #15117, I was having some conflicts after a rebase and since I didn't remember much of it I started clean instead.

The end result is pretty much the same as the linked PR, but instead of proc macro lookups, I marked the expanders that explicitly cannot be expanded and we shouldn't even attempt to do so.

## Unresolved questions

- [ ] I introduced a `DISABLED_ID` next to `DUMMY_ID` in `hir-expand`'s `ProcMacroExpander`, that is effectively exactly the same thing with slightly different semantics, dummy macros are not (yet) expanded probably due to errors, while not expanding disabled macros is part of the usual flow. I'm not sure if it's the right way to handle this, I also thought of just adding a flag instead of replacing the macro ID, so that the disabled macro can still be expanded for any reason if needed.
2024-02-12 12:42:45 +00:00
Lukas Wirth
e2a985e93f Encode disabled proc-macros via boolean flag, not special Expander 2024-02-12 13:39:38 +01:00
tamasfe
ab50ec9863 fix(macros): no diagnostics for disabled macro 2024-02-12 12:50:44 +01:00
tamasfe
6d45afd8d8 feat: ignored and disabled macro expansion 2024-02-12 12:50:40 +01:00
Nicholas Nethercote
4a13722518 Tweak delayed bug mentions.
Now that we have both `delayed_bug` and `span_delayed_bug`, it makes
sense to use the generic term "delayed bug" more.
2024-02-12 18:39:20 +11:00
Tavo Annus
125791386d Cleanup term search related changes 2024-02-11 14:35:54 +02:00
Tavo Annus
627255dd5a Add static method tactic 2024-02-11 13:33:29 +02:00
Lukas Wirth
c990587593 fix: Fix macro transcriber emitting incorrect lifetime tokens 2024-02-11 12:10:38 +01:00
Laurențiu Nicola
e41ab350d6 Merge commit 'ddf105b646c6749a2de2451c9a499a354eec79c2' into sync-from-ra 2024-02-11 08:40:19 +02:00
Lukas Wirth
5136705fad internal: Remove SELF_REF hack for self referential SyntaxContexts 2024-02-10 16:20:02 +01:00
Lukas Wirth
36fb1409ed Cleanup visibility.rs 2024-02-10 13:50:45 +01:00
Lukas Wirth
dc69255b83 Re-organize hir-def/lib.rs 2024-02-10 12:40:23 +01:00
Lukas Wirth
74eb3ecbc1 Move ChildbySource and HasSource impls to their corresponding modules 2024-02-10 12:09:12 +01:00
bors
1ef7a2329b Auto merge of #16525 - Veykril:item-loc, r=Veykril
Abstract more over ItemTreeLoc-like structs

Allows reducing some code duplication by using functions generic over said structs. The diff isn't negative due to me adding some additional impls for completeness.
2024-02-10 10:47:37 +00:00
Lukas Wirth
00303c3b67 Abstract over ItemTreeLoc 2024-02-10 11:37:59 +01:00
Lukas Wirth
2ebf0c87c2 Deduplicate some code 2024-02-10 01:51:22 +01:00
Tetsuharu Ohzeki
99f5d7ca4c hir-def: Fix warnings about clippy str_to_string rule 2024-02-10 01:00:40 +09:00
Tetsuharu Ohzeki
c6637f39c0 clippy: Enable borrowed_box rule 2024-02-10 00:14:17 +09:00
Tetsuharu Ohzeki
d45cabd029 clippy: Enable derived_hash_with_manual_eq rule 2024-02-10 00:14:17 +09:00
Tetsuharu Ohzeki
2601d19bac clippy: Enable non_canonical_clone_impl rule 2024-02-09 22:37:42 +09:00
Tetsuharu Ohzeki
7669619f9a clippy: Enable self_named_constructors rule 2024-02-09 22:31:21 +09:00