Commit Graph

176 Commits

Author SHA1 Message Date
Hamish Knight
364eba482d [AST] Use CustomAttr's DeclContext for ResolveMacroRequest
Remove the DeclContext parameter from ResolveMacroRequest, we can now
retrieve the DeclContext either from the CustomAttr or macro expansion
expr/decl directly.
2025-10-16 11:21:54 +01:00
Anthony Latsis
fec049e5e4 Address llvm::PointerUnion::{is,get} deprecations
These were deprecated in
https://github.com/llvm/llvm-project/pull/122623.
2025-07-29 18:37:48 +01:00
Allan Shortlidge
2a11d03830 IDE: Resolve unused variable warnings in SourceEntityWalker.cpp. 2025-06-11 09:53:48 -07:00
Alex Hoppen
062aaaad53 Merge pull request #81981 from ahoppen/getexpandedattrs
[IDE] Use `getExpandedAttrs` instead of `getSemanticAttrs` to get custom attributes of a declaration
2025-06-05 14:32:56 +02:00
Alex Hoppen
0ad799d133 [IDE] Use getExpandedAttrs instead of getSemanticAttrs to get custom attributes of a declaration
`getSemanticAttrs` runs a couple queries that we don’t actually need to run to get all the custom attributes, such as getting the actor isolation of the declaration. Running these things can amount to 5%-7% of the index-while-building overhead. Just running `getExpandedAttrs` should be sufficient here.
2025-06-04 18:28:17 +02:00
Alex Hoppen
c6c40de73d [IDE] Pass a SourceRange instead of a CharSourceRange in SemaAnnotator::passReference
Most `SemaAnnotator`s don’t actually care about the char source range. Instead, they only care about the start location of the reference, which is also included in `SourceRange`. Computing a `CharSourceRange` from a `SourceRange` is kind of expensive because it needs to start a new lexer.

To avoid this overhead, pass `SourceRange` to `SemaAnnotator::passReference` and related functions and let the clients compute the `CharSourceRange` when needed.

This reduces the overhead of index-while-building by about 10%.
2025-06-04 18:01:47 +02:00
Anthony Latsis
631a04e56c Merge pull request #80159 from AnthonyLatsis/danaus-plexippus-5
Sema: Extend adoption mode for `AsyncCallerExecution` to storage declarations
2025-03-26 04:40:58 +00:00
Anthony Latsis
3d3b1ca50a [NFC] AST: Turn getParameterList into a method on ValueDecl 2025-03-19 18:49:15 +00:00
Amritpan Kaur
978a5215d5 [Expr/AST] Add apply component to handle resolved method arguments. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
0c614e09d1 [Expr/AST] Add unresolvedApply component to handle method arguments. 2025-03-19 08:56:03 -07:00
Amritpan Kaur
811d54901b [NFC] Rename unresolvedProperty to unresolvedMember
to generalize for both properties and method members.
2025-03-19 08:53:18 -07:00
Amritpan Kaur
8f71f5c780 [NFC] Rename property to member to generalize
for both properties and method members.
2025-03-19 08:53:18 -07:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Tony Allevato
556ab4561b [Index] Record references to global actors in closures and function types. 2024-10-03 16:12:28 -04:00
Doug Gregor
5b2520e379 Remove IfConfigDecl from the AST
The swift-syntax tree retains information about the parsed #if
regions. Drop it from the semantic AST.
2024-09-18 20:51:54 -07:00
Doug Gregor
4c4a70f042 Remove unused shouldWalkInactiveConfigRegion 2024-09-16 16:30:57 -07:00
Tim Kientzle
1d961ba22d Add #include "swift/Basic/Assertions.h" to a lot of source files
Although I don't plan to bring over new assertions wholesale
into the current qualification branch, it's entirely possible
that various minor changes in main will use the new assertions;
having this basic support in the release branch will simplify that.
(This is why I'm adding the includes as a separate pass from
rewriting the individual assertions)
2024-06-05 19:37:30 -07:00
Alex Hoppen
ef3e1c1d4f [SourceKit] Allow generation of cursor info for declarations from solutions that haven’t aren’t applied to the AST ye
This has two benefits:
1. We can now report ambiguous variable types
2. We are more robust in the generation of results for declarations inside closures. If the closure has an error, we won’t apply the solution to the AST and thus any cursor info that tried to get types out of the AST would fail.

