Skip to content

Commit 0c045e1

Browse files
authored
Merge pull request #71366 from ahoppen/ahoppen/revert-source-location-changes
Revert Disallow multi-line filenames and non-decimal line numbers in `#sourceLocation` directive in Swift 6 mode
2 parents 124df8e + a836195 commit 0c045e1

File tree

6 files changed

+20
-52
lines changed

6 files changed

+20
-52
lines changed

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,6 @@ WARNING(escaped_parameter_name,none,
8888

8989
ERROR(forbidden_interpolated_string,none,
9090
"%0 cannot be an interpolated string literal", (StringRef))
91-
ERROR(forbidden_multiline_string,none,
92-
"%0 cannot be a multi-line string literal", (StringRef))
9391
ERROR(forbidden_extended_escaping_string,none,
9492
"%0 cannot be an extended escaping string literal", (StringRef))
9593

include/swift/Parse/Parser.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -718,11 +718,8 @@ class Parser {
718718
///
719719
/// \param Loc where to diagnose.
720720
/// \param DiagText name for the string literal in the diagnostic.
721-
/// \param AllowMultiline Whether the string literal can be a multiline string
722-
/// literal.
723721
std::optional<StringRef>
724-
getStringLiteralIfNotInterpolated(SourceLoc Loc, StringRef DiagText,
725-
bool AllowMultiline);
722+
getStringLiteralIfNotInterpolated(SourceLoc Loc, StringRef DiagText);
726723

727724
/// Returns true to indicate that experimental concurrency syntax should be
728725
/// parsed if the parser is generating only a syntax tree or if the user has

lib/Parse/ParseDecl.cpp

Lines changed: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,7 @@ ParserResult<AvailableAttr> Parser::parseExtendedAvailabilitySpecList(
569569
}
570570

571571
auto Value = getStringLiteralIfNotInterpolated(
572-
AttrLoc, ("'" + ArgumentKindStr + "'").str(),
573-
/*AllowMultiline=*/true);
572+
AttrLoc, ("'" + ArgumentKindStr + "'").str());
574573
consumeToken();
575574
if (!Value) {
576575
AnyArgumentInvalid = true;
@@ -1462,8 +1461,7 @@ bool Parser::parseExternAttribute(DeclAttributes &Attributes,
14621461
return std::nullopt;
14631462
}
14641463
std::optional<StringRef> importModuleName =
1465-
getStringLiteralIfNotInterpolated(Loc, ("'" + AttrName + "'").str(),
1466-
/*AllowMultiline=*/false);
1464+
getStringLiteralIfNotInterpolated(Loc, ("'" + AttrName + "'").str());
14671465
consumeToken(tok::string_literal);
14681466

14691467
if (!importModuleName.has_value()) {
@@ -3240,8 +3238,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
32403238
return makeParserSuccess();
32413239
}
32423240

3243-
AsmName = getStringLiteralIfNotInterpolated(
3244-
Loc, ("'" + AttrName + "'").str(), /*AllowMultiline=*/false);
3241+
AsmName =
3242+
getStringLiteralIfNotInterpolated(Loc, ("'" + AttrName + "'").str());
32453243

32463244
consumeToken(tok::string_literal);
32473245

@@ -3311,7 +3309,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
33113309
}
33123310

33133311
auto Name = getStringLiteralIfNotInterpolated(
3314-
Loc, ("'" + AttrName + "'").str(), /*AllowMultiline=*/false);
3312+
Loc, ("'" + AttrName + "'").str());
33153313

33163314
consumeToken(tok::string_literal);
33173315

@@ -3398,7 +3396,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
33983396
}
33993397

34003398
auto Value = getStringLiteralIfNotInterpolated(
3401-
Loc, ("'" + AttrName + "'").str(), /*AllowMultiline=*/false);
3399+
Loc, ("'" + AttrName + "'").str());
34023400

34033401
consumeToken(tok::string_literal);
34043402

@@ -3461,8 +3459,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
34613459
// Parse the next string literal as the original module name.
34623460
auto ModuleNameLoc = Tok.getLoc();
34633461
if (Tok.is(tok::string_literal)) {
3464-
auto NameOp = getStringLiteralIfNotInterpolated(
3465-
Tok.getLoc(), "original module name", /*AllowMultiline=*/false);
3462+
auto NameOp = getStringLiteralIfNotInterpolated(Tok.getLoc(),
3463+
"original module name");
34663464
if (NameOp.has_value())
34673465
OriginalModuleName = *NameOp;
34683466
consumeToken();
@@ -3551,8 +3549,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
35513549
diagnose(ColonLoc, diag::attr_private_import_expected_sourcefile_name);
35523550
return makeParserSuccess();
35533551
}
3554-
filename = getStringLiteralIfNotInterpolated(Loc, "_private",
3555-
/*AllowMultiline=*/false);
3552+
filename = getStringLiteralIfNotInterpolated(Loc, "_private");
35563553
if (!filename.has_value()) {
35573554
diagnose(ColonLoc, diag::attr_private_import_expected_sourcefile_name);
35583555
return makeParserSuccess();
@@ -3829,8 +3826,8 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
38293826
return makeParserSuccess();
38303827
}
38313828

