Skip to content

Commit 9d24f44

Browse files
committed
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.
1 parent 7415cb8 commit 9d24f44

File tree

6 files changed

+23
-50
lines changed

6 files changed

+23
-50
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,10 +1034,6 @@ ERROR(invalid_label_on_stmt,none,
10341034
ERROR(labeled_block_needs_do,none,
10351035
"labeled block needs 'do'", ())
10361036

1037-
ERROR(snake_case_deprecated,none,
1038-
"%0 has been replaced with %1 in Swift 3",
1039-
(StringRef, StringRef))
1040-
10411037
// Assignment statement
10421038
ERROR(expected_expr_assignment,none,
10431039
"expected expression in assignment", ())

include/swift/AST/MagicIdentifierKinds.def

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@
4040
#define MAGIC_IDENTIFIER_TOKEN(NAME, TOKEN)
4141
#endif
4242

43-
// Used when a given token always maps to a particular magic identifier kind,
44-
// but that token is deprecated.
45-
#ifndef MAGIC_IDENTIFIER_DEPRECATED_TOKEN
46-
#define MAGIC_IDENTIFIER_DEPRECATED_TOKEN(NAME, TOKEN) MAGIC_IDENTIFIER_TOKEN(NAME, TOKEN)
47-
#endif
48-
49-
50-
5143
//
5244
// Magic string literals
5345
//
@@ -71,12 +63,10 @@ MAGIC_STRING_IDENTIFIER(FilePath, "#filePath", PoundFilePathExpr)
7163
MAGIC_STRING_IDENTIFIER(FilePathSpelledAsFile, "#file", PoundFileExpr)
7264
// tok::pound_file is shared with FileIDSpelledAsFile; please write custom
7365
// code paths for it.
74-
MAGIC_IDENTIFIER_DEPRECATED_TOKEN(FilePathSpelledAsFile, kw___FILE__)
7566

7667
/// The \c #function magic identifier literal.
7768
MAGIC_STRING_IDENTIFIER(Function, "#function", PoundFunctionExpr)
7869
MAGIC_IDENTIFIER_TOKEN(Function, pound_function)
79-
MAGIC_IDENTIFIER_DEPRECATED_TOKEN(Function, kw___FUNCTION__)
8070

8171

8272

@@ -87,12 +77,10 @@ MAGIC_STRING_IDENTIFIER(Function, "#function", PoundFunctionExpr)
8777
/// The \c #line magic identifier literal.
8878
MAGIC_INT_IDENTIFIER(Line, "#line", PoundLineExpr)
8979
MAGIC_IDENTIFIER_TOKEN(Line, pound_line)
90-
MAGIC_IDENTIFIER_DEPRECATED_TOKEN(Line, kw___LINE__)
9180

9281
/// The \c #column magic identifier literal.
9382
MAGIC_INT_IDENTIFIER(Column, "#column", PoundColumnExpr)
9483
MAGIC_IDENTIFIER_TOKEN(Column, pound_column)
95-
MAGIC_IDENTIFIER_DEPRECATED_TOKEN(Column, kw___COLUMN__)
9684

9785

9886

@@ -103,14 +91,9 @@ MAGIC_INT_IDENTIFIER(Column, "#column", PoundColumnExpr)
10391
/// The \c #dsohandle magic identifier literal.
10492
MAGIC_POINTER_IDENTIFIER(DSOHandle, "#dsohandle", PoundDsohandleExpr)
10593
MAGIC_IDENTIFIER_TOKEN(DSOHandle, pound_dsohandle)
106-
MAGIC_IDENTIFIER_DEPRECATED_TOKEN(DSOHandle, kw___DSO_HANDLE__)
107-
108-
109-
11094

11195
#undef MAGIC_IDENTIFIER
11296
#undef MAGIC_STRING_IDENTIFIER
11397
#undef MAGIC_INT_IDENTIFIER
11498
#undef MAGIC_POINTER_IDENTIFIER
11599
#undef MAGIC_IDENTIFIER_TOKEN
116-
#undef MAGIC_IDENTIFIER_DEPRECATED_TOKEN

lib/IDE/CompletionLookup.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2590,7 +2590,6 @@ void CompletionLookup::addPoundLiteralCompletions(bool needPound) {
25902590
case MagicIdentifierLiteralExpr::NAME: \
25912591
kwKind = CodeCompletionKeywordKind::TOKEN; \
25922592
break;
2593-
#define MAGIC_IDENTIFIER_DEPRECATED_TOKEN(NAME, TOKEN)
25942593
#include "swift/AST/MagicIdentifierKinds.def"
25952594
}
25962595

lib/Parse/Lexer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,13 @@ bool Lexer::isOperator(StringRef string) {
641641

642642

643643
tok Lexer::kindOfIdentifier(StringRef Str, bool InSILMode) {
644+
// Temporary: treat the deprecated __FILE__, __LINE__, etc. as normal
645+
// identifiers. This can go away when we remove them as keywords.
646+
if (Str.startswith("__") &&
647+
(Str == "__FILE__" || Str == "__LINE__" || Str == "__COLUMN__" ||
648+
Str == "__FUNCTION__" || Str == "__DSO_HANDLE__"))
649+
return tok::identifier;
650+
644651
#define SIL_KEYWORD(kw)
645652
#define KEYWORD(kw) if (Str == #kw) return tok::kw_##kw;
646653
#include "swift/AST/TokenKinds.def"

lib/Parse/ParseExpr.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1569,22 +1569,8 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
15691569
BooleanLiteralExpr(isTrue, consumeToken()));
15701570
}
15711571

1572-
// Cases for deprecated magic identifier tokens
1573-
#define MAGIC_IDENTIFIER_DEPRECATED_TOKEN(NAME, TOKEN) case tok::TOKEN:
1574-
#include "swift/AST/MagicIdentifierKinds.def"
1575-
{
1576-
auto Kind = getMagicIdentifierLiteralKind(Tok.getKind(), Context.LangOpts);
1577-
auto replacement = MagicIdentifierLiteralExpr::getKindString(Kind);
1578-
1579-
diagnose(Tok.getLoc(), diag::snake_case_deprecated,
1580-
Tok.getText(), replacement)
1581-
.fixItReplace(Tok.getLoc(), replacement);
1582-
LLVM_FALLTHROUGH;
1583-
}
1584-
15851572
// Cases for non-deprecated magic identifier tokens
15861573
case tok::pound_file:
1587-
#define MAGIC_IDENTIFIER_DEPRECATED_TOKEN(NAME, TOKEN)
15881574
#define MAGIC_IDENTIFIER_TOKEN(NAME, TOKEN) case tok::TOKEN:
15891575
#include "swift/AST/MagicIdentifierKinds.def"
15901576
{
@@ -1593,7 +1579,14 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
15931579
return makeParserResult(new (Context) MagicIdentifierLiteralExpr(
15941580
Kind, Loc, /*implicit=*/false));
15951581
}
1596-
1582+
1583+
case tok::kw___FILE__:
1584+
case tok::kw___LINE__:
1585+
case tok::kw___COLUMN__:
1586+
case tok::kw___FUNCTION__:
1587+
case tok::kw___DSO_HANDLE__:
1588+
llvm_unreachable("Lexer doesn't produce these tokens any more");
1589+
15971590
case tok::identifier: // foo
15981591
case tok::kw_self: // self
15991592

test/expr/expressions.swift

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,11 @@ do {
9393
#column // expected-warning {{#column literal is unused}}
9494
#function // expected-warning {{#function literal is unused}}
9595
#dsohandle // expected-warning {{#dsohandle literal is unused}}
96-
__FILE__ // expected-error {{__FILE__ has been replaced with #file in Swift 3}} expected-warning {{#file literal is unused}}
97-
__LINE__ // expected-error {{__LINE__ has been replaced with #line in Swift 3}} expected-warning {{#line literal is unused}}
98-
__COLUMN__ // expected-error {{__COLUMN__ has been replaced with #column in Swift 3}} expected-warning {{#column literal is unused}}
99-
__FUNCTION__ // expected-error {{__FUNCTION__ has been replaced with #function in Swift 3}} expected-warning {{#function literal is unused}}
100-
__DSO_HANDLE__ // expected-error {{__DSO_HANDLE__ has been replaced with #dsohandle in Swift 3}} expected-warning {{#dsohandle literal is unused}}
96+
__FILE__ // expected-error {{cannot find '__FILE__' in scope}}
97+
__LINE__ // expected-error {{cannot find '__LINE__' in scope}}
98+
__COLUMN__ // expected-error {{cannot find '__COLUMN__' in scope}}
99+
__FUNCTION__ // expected-error {{cannot find '__FUNCTION__' in scope}}
100+
__DSO_HANDLE__ // expected-error {{cannot find '__DSO_HANDLE__' in scope}}
101101

102102
nil // expected-error {{'nil' requires a contextual type}}
103103
#fileLiteral(resourceName: "what.txt") // expected-error {{could not infer type of file reference literal}} expected-note * {{}}
@@ -172,7 +172,7 @@ var test1b = { 42 }
172172
var test1c = { { 42 } }
173173
var test1d = { { { 42 } } }
174174

175-
func test2(_ a: Int, b: Int) -> (c: Int) { // expected-error{{cannot create a single-element tuple with an element label}} {{34-37=}} expected-note {{did you mean 'a'?}} expected-note {{did you mean 'b'?}}
175+
func test2(_ a: Int, b: Int) -> (c: Int) { // expected-error{{cannot create a single-element tuple with an element label}}
176176
_ = a+b
177177
a+b+c // expected-error{{cannot find 'c' in scope}}
178178
return a+b
@@ -530,7 +530,7 @@ func testSingleQuoteStringLiterals() {
530530
}
531531

532532
// <rdar://problem/17128913>
533-
var s = "" // expected-note {{did you mean 's'?}}
533+
var s = ""
534534
s.append(contentsOf: ["x"])
535535

536536
//===----------------------------------------------------------------------===//
@@ -611,7 +611,7 @@ var ruleVar: Rule
611611
ruleVar = Rule("a") // expected-error {{missing argument label 'target:' in call}}
612612
// expected-error@-1 {{missing argument for parameter 'dependencies' in call}}
613613

614-
class C { // expected-note {{did you mean 'C'?}}
614+
class C {
615615
var x: C?
616616
init(other: C?) { x = other }
617617

@@ -659,11 +659,6 @@ func iterators() {
659659
//===----------------------------------------------------------------------===//
660660

661661
func magic_literals() {
662-
_ = __FILE__ // expected-error {{__FILE__ has been replaced with #file in Swift 3}}
663-
_ = __LINE__ // expected-error {{__LINE__ has been replaced with #line in Swift 3}}
664-
_ = __COLUMN__ // expected-error {{__COLUMN__ has been replaced with #column in Swift 3}}
665-
_ = __DSO_HANDLE__ // expected-error {{__DSO_HANDLE__ has been replaced with #dsohandle in Swift 3}}
666-
667662
_ = #file
668663
_ = #line + #column
669664
var _: UInt8 = #line + #column

0 commit comments

Comments
 (0)