Commit Graph

2145 Commits

Author SHA1 Message Date
Doug Gregor
568e943115 Enable import of the _Concurrency module by default. 2021-04-13 23:14:06 -07: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
Alex Hoppen
62aabece62 Merge pull request #36866 from ahoppen/pr/serialize-internal-closure-name
[Serialization] Serialize internal closure labels
2021-04-13 18:49:58 +02:00
Alex Hoppen
380db634fa [Serialization] Serialize internal closure labels
Since 865e80f9c4 we are keeping track of internal closure labels in the closure’s type. With this change, wer are also serializing them to the swiftmodules.

Furthermore, this change adjusts the printing behaviour to print the parameter labels in the swiftinterfaces.

Resolves rdar://63633158
2021-04-13 08:53:46 +02:00
Ben Barham
299df93a7f Merge pull request #36807 from bnbarham/use-original-locs
Replace uses of presumed locations where they do not make sense
2021-04-13 08:48:23 +10:00
Alex Hoppen
9ba892c5af [ASTPrinter] Fix issue printing Self resolved to a generic type
When printing a type in type through `ASTPrinter::printTransformedTypeWithOptions`, we are removing any contextual types by mapping the type out of context. However, when substituting `Self` (or any other type member) with their concrete type from `CurrentType`, we might re-introduce contextual types.

To fix this, make sure that `CurrentType` is always an interface type that has all contextual types removed.

Fixes rdar://76021569
2021-04-12 10:39:09 +02:00
Ben Barham
20f45ec284 Replace uses of presumed locations where they do not make sense
Various uses of `getPresumedLineAndColumnForLoc` were likely added when
that function was the very misleading name `getLineAndColumn`. Change
these to use `getLineAndColumnForBuffer` instead where appropriate, ie.
we want the underlying file rather than the location to display to the
user.

There were also some cases where the buffer identifier had been swapped
to use the display name instead, under the assumption that the presumed
location was needed. Updated those as well.

SingleRawComment: Lines are only used when merging comments, where the
original location is fine to use.

Index: Doesn't store the file set in #sourceLocation, so using the
presumed line would end up pointing to a location that makes no sense.

Editor functionality: Formatting and refactoring are on the current
file. Using the presumed location would result in incorrect
replacements.
2021-04-10 09:49:31 +10:00
Arnold Schwaighofer
9286ece71c Revert "Enable import of the _Concurrency module by default." 2021-04-09 13:20:30 -07:00
Doug Gregor
9ba0647a58 Merge pull request #36767 from DougGregor/implicit-concurrency-import 2021-04-08 18:32:45 -07:00
Richard Wei
fb66de6126 Unify mangling operators for async, @Sendable, @differentiable and @noDerivative.
Repurpose mangling operator `Y` as an umbrella operator that covers new attributes on function types. Free up operators `J`, `j`, and `k`.

```
async ::= 'Ya'                             // 'async' annotation on function types
sendable ::= 'Yb'                          // @Sendable on function types
throws ::= 'K'                             // 'throws' annotation on function types
differentiable ::= 'Yjf'                   // @differentiable(_forward) on function type
differentiable ::= 'Yjr'                   // @differentiable(reverse) on function type
differentiable ::= 'Yjd'                   // @differentiable on function type
differentiable ::= 'Yjl'                   // @differentiable(_linear) on function type
```

Resolves rdar://76299796.
2021-04-07 17:49:10 -07:00
Doug Gregor
ff06bb4051 Fix a few tests for implicit _Concurrency import on Linux 2021-04-06 14:19:29 -07:00
Doug Gregor
95fd3ede09 Update tests and testing tools for implicit _Concurrency import 2021-04-06 14:08:41 -07:00
Alex Hoppen
fd8e34913a Merge pull request #36551 from ahoppen/pr/internal-labels-in-closures
[CodeComplete] Default parameter names of completed closure to internal names
2021-04-06 15:30:26 +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
8bb3ab0920 Merge pull request #36695 from bnbarham/enable-passing-test
[SourceKit/CursorInfo] Enable passing .swiftsourceinfo test
2021-04-02 14:37:17 +10:00
Alex Hoppen
865e80f9c4 [CodeComplete] Default parameter names of completed closure to internal names
If have a function that takes a trailing closure as follows
```
func sort(callback: (_ left: Int, _ right: Int) -> Bool) {}
```
completing a call to `sort` and expanding the trailing closure results in
```
sort { <#Int#>, <#Int#> in
  <#code#>
}
```

We should be doing a better job here and defaulting the trailing closure's to the internal names specified in the function signature. I.e. the final result should be
```
sort { left, right in
  <#code#>
}
```

This commit does exactly that.

Firstly, it keeps track of the closure's internal names (as specified in the declaration of `sort`) in the closure's type through a new `InternalLabel` property in `AnyFunctionType::Param`. Once the type containing the parameter gets canonicalized, the internal label is dropped.

Secondly, it adds a new option to `ASTPrinter` to always try and print parameter labels. With this option set to true, it will always print external paramter labels and, if they are present, print the internal parameter label as `_ <internalLabel>`.

Finally, we can use this new printing mode to print the trailing closure’s type as
```
<#T##callback: (Int, Int) -> Bool##(_ left: Int, _ right: Int) -> Bool#>
```

