Commit Graph

155 Commits

Author SHA1 Message Date
Ben Barham
8e6c9962d6 [AST] Do not copy SearchPathOptions in updateNonUserModule
`updateNonUserModule` was accidentally copying `SearchPathOptions`. Take
a reference to it instead. Also, since `addFile` is actually called many
times (once for every submodule, of which there are many), change
`isNonUserModule` to a request so that it's only calculated when needed.

Resolves rdar://107155587.
2023-03-24 17:05:57 -07:00
Alexis Laferrière
201c4b6205 Merge pull request #64486 from xymus/import-filter-refactor
[Sema] Intro common sets of import filters to simplify calls to `getImportedModules`
2023-03-21 11:10:50 -07:00
Alex Hoppen
6c5ac5179a Merge pull request #63490 from ahoppen/ahoppen/split-ideinspection
Split IDEInspectionCallbacks into CodeCompletionCallbacks and DoneParsingCallback
2023-03-20 09:20:30 -07:00
Alexis Laferrière
205a2edf38 [Sema] Intro set of import filters for general use
Calling getImportedModules requires to list the desired kind of imports.
With the new kind of imports this has become cumbersome. Let's simplify
it by offering common sets of imports. Advanced call sites can still
list the desired imports explicitly.
2023-03-17 16:05:44 -07:00
Egor Zhdan
9247d53082 [cxx-interop] Do not auto-complete unsafe underscored methods, part 2
Previous patch removed unsafe C++ methods from the module interface, but not from auto-completion results.

rdar://103252957
2023-03-17 18:04:22 +00:00
Alex Hoppen
8a2cd86deb Split IDEInspectionCallbacks into CodeCompletionCallbacks and DoneParsingCallback
Cursor info only cares about the `doneParsing` callback and not about all the `complete` functions that are now defined in `CodeCompletionCallbacks`. To make the design clearer, split `IDEInspectionCallbacks`.

rdar://105120332
2023-03-17 10:31:13 -07:00
Doug Gregor
af3b41625f Make the interface type of a generic macro into a GenericFunctionType.
This correctly models their type in the type system, and fixes the
redeclaration issue reported in rdar://104183961.
2023-03-05 22:38:08 -08:00
Doug Gregor
7177a16c4c [Code completion] Provide attached macro names after @ 2023-03-04 21:42:36 -08:00
Doug Gregor
af6fe8b383 [Code completion] Don't include non-freestanding macros in results. 2023-03-03 21:39:38 -08:00
Doug Gregor
7fc7040aad [Macros] Drop special code completions for built-in macros.
We don't need special completion logic for things like `#file` and
`#line` now that they are declared in the standard library. Drop it
and update tests.
2023-03-02 20:34:58 -08:00
Doug Gregor
200f2340d9 [Macros] Be deliberate about walking macro arguments vs. expansions
Provide ASTWalker with a customization point to specify whether to
check macro arguments (which are type checked but never emitted), the
macro expansion (which is the result of applying the macro and is
actually emitted into the source), or both. Provide answers for the
~115 different ASTWalker visitors throughout the code base.

Fixes rdar://104042945, which concerns checking of effects in
macro arguments---which we shouldn't do.
2023-02-28 17:48:23 -08:00
Doug Gregor
04eca73d60 [Macros] Stop parsing the ": <type>" syntax. We always require parameters 2023-02-09 22:11:23 -08:00
Rintaro Ishizaki
4e334498e8 [CodeCompletion] Don't suggest opaque generic parameter types
'some' parameter types don't have spelling.

rdar://102958462
2022-12-15 13:26:17 -08:00
Alex Hoppen
fe2ae72ad2 [IDE] Rename CodeCompletion to IDEInspection in cases where the code path no longer exclusively applies to code completion
The code completio infrastructure is also being used for cursor info now, so it should no longer be called code completion.

rdar://103251187
2022-12-13 11:41:05 +01:00
Doug Gregor
9d24f447b7 Remove special handling of __FILE__, __LINE__, etc.
These were replaced by `#file`, `#line`, etc. with SE-0028, prior to
Swift 3. We don't need this custom error message any more, and they
shouldn't be keywords. Stop treating them as keywords in the lexer.
2022-12-10 15:38:09 -08:00
Doug Gregor
e1102cc098 Merge pull request #62204 from DougGregor/macro-declarations
Macro declarations
2022-11-29 10:04:09 -08:00
Slava Pestov
34ce74aea8 AST: Stricter invariants when constructing TypeAliasType 2022-11-28 23:57:53 -05:00
Doug Gregor
af6b30a195 [Code completion] Add code completion support for macro expansions. 2022-11-28 18:33:10 -08:00
Erik Eckstein
ab1b343dad use new llvm::Optional API
`getValue` -> `value`
`getValueOr` -> `value_or`
`hasValue` -> `has_value`
`map` -> `transform`

The old API will be deprecated in the rebranch.
To avoid merge conflicts, use the new API already in the main branch.

rdar://102362022
2022-11-21 19:44:24 +01:00
Robert Widmann
9ff5d88847 Remove SourceKit Support for the libSyntax Tree 2022-11-16 14:52:28 -08:00
Rintaro Ishizaki
0e2e315633 Remember nominal type decls for member lookup
`lookupVisibleMemberDecls` visits nominal type decls to find visible
members of the type. Remembering what decls are visited can be useful
information for the clients.

* Add a 'VisibleDeclConsumer' callback function that is called when
  'lookupVisibleDecls' visits each nominal type decls