3832-
std::optional<StringRef> value = getStringLiteralIfNotInterpolated(
3833-
Tok.getLoc(), flag, /*AllowMultiline=*/false);
3829+
std::optional<StringRef> value =
3830+
getStringLiteralIfNotInterpolated(Tok.getLoc(), flag);
38343831
if (!value)
38353832
return makeParserSuccess();
38363833
Token stringTok = Tok;
@@ -4569,8 +4566,7 @@ bool Parser::parseConventionAttributeInternal(SourceLoc atLoc, SourceLoc attrLoc
45694566
diagnose(Tok, diag::convention_attribute_ctype_expected_string);
45704567
return true;
45714568
}
4572-
if (auto ty = getStringLiteralIfNotInterpolated(Tok.getLoc(), "(C type)",
4573-
/*AllowMultiline=*/false)) {
4569+
if (auto ty = getStringLiteralIfNotInterpolated(Tok.getLoc(), "(C type)")) {
45744570
cType = Located<StringRef>(ty.value(), Tok.getLoc());
45754571
}
45764572
consumeToken(tok::string_literal);
@@ -7276,8 +7272,8 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
72767272
return makeParserError();
72777273
}
72787274

7279-
Filename = getStringLiteralIfNotInterpolated(Loc, "'#sourceLocation'",
7280-
/*AllowMultiline=*/false);
7275+
Filename =
7276+
getStringLiteralIfNotInterpolated(Loc, "'#sourceLocation'");
72817277
if (!Filename.has_value())
72827278
return makeParserError();
72837279
SourceLoc filenameLoc = consumeToken(tok::string_literal);
@@ -7295,11 +7291,6 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
72957291
}
72967292
SmallString<16> buffer;
72977293
auto text = stripUnderscoresIfNeeded(Tok.getText(), buffer);
7298-
if (text.find_first_not_of("0123456789") != StringRef::npos) {
7299-
// Disallow non-decimal line numbers in Swift 6.
7300-
diagnose(Tok, diag::expected_line_directive_number)
7301-
.warnUntilSwiftVersion(6);
7302-
}
73037294
if (text.getAsInteger(0, StartLine)) {
73047295
diagnose(Tok, diag::expected_line_directive_number);
73057296
return makeParserError();
@@ -7347,9 +7338,8 @@ ParserStatus Parser::parseLineDirective(bool isLine) {
73477338
diagnose(Tok, diag::expected_line_directive_name);
73487339
return makeParserError();
73497340
}
7350-
7351-
Filename = getStringLiteralIfNotInterpolated(Loc, "'#line'",
7352-
/*AllowMultiline=*/false);
7341+
7342+
Filename = getStringLiteralIfNotInterpolated(Loc, "'#line'");
73537343
if (!Filename.has_value())
73547344
return makeParserError();
73557345
}

lib/Parse/ParseStmt.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2773,9 +2773,8 @@ ParserResult<Stmt> Parser::parseStmtPoundAssert() {
27732773
return makeParserError();
27742774
}
27752775

2776-
auto messageOpt =
2777-
getStringLiteralIfNotInterpolated(Tok.getLoc(), "'#assert' message",
2778-
/*AllowMultiline=*/true);
2776+
auto messageOpt = getStringLiteralIfNotInterpolated(Tok.getLoc(),
2777+
"'#assert' message");
27792778
consumeToken();
27802779
if (!messageOpt)
27812780
return makeParserError();

lib/Parse/Parser.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,19 +1098,14 @@ Parser::parseList(tok RightK, SourceLoc LeftLoc, SourceLoc &RightLoc,
10981098
}
10991099

11001100
std::optional<StringRef>
1101-
Parser::getStringLiteralIfNotInterpolated(SourceLoc Loc, StringRef DiagText,
1102-
bool AllowMultiline) {
1101+
Parser::getStringLiteralIfNotInterpolated(SourceLoc Loc, StringRef DiagText) {
11031102
assert(Tok.is(tok::string_literal));
11041103

11051104
// FIXME: Support extended escaping string literal.
11061105
if (Tok.getCustomDelimiterLen()) {
11071106
diagnose(Loc, diag::forbidden_extended_escaping_string, DiagText);
11081107
return std::nullopt;
11091108
}
1110-
if (!AllowMultiline && Tok.isMultilineString()) {
1111-
diagnose(Loc, diag::forbidden_multiline_string, DiagText)
1112-
.warnUntilSwiftVersion(6);
1113-
}
11141109

11151110
SmallVector<Lexer::StringSegment, 1> Segments;
11161111
L->getStringLiteralSegments(Tok, Segments);

test/Parse/line-directive.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,6 @@ x // expected-error {{parameterless closing #sourceLocation() directive without
1414

1515
#sourceLocation(file: x.swift, line: 1) // expected-error{{expected filename string literal}}
1616

17-
// expected-warning@+1 {{expected starting line number for #sourceLocation directive; this is an error in Swift 6}}
18-
#sourceLocation(file: "x.swift", line: 0xff)
19-
20-
#sourceLocation()
21-
22-
// expected-warning@+1 {{'#sourceLocation' cannot be a multi-line string literal; this is an error in Swift 6}}
23-
#sourceLocation(file: """
24-
x.swift
25-
y.swift
26-
""", line: 42)
27-
2817
#sourceLocation(file: "x.swift", line: 42)
2918
x x ; // should be ignored by expected_error because it is in a different file
3019
x

0 commit comments

Comments
 (0)