Commit Graph

2551 Commits

Author SHA1 Message Date
Rintaro Ishizaki
0555d30b8c Merge pull request #26546 from rintaro/ide-completion-rdar53034550
[AST] Be lenient with PatternBindingIntializer without PatBindingDecl
2019-08-13 21:21:37 +02:00
Pavel Yaskevich
9526d6f90e [IDE] NFC: Fix test-case which now diagnoses correctly
Behavior changed when it became possible to omit `return` in
single expression functions but it hasn't been diagnosed correctly.
2019-08-13 11:55:08 -07:00
Rintaro Ishizaki
8fc26349c6 Merge pull request #26615 from rintaro/ide-completion-rdar54215016
[CodeCompletion] Fix a crash in collectPossibleCalleesByQualifiedLookup
2019-08-12 23:13:13 +02:00
Rintaro Ishizaki
4353a55587 [CodeCompletion] Fix a crash in collectPossibleCalleesByQualifiedLookup
We cannot assume that 'FuncDecls' have 'AnyFunctionType' interface type
or null type. They can be 'ErrorType's.

rdar://problem/54215016
2019-08-12 12:27:30 -07:00
Slava Pestov
9dd835c71b Sema: Replace the finalizeDecl() mechanism with ClassDecl::getEmittedMembers()
The only thing remaining in finalizeDecl() is synthesis of
certain class members. Let's turn that into a request.
2019-08-09 19:08:47 -04:00
swift-ci
c43eb9b1d8 Merge pull request #26418 from nathawes/type-attr-coloring 2019-08-09 13:47:29 -07:00
Rintaro Ishizaki
428bbe1060 [AST] Be lenient with PatternBindingIntializer without PatBindingDecl
PatternBindingInitializer may not be attached to any
PatternBindingDecl. e.g.

  struct S {
    @CustomAttr(something)
  }

In this case DeclContext for 'something' is PatternBindingInitializer,
but it doesn't have PatternBindingDecl because it's not written yet.

Fixes a crash in code-completion.

rdar://problem/53034550
2019-08-08 10:48:47 -07:00
Harlan Haskins
7fd8649d30 [AST] Handle printing default values for tuples of nils
If a var has optional type, e.g.

```
var x: Int?
```

It will be implicitly initialized to `nil`. However, there's a second,
undocumented behavior: tuples of optional type, potentially nested infinitely,
will also be initialized, to tuples of nil.

So this var

```
var w: ((Int?, (), Int?), (Int?, Int?))
```

Will be default-initialized to

```
((nil, (), nil), (nil, nil))
```

We need to handle this inside getDefaultValueStringRepresentation,
otherwise we will crash while emitting partial modules.

Fixes one instance of rdar://51560190
2019-08-06 11:58:50 -07:00
Nathan Hawes
5d47b45991 [IDE][Parse] Change the source location of TypeAttributes to point to the @ like DeclAttributes 2019-08-05 11:36:32 -07:00
Nathan Hawes
87d17bfb4c [IDE] Fix ModelASTWalker's handling of type attributes
When looking for the SyntaxNode corresponding to a type attribute (like
@escaping), ModelASTWalker would look for one whose range *started* at the type
attribute's source location. It never found one, though, because the
SyntaxNode's range included the @, while the type attribute's source location
pointed to the name *after* the @.
2019-08-05 11:36:32 -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
Rintaro Ishizaki
f3826b83b0 [CodeCompletion] Add dyn_cast check to prevent crash
rdar://problem/53507773
2019-07-24 12:23:45 -07:00
Rintaro Ishizaki
1d6b991086 Merge pull request #26321 from rintaro/ide-completion-rdar53401609
[AST] Use LookUpConformanceInModule to check if extension applied
2019-07-24 20:09:36 +02:00
Rintaro Ishizaki
32854b3d93 [AST] Use LookUpConformanceInModule to check if extension applied
rdar://problem/53401609
2019-07-24 09:48:46 -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
Xi Ge
2f9d87167e test: add a comment in coloring_52982457.swift to clarify the testing purpose 2019-07-23 16:39:24 -07:00
Xi Ge
d9c4a77fb5 AST: avoid unnecessarily calling getStartLoc() to avoid exponential growth of the stack trace
Issuing multiple getStartLoc() from sub-expression can exponentially grow the stack trace.
When the expression under analysis is complex enough, this could be a user-noticeable hang.
This patch fixes UnresolvedDotExpr::getStartLoc() by 'refactoring' the result of SubExpr->getStartLoc()
to a local variable.

rdar://52982457
2019-07-23 16:22:55 -07: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
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
John McCall
db4c7d2d4c Fill in source locations in implicit function builder expressions
to satisfy the code-coverage instrumentation.

