Commit Graph

1606 Commits

Author SHA1 Message Date
QuietMisdreavus
164e93e0a7 Merge pull request #63726 from apple/QuietMisdreavus/skip-proto-impls
[SymbolGraphGen] add new flag to skip "protocol implementation" symbols

rdar://59899968
2023-02-28 10:50:01 -07:00
Joe Groff
1311df6544 AST: Combine various ownership TypeReprs into one OwnershipTypeRepr.
This lets us consolidate code paths that mostly run in parallel over the
existing InOutTypeRepr/SharedTypeRepr/OwnedTypeRepr family of types. This
patch by itself is NFC but makes it easier to introduce new spellings,
particularly the newly-official `borrowing` and `consuming` modifiers
that were approved in SE-0377.
2023-02-28 09:15:43 -08:00
Rintaro Ishizaki
4190cb7978 Merge pull request #63793 from rintaro/macro-plugin-executable
[Macros] Add executable plugin support
2023-02-23 14:02:33 -08:00
Ben Barham
f7aaf02065 [SourceKit] Add an optional path and name to refactoring edits
Add two new fields to refactoring edits:
  - A file path if the edit corresponds to a buffer other than the
    original file
  - A buffer name when the edit is actually source of generated buffer

Macro expansions allow the former as a macro could expand to member
attributes, which may eg. add accessors to each member. The attribute
itself is inside the expansion, but the edit is to the member in the
original source.

The latter will later allow clients to send requests with these names to
allow semantic functionality inside synthesized buffers.
2023-02-22 16:24:02 -08:00
Rintaro Ishizaki
0e31393024 [Macros] Add executable plugin support
Executable compiler plugins are programs invoked by the host compiler
and communicate with the host with IPC via standard IO (stdin/stdout.)
Each message is serialized in JSON, prefixed with a header which is a
64bit little-endian integer indicating the size of the message.

* Basic/ExecuteWithPipe: External program invocation. Lik
  llvm::sys::ExecuteNoWait() but establishing pipes to the child's
  stdin/stdout
* Basic/Sandbox: Sandboxed execution helper. Create command line
  arguments to be executed in sandbox environment (similar to SwiftPM's
  pluging sandbox)
* AST/PluginRepository: ASTContext independent plugin manager
* ASTGen/PluginHost: Communication with the plugin. Messages are
  serialized by ASTGen/LLVMJSON

rdar://101508815
2023-02-22 10:22:14 -08:00
Victoria Mitchell
7ed30c92af refactor: stop populating SymbolGraphOptions at creation 2023-02-17 11:19:38 -07: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
Alex Hoppen
ee26b4b299 [SourceKit] Pass ResolvedCursorInfo as shared pointer instead of by value
This allows us to model the `ResolvedCursorInfo` types as a proper type hierarchy instead of having to store all values in the base `ResolvedCursorInfo` type.

rdar://102853071
2023-02-14 22:40:45 +01:00
Doug Gregor
d8e5cd91b4 Merge pull request #63625 from DougGregor/sourcekit-related-id-checker
Teach the related-id checker to ignore things from other buffers
2023-02-13 12:57:05 -08:00
Doug Gregor
a712c37c05 Teach the related-id checker to ignore things from other buffers 2023-02-13 10:13:39 -08:00
swift-ci
e80f571e71 Merge pull request #63608 from DougGregor/sourcekit-no-crash-macro-locations
Don't annotate entities not in the primary buffer
2023-02-13 00:07:40 -08:00
Doug Gregor
b87dfdf2ae Don't annotatae entities not in the primary buffer 2023-02-12 21:42:36 -08:00
swift-ci
f5488c5351 Merge pull request #63601 from DougGregor/sourcekit-macro-buffer-loc
[SourceKit] Disable optimization that's now incorrect with macros.
2023-02-12 04:04:31 -08:00
Ben Barham
e15ea7ae4d Merge pull request #63403 from bnbarham/so-much-re-index
[Index] Prevent re-indexing system modules repeatedly
2023-02-11 22:40:47 -08:00
Doug Gregor
642d0e9d36 [SourceKit] Disable optimization that's now incorrect with macros.
No test case at the moment, but it's pretty crashy here in practice :)
2023-02-11 19:56:07 -08:00
Doug Gregor
7ea0e3f096 Switch GeneratedSourceInfo ranges over to CharSourceRange.
Macro expansion buffers, along with other generated source buffers,
need more precise "original source ranges" that can be had with the
token-based `SourceRange`. Switch over to `CharSourceRange` and provide
more thoughtfully-determined original source ranges.
2023-02-11 11:23:26 -08:00
Ben Barham
6269643b4d [Index] Prevent re-indexing system modules repeatedly
If a module was first read using the adjacent swiftmodule and then
reloaded using the swiftinterface, we would do an up to date check on
the adjacent module but write out the unit using the swiftinterface.
This would cause the same modules to be indexed repeatedly for the first
invocation using a new SDK. On the next run we would instead raad the
swiftmodule from the cache and thus the out of date check would match
up.

