Skip to content

Commit e5b582f

Browse files
committed
Include module name in string
Along with a not-yet-usable way to get back to the old behavior.
1 parent 1e9d3b7 commit e5b582f

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4876,6 +4876,21 @@ getMagicFunctionString(SILGenFunction &SGF) {
48764876
return SGF.MagicFunctionString;
48774877
}
48784878

4879+
static std::string getMagicFileString(SILGenFunction &SGF, SourceLoc loc) {
4880+
if (!loc.isValid())
4881+
return "";
4882+
4883+
auto path = SGF.getASTContext().SourceMgr.getDisplayNameForLoc(loc);
4884+
if (false /* FIXME: Add a command line flag for this */)
4885+
return path;
4886+
4887+
auto value = llvm::sys::path::filename(path).str();
4888+
value += " (";
4889+
value += SGF.getModule().getSwiftModule()->getNameStr();
4890+
value += ")";
4891+
return value;
4892+
}
4893+
48794894
/// Emit an application of the given allocating initializer.
48804895
RValue SILGenFunction::emitApplyAllocatingInitializer(SILLocation loc,
48814896
ConcreteDeclRef init,
@@ -5131,12 +5146,8 @@ RValue SILGenFunction::emitLiteral(LiteralExpr *literal, SGFContext C) {
51315146
auto magicLiteral = cast<MagicIdentifierLiteralExpr>(literal);
51325147
switch (magicLiteral->getKind()) {
51335148
case MagicIdentifierLiteralExpr::File: {
5134-
std::string value;
5135-
if (loc.isValid())
5136-
value = ctx.SourceMgr.getDisplayNameForLoc(loc);
5137-
builtinLiteralArgs = emitStringLiteral(*this, literal,
5138-
llvm::sys::path::filename(value),
5139-
C,
5149+
std::string value = getMagicFileString(*this, loc);
5150+
builtinLiteralArgs = emitStringLiteral(*this, literal, value, C,
51405151
magicLiteral->getStringEncoding());
51415152
builtinInit = magicLiteral->getBuiltinInitializer();
51425153
init = magicLiteral->getInitializer();

test/PlaygroundTransform/implicit_return_never.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
func f() -> Int {
1515
fatalError()
16-
// CRASH-CHECK: {{[fF]}}atal error: file main.swift, line [[@LINE-1]]
16+
// CRASH-CHECK: {{[fF]}}atal error: file main.swift (main), line [[@LINE-1]]
1717
}
1818

1919
f()

test/PlaygroundTransform/placeholder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
func f(crash crash: Bool) -> Int {
1616
if crash {
1717
return <#T#>
18-
// CRASH-CHECK: {{[fF]}}atal error: attempt to evaluate editor placeholder: file main.swift, line [[@LINE-1]]
18+
// CRASH-CHECK: {{[fF]}}atal error: attempt to evaluate editor placeholder: file main.swift (main), line [[@LINE-1]]
1919
} else {
2020
return 42
2121
}

0 commit comments

Comments
 (0)