Commit Graph

414 Commits

Author SHA1 Message Date
Ben Barham
103f04e8df Revert "[Importer] Wrap the VFS passed to Clang with an overlay FS instead" 2022-03-02 15:12:58 -08:00
Ben Barham
bbc98aae16 [Importer] Wrap the VFS passed to Clang with an overlay FS instead
`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.
2022-02-25 10:06:04 -08:00
Ben Barham
7337e3bac2 Merge pull request #40566 from bnbarham/synthesized-harmony
[IDE] Only consider synthesized extensions when in the same module
2022-01-19 14:32:13 -08:00
Ben Barham
bf0bcfa8e1 [IDE] Only consider synthesized extensions when in the same module
Only declarations in the same module as synthesized extension's target
are placed within a synthesized extension. We should thus not add
"::SYNTHESIZED::" to the USR if the given declaration is in a different
and.

As an example, `Foundation` adds a method `components(separatedBy:)` to
`String` through an extension on `StringProtocol`. But since it is
within `Foundation` and not `Swift` it will *not* be in a synthesized
extension of `String` or `StringProtocol`. So it should not have
"::SYNTHESIZED::" added and should also not being in the `String` group.

Resolves rdar://71355632.
2021-12-24 09:17:41 +10:00
Victoria Mitchell
3011a3cfca [SymbolGraphGen] don't emit access control attributes in declarations
rdar://85280786
2021-12-22 16:35:12 -07:00
Alex Hoppen
a5b3f83223 Revert "[SourceKit] Don't build an AST if no semantic info is requested" 2021-12-09 21:20:43 +01:00
Alex Hoppen
9cd109cd16 Merge pull request #40353 from ahoppen/pr/no-semantic-info-if-not-requested
[SourceKit] Don't build an AST if no semantic info is requested
2021-12-01 22:42:11 +01:00
Alex Hoppen
debeebb443 [SourceKit] Don't build an AST if no semantic info is requested
Currently, we were building an AST on document open or edit even if
- `key_enablesyntaxmap` = 0
- `key_enablesubstructure` = 0
- `key_enablediagnostics` = 0 and
- syntax tree transfer mode is off

In those cases we were just ignoring the result.

If all of the options are 0, don’t build an AST.

rdar://85847659
2021-12-01 16:47:50 +01:00
Ben Barham
14af24c40d [rebranch] Use --leading-lines for split-file
split-file now uses `--no-leading-lines` as the default for
`split-file`. Add the new arg so that we have leading lines again.
2021-11-19 14:42:21 +10:00
Karoy Lorentey
4a18dac838 [wrangler] Revert 3bcbb5f7b3 2021-11-16 17:38:17 -08:00
Karoy Lorentey
3bcbb5f7b3 [wrangler][test] Disable SourceKit/CursorInfo/cursor_generated_interface.swift
rdar://85423858
2021-11-16 17:32:06 -08:00
Ben Barham
f6db91e3f9 [SourceKit] Ignore references without a location
A keypath using dynamic member lookup results in various `KeyPathExpr`
that have components with no location. Ignore these and any other
references that have a missing location.

Resolves rdar://85237365
2021-11-10 14:52:46 +10:00
Ben Barham
fd7d59daa6 [CursorInfo] Add a synthesized field
Mark implicit declarations with a `synthesized` field, since while we
still want them to have a cursor info result (eg. for their USR to find
possible overrides), it's likely that clients will want to treat them
differently to results that have a real location in source.

An alternative could be to remove the location entirely, but:
  - the module name would also have to be removed to prevent wasted
    lookups in the generated interface
  - having the location could still be useful as the location that
    caused the synthesized declaration (though at the moment only
    synthesized initializers have a location)

Resolves rdar://84990655
2021-11-05 15:52:10 +10:00
Ben Barham
8128450690 [CursorInfo] Always add module name to response
To simplify clients, have the cursorinfo result be consistent whether
requesting a symbol within the current module or not, ie. do not skip
adding the module name.

Resolves rdar://77003299
2021-10-22 12:35:53 +10:00
Doug Gregor
f9c34756ef Parameterize conformance lookup on whether "missing" conformances are allowed.
Many clients of the conformance lookup operations would prefer to get
an invalid conformance (== there is no conformance) rather than a
missing conformance. Parameterize the conformance lookup operations so
that most callers won't see missing conformances, by filtering them
out at the end. Opt-in those callers that do want to see missing
conformances so they can be diagnosed.
2021-08-03 00:10:45 -07:00
Rintaro Ishizaki
6e69a44c3d [ASTPrinter] Intorduce 'IntroducerKeyword' name kind
For more fine grained annoations. For now, it's handled as the same as
'Keyword' name kind.

Fix an issue where 'extension' wasn't marked as "keyword".

Also, move 'static' priting out of 'SkipIntroducerKeywords' guard
because 'static' is not an declaration introducer.
2021-07-29 12:50:24 -07:00
Doug Gregor
eeeea49764 Remove -enable-experimental-concurrency almost everywhere. 2021-07-26 21:24:43 -07:00
Doug Gregor
1e2012d816 Disable availability checking in tests that use concurrency 2021-07-20 12:46:26 -07:00
Ben Barham
28bb2505b0 [ClangImporter] Respect -working-directory in the created VFS
Pass a wrapped VFS down into `clang::createInvocationFromCommandLine` so
that the working directory is set and then used in the underlying Clang
`CompilerInstance`.

Fixes the possibility of differing modules hashes when the same
arguments are used in Clang directly vs from the importer.

Resolves rdar://79376364
2021-06-24 11:07:40 +10:00
Argyrios Kyrtzidis
53264a64d9 Merge pull request #37547 from bnbarham/line-col-crash
[SourceKit] Map line and column using the latest snapshot
2021-05-21 08:53:06 -07:00
Alex Hoppen
285cea4670 Merge pull request #37512 from ahoppen/pr/allow-driver-errors
[SourceKit] Recover if compiler arguments have errors
2021-05-21 09:17:01 +02:00
Ben Barham
0f21991f02 [SourceKit] Map line and column using the latest snapshot
During a cursor info request, the resolved offset was mapped to line and
column using the buffer inside `SwiftDocumentSyntaxInfo`.

However, prior to 54683ca607,
`editorReplaceText` was not updating the syntax info. This meant that
snapshots would be more up to date than the buffer in the syntax info,
allowing for the possibility of an invalid offset.

While 54683ca607 would also fix this,
snapshots actually have a `getLineAndColumn` anyway. Use that instead of
grabbing the buffer from syntax info.

Resolves rdar://78161348.
2021-05-21 15:42:33 +10:00
Pavel Yaskevich
aeddab4dd0 [Parse] Disallow use of actor as a declaration modifier
`actor` is a standalone contextual keyword now and should
be treated as such, `actor class` is no longer allowed
and results in a parse error.

Resolves: rdar://75753598
2021-05-19 16:18:32 -07:00
Alex Hoppen
44f8e195ef [SourceKit] Recover if compiler arguments have errors
If the compiler arguments have errors in them (e.g. because a file with the same name is used twice), we can often still fulfill SourceKit requests because the compiler argument errors are only relevant for later stages of the compilation process.

Instead of bailing out early, do a best effor retrieving the compiler arguments that are valid and ignoring the errors.

Fixes rdar://77618144
2021-05-19 22:31:15 +02:00
fwcd
8d35ed0fe9 Update diags in SourceKit tests to include key.id
- Update SourceKit/DocumentStructure tests
- Update SourceKit/CursorInfo tests
- Update SourceKit/SyntaxMapData tests
- Update SourceKit/Sema tests
- Update SourceKit/CompileNotifications tests
2021-05-07 19:32:04 +02:00
Argyrios Kyrtzidis
c417464359 Merge pull request #37252 from ahoppen/pr/missing-module-map
[ClangImporter] Load the stdlib even if there is a `-fmodule-map-file` argument pointing to a missing file
2021-05-06 09:02:22 -07:00
Alex Hoppen
aef9d5147f [ClangImporter] Load the stdlib even if there is a -fmodule-map-file argument pointing to a missing file
If there is a `-fmodule-map-file` argument whose file doesn’t exist and SwiftShims is not in the module cache, we fail to build it, because clang throws an error about the missing module map. This causes SourceKit to drop all semantic functionality, even if the missing module map isn’t required.

To work around this, drop all `-fmodule-map-file` arguments with missing files from the clang importer’s arguments, reporting the eror that `clang` would throw manually.

Fixes rdar://77449671
2021-05-06 10:23:58 +02:00
Ben Barham
415452e259 Merge pull request #37145 from bnbarham/add-external-locs
Add locations from external modules to cursor info results
2021-05-04 09:49:23 +10:00
Ben Barham
73d9f5b843 [SourceKit] Remove OptimizeForIDE global configuration
Have SourceKit return locations for symbols outside of the current
module as well. Callsites of location and comment information should
explicitly disable retrieving serialized information where performance
is a concern.

Resolves rdar://75582627
2021-05-01 11:37:23 +10:00
Ben Barham
828d12764c [SourceKit/CursorInfo] Add locations for external files to result
.swiftsourceinfo files contain the serialized location for declarations.
Use this when outputting locations in cursor info so that clients need
not perform an extra index lookup for external modules.
2021-05-01 09:38:58 +10:00
Alex Hoppen
e7d56037e8 Merge pull request #37133 from ahoppen/pr/serialize-text-module-symbolgraph
[SymbolGraph] Fix crasher when retrieving cursor info of method defined in ObjC
2021-04-30 23:13:15 +02:00
Alex Hoppen
5d3fb8f26d [SymbolGraph] Fix crasher when retrieving cursor info of method defined in ObjC
In a mixed Objective-C / Swift module, we have a Clang module overlay that’s a Source file, not a serialized AST as is currently assumed. That assumption caused a crash when retrieving the symbol graph as part of a cursor info request to SourceKit, which was invoked on a method defined in the Objective-C part of the module.

To fix the crash, recursively use the same logic that already exists to serialize a module to also serialize the clang overlay module since that function alreayd correctly handles the distinction between source files and serialized ASTs.

Resolves rdar://76951147
2021-04-29 17:54:18 +02:00
Alex Hoppen
370128e6b6 [SymbolGraph] Fix a crash for member in invalid extension
Don’t record a `memberOf` relationship if we couldn’t look up the target, e.g. because the member is declared in an extension whose extended type doesn’t exist.

Resolves rdar://74063899
2021-04-29 14:21:52 +02:00
Alex Hoppen
6b5c03208d [SourceKit] Don’t transform type when printing if CurrentType can’t have members
Since 9ba892c we always transform `CurrentType` in `ASTPrinter` to be an interface type.

This causes issues when the variable type is a generic parameter type. Previously we had `CurrentType` set to a `PrimaryArchetypeType`. With the fix in d93ae06, we are mapping the archetype out of context to a `GenericParamType`. A `GenericParamType`, however, can’t have members, so we’re hitting an assertion when creating a `TypeTransformContext`. Since the entire type transformation in `printTransformedTypeWithOptions` is only affecting type members, we should be able to safely skip over the transformation if `CurrentType` can’t have any members.

Fixes rdar://76750555 [SR-14497]
2021-04-21 11:53:06 +02:00
Alex Hoppen
d93ae06f50 [ASTPrinter] Don't transform type if current type can't have members
Since 9ba892c5af we always transform `CurrentType` in `ASTPrinter` to be an interface type.

This causes issues for variables that whose type is a protocol. Previously, when printing the type, we had `CurrentType` set to an `OpenedArchetypeType`. Now we replace the archetype by a `GenericTypeParamType`, which may not have members, so we are hitting an assertion in `ASTPrinter.cpp:270`.
To resolve this, replace any `OpenedArchetypeType`s with their protocol type before calling `mapTypeOutOfContext`.

Resolves rdar://76580851 [SR-14479]
2021-04-13 20:29:06 +02:00
Nathan Hawes
6ca5b3261e Merge pull request #36713 from nathawes/add-fragment-info-with-symbol-graph
[SourceKit/CursorInfo] Report the set of decls referenced in the symbol graph's "declarationFragments" field.
2021-04-06 18:26:21 +10:00
Nathan Hawes
08250f058a [SourceKit/CursorInfo] Report the set of decls referenced in the symbol graph's "declarationFragments" field.
Resolves rdar://75809521
2021-04-03 09:42:54 +10:00
Ben Barham
02f27c0edd [SourceKit/CursorInfo] Enable passing .swiftsourceinfo test
use-swift-source-info.swift is checking that the .swiftsourceinfo file
is being used when OptimizedForIDE is false by checking the location
output from a cursor info request.

It also checks that the module name is there, which it should be the
result is in a different file. There was previously a bug where it
*wasn't* added when a location was added (which was valid before
.swiftsourceinfo was used). The test has always worked since it was
modified in the fix to that bug, but some weirdness caused the change
and test to be out of sync (possibly the result of merges between main
and next branches).

The new line is the language, which was added after it was disabled (and
hence missed being updated).
2021-04-01 12:14:07 +10:00
Ben Barham
3ea9bed415 [SourceKit/CursorInfo] Add constructor to call results
Cursor info for a constructor would previously give the cursor info for
the containing type only. It now also adds cursor info for the
constructor itself in a "secondary_symbols" field.

Refactor `passCursorInfoForDecl` to use a single allocator rather than
keeping track of positions in a buffer and assigning everything at the
end of the function.

Refactor the various available refactoring gathering functions to take a
SmallVectorImpl and to not copy strings where they don't need to.

Resolves rdar://75385556
2021-03-30 13:23:59 +10:00
Ben Barham
8948a034c8 Merge pull request #36508 from bnbarham/static-dynamic-flag
[SourceKit/CursorInfo] Mark dynamic calls
2021-03-23 15:27:37 +10:00
Alex Hoppen
25fdf7ec3d Merge pull request #36514 from ahoppen/pr/rdar64230277
[SourceKit] Add test case for rdar://64230277
2021-03-22 13:04:02 +01:00
Ben Barham
19f23130d0 [SourceKit/CursorInfo] Mark dynamic calls
Adds two new fields to the cursor info response:
  1. is_dynamic: whether a call is dynamic
  2. receivers: receivers of the call (USRs)

Users of the CursorInfo request can use "is_dynamic" to decide whether
to lookup overrides or not, and then the "receivers" as the starting
point of the lookup.

Resolves rdar://75385900
2021-03-20 13:57:01 +10:00
Alex Hoppen
4dbfb8a135 Merge pull request #36488 from ahoppen/pr/rdar70017224
[sourcekitd] Add test case for rdar://70017224
2021-03-19 19:11:53 +01:00
Alex Hoppen
64cb1a76bb [SourceKit] Add test case for rdar://64230277
rdar://64230277 seems to already be fixed. Add a test case for it.
2021-03-19 15:23:23 +01:00
Alex Hoppen
db376a9627 [sourcekitd] Add test case for rdar://70017224
rdar://70017224 seems to be fixed. Add a test case for it.
2021-03-18 16:03:32 +01:00
Nathan Hawes
e1a4c5f846 [SourceKit][CursorInfo] Add a field for the source language the symbol was originally defined in
Resolves rdar://75446903
2021-03-18 18:49:25 +10:00
Victoria Mitchell
5d1b588273 use fully qualified titles for enum elements
rdar://74051287
2021-03-12 13:45:11 -07:00
Nathan Hawes
7886b5047d Merge pull request #36330 from nathawes/include-symbol-itself-in-parent-context-list
[SourceKit][CursorInfo] Also include the symbol itself in the "parent" contexts list
2021-03-10 12:53:52 +10:00
Nathan Hawes
b8832f4fbc [SourceKit][SymbolGraphGen] Also include the symbol itself in the "parent" contexts list.
Including the symbol itself means if clients want the same info we provide
about the parent contexts for the symbol under the cursor they won’t need to
parse it out from the symbol graph json.

Resolves rdar://problem/75121535
2021-03-06 12:04:37 +10:00
Ben Barham
ab55c19b44 [IDE] Propagate the Stmt visit failure while walking TopLevelCodeDecls
`visitTopLevelCodeDecl` ignored the `Stmt` visit returning a nullptr.
This caused the `walkToDeclPost` to run for the `TopLevelCodeDecl` and
thus an imbalance in the `RangeResolver` pre and posts (since none of
the children would have their `walkTo*Post` called).

This was originally incorrectly fixed while assuming that the
`walkTo*Post` are called regardless of whether the children were visited
or not. Those changes have been reverted - fixing an imbalance in
`ExtDecls` in `SemaAnnotator`.

Added a test case for the `ExtDecls` imbalance which can occur while an
extension is being added.

Resolves rdar://74820040
2021-03-06 11:45:11 +10:00