The impact of this varies depending on the size of the module graph in
the initial compilation and the number of jobs started at the same time.
Each SDK dependency is re-indexed *and* reloaded, which is a drain on
both CPU and memory. Thus, if many jobs are initially started and
they're all going down this path, it can cause the system to run out of
memory very quickly.

Resolves rdar://103119964.
2023-02-09 11:49:13 -08:00
Alex Hoppen
fcc5d98f1c [CursorInfo] Deliver results from solver-based cursor info
Running the SourceKit stress tester with verification of solver-based cursor info returned quite a few differences but in all of them, the old AST-based implementation was actually incorrect. So, instead of verifying  the results, deliver the results from solver-baesd cursor info and only fall back to AST-based cursor info if the solver-based implementation returned no results.

rdar://103369449
2023-02-07 14:53:54 +01:00
Alex Hoppen
a5f85ee10c [SourceKit] Make sure we reuse ASTContext in function bodies for solver-based cursor info
The main problem that prevented us from reusing the ASTContext was that we weren’t remapping the `LocToResolve` in the temporary buffer that only contains the re-parsed function back to the original buffer. Thus `NodeFinder` couldn’t find the node that we want to get cursor info for.

Getting AST reuse to work for top-level items is harder because it currently heavily relies on the `HasCodeCompletion` state being set on the parser result. I’ll try that in a follow-up PR.

rdar://103251263
2023-02-02 22:03:25 +01:00
Alex Hoppen
7811519152 [SourceKit] Only verify the solver-based cursor info implementation if requested
This allows us to mark expected deviations between the AST-based and the solver-based implementation in the stress tester as XFails without breaking actual clients

