Commit Graph

411 Commits

Author SHA1 Message Date
Hamish Knight
f524691cdf [IDE] Avoid inferring container type for implicit expressions
For e.g implicit `buildExpression` calls, we have a location that
matches the argument, but we don't want to consider the result
builder type as the container type.
2025-02-28 21:00:12 +00:00
Hamish Knight
994848f6e5 [Mangler] Handle local archetypes in getDeclTypeForMangling
Element archetypes can occur here when mangling the USR for local
variables for e.g SourceKit cursor info, as well as for regular
compilation for things like lazy variables.

Update `getDeclTypeForMangling` to map local archetypes out of
context, using both the captured generic environments and the
archetypes present in the type. More work is needed to support lazy
variable though (now it crashes in SILGen).

This patch doesn't handle mangling standalone element archetypes for
e.g `printTypeUSR`, ideally we'd fix the clients there to not pass
local archetypes.

rdar://143077965
2025-02-26 11:51:20 +00:00
Rintaro Ishizaki
37a2748e0d [ASTPrinter] Print SPI by default
`PrintOptions.InterfaceContentKind` was not initialized. Set it to
`InteraceMode::Private` by default, so SPI declarations and their `@_spi`
attribues are printed. This basically restores the behavior before
aba3b6c24e , and is align with
`AccessFilter` being `AccessLevel::Private` by default.

rdar://131726756
2025-01-22 21:37:54 -08:00
Hamish Knight
30a8f1988a [SourceKit] Use canonical type in printTypeUSR
Mangling a non-canonical type can run into
unexpected type sugar such as the newly introduced
LocatableType. USRs should be based on canonical
types anyway, so make sure we canonicalize before
mangling.

