Commit graph

1544 commits

Author SHA1 Message Date
Lukas Wirth
78f3112626 Allow interpreting consts and statics with interpret function command 2024-11-03 15:35:45 +01:00
Lukas Wirth
94c35f6138 Allow static initializers to be const evaluated 2024-11-02 12:43:11 +01:00
Lukas Wirth
70348faf2b Move child_by_source from hir-def to hir 2024-10-31 09:28:08 +01:00
Lukas Wirth
436ace3ecb
Merge pull request #18436 from Veykril/lw-yvkqwpnwsouo
Do not render meta info when hovering usages
2024-10-30 09:21:35 +00:00
Lukas Wirth
a953875f49 Style hover messages a bit differently 2024-10-29 16:59:48 +01:00
Chayim Refael Friedman
41658de227 Cleanup TypeRef lowering
By removing interior mutability from it.
2024-10-28 17:38:37 +02:00
Lukas Wirth
80e9d014be
Merge pull request #18074 from ChayimFriedman2/typeref-source-map
internal: Build source map for `hir_def::TypeRef`s
2024-10-28 11:01:12 +00:00
Lukas Wirth
715b67c425
Merge pull request #18410 from Veykril/veykril/push-lvwxpnowqrxk
internal: Invert token iteration order in macro mapping
2024-10-27 10:44:32 +00:00
Lukas Wirth
20ac30fb75 Invert token iteration order in macro mapping 2024-10-27 11:32:12 +01:00
Lukas Wirth
79b86f25b4
Merge pull request #18418 from ChayimFriedman2/explicitly-disable
feat: Split `macro-error` diagnostic so users can ignore only parts of it
2024-10-27 09:37:56 +00:00
Chayim Refael Friedman
f4585ea023 Split macro-error diagnostic so users can ignore only parts of it
Split it into `macro-error`, `proc-macros-disabled` and `proc-macro-disabled`.
2024-10-27 02:24:15 +02:00
Lukas Wirth
a12f1781eb Only construct a resolver in macro descension when needed 2024-10-25 10:23:59 +02:00
Chayim Refael Friedman
bf7edd3783 Shrink TypeRef from 16 from 32 bytes
Only references and arrays need to be boxed, and they comprise only 9.4% of the types (according to counting on r-a's code).

This saves 17mb.
2024-10-25 06:44:56 +03:00
Chayim Refael Friedman
1fae57fa55 Fix memory usage calculation's queries list 2024-10-25 06:15:06 +03:00
Chayim Refael Friedman
89c0ffa6b0 Build source map for hir_def::TypeRefs
So that given a `TypeRef` we will be able to trace it back to source code.

This is necessary to be able to provide diagnostics for lowering to chalk tys, since the input to that is `TypeRef`.

This means that `TypeRef`s now have an identity, which means storing them in arena and not interning them, which is an unfortunate (but necessary) loss but also a pretty massive change. Luckily, because of the separation layer we have for IDE and HIR, this change never crosses the IDE boundary.
2024-10-25 06:15:04 +03:00
Lukas Wirth
98935325ca minor: Remove intermediate allocations 2024-10-24 13:34:32 +02:00
Chayim Refael Friedman
8adcbdcc49 Implement semitransparent hygiene
Or macro_rules hygiene, or mixed site hygiene. In other words, hygiene for variables and labels but not items.

The realization that made me implement this was that while "full" hygiene (aka. def site hygiene) is really hard for us to implement, and will likely involve intrusive changes and performance losses, since every `Name` will have to carry hygiene, mixed site hygiene is very local: it applies only to bodies, and we very well can save it in a side map with minor losses.

This fixes one diagnostic in r-a that was about `izip!()` using hygiene (yay!) but it introduces a huge number of others, because of #18262. Up until now this issue wasn't a major problem because it only affected few cases, but with hygiene identifiers referred by macros like that are not resolved at all. The next commit will fix that.
2024-10-22 21:26:56 +03:00
Lukas Wirth
c286786888
Merge pull request #18254 from ChayimFriedman2/fix-mut
fix: Nail destructuring assignment once and for all
2024-10-22 17:40:52 +00:00
bors
d509449d7e Auto merge of #18370 - duncpro:goto-def-ranges, r=Veykril
feat: resolve range patterns to their structs

Closes #18367
2024-10-22 12:24:25 +00:00
Duncan Proctor
4fd471c571 tidy 2024-10-22 06:54:44 -04:00
Duncan Proctor
271f64f94d resolve range patterns to the their struct types 2024-10-22 06:20:16 -04:00
Lukas Wirth
6c23f25e7f Fix new nightly lints 2024-10-22 11:48:41 +02:00
bors
17055aaca9 Auto merge of #18362 - duncpro:goto-def-ranges, r=Veykril
feat: goto definition on range operators

Closes #18342
2024-10-22 07:49:18 +00:00
Duncan Proctor
2f6923b844 tidy 2024-10-22 03:19:47 -04:00
Duncan Proctor
f54a863965 goto definition on RangeFrom, RangeFull, RangeTo, and RangeToInclusive links to respective struct 2024-10-22 03:11:23 -04:00
duncanproctor
c7a8be110d Move explicit range handling out of goto_definition, use OperatorClass instead 2024-10-21 20:07:07 -04:00
Lukas Wirth
d878b8caad fix: Fix token downmapping failing for include! inputs 2024-10-21 17:22:18 +02:00
Chayim Refael Friedman
2d4d6b678f Store patterns desugared from destructuring assignments in source map
And few more fixups.

I was worried this will lead to more memory usage since `ExprOrPatId` is double the size of `ExprId`, but this does not regress `analysis-stats .`. If this turns out to be a problem, we can easily use the high bit to encode this information.
2024-10-20 19:11:32 +03:00
Chayim Refael Friedman
61f162a43d Handle destructuring assignments uniformly
Instead of lowering them to `<expr> = <expr>`, then hacking on-demand to resolve them, we lower them to `<pat> = <expr>`, and use the pattern infrastructure to handle them. It turns out, destructuring assignments are surprisingly similar to pattern bindings, and so only minor modifications are needed.

This fixes few bugs that arose because of the non-uniform handling (for example, MIR lowering not handling slice and record patterns, and closure capture calculation not handling destructuring assignments at all), and furthermore, guarantees we won't have such bugs in the future, since the programmer will always have to explicitly handle `Expr::Assignment`.

Tests don't pass yet; that's because the generated patterns do not exist in the source map. The next commit will fix that.
2024-10-20 19:09:51 +03:00
bors
5982d9c420 Auto merge of #18227 - davidbarsky:davidbarsky/push-lmntvwvznyyx, r=davidbarsky
internal: add json `tracing` Layer for profiling startup

On `buck2/integrations/rust-project`, this results in the following being printed:

```json
{"name":"discover_command","elapsed_ms":18703}
{"name":"parallel_prime_caches","elapsed_ms":0}
{"name":"vfs_load","elapsed_ms":5895}
{"name":"vfs_load","elapsed_ms":547}
{"name":"parallel_prime_caches","elapsed_ms":23}
{"name":"parallel_prime_caches","elapsed_ms":84}
{"name":"parallel_prime_caches","elapsed_ms":5819}
```
2024-10-04 17:59:02 +00:00
David Barsky
56c10ca981 internal: add JSON formatting for hprof 2024-10-04 11:26:15 -04:00
bors
510f72e12c Auto merge of #18234 - Veykril:veykril/push-vzynqtlxmrnl, r=Veykril
internal: Filter out opaque tokens in some IDE feature macro descensions
2024-10-04 10:26:04 +00:00
Lukas Wirth
24d65bb7cf internal: Filter out opaque tokens in some of IDE feature macro descensions 2024-10-04 11:53:12 +02:00
Shoyu Vanilla
e09c2a08d7 Fix: Handle block exprs as modules when finding their parents 2024-10-01 14:05:15 +09:00
bors
ac8509a74b Auto merge of #18210 - ChayimFriedman2:label-macro, r=Veykril
fix: Fix resolution of label inside macro

When working on Something Else (TM) (I left a hint in the commits :P), I noticed to my surprise that labels inside macros are not resolved. This led to a discovery of *two* unrelated bugs, which are hereby fixed in two commits.
2024-09-30 13:09:54 +00:00
Chayim Refael Friedman
cd7cbddaf6 When resolving labels in break and continue for the IDE, do not resolve them textually, instead reuse the results of HIR lowering
This fixes a bug where labels inside macros were not resolved, but more importantly this prepares us to a future where we have hygiene, and textual equivalence isn't enough to resolve identifiers.
2024-09-30 15:13:45 +03:00
Noah Bright
4255cae1bb Rename object_safety to dyn_compatibility
Up to a trait implemented by another package, linking to
$CARGO_HOME/registry/cache/index.crates.io-6f17d22bba15001f/
2024-09-29 07:26:45 -04:00
Chayim Refael Friedman
82124f33b5 Handle lint attributes that are under #[cfg_attr] 2024-09-19 22:21:48 +03:00
bors
990c48cb0d Auto merge of #18131 - ChayimFriedman2:macro-expand-dollar-crate, r=Veykril
fix: Get rid of `$crate` in expansions shown to the user

Be it "Expand Macro Recursively", "Inline macro" or few other things.

We replace it with the crate name, as should've always been.

Probably fixes some issues, but I don't know what they are.
2024-09-18 20:17:21 +00:00
Chayim Refael Friedman
cfb701ac78 Get rid of $crate in expansions shown to the user
Be it "Expand Macro Recursively", "Inline macro" or few other things.

We replace it with the crate name, as should've always been.
2024-09-18 18:30:59 +03:00
bors
f4aca78c92 Auto merge of #18117 - ChayimFriedman2:issue-18089, r=Veykril
fix: Always cache macro expansions' root node in Semantics

Previously some expansions were not cached, but were cached in the expansion cache, which caused panics when later queries tried to lookup the node from the expansion cache.

Fixes #18089.
2024-09-18 09:19:30 +00:00
Chayim Refael Friedman
f6eb5be591 Add diagnostics for unsafe_op_in_unsafe_fn
Turns out it's pretty easy, but I did have to add support for allowed-by-default lints.
2024-09-18 03:02:12 +03:00
Chayim Refael Friedman
35e171aa01 Always cache macro expansions' root node in Semantics
Previously some expansions were not cached, but were cached in the expansion cache, which caused panics when later queries tried to lookup the node from the expansion cache.
2024-09-17 00:19:39 +03:00
Chayim Refael Friedman
798c963875 Fix printing of constants greater than i128::MAX 2024-09-16 01:30:18 +03:00
Chayim Refael Friedman
4eb19df5e9 Use more correct handling of lint attributes
The previous analysis was top-down, and worked on a single file (expanding macros). The new analysis is bottom-up, starting from the diagnostics and climbing up the syntax and module tree.

While this is more efficient (and in fact, efficiency was the motivating reason to work on this), unfortunately the code was already fast enough. But luckily, it also fixes a correctness problem: outline parent modules' attributes were not respected for the previous analysis. Case lints specifically did their own analysis to accommodate that, but it was limited to only them. The new analysis works on all kinds of lints, present and future.

It was basically impossible to fix the old analysis without rewriting it because navigating the module hierarchy must come bottom-up, and if we already have a bottom-up analysis (including syntax analysis because modules can be nested in other syntax elements, including macros), it makes sense to use only this kind of analysis.

Few other bugs (not fundamental ti the previous analysis) are also fixed, e.g. overwriting of lint levels (i.e. `#[allow(lint)] mod foo { #[warn(lint)] mod bar; }`.
2024-09-12 15:24:38 +03:00
bors
c54a827f50 Auto merge of #18075 - roife:fix-issue-17858, r=Veykril
feat: render patterns in params for hovering

Fix #17858

This PR introduces an option to [hir-def/src/body/pretty.rs](08c7bbc2db/crates/hir-def/src/body/pretty.rs) to render the result as a single line, which is then reused for rendering patterns in parameters for hovering.
2024-09-11 12:05:57 +00:00
bors
77e1969c15 Auto merge of #18052 - Coekjan:fix-inline-const, r=Veykril
fix: Fix `inline_const_as_literal` error when the number >= 10

## Description

### The Bug

This PR fixes a small bug in the IDE assistence (`inline_const_as_literal`). When the being-inlined constant is a number and it is greater than or equal to 10, the assistence inserts unexpected string `(0x...)` after the number itself. A simple example is followed:

Current `inline_const_as_literal` changes

```rs
const A: usize = 16;

fn f() -> usize {
    A  // inline the constant
}
```

into

```rs
const A: usize = 16;

fn f() -> usize {
    16 (0x10)
}
```

The bug originates from #14925 & #15306 . #14925 added some unittests, but it just tested the number-inlining behavior when the number is `0`.

50882fbfa2/crates/ide-assists/src/handlers/inline_const_as_literal.rs (L124-L138)

And #15306 modified the behavior of `Const::render_eval` and added the `(0x...)` part after the number (if the number >= `10`). Because of insufficient unittests in #14925, changes about `Const::render_eval` in #15306 introduced this bug with no CI failure.

### The Fix

I think `Const::render_eval` is intended for user-facing value displaying (e.g. hover) and not designed for `inline_const_as_literal`. To fix the bug, I defined a new function named `Const::eval`, which evaluates the value itself faithfully and simply and does nothing else.

## Thanks

Thanks `@roife` for your kind help. Your guidance helped me better understand the code.
2024-09-11 10:48:32 +00:00
roife
5caa56e18a fix: use pretty_print_pat for params in fn 2024-09-09 20:59:23 +08:00
Lukas Wirth
f74a0c8801 asm! parsing and lowering fixes 2024-09-05 15:08:16 +02:00
Lukas Wirth
c075a9980e Fix name fetching being incorrect for asm operands 2024-09-05 13:41:03 +02:00