We always verify if a cursor info request is issued through `sourcekitd-test`.
2023-01-31 21:25:51 +01: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
Ellie Shin
91f785441f Merge pull request #62652 from apple/es-pkg-acl
[NFC] Add 'package' access modifier to AccessLevel
2023-01-20 13:58:15 -08:00
Ellie Shin
37af51dc4c Merge branch 'main' into es-pkg-acl 2023-01-19 16:18:17 -08:00
Ellie Shin
1c66d02f92 Add package access level to enum AccessLevel
Resolves rdar://104198440
2023-01-19 15:54:18 -08:00
Rintaro Ishizaki
8d8ec09280 [SourceKit] Move demangle/mangle logic to SwfitLangSupport
'sourcekitd' itself should not call 'swift::' functions.  It should just
deserialize the request, execute the logic in LangSupport, then serialize
the result.
2023-01-19 14:45:56 -08:00
Doug Gregor
49b42b4ef3 Handle indexing of macros 2023-01-02 21:22:05 -08:00
Alex Hoppen
fe2ae72ad2 [IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
The code completio infrastructure is also being used for cursor info now, so it should no longer be called code completion.

rdar://103251187
2022-12-13 11:41:05 +01:00
Alex Hoppen
a8dd6819b5 [IDE] Implement completion-like cursor info for ValueDecls
This brings up the ability to compute cursor info results using the completion-like type checking paradigm, which an reuse ASTContexts and doesn’t need to type check the entire file.

For now, the new implementation only supports cursor info on `ValueDecl`s (not on references) because they were easiest to implement. More cursor info kinds are coming soon.

At the moment, we only run the new implementation in a verification mode: It is only invoked in assert toolchains and when run, we check that the results are equivalent to the old implementation. Once more cursor info kinds are implemented and if the SourceKit stress tester doesn’t find any verification issues, we can enable the new implementation, falling back to the old implementation if the new one didn’t produce any results.
2022-12-08 14:39:14 +01: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
1b8b706dac Merge pull request #62405 from DougGregor/macro-diagnostics 2022-12-05 21:37:27 -08:00
Doug Gregor
f0fc1c51bb Remove compiler plugin support library
The functionality of the compiler plugin support library has been
subsumed into parts of the compiler. Remove the functionality and its
last test.
2022-12-05 12:54:36 -08:00
Alex Hoppen
8e857d55c3 Merge pull request #62292 from ahoppen/ahoppen/solver-based-cursor-info-prep
[SourceKit] Preparation for solver-based cursor info
2022-12-02 10:52:30 +01:00
Alex Hoppen
9f6bc90d6d [SourceKit] Accept a file system in SwiftASTManager::getMemoryBuffer 2022-12-01 12:11:39 +01:00
Alex Hoppen
04ff291ae0 [SourceKit] Allow executing a completion-like operation without inserting a code completion token into the buffer
We will use this for solver-based cursor info, which doesn’t use code completion tokens.
2022-12-01 12:11:39 +01:00
Alex Hoppen
54360ad0fb [SourceKit] Remove unused MainModule param from cursor info results 2022-12-01 12:11:39 +01:00
Alex Hoppen
652686034c [IDE] Split ResolvedCursorInfo into subclasses
This way, each kind of `ResolvedCursorInfo` can define its own set of properties and it’s obvious which properties are used for which kind. Also switch to getters and setters because that makes it easier to search for usages of properties by looking at the call hierarchy of the getter / setter.
2022-12-01 12:11:39 +01:00
Doug Gregor
af6b30a195 [Code completion] Add code completion support for macro expansions. 2022-11-28 18:33:10 -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
Alexis Laferrière
888fe84013 Merge pull request #62073 from xymus/module-alias-disambiguate-more
[ModuleInterface] AliasModuleNames workaround support for indirect dependencies and missing imports
2022-11-17 10:33:56 -08:00
Robert Widmann
9ff5d88847 Remove SourceKit Support for the libSyntax Tree 2022-11-16 14:52:28 -08:00
Robert Widmann
4c162b2aeb Delete libSyntax 2022-11-16 14:52:28 -08:00
Robert Widmann
91c262bcb7 Move TokenKinds.def.gyb to AST 2022-11-16 13:38:25 -08:00
Doug Gregor
70323dd318 Link _CompilerPluginSupport into the compiler and SourceKit.
Ensure that we link `swift_CompilerPluginSupport` into the compiler and
SourceKit, and set the rpath appropriately to find the library in its
installed location.

A number of driver tests copy the driver executable into a temporary
directory to isolate it from the build tree. Also copy the plugin
support library into its appropriate place near the driver executable
to ensure these tests keep working. To help with this, add a
`swift_swift_parser` lit feature, which we can use in tests that
involve the new parser's capabilities.
2022-11-15 19:32:20 -08:00
Alexis Laferrière
81c19b5107 [ASTPrinter] Move up the logic printing the module disambiguation 2022-11-15 16:20:25 -08:00
Doug Gregor
3a172fb892 [Macros] Miscellaneous build fixes for macros. 2022-11-13 17:09:12 -08:00
Alexis Laferrière
e550944826 Merge pull request #61941 from xymus/module-alias-disambiguate
[ModuleInterface] Avoid ambiguities in swiftinterfaces by writing aliases for module names
2022-11-07 08:46:32 -08:00
Alexis Laferrière
6d5e1b26fa [ASTPrinter] Pass down PrintOptions to printModuleRef 2022-11-04 12:29:55 -07:00
Rintaro Ishizaki
45828af5ed [Refactoring] Separate refactoring files to its own library
IDE/Refactoring had dependencies to libswiftIndex, but libswiftIndex
also depends on libswiftIDE (SourceEntityWalker, etc.)

To break libswiftIndex <-> libswiftIDE dependency cycle, move
"refactoring" related files to a new library 'libswiftRefactoring'

rdar://101692282
2022-11-02 12:39:26 -07:00
Allan Shortlidge
d663c11df7 IDE: Move compiler invocation utils to break cycle with Frontend.
Move compiler invocation utilities up into the IDETool library which is designed to be dependent on the Frontend and FrontendTool libraries.
2022-10-29 17:51:53 -07:00
Allan Shortlidge
58d82f03f6 IDE: Break CMake cycle involving IDE, FrontendTool, Frontend, and Migrator.
These libraries formed a strongly connected component in the CMake build graph. The weakest link I could find was from IDE to FrontendTool and Frontend, which was necessitated by the `CompileInstance` class (https://github.com/apple/swift/pull/40645). I moved a few files out of IDE into a new IDETools library to break the cycle.
2022-10-27 15:56:26 -07:00