Commit Graph

379 Commits

Author SHA1 Message Date
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
abf8067bd7 Merge pull request #83427 from hamishknight/compound-interest
[Index] Fix a couple of `reportRelatedTypeRef` issues
2025-07-31 16:01:30 +01: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
548374d289 [Index] Split up reportRelatedTypeRef
There's really two separate code paths here, one for handling
cases where we have a TypeRepr available, and one for handling cases
where we're e.g indexing a swiftmodule. IMO it's simpler to handle
these cases separately.
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
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
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
John Hui
a0d3ad7bd0 Merge pull request #82006 from j-hui/jump-to-def-for-macro-expanded-clang-imports
[SourceKit] Support location info for macro-expanded Clang imports
2025-06-19 02:01:40 -07:00
John Hui
44aba1382d [SourceKit] Support location info for macro-expanded Clang imports
Currently, when we jump-to-definition for decls that are macro-expanded
from Clang imported decls (e.g., safe overloads generated by
@_SwiftifyImport), setLocationInfo() emits a bongus location pointing to
a generated buffer, leading the IDE to try to jump to a file that does
not exist.

The root cause here is that setLocationInfo() calls getOriginalRange()
(earlier, getOriginalLocation()), which was not written to account for
such cases where a macro is generated from another generated buffer
whose kind is 'AttributeFromClang'.

This patch fixes setLocationInfo() with some refactoring:

-   getOriginalRange() is inlined into setLocationInfo(), so that the
    generated buffer-handling logic is localized to that function. This
    includes how it handles buffers generated for ReplacedFunctionBody.

-   getOriginalLocation() is used in a couple of other places that only
    care about macros expanded from the same buffer (so other generated
    buffers not not relevant). This "macro-chasing" logic is simplified
    and moved from ModuleDecl::getOriginalRange() to a free-standing
    function, getMacroUnexpandedRange() (there is no reason for it to be
    a method of ModuleDecl).

-   GeneratedSourceInfo now carries an extra ClangNode field, which is
    populated by getClangSwiftAttrSourceFile() when constructing
    a generated buffer for an 'AttributeFromClang'. This could probably
    be union'ed with one or more of the other fields in the future.

rdar://151020332
2025-06-12 18:22:06 -07:00
Alex Hoppen
021cdd4416 Merge pull request #81975 from ahoppen/sema-annotate-source-range 2025-06-05 13:49:54 +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
Pavel Yaskevich
aabfebec03 [AST] Add new declaration - using
Initially this declaration is going to be used to determine
per-file default actor isolation i.e. `using @MainActor` and
`using nonisolated` but it could be extended to support other
file-global settings in the future.
2025-05-30 00:39:06 -07:00
Egor Zhdan
b51cfa5c76 [cxx-interop] Remove symbolic import mode
Importing C++ class templates in symbolic mode has proven to be problematic in interaction with other compiler features, and it isn't used widely. This change removes the feature.

rdar://150528798
2025-05-02 18:43:09 +01: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
Tony Allevato
68876a6d4a Merge pull request #76636 from allevato/rich-identifiers
Support raw identifiers (backtick-delimited identifiers containing non-identifier characters).
2025-03-12 14:56:14 -04:00
Alexis Laferrière
c0a4056768 Merge pull request #79851 from xymus/deser-recover-conformance-xref
Serialization: Diagnose broken conformances from stale swiftmodule files
2025-03-11 15:07:38 -07:00
Tony Allevato
d71b42e524 Final tweaks from review comments. 2025-03-11 17:26:27 -04: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
Rintaro Ishizaki
002d7d7cdf [Parse/AST] Remove PoundDiagnosticDecl
There is no reson to make a AST node for '#error' and '#warning'
directives. Parser knows the diagnostics should be emitted or not.
2025-03-07 21:48:01 -08:00
Alexis Laferrière
e814b3f66c Serialization: Intro enableExtendedDeserializationRecovery
Introduce a new deserialization mode `enableExtendedDeserializationRecovery`
for use when we can afford inconsistent information from a swiftmodule
file. It's enabled automatically in debugger mode, when user errors are
allowed and during index-while-building.
2025-03-07 10:55:00 -08:00
Alexis Laferrière
eb148b1d37 Merge pull request #79713 from xymus/index-while-building-allow-errors
Index: Accept more deserialization inconsistencies during index-while-building
2025-03-03 11:33:31 -08:00
Alexis Laferrière
302d6f1dcf Index: Accept compiler errors during index-while-building
Force allowing reading from modules with compiler errors during
index-while-building as a way to recover from more deserialization
issues.
2025-02-28 14:56:26 -08:00
Alexis Laferrière
0ce7225bd6 Index: Add a pretty stacktrace line at indexing module 2025-02-28 14:56:23 -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
Xi Ge
62ce114153 Merge pull request #79067 from swiftlang/drop-copy-index
indexing: drop duplicated string copy. NFC
2025-02-03 14:59:00 -08:00
Xi Ge
fafafe458b indexing: drop duplicated string copy. NFC 2025-01-30 17:09:18 -08:00
Anthony Latsis
a84dfc8387 [Gardening] Fix some set but not used variables 2025-01-30 21:34:38 +00:00
Xi Ge
ca17ac0eee Indexing: add blocklist support for avoiding indexing specific module names
Indexing while building sometimes triggers module deserialization issues, exemplified
by a recent issue of rdar://141357099. This change introduces the blocklist support
to avoid indexing specific module names so we could rely on external data source for
unblocking builds, instead of modifying the compiler source.

Resolves: rdar://143770366
2025-01-28 10:54:50 -08:00
Ben Barham
59c53ae6d5 [Index] Skip mapping locations when there is no buffer ID
Resolves rdar://143281338.
2025-01-22 17:54:22 -08:00
Hiroshi Yamauchi
9ecb8465ce Handle delete_pending error code
Apply the same fix as
https://github.com/swiftlang/llvm-project/pull/8838 to the index
writer in swift/lib/Index/IndexRecord.cpp noting it is meant to be
merged with the IndexUnitWriter in LLVM.

This should fix intermittent permission denied errors during builds
that https://github.com/swiftlang/llvm-project/pull/8838 fixes (but
missed this one).
2025-01-13 13:49:40 -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
Allan Shortlidge
1dc7aa5b7b AST: Introduce Decl::isUnavailable().
Replace calls to `AvailableAttr::isUnavailable()` with `Decl::isUnavailable()`.
2024-12-02 07:35:58 -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
Tony Allevato
97186b0738 Merge pull request #69460 from dylansturg/indexstore
Enable indexing for refs to implicit declarations.
2024-10-30 16:38:37 -04:00
Ben Barham
f59b2f19e6 Merge branch 'main' into 2024-rebranch-to-main 2024-10-28 13:03:35 -07: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
swift-ci
1f068d3d0b Merge remote-tracking branch 'origin/main' into rebranch 2024-09-30 22:33:31 -07:00
Allan Shortlidge
fb86a721a6 AST: Remove default argument from ModuleDecl::getImportedModules(). 2024-09-30 10:31:43 -07:00
swift-ci
e5f97d79c5 Merge remote-tracking branch 'origin/main' into rebranch 2024-09-30 07:15:01 -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
swift-ci
ae4fee5d4e Merge remote-tracking branch 'origin/main' into rebranch 2024-09-19 13:54:31 -07: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
swift-ci
5039a2d86c Merge remote-tracking branch 'origin/main' into rebranch 2024-09-18 10:55:29 -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
swift-ci
f624072420 Merge remote-tracking branch 'origin/main' into rebranch 2024-08-29 03:33:30 -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