Skip to content

Commit 600de5d

Browse files
authored
---
yaml --- r: 340933 b: refs/heads/rxwei-patch-1 c: 65d63f1 h: refs/heads/master i: 340931: d25d046
1 parent db1def1 commit 600de5d

File tree

9 files changed

+81
-30
lines changed

9 files changed

+81
-30
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1015,7 +1015,7 @@ refs/tags/swift-DEVELOPMENT-SNAPSHOT-2018-08-18-a: b10b1fce14385faa6d44f6b933e95
10151015
refs/heads/rdar-43033749-fix-batch-mode-no-diags-swift-5.0-branch: a14e64eaad30de89f0f5f0b2a782eed7ecdcb255
10161016
refs/heads/revert-19006-error-bridging-integer-type: 8a9065a3696535305ea53fe9b71f91cbe6702019
10171017
refs/heads/revert-19050-revert-19006-error-bridging-integer-type: ecf752d54b05dd0a20f510f0bfa54a3fec3bcaca
1018-
refs/heads/rxwei-patch-1: 5832743c5c2a842976c42a508a4c6dcceefb0aef
1018+
refs/heads/rxwei-patch-1: 65d63f1cedce100af4387a6a5f906eb0d9e75c5b
10191019
refs/heads/shahmishal-patch-1: e58ec0f7488258d42bef51bc3e6d7b3dc74d7b2a
10201020
refs/heads/typelist-existential: 4046359efd541fb5c72d69a92eefc0a784df8f5e
10211021
refs/tags/swift-4.2-DEVELOPMENT-SNAPSHOT-2018-08-20-a: 4319ba09e4fb8650ee86061075c74a016b6baab9