rdar://123845208
2024-03-20 14:52:39 +01:00
Anthony Latsis
5b7a8b6705 [NFC] AST: Rename MemberTypeReprQualifiedIdentTypeRepr 2024-03-02 14:59:37 +03:00
Ben Barham
ef8825bfe6 Migrate llvm::Optional to std::optional
LLVM has removed llvm::Optional, move over to std::optional. Also
clang-format to fix up all the renamed #includes.
2024-02-21 11:20:06 -08:00
Anthony Latsis
ef931342ad AST/ASTWalker: Refactor for recursive MemberTypeRepr representation 2024-02-09 17:33:21 +03:00
Hamish Knight
15fa06dd37 [ASTWalker] Cleanup some cases manually doing post-walks
We can replace these with `Action::SkipChildren`.
2024-02-05 15:27:26 +00:00
Hamish Knight
16cfca4186 [ASTWalker] NFC: Rename SkipChildren -> SkipNode
This better describes what the action currently
does, and allows us to re-introduce `SkipChildren`
with the correct behavior.
2024-02-05 15:27:25 +00:00
Alex Hoppen
2507e0e9ee [SourceKit] Support getting semantic tokens for macro expansion buffers 2023-10-23 11:06:49 -07:00
Ben Barham
9bc26cbf96 [Index] Include generic macro arguments
`ASTWalker` was missing a walk into the generic arguments for
freestanding declarations and expressions. `SemaAnnotator` was missing
the walk into the `TypeRepr` when walking over custom attributes.

Resolves rdar://110856428.
2023-06-27 16:34:44 -07:00
Evan Wilde
250082df25 [NFC] Reformat all the LLVMs
Reformatting everything now that we have `llvm` namespaces. I've
separated this from the main commit to help manage merge-conflicts and
for making it a bit easier to read the mega-patch.
2023-06-27 09:03:52 -07:00
Evan Wilde
f3ff561c6f [NFC] add llvm namespace to Optional and None
This is phase-1 of switching from llvm::Optional to std::optional in the
next rebranch. llvm::Optional was removed from upstream LLVM, so we need
to migrate off rather soon. On Darwin, std::optional, and llvm::Optional
have the same layout, so we don't need to be as concerned about ABI
beyond the name mangling. `llvm::Optional` is only returned from one
function in
```
getStandardTypeSubst(StringRef TypeName,
                     bool allowConcurrencyManglings);
```
It's the return value, so it should not impact the mangling of the
function, and the layout is the same as `std::optional`, so it should be
mostly okay. This function doesn't appear to have users, and the ABI was
already broken 2 years ago for concurrency and no one seemed to notice
so this should be "okay".

