Commit Graph

157 Commits

Author SHA1 Message Date
bors[bot]
0900beeaa2
Merge #8776
8776: fix: fix unnecessary recomputations due to macros r=jonas-schievink a=jonas-schievink

This computes a macro's fragment kind eagerly (when the calling file is still available in parsed form) and stores it in the `MacroCallLoc`. This means that during expansion we no longer have to reparse the file containing the macro call, avoiding the unnecessary salsa dependencies (https://github.com/rust-analyzer/rust-analyzer/pull/8746#issuecomment-834776349).

Marking as draft until I manage to find a test for this problem, since for some reason `typing_inside_a_function_should_not_invalidate_expansions` does not catch this (which might indicate that I misunderstand the problem).

I've manually confirmed that this fixes the issue described in https://github.com/rust-analyzer/rust-analyzer/pull/8746#issuecomment-834776349:

```
    7ms - parse_query @ FileId(179)
   12ms - SourceBinder::to_module_def
       12ms - crate_def_map:wait
            5ms - item_tree_query (1 calls)
            7ms - ???
```

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-05-09 14:40:49 +00:00
Edwin Cheng
01ce37c805 Escape characters in builtin macros correctly 2021-05-09 19:57:29 +08:00
Jonas Schievink
9cf8d325a2 Precompute macro fragment kind 2021-05-09 01:36:06 +02:00
bors[bot]
0ee945e289
Merge #8280
8280: Borrow text of immutable syntax node r=iDawer a=iDawer

In https://github.com/rust-analyzer/rowan/pull/101 `rowan::SyntaxNode::green` returns `Cow<'_, GreenNodeData>`. It returns borrow of green node of immutable syntax tree node.
Using this we can return borrowed text from `ast::Name::text`.

~~However now it allocates in case of mutable syntax trees.~~ (see next comment)

The idea comes from https://github.com/rust-analyzer/rowan/pull/100#issuecomment-809330325

Co-authored-by: Dawer <7803845+iDawer@users.noreply.github.com>
2021-05-06 22:19:52 +00:00
Jonas Schievink
976a3226fe Don't store call-site text offsets in hygiene info 2021-05-06 19:59:54 +02:00
Dawer
90a5dca0a2 Fix build 2021-05-06 10:22:51 +05:00
Aleksey Kladov
1ea4dae596 Document expansion queries 2021-05-04 22:41:46 +03:00
Aleksey Kladov
3f6980e4e1 simplify macro expansion code
Using `Option` arguments such that you always pass `None` or `Some` at
the call site is a code smell.
2021-05-04 22:41:46 +03:00
Aleksey Kladov
95dc8ef265 make illegal states unrepresentable
only declarative macros have def-site token map
2021-05-04 22:41:43 +03:00
Aleksey Kladov
7d9ea39de6 Cleanups 2021-05-04 22:40:59 +03:00
bors[bot]
e17748e4b2
Merge #8727
8727: minor: use standard import style r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-04 17:37:09 +00:00
Aleksey Kladov
2e97dbcbb8 minor: use standard import style 2021-05-04 20:36:48 +03:00
bors[bot]
5e87f84211
Merge #8726
8726: internal: reduce visibility r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-05-04 17:29:55 +00:00
Aleksey Kladov
87f827bfaf internal: reduce visibility 2021-05-04 20:29:30 +03:00
Aleksey Kladov
16f7c3ea91 minor: unconfuse myself about macro def vs macro rules 2021-05-04 18:20:10 +03:00
bors[bot]
b6a7276c54
Merge #8586
8586: Replace SyntaxRewriter usage with ted in eager::eager_macro_recur r=Veykril a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-04-19 18:03:56 +00:00
Lukas Wirth
617cd7231c Remove SyntaxRewriter usage in eager::eager_macro_recur 2021-04-19 19:28:41 +02:00
bors[bot]
e4f7f1e1bd
Merge #8462
8462: Expand macros at type position r=jonas-schievink a=cynecx



Co-authored-by: cynecx <me@cynecx.net>
2021-04-19 13:01:30 +00:00
Jonas Schievink
ae84a71e4a Expand global_asm! to nothing 2021-04-18 18:43:45 +02:00
cynecx
cf3b4f1e20 hir_ty: Expand macros at type position 2021-04-17 16:24:56 +02:00
Jonas Schievink
e2c1da36f5 Support macros in pattern position 2021-04-11 01:25:50 +02:00
Jonas Schievink
44b04ebe43 Revert "Rewrite #[derive] removal to be based on AST"
This reverts commit 7e78aebc8f.
2021-04-10 20:30:28 +02:00
Jonas Schievink
050dc93e00 Revert "Use pub(crate)"
This reverts commit c51213c2e7.
2021-04-10 20:30:24 +02:00
Jonas Schievink
526dc4b5f5 Revert "Use name![derive]"
This reverts commit d6187de4cd.
2021-04-10 20:30:19 +02:00
Jonas Schievink
d6187de4cd Use name![derive] 2021-04-09 14:50:42 +02:00
Jonas Schievink
c51213c2e7 Use pub(crate) 2021-04-09 14:24:31 +02:00
Jonas Schievink
7e78aebc8f Rewrite #[derive] removal to be based on AST 2021-04-09 14:10:54 +02:00
Jonas Schievink
c0dd36fd42 Store #[derive] attribute ID along macro invoc 2021-04-09 13:38:01 +02:00
Jonas Schievink
3fcdd1bcdf Add AttrId to track attribute sources 2021-04-09 13:32:03 +02:00
Jonas Schievink
86b7861612 Use named fields in MacroCallKind 2021-04-08 20:43:07 +02:00
Jonas Schievink
053dac88ca Update OUT_DIR diagnostic to match setting 2021-04-07 20:19:28 +02:00
Jonas Schievink
3abcdc03ba Make ast_to_token_tree infallible
It could never return `None`, so reflect that in the return type
2021-04-04 01:46:45 +02:00
Jonas Schievink
6198eb74b2 Implement edition-dependent builtin panic! macro 2021-04-03 03:12:55 +02:00
Aleksey Kladov
5c0c09c9c3 internal: document semantics for missing names 2021-03-31 13:24:08 +03:00
Edwin Cheng
a193666361 Basic Support Macro 2.0 2021-03-27 13:44:54 +08:00
bors[bot]
c8066ebd17
Merge #8201
8201: Fix recursive macro statements expansion r=edwin0cheng a=edwin0cheng