This is already correctly expanded by code-expand to the desired result. I also added a test case for that behaviour.
2021-04-01 19:14:19 +02:00
Alex Hoppen
47b012d469 Merge pull request #36629 from ahoppen/pr/visit-attributes-in-order
[SemaAnnotator] Fix bug causing custom attributes to be walked out of order
2021-04-01 18:22:01 +02: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
Alex Hoppen
16baf61601 [RangeInfo] Acknowledge that SemaAnnotator walks the tree in source order *excluding* attributes
`SemaAnnotator` walks the tree in source order with respect to the source ranges *excluding* attributes, but `RangeResolver` considers attributes part of their declaration. Thus they disagree on what “walking in source order means”. `SemaAnnotator` will visit the attributes *before* the decl they are on, while `RangeResolver` as currently implemented expects them *as part of* the decl they are on.

Thus, for the purpose of `RangeResolver`, we need to assume that nodes are visited in arbitrary order and we might encounter enclosing nodes after their children.

Thus, when we find a new node, remove all nodes that it encloses from `ContainedASTNodes`.

Fixes rdar://64140713 [SR-12958]
2021-03-31 13:32:02 +02: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
Alex Hoppen
e0fca6c12f Merge pull request #36491 from ahoppen/pr/rdar64304839
[SourceKit] Fix crash in syntax model
2021-03-22 12:18:08 +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
5d9163598a [SourceKit] Fix crash in syntax model
The end location of an attribute used to point to the next token after the attribute's content, which is the closing parenthesis in valid Swift code. But when the parenthesis is missing, it points to the next token, which is most likely no longer part of the attribute.

Fix by parsting the closing parenthesis (conditionally) first and using the location of last token parsed for the attribute (`PreviuosLoc`) as the attribute range's end location.

Resolves rdar://64304839
2021-03-19 13:12:03 +01:00
swift-ci
4255a670c4 Merge pull request #36510 from DougGregor/se-0302-rename 2021-03-19 02:19:45 -07:00
Doug Gregor
9579390024 [SE-0304] Rename ConcurrentValue to Sendable 2021-03-18 22:48:20 -07:00
Nathan Hawes
839500867c Merge pull request #36486 from nathawes/add-language-to-cursor-info
[SourceKit][CursorInfo] Add a field for the source language the symbol was originally defined in
2021-03-19 13:47:09 +10: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
Ted Kremenek
8256a4e91c Update Swift version to 5.5 2021-03-16 21:29:13 -07:00
Dave Lee
fd2ba3091c Remove .#doc_clang_module.swift 2021-03-15 15:13:58 -07: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
Rintaro Ishizaki
631013cd6e Merge pull request #36316 from rintaro/sourcekit-editnowait-rdar74984613
[sourcekit] Response 'edit' immediately if client needs nothing
2021-03-06 09:29:12 -08: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
Rintaro Ishizaki
40dc8e1bd4 [sourcekit] Response "edit" immediately if client needs nothing
If the client doesn't want anything as the response of
'editor.replacetext' requests, we don't even need parsing.

rdar://problem/74984613
2021-03-05 13:18:11 -08:00
Victoria Mitchell
db3685aa29 don't emit navigator name if it's the same as subHeading 2021-03-01 10:57:54 -07:00
Nathan Hawes
bba702940c [CusorInfo] Fix ASAN heap-use-after-free failure when reporting parent contexts.
Resolves rdar://problem/74289832
2021-02-16 18:57:46 +10:00
Slava Pestov
38e82c50b2 Temporarily disable failing test 2021-02-12 16:40:21 -05:00
Argyrios Kyrtzidis
9ef86bd110 Merge pull request #35873 from nathawes/cursor-info-parent-usrs
[SourceKit][SymbolGraph] Add a 'parent_contexts' field the CursorInfo response
2021-02-11 21:24:01 -08:00
Slava Pestov
e30ced6069 Disable complete_checkdeps_notifyupdate.swift even harder 2021-02-11 16:05:06 -05:00
Evan Wilde
8b80331c3d Updating tests to use actor
This patch updates the `actor class` spelling to `actor` in almost all
of the tests. There are places where I verify that we sanely handle
`actor` as an attribute though. These include:

 - test/decl/class/actor/basic.swift
 - test/decl/protocol/special/Actor.swift
 - test/SourceKit/CursorInfo/cursor_info_concurrency.swift
 - test/attr/attr_objc_async.swift
 - test/ModuleInterface/actor_protocol.swift
2021-02-10 08:09:13 -08:00
Nathan Hawes
6d940951ca [SourceKit][SymbolGraph] Add a 'ParentContexts' field the CursorInfo response
When the SymbolGraph json is requested via (key.retrieve_symbol_graph: 1) this adds
a new field in the response that lists all the parent contexts of the symbol under
the cursor with their symbol graph kind and name, and their USR:

key.parent_contexts: [
    {
      key.kind: "swift.struct",
      key.name: "Parent",
      key.usr: "s:27cursor_symbol_graph_parents6ParentV"
    },
    ...
  ]
}

Resolves rdar://problem/73904365
2021-02-10 16:35:57 +10:00
Rintaro Ishizaki
08d57791a8 Merge pull request #35856 from rintaro/disable-rdar74150023
[Test] Disable a test case while investigating
2021-02-09 21:16:45 -08:00
Argyrios Kyrtzidis
233938a624 [test/SourceKit] Introduce a test that ensures a certain set of arguments allows both compiler and sourcekitd invocations to share the same module cache 2021-02-09 13:41:27 -08:00