Commit Graph

243 Commits

Author SHA1 Message Date
Ben Barham
59c53ae6d5 [Index] Skip mapping locations when there is no buffer ID
Resolves rdar://143281338.
2025-01-22 17:54:22 -08:00
Allan Shortlidge
1dc7aa5b7b AST: Introduce Decl::isUnavailable().
Replace calls to `AvailableAttr::isUnavailable()` with `Decl::isUnavailable()`.
2024-12-02 07:35:58 -08:00
Dylan Sturgeon
b59eb14c25 Emit refs to collections initialized with a type shorthand expression.
Normally references to initializers of collections like Array and Dict are emitted into the index data. It was missing any initializer called using the collection's literal type resentation instead of the type name.

For example:

```
_ = Array<Int>(repeating: 0, count: 1)  // Reference is emitted.
_ = [Int](repeating: 0, count: 1) // Reference is missing.
```

This PR fixes the inconsistency by emitting references for those collection intializers.

fixes #68974
2024-11-05 19:32:42 +00:00
Dylan Sturgeon
a1e888785d Enable indexing for refs to synthesized declarations.
Based on feedback in PR https://github.com/swiftlang/swift/pull/69460, enabling indexing for synthesized decls because they are usable by users and make sense to appear in the indexstore.

Sets `synthesized` on some additional decls:

  - derived `hashInto(...)`
  - Objc properties and methods derived from Objc protocols

https://github.com/apple/swift/issues/67446
2024-10-28 10:07:27 -07:00
Dylan Sturgeon
ce55a854b9 Emit references to shadowed variables in if-let shorthands as variables when indexing locals is enabled.
Track the original-decl/captured decl as part of the symbol passed to the IndexConsumer. This allows the Rename consumer to check if the symbol is a shadowed reference to a decl being renamed, without the index skipping the other relevant output when visiting shadowing variables.

https://github.com/swiftlang/swift/issues/76805
2024-10-22 16:43:24 -07:00
Allan Shortlidge
fb86a721a6 AST: Remove default argument from ModuleDecl::getImportedModules(). 2024-09-30 10:31:43 -07:00
Nate Chandler
091368ba21 [CoroutineAccessors] Added read.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Nate Chandler
98a2e6a7df [CoroutineAccessors] Added modify.
The name is a placeholder for the mutating single-yield coroutine
accessor.
2024-09-26 18:10:39 -07:00
Doug Gregor
49aa0e966f Ensure that SourceFiles always have a backing buffer in the SourceManager
The "buffer ID" in a SourceFile, which is used to find the source file's
contents in the SourceManager, has always been optional. However, the
effectively every SourceFile actually does have a buffer ID, and the
vast majority of accesses to this information dereference the optional
without checking.

Update the handful of call sites that provided `nullopt` as the buffer
ID to provide a proper buffer instead. These were mostly unit tests
and testing programs, with a few places that passed a never-empty
optional through to the SourceFile constructor.

Then, remove optionality from the representation and accessors. It is
now the case that every SourceFile has a buffer ID, simplying a bunch
of code.
2024-09-16 21:46:42 -07:00
Hamish Knight
1cb0f8fdd5 [AST] Rename isPrivateStdlibDecl -> isPrivateSystemDecl
This better reflects what we're actually checking
here.
2024-08-28 18:31:51 +01:00
Hamish Knight
98ffddb016 [Index] Record relations for pseudo accessors
I recently accidentally broke this, make sure
we carve out an exception for pseudo accessors in
`shouldIndex` such that we record e.g override
relations for them.

rdar://131749546
2024-07-15 15:42:48 +01:00
Hamish Knight
f26d1e7bd3 [Index] Mark accessors as implicit in modules
These won't have bodies in generated interfaces,
and generally aren't useful things to jump to. The
property ought to be used instead.

rdar://130775560
2024-07-05 16:28:33 +01: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
1a67c61d19 [RelatedIdents] Fix an assertion failure if two invalid declarations have the same base name
For example, the following declarations have the same USR with a single ERROR_TYPE parameter despite being distinct declarations.

```swift
func bar(body: Invalid) {}
func bar(ignoreCase: Bool, body: Invalid) {}
```

We originally intended to check the USR so that local rename behaves more like global rename, which also looks symbols up by USR. But the above example proves that assumption wrong.

rdar://126803702
2024-05-07 18:17:11 -07:00
Hamish Knight
b65d8c212e [Index] Avoid forming relations to non-indexed decls
If we shouldn't index the related decl, don't record
it as a relation.
2024-04-09 21:28:22 +01:00
Hamish Knight
e22ac1419c [Index] Avoid reporting containers for non-indexed decls
Check to see whether we can index the given decl
before reporting it as a container, walking up to
a parent if we need to. This also lets us simplify
the AnyPattern handling a bit.