This PR attempts to properly handle macro statement expansion by implementing the following:

1.  Merge macro expanded statements to parent scope statements.
2.  Add a new hir `Expr::MacroStmts` for handle tail expression infer.

PS : The scope of macro expanded statements are so strange that it took more time than I thought to understand and implement it :(

Fixes  #8171



Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-03-27 02:57:02 +00:00
cynecx
5ff3299dd6 syntax: return owned string instead of leaking string 2021-03-26 18:30:59 +01:00
Edwin Cheng
8ce15b02de Fix recursive macro statement expansion 2021-03-26 04:21:15 +08:00
bors[bot]
31ed164161
Merge #8134
8134: Correct the paths of submodules from the include! macro r=edwin0cheng a=sticnarf

This PR should fix #7846. It mostly follows the instructions from @edwin0cheng in that issue.

Co-authored-by: Yilin Chen <sticnarf@gmail.com>
2021-03-21 17:57:45 +00:00
Yilin Chen
3bb9efb6b7
use the included file as the source of expanded include macro
Signed-off-by: Yilin Chen <sticnarf@gmail.com>
2021-03-21 23:02:01 +08:00
Matthias Krüger
8a67116857 use strip_prefix() instead of starts_with and slicing (clippy::manual_strip) 2021-03-21 12:38:21 +01:00
Matthias Krüger
3d9b3a8575 remove more redundant clones (clippy::redundant_clone()) 2021-03-21 12:10:39 +01:00
Jonas Schievink
93aeb16eb2 Return Either from MacroDefId::ast_id 2021-03-19 19:56:13 +01:00
Jonas Schievink
54c78c96db Rename derive-specific APIs 2021-03-19 14:23:13 +01:00
Jonas Schievink
c05a1a6e37 Store an AstId for procedural macros 2021-03-18 16:11:18 +01:00
Jonas Schievink
b84efbaacf Make MacroDefId's AstId mandatory when possible 2021-03-18 15:37:14 +01:00
Jonas Schievink
4cf36545e6 Create AstId for builtin_derive macro in tests 2021-03-18 15:14:52 +01:00
Jonas Schievink
5f80364ede Improve diagnostic when including nonexistent file 2021-03-17 21:56:09 +01:00
bors[bot]
f7fbea509f
Merge #8063
8063: couple clippy::complexity fixes r=matklad a=matthiaskrgr

avoid redundant `.into()` calls to convert T into identical T (`let x: String = String::from("hello").into();`)
use `if let Some(x)` instead of `.is_some()` + `.unwrap()`
don't clone Copy types
remove redundant wrapped ?s:  `Some(Some(3)?)` can just be `Some(3)`
use `.map(|x| y)` instead of `and_then(|x| Some(y)` on `Option`s

Co-authored-by: Matthias Krüger <matthias.krueger@famsik.de>
2021-03-17 08:12:34 +00:00
bors[bot]
6fcb5d772f
Merge #8048
8048: Fix missing unresolved macro diagnostic in function body r=edwin0cheng a=brandondong

This was an issue I found while working on https://github.com/rust-analyzer/rust-analyzer/pull/7970.

**Reproduction:**
1. Call a non-existent macro in a function body.
```
fn main() {
  foo!();
}
```
2. No diagnostics are raised. An unresolved-macro-call diagnostic is expected.
3. If the macro call is instead outside of the function body, this works as expected.

I believe this worked previously and regressed in https://github.com/rust-analyzer/rust-analyzer/pull/7805.

**Behavior prior to https://github.com/rust-analyzer/rust-analyzer/pull/7805:**
- The unresolved-macro-call diagnostic did not exist. Instead, a macro-error diagnostic would be raised with the text "could not resolve macro [path]".
- This was implemented by adding an error to the error sink (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8L657).
- The error was propagated through 1a82af3527/crates/hir_def/src/body.rs (L123) eventually reaching 1a82af3527/crates/hir_def/src/body/lower.rs (L569).

**Behavior after:**
- Instead of writing to the error sink, an UnresolvedMacro error is now returned (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8R631).
- The parent caller throws away the error as its function signature is `Option<MacroCallId>` (https://github.com/rust-analyzer/rust-analyzer/pull/7805/files#diff-50a326c5ae465bd9b31ee4310186380aa06e4fa1f6b41dbc0aed5bcc656a3cb8R604).
- We instead now reach the warn condition (1a82af3527/crates/hir_def/src/body.rs (L124)) and no diagnostics are created in 1a82af3527/crates/hir_def/src/body/lower.rs (L575).

**Fix:**
- Make sure to propagate the UnresolvedMacro error. Report the error using the new unresolved-macro-call diagnostic.


Co-authored-by: Brandon <brandondong604@hotmail.com>
2021-03-17 07:20:28 +00:00