Commit Graph

672 Commits

Author SHA1 Message Date
Nuri Amari
c12b6e2bd3 Merge pull request #69970 from NuriAmari/swift-ide-test-updates
[swift-ide-test] Add -enable-upcoming-feature ImportObjcForwardDeclarations support
2023-11-27 12:50:18 -08:00
Nuri Amari
7fb7e42f37 [swift-ide-test] Tie ClangImporter fwd-decl option to chosen lang feature
Prviously swift-ide-test enabled importing of ObjC forward declarations
with the -enable-objc-forward-declarations option. The compiler enables
the same behavior via -enable-upcoming-feature.

Now that swift-ide-test also supports upcoming-features, make enabling
the ImportObjcForwardDeclarations language feature have the expected
effect in swift-ide-test.

The old flag is also removed.
2023-11-20 10:28:23 -08:00
Nuri Amari
011b669023 [swift-ide-test] Add support for -enable-upcoming-feature 2023-11-17 14:38:01 -08:00
Alex Hoppen
b19a7eac33 [SourceKit] Mark functions on CancellableResult const 2023-11-14 15:08:16 -08:00
Egor Zhdan
efc008a2ca [cxx-interop] Import using decls that expose methods from private base classes
If a C++ type `Derived` inherits from `Base` privately, the public methods from `Base` should not be callable on an instance of `Derived`. However, C++ supports exposing such methods via a using declaration: `using MyPrivateBase::myPublicMethod;`.

MSVC started using this feature for `std::optional` which means Swift doesn't correctly import `var pointee: Pointee` for instantiations of `std::optional` on Windows. This prevents the automatic conformance to `CxxOptional` from being synthesized.

 rdar://114282353 / resolves https://github.com/apple/swift/issues/68068
2023-11-14 00:30:54 +00:00
Allan Shortlidge
50fdfbf7b4 Sema: Support multiple -debug-forbid-typecheck-prefix arguments.
An existing test (Frontend/skip-function-bodies.swift) was designed under the
assumption that multiple `-debug-forbid-typecheck-prefix` arguments were
already supported, and as a result the test was not actually asserting what it
was written to assert.
2023-09-25 16:43:11 -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
Rintaro Ishizaki
5791a2cb37 [Macros] Plugin search options group
'load-plugin-library', 'load-plugin-executable', '-plugin-path' and
'-external-plugin-path' should be searched in the order they are
specified in the arguments.

Previously, for example '-plugin-path' used to precede
'-external-plugin-path' regardless of the position in the arguments.
2023-06-14 15:46:39 -07:00
Holly Borla
684ef9c482 [AST] Add a new accessor kind for init accessors. 2023-06-06 18:57:31 -07:00
Hamish Knight
4ce49bd4d2 [Parse] Sink registerParseRequestFunctions call into ParserUnit 2023-05-22 14:55:18 +01:00
Ben Barham
3368e710a2 Merge pull request #65515 from bnbarham/add-attached-type-relation
[Completion] Add convertible type relation for attached macros
2023-05-01 09:52:04 -07:00
Ben Barham
f7d1cc8426 [Completion] Add convertible type relation for attached macros
Resolves rdar://108678938.
2023-04-28 16:15:51 -07:00
Hamish Knight
b8ae0666ad Rename getBriefComment -> getSemanticBriefComment
Make it clear that we will walk the comment providing
decls if needed.
2023-04-26 12:38:38 +01:00
Alexis Laferrière
1ddc7939cd Merge pull request #65168 from xymus/display-public-only
[IDE] Inject Sendable conformance on public types only in `getTopLevelDeclsForDisplay`
2023-04-17 17:36:28 -07:00
Alexis Laferrière
7f32a9e8c4 [IDE] Inject Sendable conformance on public types only
When getTopLevelDeclsForDisplay is called on an imported module, it may
lists non-public decls. If we they try to inject the conformance on
Sendable on internal types, the compiler may crash on failing to
deserialize internal details. As a fix, let's only inject the
conformance on public or package types.

rdar://95430471
2023-04-14 13:40:02 -07:00
Rintaro Ishizaki
3517db4c3b [SourceKit] Pass 'swiftc' path to Driver when creating frontend args
Driver uses its path to derive the plugin paths (i.e.
'lib/swift/host/plugins' et al.) Previously it was a constant string
'swiftc' that caused SourceKit failed to find dylib plugins in the
toolchain. Since 'SwiftLangSupport' knows the swift-frontend path,
use it, but replacing the filename with 'swiftc', to derive the plugin
paths.

rdar://107849796
2023-04-12 09:53:43 -07:00
Rintaro Ishizaki
96ff0e2c3b [swift-ide-test] Add plugin related options 2023-04-11 17:35:52 -07:00
Hamish Knight
af7134b884 Fully enable ExperimentalStringProcessing
Previously we would only enable by default when
`parseArgs` was called. However this wouldn't
enable it for clients such as LLDB, who provide
their own invocation. Switch the default to `true`
in the `LangOptions`, and remove some redundant
uses of `-enable-experimental-string-processing`.
The frontend flag remains, as it may be useful to
disable.

