Commit Graph

3981 Commits

Author SHA1 Message Date
Robert Widmann
8b9521d6bf [NFC] Switch to the Normal EnumDecl::getAllElements
We don't have to create and iterate over a dense set here.
2022-09-13 15:22:02 -07: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
Hamish Knight
6804623a82 Fix some nullptr dereferences
Turns out we were getting away with dereferencing
`nullptr` in a few cases as `walk` would use
`nullptr` to indicate that the walk should be
stopped, and luckily Clang didn't optimize it to
something broken.

This commit is fairly defensive and sprinkles
some null checks for calls to `walk` directly
on a body of a function or top-level code decl.
2022-09-13 10:35:28 +01:00
Slava Pestov
c1b8690401 AST: Introduce special Builtin.TheTupleType singleton 2022-09-10 00:26:42 -04:00
Alex Hoppen
442cf9bd4e [Sema] Add custom functions to ActorIsolationChecker to determine expr type and closure actor isolation
When we get rid of `LeaveClosureBodiesUnchecked` we no longer save closure types to the AST and thus also don’t save their actor isolation to the AST. Hence, we need to extract types and actor isolations of parent closures from the constraint system solution instead of the AST. This prepares `ActorIsolationChecker` to take custom functions to determine the type of an expression or the actor isolation of a closure.
2022-09-07 11:12:23 +02:00
Tony Allevato
9c84149b10 Merge pull request #60432 from allevato/index-expressible-by-literal
Index expressible-by-literal expressions.
2022-08-30 07:57:25 -07:00
Tony Allevato
31d1b3a6d8 Index expressible-by-literal expressions.
When a value is initialized or coerced for a type that conforms to
one of the `ExpressibleBy*Literal` protocols (or
`ExpressibleByStringInterpolation`), this change records an implicit
call to the corresponding `init(...Literal:)` in the indexstore,
located at the beginning of the literal.
2022-08-27 20:06:13 -07:00
Alex Hoppen
b6377ff54a Merge pull request #60765 from ahoppen/pr/rdar98623438
[SourceKit] Workaround a bug that parameterized protocols without 'any' cannot be mangled
2022-08-27 00:36:32 +02:00
Alex Hoppen
c8a7e55f6a [SourceKit] Workaround a bug that parameterized protocols without 'any' cannot be mangled
`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
2022-08-26 19:08:06 +02:00
Alex Hoppen
47c1fd9055 Merge pull request #60751 from ahoppen/pr/rdar99096663
[SourceKit] Fix a crash because the API for retrieving intherited protocols of a ProtocolDecl changed
2022-08-25 14:29:08 +02:00
Alex Hoppen
bd2771e756 [CodeComplete] Show global completions from modules that are imported as @_spi
If a module is imported as `@_spi`, we didn’t receive any global completions from it.

rdar://99027179
2022-08-24 23:52:21 +02:00
Alex Hoppen
8f421a7e06 [SourceKit] Fix a crash because the API for retrieving intherited protocols of a ProtocolDecl changed
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
2022-08-24 23:19:31 +02:00
Slava Pestov
e307860d73 IDE: Stop calling getAllConformances() on protocols 2022-08-23 00:03:37 -04:00
Suyash Srijan
390d8cc44b [IDE] Add result builder code completion for buildPartialBlock (#60669) 2022-08-20 15:36:15 +01:00
Slava Pestov
7d8f3e6b63 AST: Change return type of Requirement::subst() to Requirement
Instead of returning None, let callers check hasError() if they need to.

Fixes rdar://problem/98565072.
2022-08-12 14:03:57 -04:00
Slava Pestov
172bcdca8b Sema: Type resolution only needs a GenericSignature and not a GenericEnvironment 2022-08-08 01:20:04 -04: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
2304bb9882 Merge pull request #59837 from ahoppen/pr/rename-dotexprcompletion-postfixcompletion
[CodeCompletion] Rename DotExprCompletion -> PostfixCompletion
2022-08-02 11:46:41 +02:00
Alex Hoppen
daec367b46 [CodeCompletion] Don't recommend functions with async alternatives in async contexts
When an function has an async alternative, that should be preferred when we are completing in an async context. Thus, the sync method should be marked as not recommended if the current context can handle async methods.

rdar://88354910
2022-08-01 14:28:51 +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
837ce1738c Merge pull request #60207 from simanerush/code-completion-foreach 2022-07-25 06:46:37 +02:00
Sima Nerush
5e28b06baf Add in keyword completion and a test 2022-07-24 15:10:01 -06:00
Victoria Mitchell
fe14235116 review: rename Attribute to InlineAttributes in MarkupXML 2022-07-22 10:50:17 -06:00
Victoria Mitchell
0639a9e2fb review: rename Attribute to InlineAttributes 2022-07-21 17:22:41 -06:00
Alex Hoppen
1150e700a5 [CodeComplete] Store the compiler instace as a shared pointer in CompletionInstance 2022-07-21 18:29:34 +02:00
Victoria Mitchell
76fe621c1f markup: add support for swift-cmark inline attributes
rdar://96830173
2022-07-21 08:13:07 -06: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
Alex Hoppen
9fc850abed [CodeCompletion] Lazily compute contextual diagnostics 2022-07-21 14:19:48 +02:00
Ben Barham
5c9487286e [CursorInfo] References should not include shadowed declarations
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.
2022-07-01 13:17:54 -07:00
Alex Hoppen
803e667024 [CodeCompletion] Rename DotExprCompletion -> PostfixCompletion 2022-07-01 15:57:54 +02:00
Doug Gregor
248b72bbff Track the pre-adjusted "reference" type for declaration reference. 2022-06-30 17:00:32 -07:00
Rintaro Ishizaki
e748ab41a3 [CodeCompletion] Avoid crash for not recommended item without a decl
Generating diagnostics for "not recommended" items requires an
associated declaration. However, cases like this:

  func test(fn: (Int) async -> Void) {
    fn(#^HERE^#)
  }

For the function call pattern item, there's no associated decl because
the callee is an expression. Ideally it should emit a diagnostic, but
for now, to avoid the crash, don't emit diagnostics unless the item has
the associated decl.

rdar://95306033
2022-06-16 11:25:35 -07:00
Rintaro Ishizaki
89761de82a [CodeCompletion] Don't suggest initializers on existential types
Existential types cannot be instantiated.

rdar://94369218
2022-06-09 20:15:13 -07:00
Rintaro Ishizaki
9507315c6b Merge pull request #58973 from rintaro/ide-primaryassociatedtype-rdar93275458
[SourceKit] Update for primary associated types
2022-06-08 11:27:42 -07:00
Rintaro Ishizaki
8fe890b90e [CodeCompletion] Don't suggest precedence groups in expr/type position
Precedence groups should be suggested only at
* After colon in operator decls
* After 'higherThan:' or 'lowerThan:' in precedence group decls

rdar://76977760
2022-06-03 15:18:57 -07:00
Pavel Yaskevich
b7860ea055 [TypeChecker] Split for-in sequence into parsed and type-checked versions 2022-05-30 23:17:41 -07:00
Alex Hoppen
ee34db4c49 [CodeCompletion] Don’t compute type relations if the contextual type is Any
Computing type relations to 'Any' is not very enlightning because everything would be convertible to it. If the contextual type is 'Any', just report all type relations as 'Unknown'.

rdar://64812321
rdar://84684686
2022-05-23 16:16:43 +02:00
Rintaro Ishizaki
8bda524cd2 [SourceKit] Update for primary associated types
* 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
2022-05-18 17:16:49 -07:00
Alex Hoppen
42655e1181 Merge pull request #58736 from ahoppen/pr/fix-dynamic-keypath-completion
[CodeCompletion] Look through @dynamicMemberLookup key path functions
2022-05-18 10:55:57 +02:00
Ben Barham
0b20f2117c Merge pull request #58775 from bnbarham/add-is-dynamic-to-properties
[SourceKit] Add whether a property is dynamic
2022-05-16 09:48:14 -07:00
Alex Hoppen
727d3fec86 Merge pull request #58852 from ahoppen/pr/ubuntu-22-failure
[SourceKit] Pass the main swift executable path when constructing a compiler invocation
2022-05-14 08:36:35 +02:00
Ben Barham
8889daedce [SourceKit] Add whether a property is dynamic
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.
2022-05-13 15:13:49 -07:00
Alex Hoppen
ca4abab9a9 Merge pull request #58746 from ahoppen/pr/enum-assoc-value-is-call
[Index] Consider construction of enums with associated values as a function call
2022-05-13 16:39:07 +02:00
Alex Hoppen
1843f22066 Merge pull request #58787 from ahoppen/pr/shorthand-closure-info
[CursorInfo] Report values shadowed using shorthand syntax as secondary results
2022-05-13 16:28:47 +02:00
Alex Hoppen
795be6c2bb Merge pull request #58734 from ahoppen/pr/fix-completion-in-property-attribute
[CodeCompletion] Support type checking attributes even if they are not part of the AST
2022-05-13 09:39:00 +02:00
Alex Hoppen
1525f6b982 [SourceKit] Pass the main swift executable path when constructing a compiler invocation
#58786 (rdar://93030932) was failing because the `swift-frontend` invocations passed a `swiftExecutablePath` to `Invocation.parseArgs`. This caused the `ClangImporter` instance to point to a `clang` binary next to the `swift-frontend` executable while SourceKit used PATH to find `clang`. The clang executable next to `swift-frontend` doesn’t actually exist because `clang` lives in `llvm-linux-aarch64/bin` and `swift-frontend` lives in `swift-linux-aarch64/bin`.
So some checks for a minimum clang verison failed for the normal build (because the executable doesn’t actually exists) while they pass during the SourceKit build (which used `clang` from `PATH`). This in turn caused the `outline-atomics` to be enabled to the SourceKit clang compiler arguments but not the clang compiler arguments for a normal build and thus resulted in two separate module cache directories (which includes the enabled features in the module directory hash).

To fix this issue, also set the swift executable path for compiler invocations created from SourceKit.

Fixes #58786 (rdar://93030932)
2022-05-13 09:05:38 +02:00
Alex Hoppen
d5e48d7404 Merge pull request #58822 from ahoppen/pr/effectful-specifier
[CodeCompletion] Annotate variables with effectful getters
2022-05-13 08:46:44 +02:00
Rintaro Ishizaki
d32b9c885c [CodeCompletion] Don't suggest initializers on 'AnyObject'
'AnyObject' cannot be instantiated, we shouldn't be providing any
initializers on 'AnyObject' type. 'AnyObject(<HERE>' and global
completions with initializers (i.e. `addinitstotoplevel`) showed all
initializers from objc classes.

Note that, 'lookupVisibleMemberDecls()' on 'AnyObject' (i.e.
'AnyObject.<HERE>') doesn't return initializers even before this change.
But 'QualifiedLookup' did.

rdar://93059166
2022-05-12 16:40:34 -07:00
Alex Hoppen
66b08c5bbb [CodeCompletion] Annotate variables with effectful getters
Previously, we weren’t annotation code completion results for variables with async or throwing getters as 'async' or 'throws'.

rdar://93085311
2022-05-12 08:20:31 +02:00