branches/rxwei-patch-1/include/swift/Parse/CodeCompletionCallbacks.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ class CodeCompletionCallbacks {
189189
virtual void completeAccessorBeginning(CodeCompletionExpr *E) {};
190190

191191
/// Complete the keyword in attribute, for instance, @available.
192-
virtual void completeDeclAttrBeginning(bool Sil) {};
192+
virtual void completeDeclAttrBeginning(bool Sil, bool isIndependent) {};
193193

194194
/// Complete the parameters in attribute, for instance, version specifier for
195195
/// @available.

branches/rxwei-patch-1/lib/IDE/CodeCompletion.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,6 +1263,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
12631263
bool HasSpace = false;
12641264
bool ShouldCompleteCallPatternAfterParen = true;
12651265
bool PreferFunctionReferencesToCalls = false;
1266+
bool AttTargetIsIndependent = false;
12661267
Optional<DeclKind> AttTargetDK;
12671268
Optional<StmtKind> ParentStmtKind;
12681269

@@ -1351,7 +1352,12 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13511352
void setAttrTargetDeclKind(Optional<DeclKind> DK) override {
13521353
if (DK == DeclKind::PatternBinding)
13531354
DK = DeclKind::Var;
1354-
AttTargetDK = DK;
1355+
else if (DK == DeclKind::Param)
1356+
// For params, consider the attribute is always for the decl.
1357+
AttTargetIsIndependent = false;
1358+
1359+
if (!AttTargetIsIndependent)
1360+
AttTargetDK = DK;
13551361
}
13561362

13571363
void completeExpr() override;
@@ -1373,7 +1379,7 @@ class CodeCompletionCallbacksImpl : public CodeCompletionCallbacks {
13731379
void completeCaseStmtKeyword() override;
13741380
void completeCaseStmtBeginning() override;
13751381
void completeCaseStmtDotPrefix() override;
1376-
void completeDeclAttrBeginning(bool Sil) override;
1382+
void completeDeclAttrBeginning(bool Sil, bool isIndependent) override;
13771383
void completeDeclAttrParam(DeclAttrKind DK, int Index) override;
13781384
void completeInPrecedenceGroup(SyntaxKind SK) override;
13791385
void completeNominalMemberBeginning(
@@ -4606,10 +4612,12 @@ void CodeCompletionCallbacksImpl::completeDeclAttrParam(DeclAttrKind DK,
46064612
CurDeclContext = P.CurDeclContext;
46074613
}
46084614

4609-
void CodeCompletionCallbacksImpl::completeDeclAttrBeginning(bool Sil) {
4615+
void CodeCompletionCallbacksImpl::completeDeclAttrBeginning(
4616+
bool Sil, bool isIndependent) {
46104617
Kind = CompletionKind::AttributeBegin;
46114618
IsInSil = Sil;
46124619
CurDeclContext = P.CurDeclContext;
4620+
AttTargetIsIndependent = isIndependent;
46134621
}
46144622

46154623
void CodeCompletionCallbacksImpl::completeInPrecedenceGroup(SyntaxKind SK) {

branches/rxwei-patch-1/lib/Parse/ParseDecl.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1753,8 +1753,13 @@ ParserStatus Parser::parseDeclAttribute(DeclAttributes &Attributes, SourceLoc At
17531753
Tok.isNot(tok::kw_inout)) {
17541754

17551755
if (Tok.is(tok::code_complete)) {
1756-
if (CodeCompletion)
1757-
CodeCompletion->completeDeclAttrBeginning(isInSILMode());
1756+
if (CodeCompletion) {
1757+
// If the next token is not on the same line, this attribute might be
1758+
// starting new declaration instead of adding attribute to existing
1759+
// decl.
1760+
auto isIndependent = peekToken().isAtStartOfLine();
1761+
CodeCompletion->completeDeclAttrBeginning(isInSILMode(), isIndependent);
1762+
}
17581763
consumeToken(tok::code_complete);
17591764
return makeParserCodeCompletionStatus();
17601765
}

branches/rxwei-patch-1/lib/Sema/CSDiagnostics.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2671,21 +2671,31 @@ bool ClosureParamDestructuringFailure::diagnoseAsError() {
26712671
auto bodyStmts = closureBody->getElements();
26722672

26732673
SourceLoc bodyLoc;
2674+
SourceLoc inLoc = closure->getInLoc();
2675+
// If location for `in` is unknown we can't proceed
2676+
// since we'll not be able to figure out source line
2677+
// to place the fix-it on.
2678+
if (inLoc.isInvalid())
2679+
return true;
2680+
26742681
// If the body is empty let's put the cursor
26752682
// right after "in", otherwise make it start
26762683
// location of the first statement in the body.
26772684
if (bodyStmts.empty())
2678-
bodyLoc = Lexer::getLocForEndOfToken(sourceMgr, closure->getInLoc());
2685+
bodyLoc = Lexer::getLocForEndOfToken(sourceMgr, inLoc);
26792686
else
26802687
bodyLoc = bodyStmts.front().getStartLoc();
26812688

2689+
if (bodyLoc.isInvalid())
2690+
return true;
2691+
26822692
SmallString<64> fixIt;
26832693
llvm::raw_svector_ostream OS(fixIt);
26842694

26852695
// If this is multi-line closure we'd have to insert new lines
26862696
// in the suggested 'let' to keep the structure of the code intact,
26872697
// otherwise just use ';' to keep everything on the same line.
2688-
auto inLine = sourceMgr.getLineNumber(closure->getInLoc());
2698+
auto inLine = sourceMgr.getLineNumber(inLoc);
26892699
auto bodyLine = sourceMgr.getLineNumber(bodyLoc);
26902700
auto isMultiLineClosure = bodyLine > inLine;
26912701
auto indent =

branches/rxwei-patch-1/test/IDE/complete_decl_attribute.swift

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,13 @@
99
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ON_INIT | %FileCheck %s -check-prefix=ON_INIT
1010
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ON_PROPERTY | %FileCheck %s -check-prefix=ON_PROPERTY
1111
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ON_METHOD | %FileCheck %s -check-prefix=ON_METHOD
12-
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ON_PARAM | %FileCheck %s -check-prefix=ON_PARAM
12+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ON_PARAM_1 | %FileCheck %s -check-prefix=ON_PARAM
13+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ON_PARAM_2 | %FileCheck %s -check-prefix=ON_PARAM
14+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ON_MEMBER_INDEPENDENT_1 | %FileCheck %s -check-prefix=ON_MEMBER_LAST
15+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ON_MEMBER_INDEPENDENT_2 | %FileCheck %s -check-prefix=ON_MEMBER_LAST
1316
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=ON_MEMBER_LAST | %FileCheck %s -check-prefix=ON_MEMBER_LAST
17+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=KEYWORD_INDEPENDENT_1 | %FileCheck %s -check-prefix=KEYWORD_LAST
18+
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=KEYWORD_INDEPENDENT_2 | %FileCheck %s -check-prefix=KEYWORD_LAST
1419
// RUN: %target-swift-ide-test -code-completion -source-filename %s -code-completion-token=KEYWORD_LAST | %FileCheck %s -check-prefix=KEYWORD_LAST
1520

1621
struct MyStruct {}
@@ -44,8 +49,7 @@ struct MyStruct {}
4449
// AVAILABILITY2-NEXT: Keyword/None: deprecated: [#Specify version number#]; name=deprecated{{$}}
4550
// AVAILABILITY2-NEXT: End completions
4651

47-
@#^KEYWORD2^#
48-
func method(){}
52+
@#^KEYWORD2^# func method(){}
4953

5054
// KEYWORD2: Begin completions
5155
// KEYWORD2-NEXT: Keyword/None: available[#Func Attribute#]; name=available{{$}}
@@ -63,8 +67,7 @@ func method(){}
6367
// KEYWORD2: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
6468
// KEYWORD2: End completions
6569

66-
@#^KEYWORD3^#
67-
class C {}
70+
@#^KEYWORD3^# class C {}
6871

6972
// KEYWORD3: Begin completions
7073
// KEYWORD3-NEXT: Keyword/None: available[#Class Attribute#]; name=available{{$}}
@@ -81,12 +84,10 @@ class C {}
8184
// KEYWORD3-NEXT: Keyword/None: _functionBuilder[#Class Attribute#]; name=_functionBuilder
8285
// KEYWORD3-NEXT: End completions
8386

84-
@#^KEYWORD3_2^#IB
85-
class C2 {}
87+
@#^KEYWORD3_2^#IB class C2 {}
8688
// Same as KEYWORD3.
8789

88-
@#^KEYWORD4^#
89-
enum E {}
90+
@#^KEYWORD4^# enum E {}
9091
// KEYWORD4: Begin completions
9192
// KEYWORD4-NEXT: Keyword/None: available[#Enum Attribute#]; name=available{{$}}
9293
// KEYWORD4-NEXT: Keyword/None: objc[#Enum Attribute#]; name=objc{{$}}
@@ -98,8 +99,7 @@ enum E {}
9899
// KEYWORD4-NEXT: End completions
99100

100101

101-
@#^KEYWORD5^#
102-
struct S{}
102+
@#^KEYWORD5^# struct S{}
103103
// KEYWORD5: Begin completions
104104
// KEYWORD5-NEXT: Keyword/None: available[#Struct Attribute#]; name=available{{$}}
105105
// KEYWORD5-NEXT: Keyword/None: dynamicCallable[#Struct Attribute#]; name=dynamicCallable
@@ -109,8 +109,7 @@ struct S{}
109109
// KEYWORD5-NEXT: Keyword/None: _functionBuilder[#Struct Attribute#]; name=_functionBuilder
110110
// KEYWORD5-NEXT: End completions
111111

112-
@#^ON_GLOBALVAR^#
113-
var globalVar
112+
@#^ON_GLOBALVAR^# var globalVar
114113
// ON_GLOBALVAR: Begin completions
115114
// ON_GLOBALVAR-DAG: Keyword/None: available[#Var Attribute#]; name=available
116115
// ON_GLOBALVAR-DAG: Keyword/None: objc[#Var Attribute#]; name=objc
@@ -128,8 +127,7 @@ var globalVar
128127
// ON_GLOBALVAR: End completions
129128

130129
struct _S {
131-
@#^ON_INIT^#
132-
init()
130+
@#^ON_INIT^# init()
133131
// ON_INIT: Begin completions
134132
// ON_INIT-DAG: Keyword/None: available[#Constructor Attribute#]; name=available
135133
// ON_INIT-DAG: Keyword/None: objc[#Constructor Attribute#]; name=objc
@@ -140,8 +138,7 @@ struct _S {
140138
// ON_INIT-DAG: Keyword/None: discardableResult[#Constructor Attribute#]; name=discardableResult
141139
// ON_INIT: End completions
142140

143-
@#^ON_PROPERTY^#
144-
var foo
141+
@#^ON_PROPERTY^# var foo
145142
// ON_PROPERTY: Begin completions
146143
// ON_PROPERTY-DAG: Keyword/None: available[#Var Attribute#]; name=available
147144
// ON_PROPERTY-DAG: Keyword/None: objc[#Var Attribute#]; name=objc
@@ -159,7 +156,7 @@ struct _S {
159156
// ON_PROPERTY-NOT: Decl[PrecedenceGroup]
160157
// ON_PROPERTY: End completions
161158

162-
@#^ON_METHOD^#
159+
@#^ON_METHOD^# private
163160
func foo()
164161
// ON_METHOD: Begin completions
165162
// ON_METHOD-DAG: Keyword/None: available[#Func Attribute#]; name=available
@@ -177,13 +174,30 @@ struct _S {
177174
// ON_METHOD: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
178175
// ON_METHOD: End completions
179176

180-
func bar(@#^ON_PARAM^#)
177+
func bar(@#^ON_PARAM_1^#)
181178
// ON_PARAM: Begin completions
182179
// ON_PARAM-NOT: Keyword
183180
// ON_PARAM: Decl[Struct]/CurrModule: MyStruct[#MyStruct#]; name=MyStruct
184181
// ON_PARAM-NOT: Keyword
185182
// ON_PARAM: End completions
186183

184+
func bar(
185+
@#^ON_PARAM_2^#
186+
187+
arg: Int
188+
)
189+
// Same as ON_PARAM.
190+
191+
@#^ON_MEMBER_INDEPENDENT_1^#
192+
193+
func dummy1() {}
194+
// Same as ON_MEMBER_LAST.
195+
196+
@#^ON_MEMBER_INDEPENDENT_2^#
197+
func dummy2() {}
198+
// Same as ON_MEMBER_LAST.
199+
200+
187201
@#^ON_MEMBER_LAST^#
188202
// ON_MEMBER_LAST: Begin completions
189203
// ON_MEMBER_LAST-DAG: Keyword/None: available[#Declaration Attribute#]; name=available
@@ -216,6 +230,15 @@ struct _S {
216230
// ON_MEMBER_LAST: End completions
217231
}
218232

233+
@#^KEYWORD_INDEPENDENT_1^#
234+
235+
func dummy1() {}
236+
// Same as KEYWORD_LAST.
237+
238+
@#^KEYWORD_INDEPENDENT_2^#
239+
func dummy2() {}
240+
// Same as KEYWORD_LAST.
241+
219242
@#^KEYWORD_LAST^#
220243

221244
// KEYWORD_LAST: Begin completions

branches/rxwei-patch-1/test/IDE/complete_pound_decl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
// MEMBER: End completions
1616

1717
// ATTR: Begin completions
18-
// ATTR: available[#Func Attribute#]; name=available
18+
// ATTR: available[#Declaration Attribute#]; name=available
1919
// ATTR: End completions
2020

2121
// GLOBAL: Begin completions

branches/rxwei-patch-1/test/IRGen/abi_v7k.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func testClike8(t: Int, x: CLike8) -> Int {
142142
// assigned values in the data area of the enum in declaration order
143143
// CHECK-LABEL: define hidden swiftcc double @"$s8test_v7k0A7SingleP{{.*}}"(i32, i32, i8)
144144
// CHECK: br i1
145-
// CHECK: switch i32 [[ID:%[0-9]+]]
145+
// CHECK: switch i64 [[ID:%[0-9]+]]
146146
// CHECK: [[FIRST:%[0-9]+]] = zext i32 %0 to i64
147147
// CHECK: [[SECOND:%[0-9]+]] = zext i32 %1 to i64
148148
// CHECK: [[TEMP:%[0-9]+]] = shl i64 [[SECOND]], 32
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// RUN: not %target-swift-frontend %s -typecheck
2+
3+
func foo() -> [String] {
4+
let dict: [String: String] = [:]
5+
return dict.filter({ (_

0 commit comments

Comments
 (0)