* Remember the decl names in 'CodeCompletionContext' for future use
2022-10-21 16:46:06 -07:00
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
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
Slava Pestov
e307860d73 IDE: Stop calling getAllConformances() on protocols 2022-08-23 00:03:37 -04: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
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
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
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
Ben Barham
f66d9bdf9b Merge pull request #42529 from ahoppen/pr/no-duplicate-results-from-other-modules
[CodeCompletion] Only include results from other modules once
2022-04-21 11:20:09 -07:00
Alex Hoppen
310ec6eb8d [CodeCompletion] Only include results from other modules once
In case of ambigous expression/global completions, we call `getValueCompletionsInDeclContext` multiple times for the amigous solutions to the constraint system. This can cause modules to be included multiple times in `RequestedCachedResults` and thus global results from these modules are reported multiple times. Make `RequestedCachedResults` a set so we don’t get duplicate results.

rdar://92048610
2022-04-21 10:48:40 +02:00
Doug Gregor
4116d7a3d7 Rename the -strict-concurrency= options to be more descriptive.
The three options are now:

* `explicit`: Enforce Sendable constraints where it has been explicitly adopted and perform actor-isolation checking wherever code has adopted concurrency. (This is the default)
* `targeted`: Enforce Sendable constraints and perform actor-isolation checking wherever code has adopted concurrency, including code that has explicitly adopted Sendable.
* `complete`: Enforce Sendable constraints and actor-isolation checking throughout the entire module.
2022-04-20 18:17:33 -07:00
Doug Gregor
d20064443f Use the strict concurrency level to make decisions.
`isConcurrencyChecked()` was being used as a proxy for
`-warn-concurrency` that didn't account for Swift 6. Replace
checks against it within the current module with checks against the
strict concurrency level, which subsumes the Swift 6 check and can
account for the difference between "limited" and "on".

`isConcurrencyChecked()` is used now used exclusively to mean "treat a
missing Sendable conformance as an explicitly-non-Sendable type".
2022-04-18 23:52:07 -07:00
Rintaro Ishizaki
624c07b13a Merge pull request #42200 from rintaro/ide-completion-rdar89051832
[CodeCompletion] Don't mark some undesirable imported default values
2022-04-12 11:34:44 -07:00
Rintaro Ishizaki
2b9ee76677 [CodeCompletion] Don't mark some undesirable imported default values
For ObjC NS_OPTIONS/NSDictionary parameters with some specific names,
ClangImporter implicitly adds default values. However, that behavior is
sometimes not really desirable. For example, for:

  -(void)addAttributes:(NSDictionary *)attrs;

'attrs' is defaulted, but calling 'addAttributes()' doesn't make any sense.
In code-completion, consider such paramters non-defaulted.

rdar://89051832
2022-04-06 09:58:49 -07:00
Alex Hoppen
c21a75def4 [CodeCompletion] Migrate CaseStmtBeginning to solver-based 2022-04-06 09:59:33 +02:00
Rintaro Ishizaki
0dad5ff24e [NFC][CodeCompletion] Prepend 'should' to 'addItemWithoutDefaultArgs'
Rename 'addItemWithoutDefaultArgs' to 'shouldAddItemWithoutDefaultArg'
because this function only returns bool indicating "should or not".
2022-04-05 16:53:37 -07:00
Rintaro Ishizaki
cd4bc88443 Merge pull request #42145 from rintaro/ide-completion-rdar90399603
[CodeCompletion] Update for SE-0345 shorthand optional binding
2022-04-05 16:30:29 -07:00
Rintaro Ishizaki
bcc003bd2d [CodeCompletion] Update for SE-0345 shorthand optional binding
Suggest visible optional values after 'if let'.

rdar://90399603
2022-04-05 09:56:14 -07:00
Alex Hoppen
32dc26139b [CodeCompletion] Don't crash in CompletionLookup if function type has no extInfo 2022-03-25 09:36:05 +01:00
Alex Hoppen
03d819f442 [CodeCompletion] Check whether surrounding context supports async in all solver-based completion kinds 2022-03-21 20:04:32 +01:00
Alex Hoppen
e2a62f1a60 [CodeCompletion] Migrate expression completions to solver-based 2022-03-21 13:00:33 +01:00
Rintaro Ishizaki
b08993f1ab Merge pull request #41787 from rintaro/ide-completion-rdar90136020
[CodeCompletion] Remove a hack adding type matching nominal types
2022-03-14 09:45:21 -07:00
Rintaro Ishizaki
504e73d5ad [CodeCompletion] Remove a hack adding type matching nominal types
Previously we didn't give any type relations to cached imported symbols.
So there was a hack to add the type matching nominal type with type
relation manually, which caused duplicated candiates, one from the
cache, one added manually.
Now that we have type relations for cached symbols so we don't need this
hack anymore.

rdar://90136020
2022-03-11 10:51:02 -08:00
Konrad `ktoso` Malawski
13cc8b3157 [Distributed] Enable no-longer-experimental distributed by default 2022-03-11 22:14:49 +09:00
Robert Widmann
ab44a07045 Convert DeclContext Parameters to their Associated Generic Signatures Instead 2022-03-07 22:54:23 -08:00
Robert Widmann
d6186c9cfb Add a DeclContext Parameter to Opened Archetype Construction
This ensures that opened archetypes always inherit any outer generic parameters from the context in which they reside. This matters because class bounds may bind generic parameters from these outer contexts, and without the outer context you can wind up with ill-formed generic environments like

<τ_0_0, where τ_0_0 : C<T>, τ_0_0 : P>

Where T is otherwise unbound because there is no entry for it among the generic parameters of the environment's associated generic signature.
2022-03-07 22:54:22 -08:00
Rintaro Ishizaki
92b9df0725 [CodeCompletion] Remove 'declTypeContext' field from the result builder
This field is not used anymore
2022-03-03 11:47:33 -08:00