rdar://51612977
2019-07-18 19:36:02 -04:00
swift-ci
7e5521cd89 Merge pull request #26071 from DougGregor/property-wrappers-final-rename 2019-07-10 16:34:57 -07:00
Doug Gregor
9a444242fb [SE-0258] Fixups for various renames of property wrappers. 2019-07-10 15:28:24 -07:00
Xi Ge
1535bea268 FixCode: issue a separate note for protocol-stub fixit when the fixit location is in another file
Under non-editor mode, the fixit for inserting protocol stubs is associated with a note
pointing to the missing protocol member declaration which could stay in a separate file from
the conforming type, leading to the behavior of rdar://51534405. This change checks if
the fixit is in a separate file and issues another note to carry the fixit if so.

rdar://51534405
2019-07-10 12:30:54 -07:00
Xi Ge
0e438f6ebd IDE: always print custom attributes associated with function builder
rdar://51592635
2019-07-09 10:33:30 -07:00
Ben Langmuir
6b3411cc44 Merge pull request #25910 from benlangmuir/remove-dead-dup
[test] Remove dead and duplicated check
2019-07-01 13:25:14 -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
Ben Langmuir
9f8eec2048 [test] Fix typo in a check-dag 2019-07-01 10:02:29 -07:00
Ben Langmuir
67a0fec06c [test] Remove dead and duplicated check
The check was disabled because of a typo, but was also duplicating a
check two lines above anyway, so remove it.

Credit to David Ungar for spotting it!
2019-07-01 09:56:15 -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
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
Doug Gregor
f044d70b74 Merge pull request #25781 from DougGregor/property-wrappers-revision-3
[SE-0258] Implement revision #3 of property wrappers
2019-06-26 18:12:42 -07:00
Rintaro Ishizaki
114f473fea Merge pull request #25787 from rintaro/ide-completion-eliminatesuper
[CodeCompletion] Eliminate super related completion
2019-06-26 15:44:56 -07:00
Jordan Rose
8157ccfce5 Teach SubstitutionMap::isIdentity about non-canonical generic params (#25767)
Do a weaker check here that only looks at the canonical generic params
and guarantees that *those* substitute to themselves. There may be
replacement types for other generic params too, to canonicalize them,
but that's not a problem.

This fixes a crash trying to mangle decls with opaque result types
that have generic signatures that canonicalize away a generic
parameter.

rdar://problem/51775857
2019-06-26 13:09:36 -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
Doug Gregor
446d0b3953 [SE-0258] Rename backing storage property to _foo.
In anticipation of upcoming changes to the property wrapper proposal,
rename the backing storage for a wrapped property to "foo", unconditionally.
2019-06-26 07:39:01 -07:00
Doug Gregor
e0e2d77bbe Merge pull request #25752 from DougGregor/property-wrapper-default-arg-default-init
[SE-0258] Enable default argument for wrapped property going through init()
2019-06-26 00:04:35 -07:00
Rintaro Ishizaki
9f9f5ea6b6 Merge pull request #25760 from rintaro/ide-completion-test-type-any
[NFC][test] Remove unused test file
2019-06-25 14:36:35 -07:00
Rintaro Ishizaki
3da29d1e81 [NFC][test] Remove unused test file
`complete_type_any.swift.tmp.types.txt` was probably added by accident.

Also `complete_type_any.swift` doesn't need to use temporary file for
`FileCheck`.
2019-06-25 12:27:51 -07:00
Rintaro Ishizaki
35f8686574 [CodeCompletion] Remove getTypeContextEnumElementCompletions()
Use getUnresolvedmemberCompletion() instead.

rdar://problem/45219937
2019-06-25 11:58:12 -07:00
Doug Gregor
22e40fedf5 [SE-0258] Enable default argument for wrapped property going through init().
My recent refactoring of default arguments for the memberwise initializer
accidentally dropped support for getting a default argument when the
attached property wrapper has an init(). Reinstate that support,
fixing rdar://problem/52116923.
2019-06-25 10:03:15 -07:00
Rintaro Ishizaki
e7c8e22ce9 Merge pull request #25717 from rintaro/ide-completion-keypathlookup-rdar50073837
[CodeCompletion] Map the result type for keypath member lookup
2019-06-24 14:48:44 -07:00
swift-ci
2538ae3695 Merge pull request #25718 from akyrtzi/comment-marker-single-line-block 2019-06-24 13:13:07 -07:00
Rintaro Ishizaki
9f02fa7b06 [CodeCompletion] Map the result type for keypath member lookup
rdar://problem/50073837
2019-06-24 12:34:31 -07:00
Argyrios Kyrtzidis
dbc35b4531 [IDE/SyntaxModel] Make sure to properly annotate comment markers in single-line comment blocks
rdar://51893731
2019-06-24 12:19:12 -07:00
Rintaro Ishizaki
bb3edd5dde [CodeCompletion] contextual attribute completion only on the same line
It's common to have decls on consecutive lines. Better to show too many
attributes than too few.
2019-06-21 14:03:09 -07:00
Rintaro Ishizaki
09ca68e485 [CodeCompletion] Don't attach attr to decl if blank line exists
```
@#^COMPLETE^#

public func something() {}
```
In this case, we can't say the user is adding attribute to the func or
starting a new declaration. So if there're one or more blank lines after the
completion, suggest context free attribute list.

rdar://problem/50441643
2019-06-20 17:06:32 -07:00