Commit Graph

2426 Commits

Author SHA1 Message Date
Slava Pestov
1ee2db4520 AST: Accessors no longer appear as members of their parent DeclContext
Accessors logically belong to their storage and can be synthesized
on the fly, so removing them from the members list eliminates one
source of mutability (but doesn't eliminate it; there are also
witnesses for derived conformances, and implicit constructors).

Since a few ASTWalker implementations break in non-trivial ways when
the traversal is changed to visit accessors as children of the storage
rather than peers, I hacked up the ASTWalker to optionally preserve
the old traversal order for now. This is ugly and needs to be cleaned up,
but I want to avoid breaking _too_ much with this commit.
2019-07-30 15:56:00 -04:00
Xi Ge
7658d63d62 IDE+Evaluator: refactor IDE type-checking utilities for subscript decl into requests
We used to have a function getRootAndResultTypeOfKeypathDynamicMember to return
both the root and result type of a subscript. This patch splits the function
into two functions returning root type and result type respectively. It also refactors
the implementation into the evaluator model.
2019-07-30 11:54:16 -07:00
Argyrios Kyrtzidis
348fa2145e Merge pull request #26371 from akyrtzi/swift-indent
Rename the `swift-format` utility to `swift-indent`
2019-07-26 15:19:36 -07:00
Argyrios Kyrtzidis
0135e01d02 Rename the swift-format utility to swift-indent
This is to distinguish the C++ indenting functionality from the new formatter that is written in Swift.
2019-07-26 11:40:54 -07:00
Rintaro Ishizaki
54a99eb5fb Merge pull request #26334 from rintaro/ide-completion-errorautoclosure-rdar53507773
[CodeCompletion] Add dyn_cast check to prevent crash
2019-07-24 23:51:58 +02:00
Xi Ge
b6e6f69e80 IDE+Evaluator: converge multiple type relation checks into a single sema request, NFC
From libIDE, the utility functions will invoke the request in the implementation.
2019-07-24 12:53:10 -07:00
Rintaro Ishizaki
f3826b83b0 [CodeCompletion] Add dyn_cast check to prevent crash
rdar://problem/53507773
2019-07-24 12:23:45 -07:00
Nathan Hawes
71c4c16b38 Merge pull request #26270 from nathawes/53313197-syntaxmodel-crash
[IDE] Fix SyntaxModel crash due to out-of-order walking of EnumElementDecls
2019-07-24 09:45:28 -07:00
Slava Pestov
3e45b327de Parse: Remove some bogus error recovery code for 'lazy' 2019-07-23 22:00:31 -04:00
Nathan Hawes
218f49052a [IDE] Fix SyntaxModel crash due to out-of-order walking of EnumElementDecls
ModelASTWalker was previously constructing SyntaxNodes for EnumElementDecls
manually when visiting their associated EnumCaseDecl so that they would appear
as children rather than siblings. It wasn't actually walking these nodes
though, so missed handling some things, e.g. closures passed as default
argument values. These were also still being visited later, and because the
first visit consumed all the associated TokenNodes, this was triggering an
assertion due to the associated TokenNodes not matching expectations.
2019-07-23 09:34:25 -07:00
Slava Pestov
755c02c079 Merge pull request #26235 from slavapestov/accessor-refactoring
Split off StorageImplInfo from AccessorRecord
2019-07-22 23:17:15 -04:00
Slava Pestov
a532a325e1 AST: Move a few methods from VarDecl down to ParamDecl 2019-07-22 20:19:09 -04:00
Xi Ge
1cb746b47c IDE+Evaluator: refactor resolveProtocolName to using the request evaluator, NFC 2019-07-22 15:35:14 -07:00
Xi Ge
77ba3a21b4 IDE+Evaluator: refactor the implementation of two type checker utilities to evaluator requests. NFC
IDE functionality needs some internal type checking logics, e.g. checking
whether an extension is applicable to a concrete type. We used to directly
expose an header from sema called IDETypeChecking.h so that IDE functionalities
could invoke these APIs. The goal of the commit and following commits is to
expose evaluator requests instead of directly exposing function entry points from
sema so that we could later move IDETypeChecking.h to libIDE and implement these functions
by internally evaluating these requests.
2019-07-22 12:49:36 -07:00
Xi Ge
be609e82ef Merge pull request #26230 from nkcsgexi/evalutor-collect-overriding-decls
IDE+Evaluator: refactor the implementation of two common IDE utilities to the evaluator model
2019-07-19 14:11:25 -07:00
Xi Ge
4d57590fa9 IDE+Evaluator: refactor the implementation of two common IDE utilities to the evaluator model
These APIs are 'canDeclProvideDefaultImplementationFor' and 'collectAllOverriddenDecls'.
2019-07-19 11:14:21 -07:00
Ben Langmuir
65ed4cb4f7 Merge pull request #26236 from rintaro/ide-completion-exprcontext-arrayliteral-rdar50696432
[CodeCompletion] Expr context type analysis for failed array literal expression
2019-07-19 07:19:08 -07:00
Rintaro Ishizaki
ee2f39cc21 [CodeCompletion] Expr context type analysis for failed array literal expr
let _: [Foo] = [
  .create(str: Int)
  .create(#^COMPLETE^#)
]

Previously, this completion used to fail because the array expression
isn't typechecked. We need to analyze the context type of the array
literal first, that defines the type of the unresolved member
expression.

rdar://problem/50696432
2019-07-18 21:36:47 -07:00
Xi Ge
ab86991958 IDE: move two AST traversal utilities from libIndex to IDE type checking. NFC 2019-07-18 16:17:10 -07:00
Xi Ge
8f1a9b4789 IDE+Evaluator: refactor range info resolver to an IDE evaluator request. NFC 2019-07-17 12:20:09 -07:00
Xi Ge
1aaf5fcbe2 Merge pull request #26155 from nkcsgexi/request-cursor-info
Sourcekit+Evaluator: refactor cursor-info resolver to using the evaluator model. NFC
2019-07-16 16:26:27 -07:00
Xi Ge
f2a30bb131 IDE: cache resolved cursor info in the request evaluator
Resolving cursor info is a necessary step both when checking the availability
of a refactoring kind and performing the refactoring action. These
two steps are two high-level sourcekitd requests issued from IDE.
By caching the result of the resolved cursor info in the evaluator of
the ASTContext, we can reuse the cursor info result across these separate
IDE requests.
2019-07-16 14:47:23 -07:00
Xi Ge
8915cf8c4d Sourcekit/Evaluator: refactor cursor-info resolver to using the evaluator model. NFC
This change adds a new IDE request ID zone and refactors the cursor-info resolver
to use the request evaluator model.
2019-07-16 09:55:16 -07:00
Rintaro Ishizaki
3601cc05fb Merge pull request #25876 from rintaro/ide-completion-checkhasinterfacety-rdar51599533
[CodeCompletion] Add defensive nullptr check
2019-07-16 00:57:08 +02:00
Xi Ge
a35ee51502 Merge pull request #26117 from nkcsgexi/52392291
SourceKit/Formatting: avoid indenting for consecutive dot-member calls
2019-07-12 16:58:03 -07:00
Xi Ge
f27ccabdb1 SourceKit/Formatting: avoid indenting for consecutive dot-member calls
rdar://52392291
2019-07-12 14:03:03 -07:00
Gwen Mittertreiner
7c78a7a2b0 Merge pull request #26099 from gmittert/ATrueOrdering
Sort `DeclAttributeAndRange`s Deterministically
2019-07-12 12:52:04 -07:00
Gwen Mittertreiner
bfae01547f Sort DeclAttributeAndRanges Deterministically
Comparing the start and end of ranges doesn't work in all cases since
both a < b and b < a can be true if a = b. This behavior was causing an
assertion fail in the Windows standard library which while sorting,
asserts that if `a < b`, then  `!(b < a)` in debug mode.

Since ranges don't overlap otherwise, comparing just the starts of the
ranges will properly sort them.
2019-07-12 10:57:02 -07:00
Doug Gregor
015b7c5266 [AST] Use AbstractFunctionDecl::getBodySourceRange() more frequently.
A number of callers to AbstractFunctionDecl::getBody() were only
extracting the source range of the body... which can be retrieved more
efficiently with getBodySourceRange().
2019-07-11 21:31:21 -07:00
Nathan Hawes
306584339e Merge pull request #26016 from cltnschlosser/SR-11077-inner-rename-nested-type
[refactoring] Fix error when renaming nested type at constructor - init() has no declaration location
2019-07-11 17:49:12 -07:00
Xi Ge
d0f0069488 Merge pull request #24566 from Regno/feature/vlasov/SR-5744
[SR-5744] Refactoring action to convert if-let to guard-let and vice versa
2019-07-11 11:31:57 -07:00
Colton Schlosser
07675a75e0 [refactoring] Fix error when renaming nested type at constructor - init() has no declaration location
Resolves SR-11077
2019-07-10 21:02:00 -04:00
Doug Gregor
1284878ad8 [SE-0258] Rename init(initialValue:) --> init(wrappedValue:).
Addresses core team decision on acceptance of property wrappers.

Fixes rdar://problem/48871069.
2019-07-10 14:26:53 -07:00
Власов Антон Вячеславович
f119f211e6 SR-5744 Fixs from comments to pull request 2019-07-09 17:49:19 +03:00
Власов Антон Вячеславович
8acd794935 SR-5744 Refactoring action to convert if-let to guard-let and vice versa 2019-07-09 16:21:25 +03:00
Slava Pestov
4c499fd4ac AST: Stop passing around LazyResolvers in various places 2019-07-06 00:43:22 -04:00
Xi Ge
c2d8c460f3 SourceKit/Indentation: avoid indenting closing paren of function-like decls if it appears in a new line
rdar://51719094
2019-07-02 12:41:08 -07:00
Rintaro Ishizaki
dfc4d77c32 [CodeCompletion] Fix a crash in callee analysis
struct Wrap<T> {
  func method<U>(_ fn: (T) -> U) -> Wrap<U> {}
}
func testGenricMethodOnGenericOfArchetype<Val>(value: Wrap<Val>) {
  value.method(#^HERE^#)
}

In this case, the type of value is `Wrap<Val[archetype]>`.
`Type::getTypeOfMember()` for 'method' method returns
`( (Val[archetype]) -> U[generic param]) -> Wrap<U[generic param]>`
which crashs 'mapTypeIntoContext()' because it already hass archetype.

rdar://problem/52386176
2019-07-01 10:11:07 -07:00
Rintaro Ishizaki
8c8b89c499 [CodeCompletion] Add defensive nullptr check
Prevent crash.
rdar://problem/51599533
2019-06-28 17:45:35 -07:00
Rintaro Ishizaki
038c4f3e85 Merge pull request #25872 from rintaro/ide-complete-contextype-openarchetypes-rdar51723460
[CodeCompletion] Enable 'openArchetypes' when checking if convertible
2019-06-28 16:50:45 -07:00
Nathan Hawes
a0052c9c06 Merge pull request #25758 from nathawes/property-wrapper-rename
[IDE][Index] Property wrapper rename support
2019-06-28 16:25:45 -07:00
Rintaro Ishizaki
4d076e85c7 [CodeCompletion] Enable 'openArchetypes' when checking if convertible
```swift
protocol Proto {}
struct ConcreteProto {}
struct MyStruct<T> {}

extension MyStruct where T: Proto {
  static var option: MyStruct<ConcreteProto> { get }
}
func foo<T: Proto>(arg: MyStruct<T>) {}
func test() {
  foo(arg: .#^HERE^#)
}
```
In this case, the type of `MyStruct.option` is `MyStruct<ConcreteProto>`
whereas the context type is `MyStruct<T> where T: Proto`.
When checking the convertibility of them , we need to "open archetype types".

rdar://problem/24570603
rdar://problem/51723460
2019-06-28 15:25:52 -07:00
Xi Ge
ff32d5899a SourceKit/ExpressionType: allow users to canonicalize collected expression types
The default response of the expression type request doesn't canonicalize expression
types. This patch adds a flag to allow users to canonicalize them.
2019-06-28 11:36:44 -07:00
Nathan Hawes
e08a6c1994 [IDE][Index][test] Update sourcekit/indexing support for latest property wrapper changes
The backing property for 'foo' is now '_foo', and the projected value '$foo'.
This updates Indexing to report occurrences of foo within both $foo and
_foo occurrences (rather than just $foo - the old _foo).

FindRelatedIdents was similarlar updated, so it reports 'foo' ranges in both
_foo and $foo.

CursorInfo now reports the USR, documentation, and location of foo when invoked
occurrences of $foo or _foo, but now leaves the name, type, and annotated
declaration of _foo/$foo as is. Having the same USR ensures rename invoked on
any of them will still rename via foo. Reporting foo's documentation comment
instead is just to present something more useful to the user.
2019-06-28 10:15:00 -07:00
Nathan Hawes
c547e6885e [test] Add more index/refactoring/cursor-info tests for property wrappers
Make sure they handle the case when a property wrapper type's constructor is
called with the first argument coming from the var initializer, and the rest
from the custom attribute's argument.
2019-06-26 18:37:47 -07:00
Nathan Hawes
c7e8b3f693 [test] Update Index/refactoring property wrapper tests to use wrappedValue rather than value
Plus other small cleanups to comments and variable names.
2019-06-26 18:37:47 -07:00
Nathan Hawes
91e2e35a77 [IDE] Update CursorInfo and FindRelatedIdents to treat property wrapper backing properties as the underlying property
This is the final piece to get rename and findRelatedIdents to include all foo
and $foo occurrences, for example, in the set of occurrences to be renamed or
shown, regardless of whether they were initiated on a foo or $foo.

Resolves rdar://problem/51695783.
2019-06-26 18:37:47 -07:00
Nathan Hawes
d389652998 [IDE][Index] Renaming a wrapped property should also rename the synthesized $-prefixed backing property
This patch achieves this by updating indexing to reporting the position of
`foo` in occurrences of `$foo` as an occurrence of the `foo` symbol, so
that renames initiated on occurrences of the `foo` symbol will also result
in occurrences of the `$foo` symbol being updated correctly. This also means
find-references on foo will show places where $foo is used.

Making rename work in the other direction (invoking rename on $foo upating foo
occurrences too) is still todo.
2019-06-26 18:37:47 -07:00
Nathan Hawes
a565430239 [IDE][Index] Fix syntax coloring, index, and rename support for custom attributes
This fixes custom attribute syntax highlighting on parameters and functions
(where function builders can be applied). They weren't being walked in
the function position previously and were walked out of source order in the
parameter position.

It also fixes rename of the property wrapper and function builder type
names that can appear in custom attributes, as well as rename of property
wrapper constructors, that can appear after the type names, e.g.
`@Wrapper(initialValue: 10)`. The index now also records these constructor
occurrences, along with implicit occurrences whenever a constructor is
called via default value assignment, e.g. `@Wrapper var foo = 10`, so that
finding calls/references to the constructor includes these locations.

Resolves rdar://problem/49036613
Resolves rdar://problem/50073641
2019-06-26 18:37:47 -07:00
Rintaro Ishizaki
257b61744e [CodeCompletion] Eliminate super related completion
In parser, 'parseExprPostfixSuffix()' can parse postfix expression for
'super'. 'parseExprSuper()' doesn't need to parse them.

In code-completion, 'completeExprSuper()' and 'completeExprSuperDot()'
can be consolidated to 'completePostfixExpr()' and 'completeDotExpr()'.
2019-06-26 09:59:47 -07:00