rdar://126137541
2024-04-09 21:28:22 +01:00
Konrad `ktoso` Malawski
6132386371 [Distributed] Complete handling of protocol calls and witnesses using adjusted mangling scheme (#72416) 2024-03-23 23:54:23 +09:00
Slava Pestov
d86a3010b9 Index: Don't look at getInherited() on deserialized protocol 2024-03-01 15:46:59 -05: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
Allan Shortlidge
0dd8f4c492 AST: Introduce abstraction for extension/type decl inheritance clauses.
Wrap the `InheritedEntry` array available on both `ExtensionDecl` and
`TypeDecl` in a new `InheritedTypes` class. This class will provide shared
conveniences for working with inherited type clauses. NFC.
2023-09-06 10:41:57 -07:00
Slava Pestov
9ebb5f2e03 AST: Rename VarDecl::getType() to VarDecl::getTypeInContext()
This is a futile attempt to discourage future use of getType() by
giving it a "scary" name.

We want people to use getInterfaceType() like with the other decl kinds.
2023-08-04 14:19:25 -04: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
Holly Borla
da8e84caac Merge pull request #66914 from hborla/conformance-macro-in-extension
[Macros] Don't visit macro-generated extensions in `visitAuxiliaryDecls`.
2023-06-26 15:45:03 -07:00
Holly Borla
83030a9c63 [Macros] Don't visit macro-generated extensions in 'visitAuxiliaryDecls'.
Macro-generated extensions are hoisted to file scope, because extensions are
not valid in nested scopes. Callers of 'visitAuxiliaryDecls' assume that the
auxiliary decls are in the same decl context as the original, which is clearly
not the case for extensions, and it leads to issues like visiting extension at
the wrong time during SILGen. The extensions are already added to the top-level
decls, so we don't need to visit them as auxiliary decls, and we can type-check
macro-expanded decls at the end of visitation in TypeCheckDeclPrimary.
2023-06-23 23:25:32 -07:00
Doug Gregor
a1464cfc2e Correctly remove properties subsumed by init accessors from memberwise inits
The code to remove these subsumed properties was part of creating the
memberwise initializer declaration, which could lead to
inconsistencies with the newly-introduced request for gathering the
memberwise-initialized properties. Move the code into the computation
of the list of memberwise-initialized properties.

Also update a few more places that were effectively recomputing the
set of memberwise-initialized properties themselves over to the
request.
2023-06-23 11:34:54 -07:00
Holly Borla
684ef9c482 [AST] Add a new accessor kind for init accessors. 2023-06-06 18:57:31 -07:00
swift-ci
27d9d65872 Merge pull request #65512 from keith/ks/fix-missing-indexing-data-when-using-self-initializer
Fix missing indexing data when using Self initializer
2023-05-04 16:04: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
Keith Smiley
6c2ccb4c43 reland: Fix RelBase indexing with composite types (#65550)
Previously the index data differed when using `Foo, Bar` vs `Foo & Bar`.

Fixes #56255

This reverts commit 5e2c7a9d47.
2023-05-02 17:01:28 -07:00
Keith Smiley
d445a18a32 [Index] Remove unused function (NFC) (#65334) 2023-05-01 14:06:31 -07:00
Keith Smiley
5e2c7a9d47 Revert "Fix RelBase indexing with composite types"
This crashes with typealiases referenced across files. I will resubmit
with a fix. See also https://github.com/apple/swift/pull/65545

This reverts commit 7a5e9dcf19.
2023-05-01 11:24:32 -07:00
swift-ci
404b925d8b Merge pull request #64997 from keith/ks/fix-relbase-indexing-with-composite-types
Fix RelBase indexing with composite types
2023-04-29 17:22:45 -07:00
Keith Smiley
7a5e9dcf19 Fix RelBase indexing with composite types
Previously the index data differed when using `Foo, Bar` vs `Foo & Bar`.

Fixes https://github.com/apple/swift/issues/56255
2023-04-29 12:46:31 -07:00
Keith Smiley
e80bbd5454 Include extended typealias in index data
Previously only the type underlying the typealias was included in the
index data. Now the extension of a typealias includes 2 entries, 1 for
the underlying type and one for the typealias definition.

Fixes https://github.com/apple/swift/issues/64594
2023-04-28 14:41:49 -07:00
Ben Barham
b9810fb0a3 [SourceKit] Return the original location for decls within generated code
Pass back the original location (ie. where the macro was expanded, not
the location that the generated code would be inserted) for cursor info
and indexing. Also mark any declarations/references within generated
source as implicit.

Resolves rdar://107209132.
2023-03-30 11:20:33 -07:00
Alexis Laferrière
205a2edf38 [Sema] Intro set of import filters for general use
Calling getImportedModules requires to list the desired kind of imports.
With the new kind of imports this has become cumbersome. Let's simplify
it by offering common sets of imports. Advanced call sites can still
list the desired imports explicitly.
2023-03-17 16:05:44 -07:00
Ben Barham
eec2848508 [SourceKit] Stop using isSystemModule to represent "non-user" modules
Rather than using `ModuleDecl::isSystemModule()` to determine whether a
module is not a user module, instead check whether the module was
defined adjacent to the compiler or if it's part of the SDK.

If no SDK path was given, then `isSystemModule` is still used as a
fallback.

Resolves rdar://89253201.
2023-03-15 14:29:48 -07: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
Ben Barham
1808a398f1 [Index] Use access level to check decls to include
`isAccessibleFrom` has special handling for `@_objcImplementation`
members, which causes the definition in Swift to be missed. Use access
level directly rather than passing `nullptr` into `isAccessibleFrom`.
2023-02-06 15:59:54 -08:00
Ben Barham
4cc7167b60 [Index] Handle shorthand if let/closure captures in local rename
Update rename to pull the outermost-declaration so that references are correctly found.

Rather than keeping suppressed locations in the current parent, keep
them for the whole index. Local rename starts the lookup from the
innermost context it can, which could be a closure. In that case there
is no parent decl on the stack and thus no where to store the locations
to suppress. We could have a specific store for this case, but there
shouldn't be that many of these and they're relatively cheap to store
anyway.

Resolves rdar://104568539.
2023-01-24 11:10:38 -08:00
Ben Barham
7b4ab8d0e6 [Index] Resolve any shadowed references to the decl they shadow
Skip the shadowing decl and instead reference the top-most shadowed decl
(ie. follow any shadowed decls up the chain).

Also fix `getShorthandShadows` missing references in `MemberDeclRefExpr`
by using `getReferencedDecl` instead of assuming it is a `DeclRefExpr`.

Resolves rdar://99730146, rdar://100006415, and rdar://103449038.
2023-01-20 14:34:10 -08:00
Anthony Latsis
ad5d55c36e [NFC] AST: Rename IdentTypeReprDeclRefTypeRepr 2023-01-07 07:14:44 +03:00
Anthony Latsis
2113e175f5 [NFC] AST: Remove IdentTypeRepr::ComponentRange 2023-01-07 07:11:30 +03:00
Doug Gregor
9e61b01ec1 Rework computation of local discriminators for named entities.
Local discriminators for named entities are currently being set by the
parser, so entities not created by the parser (e.g., that come from
synthesized code) don't get local discriminators. Moreover, there is
no checking to ensure that every named local entity gets a local
discriminator, so some entities would incorrectly get a local
discriminator of 0.

Assign local discriminators as part of setting closure discriminators,
in response to a request asking for the local discriminator, so the
parser does not need to track this information, and all local
declarations---including synthesized ones---get local discriminators.
And add checking to make sure that every entity that needs a local
discriminator gets assigned one.

There are a few interesting cases in here:
* There was a potential mangling collision with local property
wrappers because their generated variables weren't getting local
discriminators
* $interpolation variables introduced for string interpolation weren't
getting local discriminators, they were just wrong.
* "Local rename" when dealing with captures like `[x]` was dependent on
the new delcaration of `x` *not* getting a local discriminator. There
are funny cases involving nesting where it would do the wrong thing.
2022-12-21 15:01:07 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Ben Barham
872001f28b [Index] Use original arguments for indexing memberwise init labels
This isn't actually an issue any more because we return early when the
location is invalid, but we shouldn't be attempting to add a reference
to a label that wasn't actually written in the first place.
2022-11-08 15:17:40 -08:00
Ben Barham
88f0e75b27 [Index] Always skip invalid locations outside of modules
There's a number of paths that end up calling into `initIndexSymbol`
that may or may not have checked that the given location is actually
valid. Add an extra check within the method to guarantee we only output
0:0 locations when indexing modules.

Resolves rdar://98645486.
2022-09-20 13:09:12 -07:00
Ben Barham
38d2b96e6d [NFC] Small Index.cpp cleanups 2022-09-20 13:06:47 -07:00