rdar://141168628
2024-12-09 22:04:10 +00:00
Hamish Knight
c4efa0d5f0 [AST] Factor out Expr::getNameLoc
There are a bunch of AST nodes that can have
associated DeclNameLocs, make sure we cover them
all. I don't think this makes a difference for
`unwrapPropertyWrapperParameterTypes` since the
extra cases should be invalid, but for cursor info
it ensures we handle UnresolvedMemberExprs.
2024-12-05 15:55:19 +00:00
Gabor Horvath
6d24c52b80 [cxx-interop] Use the locations imported from C++
A recent PR (#77204) started to import C++ source locations into Swift.
This PR flips a switch so these locations are actually used more widely.
Now some of the diagnostic locations are changed, but they generally
improved the quality of the diagnostics, pointing out conformances
imported from Obj-C code right when they are declared.
2024-11-01 13:49:09 +00:00
swift-ci
6ea9995a81 Merge remote-tracking branch 'origin/main' into rebranch 2024-10-19 18:57:20 -07:00
Allan Shortlidge
cb578172ea Tests: Remove -disable-availability-checking in more tests that use concurrency.
Use the `%target-swift-5.1-abi-triple` substitution to compile the tests for
deployment to the minimum OS versions required for use of _Concurrency APIs,
instead of disabling availability checking.
2024-10-19 12:35:20 -07:00
Becca Royal-Gordon
fd84e7273d Rename module.map -> module.modulemap in tests
The legacy `module.map` spelling of module map files was deprecated by llvm/llvm-project#75142 and clang expects to remove support for them in the future. Switch all tests to use the supported spelling.

Fixes rdar://128431478.
2024-08-12 17:47:26 -07:00
Alex Hoppen
eec3d752cb Inherit doc comments from default implementations of inherited protocols
For example when we have

```swift
protocol BaseProtocol {}

extension BaseProtocol {
  /// Say hello
  func hello() { }
}
struct MyStruct: BaseProtocol {
  func hello() {}
}
```

Then `MyStruct.hello` should inherit the doc comment from the implementation of `BaseProtocol.hello`. Currently no doc comment is associated with `MyStruct.hello`.

rdar://126240546
2024-08-02 11:26:51 -07:00
Hamish Knight
9da87d1b1c [CursorInfo] Resolve solver-based in VarDecls
Previously we would skip resolving any solver-based
cursor info in a VarDecl accessor as the VarDecl
source range does not encompass the AccessorDecl.
Avoid looking at the VarDecl source range in this
case.

rdar://131135631
2024-07-04 22:49:46 +01:00
Hamish Knight
eeced060fa [Parse] Handle #if in brace skipping logic
Previously we would strictly match `{` + `}`, but
that ignored the fact that when parsing we consider
`#if` + `#endif` to be a stronger delimiter than
`{` + `}`, so can ignore a stray `}` in a `#if`.
Update the logic to also track opening and closing
`#if` decls, ignoring any braces that happen within
them.

rdar://129195380
2024-06-19 21:39:40 +01:00
Hamish Knight
5ec4d1cc98 [CS] Fill in ErrorTypes for expressions that fail to type-check
Ensure we always produce typed AST, even if we
fail to apply a solution. This fixes a cursor info
issue where we'd to type-check a closure twice
due to it not having a type set.

rdar://129417672
2024-06-17 17:58:52 +01:00
Alex Hoppen
a38e7cce49 [SourceKit] Mark overridable declarations as dynamic
We only set `isDynamic` to `true` if we were inside an expression. Also set `isDynamic` when we are performing cursor info at an overridable declaration. This allows jump-to-definition to jump to declarations that override the one that we performed cursor info on.

rdar://128300752
2024-06-01 22:59:38 -07:00
Rintaro Ishizaki
7b3738d1d0 [SourceKit] Adjust newlines between decls
Previously, Clang modules didn't have empty lines between top-level
decls. This was inconsistent with Swift module.
2024-03-25 22:07:50 +09:00
Rintaro Ishizaki
b019fd0c1b Merge pull request #72420 from rintaro/sourcekit-clang-printer-rdar93731287
[SourceKit] Stop printing normal comments in clang generated interface
2024-03-25 17:29:45 +09:00
Rintaro Ishizaki
c9785d955d [SourceKit] Stop printing normal comments in clang generated interface
Generated interfaces for Clang modules used to try printing normal
comments between decls extracted from the header text. That was because
doc-comment was not common in C/ObjC headers. But mainly because of
"import as member feature" Clang decls aren't printed in the order as
they appear in the header file, the logic determinig which comment
belongs to which decl was not working property. We've decided to remove
that feature and only print the proper doc-comments as it has been
getting common.

rdar://93731287
2024-03-21 11:52:32 +09:00
Alex Hoppen
ef3e1c1d4f [SourceKit] Allow generation of cursor info for declarations from solutions that haven’t aren’t applied to the AST ye
This has two benefits:
1. We can now report ambiguous variable types
2. We are more robust in the generation of results for declarations inside closures. If the closure has an error, we won’t apply the solution to the AST and thus any cursor info that tried to get types out of the AST would fail.

rdar://123845208
2024-03-20 14:52:39 +01:00
Holly Borla
ba76c3c11b [Concurrency] Never skip global actor attributes in the ASTPrinter.
Custom attributes like global actors carry crucial semantic information
and should never be suppressed in the ASTPrinter. In particular,
`printQuickHelpDeclaration()` sets `PrintImplicitAttrs` to false,
but it's important for quick help / cursor info to include global
actors.
2024-03-01 22:23:51 -08:00
Alex Hoppen
873ed19786 [SourceKit] Add the raw doc comment to the cursor info response
SourceKit-LSP currently parses the XML comment to generate Markdown again but round-tripping a (probably markdown) doc comment to XML to Markdown is lossy in many cases and unnecessary work. Include the comment as it is spelled in source in the cursor info response so that sourcekit-lsp can display it.

Part of rdar://120685874
2024-02-24 08:41:08 -08:00
Hamish Knight
05612bffe2 Remove special case for stdlib in IsNonUserModuleRequest
It's possible this may be the main module, or a
"local" dependency within the same project, and
should be treated as a user module in such cases.
2024-02-09 11:30:52 +00:00
Rick van Voorden
f8ae46b3f3 [inclusive-language] changed sanity to soundness 2024-01-25 18:18:02 -08:00
Alex Hoppen
8625b3f119 [SourceKit] Don't realpath the primary file path
If the file didn’t exist on disk, `fileSystem->getRealPath` returns an empty string, which means we can’t find the `InputBuffer` and thsu won’t run solver-based cursor info. There’s no reason to realpath `PrimaryInputPath`, `getMemoryBuffer` already does that.

rdar://120737244
2024-01-22 14:36:24 -08:00
Alex Hoppen
a710111001 [SourceKit] Support building sourcekitd without building swift-syntax
This allows building sourcekitd and swift-refactor with `SWIFT_BUILD_SWIFT_SYNTAX=NO`. In these builds, the `relatedidents` and `find-syntactic-rename-ranges` requests will always return an error.
2023-12-04 19:14:01 -08:00
Alex Hoppen
8dec9addfc [ASTGen] Relax assertion on BridgedSourceLoc initializer
We do allow `SourceLoc` to point to the address right after the buffer ends to point to the end of a file.
2023-09-26 15:46:54 -07:00
Michael Spencer
b2640e15e4 [test] Rename all module.map files to module.modulemap
`module.map` as a module map name has been discouraged since 2014, and
Clang will soon warn on its usage. This patch renames all instances of
`module.map` in the Swift tests to `module.modulemap` in preparation
for this change to Clang.

rdar://106123303
2023-08-21 15:58:59 -07:00
Alex Hoppen
bba2f476ab Merge pull request #67613 from barinsim/my-main
[SourceKit] Report cursor info information for literals
2023-08-08 20:54:00 -07:00
Simon Barinka
9342e78e3e [SourceKit] Fix support for interpolated strings 2023-08-08 23:36:16 +02:00
Simon Barinka
06af7494e9 [SourceKit] Report type decl info instead of hidden inits 2023-08-02 23:40:08 +02:00
Simon Barinka
b7ee6e4c1d [SourceKit] Remove unnecessary open request 2023-08-01 19:16:41 +02:00
Simon Barinka
944a81836c [SourceKit] Remove sourcekit-test_plain 2023-08-01 19:13:20 +02:00
Simon Barinka
d0cf2e4bf3 [SourceKit] Fix formatting issues 2023-08-01 13:26:14 +02:00
Simon Barinka
e32a20a55c [SourceKit] Report init info instead of the type decl info
Addresses PR review comments.
2023-08-01 12:51:39 +02:00
Simon Barinka
fcd084f9dd [SourceKit] Report cursor info information for literals
Adds literals support for the CursorInfo request.
Previously CursorInfo just returned error for literals.
Implements issue #57725
2023-07-30 14:22:08 +02:00
Alex Hoppen
862e14e084 [CursorInfo] De-duplicate reported cursor info results
The constraint system might produce multiple solutions that all reference the same declaration. We should only report the declaration once in those cases instead of multiple times.

rdar://111814276
2023-07-27 16:48:28 -07:00
QuietMisdreavus
2565925f88 [SymbolGraphGen] allow cursor symbol graphs from function params (#67267)
rdar://105516823
2023-07-13 13:48:12 -06:00
Ben Barham
ab95dba720 [CursorInfo] Pass primary path to allow comparing previous ASTs
Update the cursor requests to also pass in their primary file. Snapshots
should be compared using this file, not the input buffer name. This
fixes AST re-use when the AST is usable with snapshots.

Resolves rdar://110344363.
2023-06-23 20:00:19 -07:00
Ben Barham
037ddc92ee [CursorInfo] Re-use already built ASTs ahead of currently building ones
Resolves rdar://110344363.
2023-06-22 14:12:48 -07:00
Anthony Latsis
3f629315a9 Merge pull request #65731 from AnthonyLatsis/always-print-any
ASTPrinter: Turn on explicit `any` printing for everything and remove the option to disable it
2023-05-16 03:27:36 +03:00
Anthony Latsis
7f6d3bcd41 ASTPrinter: Turn on explicit any printing for everything and remove the option to disable it 2023-05-13 02:55:49 +03:00
Ben Barham
d0c892297c [Test] Avoid verifying SILGen in cursor info test
Verifying SILGen causes `loadAllMembers` to be run, which in turn ends
up actually creating the parent PBD of each `VarDecl` in this test.
Without verification, we never deserialize that PBD and thus end up with
`class` instead of `static` as we should. That's incorrect, but it's an
existing failure (rdar://105239467).

Resolves rdar://109037827.
2023-05-09 13:29:32 -07:00
Ben Barham
5beeca7cf1 [CursorInfo] Prefer AST based results over solver based
Solver based results are fast within a function, where the `ASTContext`
can be re-used. But it is significantly slower than the AST based
results when outside of a function. Instead of using solver based as the
primary results, only use them as a fallback for when AST based fails.

Resolves rdar://108930110.
2023-05-04 20:53:38 -07:00
Alex Hoppen
6fcfe7fe28 [CursorInfo] Don’t crash if we are performing cursor info at EOF
When performing code completion at the end of a file, the IDE inspection target would point to the null byte terminating the end of the string. That would cause us to consider this null byte as a code completion marker. When continuing to scan for the actual EOF, we would walk past the end of the buffer.

Simply don’t consider the last null byte as a candidate for the code completion marker to fix the problem.
2023-04-24 15:24:59 -07:00
QuietMisdreavus
47bf147605 add AST printer support for _documentation attribute (#64326)
fixes #64309
fixes rdar://106657906
2023-03-31 10:33:16 -06:00
Ben Barham
b9810fb0a3 [SourceKit] Return the original location for decls within generated code
Pass back the original location (ie. where the macro was expanded, not
the location that the generated code would be inserted) for cursor info
and indexing. Also mark any declarations/references within generated
source as implicit.

Resolves rdar://107209132.
2023-03-30 11:20:33 -07:00
QuietMisdreavus
d9c8dca5d1 [SymbolGraphGen] allow SourceKit to print declarations for private stdlib symbols (#64556)
Resolves rdar://103112656
Resolves #62457
2023-03-28 10:30:36 -06:00
Alex Hoppen
2108d01e46 Merge pull request #63613 from ahoppen/ahoppen/ambiguous-cursor-info-results
[IDE] Report ambiguous cursor info results
2023-03-20 13:07:09 -07:00
Alex Hoppen
e5c521c999 [CursorInfo] Fix issues found by the stress tester 2023-03-20 08:09:10 -07:00
Alex Hoppen
eb6729754d [IDE] Report ambiguous cursor info results 2023-03-20 08:09:10 -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