I'm doing the migration incrementally so that folks working on main can
cherry-pick back to the release/5.9 branch. Once 5.9 is done and locked
away, then we can go through and finish the replacement. Since `None`
and `Optional` show up in contexts where they are not `llvm::None` and
`llvm::Optional`, I'm preparing the work now by going through and
removing the namespace unwrapping and making the `llvm` namespace
explicit. This should make it fairly mechanical to go through and
replace llvm::Optional with std::optional, and llvm::None with
std::nullopt. It's also a change that can be brought onto the
release/5.9 with minimal impact. This should be an NFC change.
2023-06-27 09:03:52 -07:00
Keith Smiley
e9ff334778 Fix missing indexing data with overloaded type (#65729)
When you have a type that's ambiguous because it's defined in 2 imported
modules, but you don't have to disambiguate by using the module name,
previously no index references were produced. Now most are for the
common case, but notably nested type constructors and generics still
aren't emitted, partially because of https://github.com/apple/swift/issues/65726

Fixes: https://github.com/apple/swift/issues/64598
2023-06-23 09:58:17 -07:00
Ben Barham
b3af130e90 [IDE] Visit auxiliary declarations if walking expansions
After visiting declarations, also walk into their auxiliary decls if
expansions are being walked.

Resolves rdar://109548265.
2023-06-07 20:02:06 -07:00
Keith Smiley
f5fbee2f26 Fix indexing constructors with generic parameters (#65597)
Previously in the case of a constructor like `A<Int>(value: 1)`
`Fn->getLoc()` returned the location of `>(value: 1)` while the actual
location we're looking for is correctly the start of `A<Int>(value: 1)`.
This adjusts the location we're looking up to use the start location of
the constructor instead.

Fixes: https://github.com/apple/swift/issues/54532
2023-05-05 15:20:07 -07:00
Keith Smiley
1d3a9baed2 Fix missing indexing data when using Self initializer
Fixes: https://github.com/apple/swift/issues/64686
2023-05-04 10:47:15 -07:00
Holly Borla
265c8a47d9 [Macros] Fix an issue where the constraint system skipped local declarations
inside closures while type checking a macro expansion.

PreCheckExpr, ConstraintGenerator, and other walkers do not walk into macro
expansions. However, the implementation of this macro walking behavior in
ASTWalker would skip any declaration that appears inside any macro expansion
buffer. This is incorrect for cases where the parent is in the same macro
expansion buffer, because the local declaration is not inside a new macro
expansion. This caused bogus errors when type checking expanded macro expressions
containing closures with local declarations, because pre-check and constraint
generation mistakenly skipped local pattern bindings.
2023-04-19 20:11:38 -07:00
Ben Barham
3e76a5edae [Refactoring] Allow expanding freestanding decl expansions 2023-03-09 10:11:11 -08:00
Ben Barham
bb7760b9e0 [Refactor] Allow expanding nested macros
This adds a new `primary_file` key, which defaults to `sourcefile`. For
nested expansions, `primary_file` should be set to the containing file
and `sourcefile` to the name of the macro expansion buffer.
2023-03-02 14:04:46 -08:00
Doug Gregor
200f2340d9 [Macros] Be deliberate about walking macro arguments vs. expansions
Provide ASTWalker with a customization point to specify whether to
check macro arguments (which are type checked but never emitted), the
macro expansion (which is the result of applying the macro and is
actually emitted into the source), or both. Provide answers for the
~115 different ASTWalker visitors throughout the code base.

Fixes rdar://104042945, which concerns checking of effects in
macro arguments---which we shouldn't do.
2023-02-28 17:48:23 -08:00
Ben Barham
0c3f538822 [AST] Allow ignoring macro expansions
Various requests expect to be walking over the current source file.
While we could add checks to all these to skip decls outside of the
current buffer, it's a little nicer to handle this during the walk
instead.

Allow ignoring nodes that are from macro expansions and add that flag to
the various walks that expect it.

Also add a new `getOriginalAttrs` that filters out attributes in
generated source.
2023-02-16 18:04:56 -08:00
Holly Borla
85f2a1a234 [Macros] Factor calls to ResolveMacroRequest into Decl::getResolvedMacro.
This prevents call-sites from making the mistake of passing an incorrect
DeclContext to the request, which can cause re-typechecking issues.
2023-02-15 18:52:02 -08:00
Holly Borla
f1953f311f [Macros] Don't invoke ResolveMacroRequest for the same custom attribute with
different DeclContexts.
2023-02-15 14:58:24 -08:00
Holly Borla
c33c925e81 [Macros] Remove the macro role argument to ResolveMacroRequest.
The macro role argument presented an opportunity for callers to accidentally
invoke this request twice for the same macro with slightly different macro
roles passed in, which resulted in re-typechecking the macro arguments.
Instead, derive the corresponding macro roles from the macro reference syntax.
2023-02-14 22:38:53 -08:00
Doug Gregor
96380624db [SourceKit] Implement macro expansion for (some) attached macros.
Extend the macro-expansion refactoring to work with member and
member-attribute attached macros. These expansions can return several
different changes, e.g., adding new members, sprinkling member
attributes around, and so on.
2023-02-11 11:23:28 -08:00
Anthony Latsis
1bb407ac8c [NFC] AST: Rename ComponentIdentTypeReprIdentTypeRepr 2023-01-07 07:15:36 +03:00
Doug Gregor
db801afbe9 Handle null macro references in the semantic annotator 2023-01-04 10:56:57 -08:00
Saleem Abdulrasool
7415cb8d5f Merge pull request #62455 from bnbarham/index-handle-implicit-conversions
[Index] Use `ide::getReferencedDecl` instead of custom `extractDecl`
2022-12-08 22:56:56 -05:00
Ben Barham
7fb229a5d5 [Index] Use ide::getReferencedDecl instead of custom extractDecl
`passReference` was failing to find the underlying declaration for a
constructor reference. In this case it was for a
`FunctionConversionExpr`, but there's likely others. Use
`ide::getReferencedDecl` instead.

Resolves rdar://102563191.
2022-12-08 09:16:23 -08:00
Rintaro Ishizaki
9f137074af [SourceKit/Refactoring] Macro expansion
Add refactoring "Expand Macro" that expands macro expressions.

rdar://102739026
2022-12-06 16:20:07 -08:00
Doug Gregor
c8819bd266 [Indexing] Index macro expansion expressions. 2022-11-28 18:33:10 -08:00
Anthony Latsis
18156d1177 Merge pull request #61347 from AnthonyLatsis/migrate-compiler-to-gh-issues
Gardening: Migrate compiler sources to GitHub issues
2022-09-30 10:48:52 +03:00
Anthony Latsis
2843e0c871 Gardening: Migrate compiler sources to GitHub issues 2022-09-29 23:58:55 +03:00
Hamish Knight
0a7b436c09 Use Action::Stop in more places
This used to be something we couldn't express in
certain walker methods. Update various places
where we can now use it.
2022-09-26 19:15:48 +01:00
Hamish Knight
4716f61fba [AST] Introduce explicit actions for ASTWalker
Replace the use of bool and pointer returns for
`walkToXXXPre`/`walkToXXXPost`, and instead use
explicit actions such as `Action::Continue(E)`,
`Action::SkipChildren(E)`, and `Action::Stop()`.
There are also conditional variants, e.g
`Action::SkipChildrenIf`, `Action::VisitChildrenIf`,
and `Action::StopIf`.

There is still more work that can be done here, in
particular:

- SourceEntityWalker still needs to be migrated.
- Some uses of `return false` in pre-visitation
methods can likely now be replaced by
`Action::Stop`.
- We still use bool and pointer returns internally
within the ASTWalker traversal, which could likely
be improved.

But I'm leaving those as future work for now as
this patch is already large enough.
2022-09-13 10:35:29 +01:00