Skip to content

Commit 0619e57

Browse files
committed
Switch the stdlib to use #file instead of __FILE__, and deprecate the __FILE__ identifiers.
This also updates the tests that would otherwise fail.
1 parent 7f77733 commit 0619e57

21 files changed

+164
-139
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,11 @@ ERROR(invalid_label_on_stmt,none,
699699
NOTE(discard_result_of_closure,none,
700700
"explicitly discard the result of the closure by assigning to '_'", ())
701701

702+
WARNING(snake_case_deprecated,none,
703+
"%0 is deprecated and will be removed in Swift 3, please use %1",
704+
(StringRef, StringRef))
705+
706+
702707
// Assignment statement
703708
ERROR(expected_expr_assignment,none,
704709
"expected expression in assignment", ())

lib/Parse/ParseExpr.cpp

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -881,16 +881,31 @@ ParserResult<Expr> Parser::parseExprPostfix(Diag<> ID, bool isExprBasic) {
881881
break;
882882
}
883883

884-
case tok::pound_column:
885-
case tok::pound_file:
886-
case tok::pound_function:
887-
case tok::pound_line:
888-
case tok::pound_dsohandle:
889884
case tok::kw___FILE__:
890885
case tok::kw___LINE__:
891886
case tok::kw___COLUMN__:
892887
case tok::kw___FUNCTION__:
893888
case tok::kw___DSO_HANDLE__: {
889+
StringRef replacement = "";
890+
switch (Tok.getKind()) {
891+
default: llvm_unreachable("can't get here");
892+
case tok::kw___FILE__: replacement = "#file"; break;
893+
case tok::kw___LINE__: replacement = "#line"; break;
894+
case tok::kw___COLUMN__: replacement = "#column"; break;
895+
case tok::kw___FUNCTION__: replacement = "#function"; break;
896+
case tok::kw___DSO_HANDLE__: replacement = "#dsohandle"; break;
897+
}
898+
899+
diagnose(Tok.getLoc(), diag::snake_case_deprecated,
900+
Tok.getText(), replacement)
901+
.fixItReplace(Tok.getLoc(), replacement);
902+
SWIFT_FALLTHROUGH;
903+
}
904+
case tok::pound_column:
905+
case tok::pound_file:
906+
case tok::pound_function:
907+
case tok::pound_line:
908+
case tok::pound_dsohandle: {
894909
auto Kind = getMagicIdentifierLiteralKind(Tok.getKind());
895910
SourceLoc Loc = consumeToken();
896911
Result = makeParserResult(

stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public struct SubscriptRangeTest {
3131
public init(
3232
expected: [Int], collection: [Int], bounds: Range<Int>,
3333
count: Int,
34-
file: String = __FILE__, line: UInt = __LINE__
34+
file: String = #file, line: UInt = #line
3535
) {
3636
self.expected = expected.map(OpaqueValue.init)
3737
self.collection = collection.map(OpaqueValue.init)
@@ -49,7 +49,7 @@ public struct PrefixThroughTest {
4949

5050
init(
5151
collection: [Int], position: Int, expected: [Int],
52-
file: String = __FILE__, line: UInt = __LINE__
52+
file: String = #file, line: UInt = #line
5353
) {
5454
self.collection = collection
5555
self.position = position
@@ -66,7 +66,7 @@ public struct PrefixUpToTest {
6666

6767
public init(
6868
collection: [Int], end: Int, expected: [Int],
69-
file: String = __FILE__, line: UInt = __LINE__
69+
file: String = #file, line: UInt = #line
7070
) {
7171
self.collection = collection
7272
self.end = end
@@ -83,7 +83,7 @@ internal struct RemoveFirstNTest {
8383

8484
init(
8585
collection: [Int], numberToRemove: Int, expectedCollection: [Int],
86-
file: String = __FILE__, line: UInt = __LINE__
86+
file: String = #file, line: UInt = #line
8787
) {
8888
self.collection = collection
8989
self.numberToRemove = numberToRemove
@@ -100,7 +100,7 @@ public struct SuffixFromTest {
100100

101101
init(
102102
collection: [Int], start: Int, expected: [Int],
103-
file: String = __FILE__, line: UInt = __LINE__
103+
file: String = #file, line: UInt = #line
104104
) {
105105
self.collection = collection
106106
self.start = start
@@ -305,10 +305,10 @@ extension TestSuite {
305305
) {
306306
var testNamePrefix = testNamePrefix
307307

308-
if checksAdded.value.contains(__FUNCTION__) {
308+
if checksAdded.value.contains(#function) {
309309
return
310310
}
311-
checksAdded.value.insert(__FUNCTION__)
311+
checksAdded.value.insert(#function)
312312

313313
addSequenceTests(
314314
testNamePrefix,
@@ -842,10 +842,10 @@ self.test("\(testNamePrefix).popFirst()/slice/empty/semantics") {
842842
outOfBoundsSubscriptOffset: Int = 1
843843
) {
844844
var testNamePrefix = testNamePrefix
845-
if checksAdded.value.contains(__FUNCTION__) {
845+
if checksAdded.value.contains(#function) {
846846
return
847847
}
848-
checksAdded.value.insert(__FUNCTION__)
848+
checksAdded.value.insert(#function)
849849

850850
addForwardCollectionTests(
851851
testNamePrefix,
@@ -1191,10 +1191,10 @@ self.test("\(testNamePrefix).suffix/semantics") {
11911191
) {
11921192
var testNamePrefix = testNamePrefix
11931193

1194-
if checksAdded.value.contains(__FUNCTION__) {
1194+
if checksAdded.value.contains(#function) {
11951195
return
11961196
}
1197-
checksAdded.value.insert(__FUNCTION__)
1197+
checksAdded.value.insert(#function)
11981198

11991199
addBidirectionalCollectionTests(
12001200
testNamePrefix,

stdlib/private/StdlibCollectionUnittest/CheckMutableCollectionType.swift.gyb

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public struct PartitionExhaustiveTest {
1919

2020
public init(
2121
_ sequence: [Int],
22-
file: String = __FILE__, line: UInt = __LINE__
22+
file: String = #file, line: UInt = #line
2323
) {
2424
self.sequence = sequence
2525
self.loc = SourceLoc(file, line, comment: "test data")
@@ -102,10 +102,10 @@ extension TestSuite {
102102
) {
103103
var testNamePrefix = testNamePrefix
104104

105-
if checksAdded.value.contains(__FUNCTION__) {
105+
if checksAdded.value.contains(#function) {
106106
return
107107
}
108-
checksAdded.value.insert(__FUNCTION__)
108+
checksAdded.value.insert(#function)
109109

110110
addForwardCollectionTests(
111111
testNamePrefix,
@@ -407,10 +407,10 @@ self.test("\(testNamePrefix).sort/${'Predicate' if predicate else 'WhereElementI
407407
) {
408408
var testNamePrefix = testNamePrefix
409409

410-
if checksAdded.value.contains(__FUNCTION__) {
410+
if checksAdded.value.contains(#function) {
411411
return
412412
}
413-
checksAdded.value.insert(__FUNCTION__)
413+
checksAdded.value.insert(#function)
414414

415415
addForwardMutableCollectionTests(
416416
testNamePrefix,
@@ -525,10 +525,10 @@ if resiliencyChecks.subscriptOnOutOfBoundsIndicesBehavior != .None {
525525
) {
526526
var testNamePrefix = testNamePrefix
527527

528-
if checksAdded.value.contains(__FUNCTION__) {
528+
if checksAdded.value.contains(#function) {
529529
return
530530
}
531-
checksAdded.value.insert(__FUNCTION__)
531+
checksAdded.value.insert(#function)
532532

533533
addBidirectionalMutableCollectionTests(
534534
testNamePrefix,

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableCollectionType.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ internal struct ReplaceRangeTest {
6969
internal init(
7070
collection: [Int], newElements: [Int],
7171
rangeSelection: RangeSelection, expected: [Int],
72-
file: String = __FILE__, line: UInt = __LINE__
72+
file: String = #file, line: UInt = #line
7373
) {
7474
self.collection = collection.map(OpaqueValue.init)
7575
self.newElements = newElements.map(OpaqueValue.init)
@@ -87,7 +87,7 @@ internal struct AppendTest {
8787

8888
internal init(
8989
collection: [Int], newElement: Int, expected: [Int],
90-
file: String = __FILE__, line: UInt = __LINE__
90+
file: String = #file, line: UInt = #line
9191
) {
9292
self.collection = collection.map(OpaqueValue.init)
9393
self.newElement = OpaqueValue(newElement)
@@ -104,7 +104,7 @@ internal struct AppendContentsOfTest {
104104

105105
internal init(
106106
collection: [Int], newElements: [Int], expected: [Int],
107-
file: String = __FILE__, line: UInt = __LINE__
107+
file: String = #file, line: UInt = #line
108108
) {
109109
self.collection = collection.map(OpaqueValue.init)
110110
self.newElements = newElements.map(OpaqueValue.init)
@@ -122,7 +122,7 @@ internal struct InsertTest {
122122

123123
internal init(
124124
collection: [Int], newElement: Int, indexSelection: IndexSelection,
125-
expected: [Int], file: String = __FILE__, line: UInt = __LINE__
125+
expected: [Int], file: String = #file, line: UInt = #line
126126
) {
127127
self.collection = collection.map(OpaqueValue.init)
128128
self.newElement = OpaqueValue(newElement)
@@ -141,7 +141,7 @@ internal struct InsertContentsOfTest {
141141

142142
internal init(
143143
collection: [Int], newElements: [Int], indexSelection: IndexSelection,
144-
expected: [Int], file: String = __FILE__, line: UInt = __LINE__
144+
expected: [Int], file: String = #file, line: UInt = #line
145145
) {
146146
self.collection = collection.map(OpaqueValue.init)
147147
self.newElements = newElements.map(OpaqueValue.init)
@@ -161,7 +161,7 @@ internal struct RemoveAtIndexTest {
161161
internal init(
162162
collection: [Int], indexSelection: IndexSelection,
163163
expectedRemovedElement: Int, expectedCollection: [Int],
164-
file: String = __FILE__, line: UInt = __LINE__
164+
file: String = #file, line: UInt = #line
165165
) {
166166
self.collection = collection.map(OpaqueValue.init)
167167
self.indexSelection = indexSelection
@@ -179,7 +179,7 @@ internal struct RemoveLastNTest {
179179

180180
internal init(
181181
collection: [Int], numberToRemove: Int, expectedCollection: [Int],
182-
file: String = __FILE__, line: UInt = __LINE__
182+
file: String = #file, line: UInt = #line
183183
) {
184184
self.collection = collection.map(OpaqueValue.init)
185185
self.numberToRemove = numberToRemove
@@ -196,7 +196,7 @@ internal struct RemoveRangeTest {
196196

197197
internal init(
198198
collection: [Int], rangeSelection: RangeSelection, expected: [Int],
199-
file: String = __FILE__, line: UInt = __LINE__
199+
file: String = #file, line: UInt = #line
200200
) {
201201
self.collection = collection.map(OpaqueValue.init)
202202
self.rangeSelection = rangeSelection
@@ -212,7 +212,7 @@ internal struct RemoveAllTest {
212212

213213
internal init(
214214
collection: [Int], expected: [Int],
215-
file: String = __FILE__, line: UInt = __LINE__
215+
file: String = #file, line: UInt = #line
216216
) {
217217
self.collection = collection.map(OpaqueValue.init)
218218
self.expected = expected
@@ -227,7 +227,7 @@ internal struct ReserveCapacityTest {
227227

228228
internal init(
229229
collection: [Int], requestedCapacity: Int,
230-
file: String = __FILE__, line: UInt = __LINE__
230+
file: String = #file, line: UInt = #line
231231
) {
232232
self.collection = collection.map(OpaqueValue.init)
233233
self.requestedCapacity = requestedCapacity
@@ -243,7 +243,7 @@ internal struct OperatorPlusTest {
243243

244244
internal init(
245245
lhs: [Int], rhs: [Int], expected: [Int],
246-
file: String = __FILE__, line: UInt = __LINE__
246+
file: String = #file, line: UInt = #line
247247
) {
248248
self.lhs = lhs.map(OpaqueValue.init)
249249
self.rhs = rhs.map(OpaqueValue.init)
@@ -365,10 +365,10 @@ extension TestSuite {
365365
) {
366366
var testNamePrefix = testNamePrefix
367367

368-
if checksAdded.value.contains(__FUNCTION__) {
368+
if checksAdded.value.contains(#function) {
369369
return
370370
}
371-
checksAdded.value.insert(__FUNCTION__)
371+
checksAdded.value.insert(#function)
372372

373373
addForwardCollectionTests(
374374
testNamePrefix,
@@ -1126,10 +1126,10 @@ self.test("\(testNamePrefix).OperatorPlus") {
11261126
) {
11271127
var testNamePrefix = testNamePrefix
11281128

1129-
if checksAdded.value.contains(__FUNCTION__) {
1129+
if checksAdded.value.contains(#function) {
11301130
return
11311131
}
1132-
checksAdded.value.insert(__FUNCTION__)
1132+
checksAdded.value.insert(#function)
11331133

11341134
addForwardRangeReplaceableCollectionTests(
11351135
testNamePrefix,
@@ -1252,10 +1252,10 @@ self.test("\(testNamePrefix).removeLast(n: Int)/whereIndexIsBidirectional/remove
12521252
) {
12531253
var testNamePrefix = testNamePrefix
12541254

1255-
if checksAdded.value.contains(__FUNCTION__) {
1255+
if checksAdded.value.contains(#function) {
12561256
return
12571257
}
1258-
checksAdded.value.insert(__FUNCTION__)
1258+
checksAdded.value.insert(#function)
12591259

12601260
addBidirectionalRangeReplaceableCollectionTests(
12611261
testNamePrefix,

stdlib/private/StdlibCollectionUnittest/CheckRangeReplaceableSliceType.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ extension TestSuite {
3838
var testNamePrefix = testNamePrefix
3939

4040
// Don't run the same tests twice.
41-
if checksAdded.value.contains(__FUNCTION__) {
41+
if checksAdded.value.contains(#function) {
4242
return
4343
}
44-
checksAdded.value.insert(__FUNCTION__)
44+
checksAdded.value.insert(#function)
4545

4646
addForwardRangeReplaceableCollectionTests(
4747
testNamePrefix,
@@ -169,10 +169,10 @@ extension TestSuite {
169169
var testNamePrefix = testNamePrefix
170170

171171
// Don't run the same tests twice.
172-
if checksAdded.value.contains(__FUNCTION__) {
172+
if checksAdded.value.contains(#function) {
173173
return
174174
}
175-
checksAdded.value.insert(__FUNCTION__)
175+
checksAdded.value.insert(#function)
176176

177177
addForwardRangeReplaceableSliceTests(
178178
testNamePrefix,
@@ -314,10 +314,10 @@ extension TestSuite {
314314
var testNamePrefix = testNamePrefix
315315

316316
// Don't run the same tests twice.
317-
if checksAdded.value.contains(__FUNCTION__) {
317+
if checksAdded.value.contains(#function) {
318318
return
319319
}
320-
checksAdded.value.insert(__FUNCTION__)
320+
checksAdded.value.insert(#function)
321321

322322
addBidirectionalRangeReplaceableSliceTests(
323323
testNamePrefix,

0 commit comments

Comments
 (0)