Commit Graph

335 Commits

Author SHA1 Message Date
Alexis Laferrière
c8f99af698 Merge pull request #86335 from xymus/exportability-nle-warn
Sema: Enable exportability checks in non-library-evolution mode as warnings by default
2026-01-22 09:47:52 -08:00
Hamish Knight
3dd74ae66e [test] Add indexing test case for implicit makeIterator/next 2026-01-16 19:24:11 +00:00
Ian Leitch
2d803ef3d2 [IDE] Reference appendInterpolation calls in string interpolation (#86166)
Fix missing references to `appendInterpolation` functions called
implicitly in string interpolations.

Fixes #56189
2026-01-10 19:45:44 -08:00
Ian Leitch
bbeac5b8c2 [Index] Fix incorrect setter references for subscript keys (#86119)
Properties used as subscript keys (e.g., `dictionary[key] = 42`) were
incorrectly indexed as writes, referencing setters instead of getters.
Fix by forcing subscript arguments to be treated as reads, except for
dynamic member lookup subscripts where the argument represents the
member being accessed.

Resolves #56541
2026-01-10 17:34:33 -08:00
Hamish Knight
0ca0c37875 Merge pull request #86167 from ileitch/issue-56327
[Index] Relate ObjC optional protocol methods to protocol requirement
2026-01-09 23:23:41 +00:00
Alexis Laferrière
fa9d85222f Sema: Stop downgrading to private enums cases and destructors with errors
Recent commits changed the behavior downgrading enum cases with errors
to private in `AccessLevelRequest`. It checks `hasInterfaceType` likely
to avoid circular references. This is very prone to side effects. It is
dependent on the timing of the check but the result was cached, making
this behavior unreliable. Let's remove the downgrade to private
behavior.
2026-01-06 15:12:05 -08:00
Ian Leitch
492047b3e3 [Index] Relate ObjC optional protocol methods to protocol requirement
When a class implements an optional ObjC protocol method, the indexer
was not creating a RelationOverrideOf relation to the protocol
requirement. Use findWitnessedObjCRequirements to find and index these
optional requirements.

Fixes #56327
2025-12-20 19:22:22 +01:00
Slava Pestov
b96de5bb85 Sema: Fold 'Self.NestedType' correctly in pre-checking
If 'Self' was a DynamicSelfType, we would skip folding it down to a type.
2025-12-19 10:49:11 -05:00
Hamish Knight
a527e20341 [Index] Fix extension type location
The end loc is wrong when generic args are present, just use `getLoc`
which uses the name loc.
2025-11-30 17:17:36 +00:00
Hamish Knight
582462edac [Index] Handle implicit reference relations for type sugar
I missed handling this case in my previous patch, make sure we can
fallback to retrieving the nominal from type sugar such as `Array` for
`[Int]`.

rdar://161036418
2025-11-30 17:17:36 +00:00
Alex Hoppen
aa9c295ad5 [Index] Record the access level of declarations in the index
rdar://163256878
2025-10-30 14:36:29 +01:00
Hamish Knight
c7e9809480 [IDE] Mangle USRs using API decls rather than ABI decls
For semantic functionality the API decl is the more useful thing to
mangle, and redeclaration checking ensures we can't end up with
conflicts. This ensures we're able to perform a name lookup for the
decl based on its USR without having to maintain a separate lookup 
table for ABI names.
2025-10-23 09:11:17 +01:00
Pavel Yaskevich
2b7adbc4ff Merge pull request #84800 from xedin/remove-csapply-operator-devirt
[CSApply] Don't attempt operator devirtualization
2025-10-18 23:09:23 +09:00
Pavel Yaskevich
9d00c7bd18 [CSApply] Don't attempt operator devirtualization
This appears to only support synthesized conformances because
operators in such cases use different names - `__derived_*`.

These days devirtualization like this is performed as part of
mandatory inlining. And this approach doesn't stack well with
features like `MemberImportVisibility` because there is change
to check whether witness is available or not.
2025-10-10 16:31:11 -07:00
Hamish Knight
a83ea3c8bb Merge pull request #84745 from hamishknight/fishmonger
[Evaluator] Enforce consistent results for cyclic requests
2025-10-09 17:08:04 +01:00
Hamish Knight
57557dec8e [Evaluator] Enforce consistent results for cyclic requests
Record when we encounter a request cycle, and enforce that the outer
step of the cycle also returns the default value. This fixes a couple
of crashers where we were ending up with conflicting values depending
on whether the request was queried from within the cycle or from
outside it.
2025-10-08 21:16:02 +01:00
Alex Hoppen
5324d56e1d [Index] Convert the -index-store-compress command line option to a FrontendOption
When I added the `-index-store-compress` option, I forgot to translate it into the `FrontendOptions` struct, which rendered the command line option useless. Correctly set the value in `FrontendOptions` to fix this.
2025-10-08 10:41:53 +02:00
Alex Hoppen
2d2adfb017 Merge pull request #82947 from ahoppen/compress-index
[Index] Add an option to compress the record and unit files
2025-08-07 21:12:39 +02:00
Hamish Knight
99f63410cf [Index] Handle more cases in reportRelatedTypeRef
Look through attributed/specifier/paren TypeReprs, avoid reporting
`RelBase` relations for suppressed conformances, and handle protocol
compositions for the `Type` code path.

rdar://146331982
2025-07-30 14:59:05 +01:00
Hamish Knight
5e8c1a4b69 [Index] Avoid passing composition SourceLoc in reportRelatedTypeRef
We want to use the SourceLoc of each individual member of the
composition.
2025-07-30 14:59:05 +01:00
Hamish Knight
87f9820c85 [AST] Visit TypeValueExpr's TypeRepr in ASTWalker
Ensure that we walk the TypeRepr to ensure that both cursor info and
indexing pick up on the reference to the generic parameter.

rdar://145509737
2025-07-16 21:19:15 +01:00
Alex Hoppen
ed3b64af2c [Index] Add an option to compress the record and unit files
Companion of https://github.com/swiftlang/llvm-project/pull/10977.
2025-07-10 15:23:51 +02:00
Dylan Sturgeon
5e38e1ebe8 Fix missing refs to accesor when shadowing with if-let shorthand.
After ce55a854b9 the references to accessors for the shadowed accessor were discarded when indexing without locals.
2025-04-01 11:43:30 -07:00
Dylan Sturgeon
2c8e337f25 Merge pull request #80074 from dylansturg/objc_enum_refs
The Error enum synthesized declarations, e.g. the struct and its static accessors, should generally appear to be identical to the underlying Clang definitions. There are some specific use cases where the synthesized declarations are necessary though.

I've added an option for USR generation to override the Clang node and emit the USR of the synthesized Swift declaration. This is used by SwiftDocSupport so that the USRs of the synthesized declarations are emitted.

Fixes 79912
2025-03-25 11:21:21 +00:00
Tony Allevato
d94bd80c62 Add support for raw identifiers.
Raw identifiers are backtick-delimited identifiers that can contain any
non-identifier character other than the backtick itself, CR, LF, or other
non-printable ASCII code units, and which are also not composed entirely
of operator characters.
2025-03-11 17:18:43 -04:00
Alex Hoppen
f53ca06513 Merge pull request #79673 from dylansturg/overrides_rel
Add a test for index of overriding an Objc protocol method in Swift
2025-02-27 18:20:41 -08:00
Dylan Sturgeon
3d4e8a4771 Add a test for indexing of overriding an Objc protocol declared method in Swift. 2025-02-27 08:41:17 -08:00
Dylan Sturgeon
d21b7d68ad Discard non-indexed relations instead of entire references.
References for function calls where there would normally be a received-by relationship were being discarded. This happened when the receiver type is a non-indexed type, e.g. a private type in a system framework. The function call could be public or defined in any module though, so discarding it entirely because of the receiver type is not desirable.

Follow up to refine the behavior of [previous commit](b65d8c212e).
2025-02-24 11:30:00 -08:00
Becca Royal-Gordon
6e9d386d9e Fix indexing crasher with implicit objcImpl inits
Implicit initializers are given a source location within the type they belong to. This works poorly for @objc @implementation classes, because the class they belong to is imported and so those SourceLocs are in a different source buffer from the extension they’re inside, breaking an invariant enforced by index-while-building features.

Fix these SourceLocs to come from the implementation context, so they’ll come from the extension for an objcImpl class and the type itself otherwise.
2025-02-07 13:22:43 -08:00
Artem Chikin
fdda02b596 [Indexing] Disable indexing textual-interface-blocklisted modules during Explicit Module Builds
If a module is blocklisted from the compiler using its textual interface, then under Implicitly-Built modules it will not get indexed, since indexing will not be able to spawn swiftinterface compilation. With explicitly-built modules, none of the dependency modules get built from interface during indexing, which means we directly index input binary modules.

For now, for functional parity with Implicit Module Builds, disable indexing of modules during Explicit Module Builds which would not get indexed during Implicit Module Builds.
2024-12-12 09:18:10 -08:00
Saleem Abdulrasool
8a6a5d36c7 test: adjust the tests for swiftc-legacy-driver.exe (#77904)
When enabling the early swift driver on Windows, these tests need to be
adjusted for the new driver name that is reported. Add an additional
spelling for the driver to accommodate that for the testsuite.
2024-12-03 14:40:18 -08:00
Kuba Mracek
b760541c1d [embedded] Annotate test/Index/index_embedded.swift as REQUIRES: swift_feature_Embedded 2024-12-02 15:04:06 -08:00
Kuba Mracek
2f043ff59b [embedded] Add an indexer test for Embedded Swift 2024-12-02 15:01:24 -08:00
Saleem Abdulrasool
8eaf6d55fc test: adjust the tests for swiftc-legacy-driver.exe
When enabling the early swift driver on Windows, these tests need to be
adjusted for the new driver name that is reported. Add an additional
spelling for the driver to accommodate that for the testsuite.
2024-12-02 11:50:57 -08:00
Ben Barham
0288df0b89 Merge pull request #77116 from bnbarham/use-stable-hash-for-index
[Index] Convert to hashing to `HashBuilder` with BLAKE3
2024-11-14 10:39:45 +10: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
Ben Barham
10f43a8365 [Index] Convert to hashing to HashBuilder with BLAKE3
`Hashing.h` is non-deterministic between runs. Update the index hashing
to use BLAKE3 for the record hash. xxhash is faster in benchmarks that
I've found, but there's no easy `HashBuilder` option for it today.
2024-10-31 14:46:00 +10: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
Tony Allevato
556ab4561b [Index] Record references to global actors in closures and function types. 2024-10-03 16:12:28 -04:00
Hamish Knight
864e9e8d95 [test] Remove driver-index-with-auxiliary-outputs.swift
The new driver forms additional jobs for the
auxiliary outputs here, whereas the old driver
would only do a single job. This shouldn't really
matter in practice though since we make an effort
not to include auxiliary outputs in indexing
invocations.
2024-09-22 21:15:45 +01:00
Tony Allevato
67d9eecd50 [AST] Make IsNonUserModuleRequest consider SourceFile inputs as well.
We're using a small custom frontend tool to generate indexstore data for `.swiftinterface` files in the SDKs. We do this by treating the `.swiftinterface` file as the input of an interface compilation, but this exits early because it treats it as a `SourceFile` instead of an external `LoadedFile`. This happens even if we call `setIsSystemModule(true)` unless we skip setting the SDK path, but that causes other problems. It seems harmless to check for `SourceFile`s as well, so that a tool processing an SDK interface as a direct input still gets the right state.
2024-09-17 09:44:42 -04: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
588a7db17c Merge pull request #74991 from hamishknight/mod-access
[Index] Mark accessors as implicit in modules
2024-07-09 20:54:23 +01:00
Hamish Knight
43abe7f8b8 [test] Re-enable an index test
This no longer crashes the compiler
2024-07-06 23:42:10 +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
Hamish Knight
d98cb9e2b3 [Mangler] Mangle function type for invalid enum element
Previously we would mangle a single ErrorType as
the type for the element, but that would fail to
demangle since we expect a function type. Use the
same logic as AbstractFunctionDecl, mangling a
function type of ErrorType. While here, also
handle SubscriptDecls and check for error types
rather than `isInvalid()`.

rdar://129065620
2024-06-11 21:24:11 +01:00
Alex Hoppen
0614fc972d [Index] Write empty record files
When indexing an empty Swift file, we get a unit file that doesn’t have any record dependency declared on the source file. Because of this, we always assume that the empty file has an out of date index store entry and re-index it on project open. Write empty record files to fix this.

rdar://128711594
2024-05-25 08:21:25 -07:00
Becca Royal-Gordon
6d3e1ad794 Fix -target in several objcImpl tests 2024-04-30 12:03:46 -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