rdar://107419385
rdar://101765556
2023-03-31 18:10:39 +01:00
Rintaro Ishizaki
a4d1fc6abe [SourceKit] Use a single PluginRegistry in multiple ASTContexts
Make a single 'PluginRegistry' and share it between SwiftASTManager,
IDEInspectionInstance, and CompileInstance. And inject the plugin
registry to ASTContext right after 'CompilerInstance.setup()'

That way, all sema-capable ASTContext in SourceKit share a single
PluginRegistry.
2023-03-27 14:59:08 -07:00
Ben Barham
fd84ae98c2 Merge pull request #64367 from bnbarham/system-to-sdk
[SourceKit] Stop using `isSystemModule` to represent "non-user" modules
2023-03-17 10:15:04 -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
Egor Zhdan
8326c84bfc [cxx-interop] Do not auto-complete unsafe underscored methods
e.g. `__beginUnsafe()` or `__endUnsafe()` which return iterators

rdar://103252957
2023-03-10 19:31:04 +00:00
Alastair Houghton
44783e72c6 [Frontend] Add support for implicit import of _Backtracing
Once the API has gone through Swift Evolution, we will want to implicitly
import the _Backtracing module.  Add code to do that, but set it to off
by default for now.

rdar://105394140
2023-03-04 08:00:06 +00:00
Doug Gregor
7a1c558899 Add more missing ASTWalker macro behavior entries 2023-02-28 19:13:02 -08:00
Alex Hoppen
10edbb78f9 [swift-ide-test] Use same code completion extraction logic for batch code completion and single code completion
If the test case hase a code completion token of the form `#^TOKEN?check=CHECK^#` from batch code completion, this allows us to run `swift-ide-test` with `--code-completion-token TOKEN` instead of `--code-completion-token 'TOKEN?check=CHECK'`, which is more convenient.
2023-02-28 10:58:56 +01:00
Ben Barham
959e5bba7e Merge pull request #63666 from bnbarham/fix-new-assert
Fix a couple references to nullptr
2023-02-15 16:59:24 -08:00
Ben Barham
fd4f51a677 [Test] Only print completion diagnostics when an ASTContext is available
swift-ide-test was creating a `CompilerInstance` and then passing its
`ASTContext` along for printing diagnostics. But `CompilerInstance` only
has an `ASTContext` if it has been initialized, which it hasn't.

Change the print to only print diagnostics when an `ASTContext` is
actually available.
2023-02-15 10:13:59 -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
Alexis Laferrière
940b7d99d1 [Tools] Explicitly disable deserialization safety in some testing tools 2023-01-06 12:02:47 -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
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
Xi Ge
5987654b3a Merge branch 'main' into allowable-serialization 2022-11-28 09:36:04 -08:00
Xi Ge
67bbab7e02 serialization: encode allowable client names in binary module format 2022-11-25 18:43:40 -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
Alexis Laferrière
81c19b5107 [ASTPrinter] Move up the logic printing the module disambiguation 2022-11-15 16:20:25 -08:00
Alexis Laferrière
6d5e1b26fa [ASTPrinter] Pass down PrintOptions to printModuleRef 2022-11-04 12:29:55 -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
Rintaro Ishizaki
0e2e315633 Remember nominal type decls for member lookup
`lookupVisibleMemberDecls` visits nominal type decls to find visible
members of the type. Remembering what decls are visited can be useful
information for the clients.

* Add a 'VisibleDeclConsumer' callback function that is called when
  'lookupVisibleDecls' visits each nominal type decls
* Remember the decl names in 'CodeCompletionContext' for future use
2022-10-21 16:46:06 -07:00
Sam Kortekaas
0efc3ea745 [SourceKit] Add option for returning fully qualified types in expression type request 2022-09-27 14:13:10 +02: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
Robert Widmann
18b79ffcfd Resolve a Layering Violation in libBasic
Basic should not be allowed to link Parse, yet it was doing so
to allow Version to provide a constructor that would conveniently
parse a StringRef. This entrypoint also emitted diagnostics, so it
pulled in libAST.

Sink the version parser entrypoint down into Parse where it belongs
and point all the clients to the right place.
2022-09-09 00:21:30 -07:00
Alex Hoppen
fa75cfba72 Merge pull request #60210 from ahoppen/pr/operator-syntax-kind
[SourceKit] Add an operator syntax kind
2022-08-02 19:33:36 +02:00
Alex Hoppen
c5c34464de Merge pull request #58999 from ahoppen/pr/cache-function-asyncness
[CodeCompletion] Cache 'async'-ness of free functions
2022-08-01 10:15:23 +02:00
Alex Hoppen
a7dcd4604e [SourceKit] Add an operator syntax kind
This will allow us to do semantic highlighting for operators in SourceKit-LSP.
2022-07-25 07:19:49 +02:00
Alex Hoppen
1150e700a5 [CodeComplete] Store the compiler instace as a shared pointer in CompletionInstance 2022-07-21 18:29:34 +02:00
Alex Hoppen
dec32674ef [CodeCompletion] Compute InvalidAsyncContext warning when making a completion result contextual
Store whether a result is async in the `ContextFreeCodeCompletionResult` and determine whether an async method is used in a sync context when promoting the context free result to a contextual result.

rdar://78317170
2022-07-21 14:27:19 +02:00