Skip to content

Commit 63ec1cf

Browse files
committed
Introduce a separate #filePath, remove -pound-file
This makes the path behavior more first-class. The feature is now hidden behind an experimental flag, -enable-experimental-concise-pound-file.
1 parent 2acaf38 commit 63ec1cf

27 files changed

+120
-42
lines changed

include/swift/AST/DefaultArgumentKind.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ enum class DefaultArgumentKind : uint8_t {
3838
Inherited,
3939
/// The #file default argument, which is expanded at the call site.
4040
File,
41+
/// The #filePath default argument, which is expanded at the call site.
42+
FilePath,
4143
/// The #line default argument, which is expanded at the call site.
4244
Line,
4345
/// The #column default argument, which is expanded at the call site.

include/swift/AST/Expr.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1040,7 +1040,7 @@ class InterpolatedStringLiteralExpr : public LiteralExpr {
10401040
class MagicIdentifierLiteralExpr : public LiteralExpr {
10411041
public:
10421042
enum Kind : unsigned {
1043-
File, Line, Column, Function, DSOHandle
1043+
File, FilePath, Line, Column, Function, DSOHandle
10441044
};
10451045
private:
10461046
SourceLoc Loc;
@@ -1067,6 +1067,7 @@ class MagicIdentifierLiteralExpr : public LiteralExpr {
10671067
bool isString() const {
10681068
switch (getKind()) {
10691069
case File:
1070+
case FilePath:
10701071
case Function:
10711072
return true;
10721073
case Line:

include/swift/Basic/LangOptions.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,9 @@ namespace swift {
9494
/// when using RequireExplicitAvailability.
9595
std::string RequireExplicitAvailabilityTarget;
9696

97-
/// If true, '#file' evaluates to the full path rather than a
97+
/// If false, '#file' evaluates to the full path rather than a
9898
/// human-readable string.
99-
bool MagicFileIdentifierEvaluatesToPath = true;
99+
bool EnableConcisePoundFile = false;
100100

101101
///
102102
/// Support for alternate usage modes

include/swift/Option/Options.td

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,6 @@ def output_file_map_EQ : Joined<["-"], "output-file-map=">,
267267
Flags<[NoInteractiveOption, ArgumentIsPath]>,
268268
Alias<output_file_map>;
269269

270-
def pound_file : Separate<["-"], "pound-file">,
271-
Flags<[FrontendOption]>,
272-
HelpText<"Specifies whether '#file' evaluates to a full path or a compact human-readable string">,
273-
MetaVarName<"compact|path">;
274-
def pound_file_EQ : Joined<["-"], "pound-file=">,
275-
Flags<[FrontendOption]>,
276-
Alias<pound_file>;
277-
278270
def save_temps : Flag<["-"], "save-temps">,
279271
Flags<[NoInteractiveOption,DoesNotAffectIncrementalBuild]>,
280272
HelpText<"Save intermediate compilation results">;
@@ -462,6 +454,11 @@ def enable_experimental_differentiable_programming : Flag<["-"], "enable-experim
462454
Flags<[FrontendOption]>,
463455
HelpText<"Enable experimental differentiable programming features">;
464456

457+
def enable_experimental_concise_pound_file : Flag<["-"],
458+
"enable-experimental-concise-pound-file">,
459+
Flags<[FrontendOption]>,
460+
HelpText<"Enable experimental concise '#file' identifier and '#filePath' alternative">;
461+
465462
// Diagnostic control options
466463
def suppress_warnings : Flag<["-"], "suppress-warnings">,
467464
Flags<[FrontendOption]>,

lib/AST/ASTDumper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,7 @@ static StringRef getDefaultArgumentKindString(DefaultArgumentKind value) {
300300
case DefaultArgumentKind::Column: return "#column";
301301
case DefaultArgumentKind::DSOHandle: return "#dsohandle";
302302
case DefaultArgumentKind::File: return "#file";
303+
case DefaultArgumentKind::FilePath: return "#filePath";
303304
case DefaultArgumentKind::Function: return "#function";
304305
case DefaultArgumentKind::Inherited: return "inherited";
305306
case DefaultArgumentKind::Line: return "#line";
@@ -316,6 +317,7 @@ static StringRef
316317
getMagicIdentifierLiteralExprKindString(MagicIdentifierLiteralExpr::Kind value) {
317318
switch (value) {
318319
case MagicIdentifierLiteralExpr::File: return "#file";
320+
case MagicIdentifierLiteralExpr::FilePath: return "#filePath";
319321
case MagicIdentifierLiteralExpr::Function: return "#function";
320322
case MagicIdentifierLiteralExpr::Line: return "#line";
321323
case MagicIdentifierLiteralExpr::Column: return "#column";

lib/AST/Decl.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6083,6 +6083,7 @@ bool ParamDecl::hasDefaultExpr() const {
60836083
return false;
60846084
case DefaultArgumentKind::Normal:
60856085
case DefaultArgumentKind::File:
6086+
case DefaultArgumentKind::FilePath:
60866087
case DefaultArgumentKind::Line:
60876088
case DefaultArgumentKind::Column:
60886089
case DefaultArgumentKind::Function:
@@ -6105,6 +6106,7 @@ bool ParamDecl::hasCallerSideDefaultExpr() const {
61056106
case DefaultArgumentKind::Normal:
61066107
return false;
61076108
case DefaultArgumentKind::File:
6109+
case DefaultArgumentKind::FilePath:
61086110
case DefaultArgumentKind::Line:
61096111
case DefaultArgumentKind::Column:
61106112
case DefaultArgumentKind::Function:
@@ -6414,6 +6416,7 @@ ParamDecl::getDefaultValueStringRepresentation(
64146416
}
64156417
case DefaultArgumentKind::Inherited: return "super";
64166418
case DefaultArgumentKind::File: return "#file";
6419+
case DefaultArgumentKind::FilePath: return "#filePath";
64176420
case DefaultArgumentKind::Line: return "#line";
64186421
case DefaultArgumentKind::Column: return "#column";
64196422
case DefaultArgumentKind::Function: return "#function";

lib/Driver/ToolChains.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,8 @@ static void addCommonFrontendArgs(const ToolChain &TC, const OutputInfo &OI,
238238
inputArgs.AddLastArg(arguments, options::OPT_enable_astscope_lookup);
239239
inputArgs.AddLastArg(arguments, options::OPT_disable_astscope_lookup);
240240
inputArgs.AddLastArg(arguments, options::OPT_disable_parser_lookup);
241-
inputArgs.AddLastArg(arguments, options::OPT_pound_file);
241+
inputArgs.AddLastArg(arguments,
242+
options::OPT_enable_experimental_concise_pound_file);
242243

243244
// Pass on any build config options
244245
inputArgs.AddAllArgs(arguments, options::OPT_D);

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -453,16 +453,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
453453
Opts.OptimizationRemarkMissedPattern =
454454
generateOptimizationRemarkRegex(Diags, Args, A);
455455

456-
if (Arg *A = Args.getLastArg(OPT_pound_file)) {
457-
StringRef value = A->getValue();
458-
if (value == "path")
459-
Opts.MagicFileIdentifierEvaluatesToPath = true;
460-
else if (value == "compact")
461-
Opts.MagicFileIdentifierEvaluatesToPath = false;
462-
else
463-
Diags.diagnose(SourceLoc(), diag::error_invalid_arg_value,
464-
A->getSpelling(), value);
465-
}
456+
Opts.EnableConcisePoundFile =
457+
Args.hasArg(OPT_enable_experimental_concise_pound_file);
466458

467459
llvm::Triple Target = Opts.Target;
468460
StringRef TargetArg;

lib/IDE/CodeCompletion.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,7 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
22442244
return !includeDefaultArgs;
22452245

22462246
case DefaultArgumentKind::File:
2247+
case DefaultArgumentKind::FilePath:
22472248
case DefaultArgumentKind::Line:
22482249
case DefaultArgumentKind::Column:
22492250
case DefaultArgumentKind::Function:
@@ -3653,6 +3654,10 @@ class CompletionLookup final : public swift::VisibleDeclConsumer {
36533654
CodeCompletionLiteralKind::StringLiteral, "String");
36543655
addFromProto("#file", CodeCompletionKeywordKind::pound_file,
36553656
CodeCompletionLiteralKind::StringLiteral, "String");
3657+
if (Ctx.LangOpts.EnableConcisePoundFile) {
3658+
addFromProto("#filePath", CodeCompletionKeywordKind::pound_file,
3659+
CodeCompletionLiteralKind::StringLiteral, "String");
3660+
}
36563661
addFromProto("#line", CodeCompletionKeywordKind::pound_line,
36573662
CodeCompletionLiteralKind::IntegerLiteral, "Int");
36583663
addFromProto("#column", CodeCompletionKeywordKind::pound_column,

lib/Parse/ParseExpr.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,6 +1014,8 @@ getMagicIdentifierLiteralKind(tok Kind) {
10141014
case tok::kw___FILE__:
10151015
case tok::pound_file:
10161016
return MagicIdentifierLiteralExpr::Kind::File;
1017+
case tok::pound_filePath:
1018+
return MagicIdentifierLiteralExpr::Kind::FilePath;
10171019
case tok::kw___FUNCTION__:
10181020
case tok::pound_function:
10191021
return MagicIdentifierLiteralExpr::Kind::Function;
@@ -1446,6 +1448,15 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
14461448
.fixItReplace(Tok.getLoc(), replacement);
14471449
LLVM_FALLTHROUGH;
14481450
}
1451+
1452+
case tok::pound_filePath:
1453+
// Check twice because of fallthrough--this is ugly but temporary.
1454+
if (Tok.is(tok::pound_filePath) && !Context.LangOpts.EnableConcisePoundFile)
1455+
diagnose(Tok.getLoc(), diag::unknown_pound_expr, "filePath");
1456+
// Continue since we actually do know how to handle it. This avoids extra
1457+
// diagnostics.
1458+
LLVM_FALLTHROUGH;
1459+
14491460
case tok::pound_column:
14501461
case tok::pound_file:
14511462
case tok::pound_function:
@@ -1455,6 +1466,7 @@ ParserResult<Expr> Parser::parseExprPrimary(Diag<> ID, bool isExprBasic) {
14551466
switch (Tok.getKind()) {
14561467
case tok::pound_column: SKind = SyntaxKind::PoundColumnExpr; break;
14571468
case tok::pound_file: SKind = SyntaxKind::PoundFileExpr; break;
1469+
case tok::pound_filePath: SKind = SyntaxKind::PoundFilePathExpr; break;
14581470
case tok::pound_function: SKind = SyntaxKind::PoundFunctionExpr; break;
14591471
// FIXME: #line was renamed to #sourceLocation
14601472
case tok::pound_line: SKind = SyntaxKind::PoundLineExpr; break;

0 commit comments

Comments
 (0)