This modifies the ClangImporter to introduce an opaque placeholder
representation for forward declared Objective-C interfaces and
protocols when imported into Swift.
In the compiler, the new functionality is hidden behind a frontend
flag -enable-import-objc-forward-declarations, and is on by default
for language mode >6.
The feature is disabled entirely in LLDB expression evaluation / Swift
REPL, regardless of language version.
Re-enable `static_vs_class_spelling.swift` - it was just missing the
`-target` in the `sourcekitd-test` lines.
While here, cleanup all the cursor info tests that used `split_file` to
use `split-file` instead.
Resolves rdar://105287822.
In these cases the solver-based and AST-based cursor info differed in their results. Fix the AST-based cursor info to return the correct results and add test cases to make sure the solver-based implementation doesn’t regress them.
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
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
The self nominal type decl needs to be passed as a parameter in here so this request doesn't tigger self nominal type computation, which results in an assertion failure.
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.
Type checking a StmtConditionElement is slightly different than type checking the VarDecl declared by it because it doesn’t complain about redeclaration like `if let myVar = myVar`. Thus, we need to handle it in `typeCheckASTNodeAtLoc`
We need swiftsourcedocinfo for cursor info and to be able to reuse the ASTContext from code completion for cursor info, we need to also retrieve the sourcedocinfo for code completion requests.
The lexer will be responsible for knowing whether we have a code completion token, everything else will also work for other IDE inspection features.
The changes start to really make sense once I rename CodeCompletion -> IDEInspection in a lot of places.
Otherwise, the closure discriminator will be incremented by one when the closure witht he code completion token is parsed a second time during the second pass, and thus it would receive a different discriminator during the second pass.
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.
`typealias` is currently allowed to refer to a protocol without the `any` keyword. This breaks mangling the typealias type into a USR will crash because parameterized protocols are expected to be `any` types.
Implement a SourceKit-specific minimal workaround for that problem by not computing USRs for parameterized protocols.
rdar://98623438
apple/swift#60716 changed `NominalTypeDecl::getAllProtocols` to no longer work on `ProtocolDecl`. Add a new wrapper to Refactoring.cpp that dispatches to either `getInheritedProtocols` or `getAllProtocols` depending on whether the type is a protocol or not.
rdar://99096663
Cursor info on a reference to a decl that shadows other decls should not
include those decls in the secondary symbols. They should only be
added on the decl itself, if that particular location is *also* the
reference to the shadowed decl (eg. in a shorthand if let or closure
capture).
Resolves rdar://96305891.
* move symbol graph samples to the bottom of the file
* add information about a doc comment's file and module
rdar://81190369
* refactor: group file URI collection/serialization together
* test for docComment.module to identify externally-inherited docs
* InterfaceGen reports a primary associated type as a reference to the
'associatedtype' declaration
* CursorInfo on a primary associated type returns information of the
'associatedtype' declaration
rdar://93275458
Properties can also be specified in a protocol/overridden by subclasses,
so they should also be classed as "dynamic" in these cases.
Removed receiver USRs when *not* dynamic, since it's not used for
anything in that case and should be equivalent to the container anyway.
Resolves rdar://92882348.
When a variable is re-declared using shorthand syntax (`[foo]` closure capture or `if let foo {`), the user doesn’t perceive this as a new variable declaration. Thus, we should return the original declaration as a secondary result.
rdar://91311033
rdar://75455650
Pull request apple/llvm-project#4442 brings in a change to
`RawComment::getFormattedText` that removes spurious new lines
and whitespaces at the end of block comments. It breaks the
`cursor_symbol_graph_objc` test which is assuming the old behavior.
Temporarily disable the relevant check lines in the test to merge the
llvm change, and then fix the test properly and switch to the new
`getFormattedLines` in SymbolGraphGen.
Add the file for an imported ObjC-symbol to the generated symbol graph
when ObjC documentation is requested.
Skips line/column information for now since it's not needed. If we add
those we should extract location retrieval to a common method for both
cursor info and symbol graph gen.
Resolves rdar://91658873.
This currently doesn't check for inherited docs, ie. either the
imported declaration has docs or it doesn't. There's also a few odd
cases with mixed doc types and when each line is prefixed with '*', but
it's good enough for an initial implementation.
Moves UTF8 sanitisation out of ASTPrinter.h and into Unicode.h so that
it can be used here as well.
Resolves rdar://91388603.
Two paths missed setting up overlays:
- `CompletionInstance` when checking files from dependencies
- `SwiftASTManager` when reading in files that it would later replace
all inputs with
(1) would cause the AST context not to be re-used, even though nothing
had changed. (2) caused all non-completion functionality to fail for any
symbols within files only specified by the overlay.
Resolves rdar://85508213.
`OverlayFileSystem` is very simple - it just passes along each request
to each VFS it contains until one is successful (or none are). Use it
when wrapping the VFS to pass down into the Clang invocation creation,
instead of the much more complicated `RedirectingFileSystem`.
This has the side effect of also fixing a case where due to a bug in
`RedirectingFileSystem`, the originally passed in path will be returned
regardless of `use-external-name`. While that should also be fixed,
there is no reason to use this VFS here anyway.
Added a small cursor info test case that should catch issues like this
in the future.