Skip to content

Commit 745dbef

Browse files
committed
Use file IDs in generated code
Such as force unwraps, as! casts, etc.
1 parent 0e569f5 commit 745dbef

File tree

5 files changed

+9
-12
lines changed

5 files changed

+9
-12
lines changed

lib/SILGen/SILGenConvert.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,8 +144,7 @@ auto SILGenFunction::emitSourceLocationArgs(SourceLoc sourceLoc,
144144
unsigned line = 0;
145145
unsigned column = 0;
146146
if (sourceLoc.isValid()) {
147-
// FIXME: Should be getMagicFileIDString()
148-
filename = getMagicFilePathString(sourceLoc);
147+
filename = getMagicFileIDString(sourceLoc);
149148
std::tie(line, column) =
150149
ctx.SourceMgr.getPresumedLineAndColumnForLoc(sourceLoc);
151150
}

lib/Sema/CodeSynthesis.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ synthesizeStubBody(AbstractFunctionDecl *fn, void *) {
355355
initName->setBuiltinInitializer(staticStringInit);
356356

357357
auto *file = new (ctx) MagicIdentifierLiteralExpr(
358-
MagicIdentifierLiteralExpr::File, loc, /*Implicit=*/true);
358+
MagicIdentifierLiteralExpr::FileID, loc, /*Implicit=*/true);
359359
file->setType(staticStringType);
360360
file->setBuiltinInitializer(staticStringInit);
361361

test/SILGen/magic_identifier_file.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@ func indirectUse() {
2121
func forceUnwrap(_ x: ()?) {
2222
// BOTH-LABEL: sil {{.*}} @$s3Foo11forceUnwrapyyytSgF
2323
_ = x!
24-
// ABSOLUTE: string_literal utf8 "SOURCE_DIR/test/SILGen/magic_identifier_file.swift"
25-
// CONCISE: string_literal utf8 "Foo/magic_identifier_file.swift"
24+
// BOTH: string_literal utf8 "Foo/magic_identifier_file.swift"
2625
}
2726

2827
func forceTry(_ fn: () throws -> ()) {
2928
// BOTH-LABEL: sil {{.*}} @$s3Foo8forceTryyyyyKXEF
3029
try! fn()
31-
// ABSOLUTE: string_literal utf8 "SOURCE_DIR/test/SILGen/magic_identifier_file.swift"
32-
// CONCISE: string_literal utf8 "Foo/magic_identifier_file.swift"
30+
// BOTH: string_literal utf8 "Foo/magic_identifier_file.swift"
3331
}
3432

3533
// CONCISE-LABEL: // Mappings from '#fileID' to '#filePath':

test/SILGen/optional.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func crash_on_dealloc(_ dict : [Int : [Int]] = [:]) {
105105
func use_unwrapped(_: Int) {}
106106

107107
// CHECK-LABEL: sil hidden [ossa] @$s8optional15explicit_unwrap{{[_0-9a-zA-Z]*}}F
108-
// CHECK: [[FILESTR:%.*]] = string_literal utf8 "{{.*}}optional.swift"
108+
// CHECK: [[FILESTR:%.*]] = string_literal utf8 "optional/optional.swift"
109109
// CHECK-NEXT: [[FILESIZ:%.*]] = integer_literal $Builtin.Word,
110110
// CHECK-NEXT: [[FILEASC:%.*]] = integer_literal $Builtin.Int1,
111111
// CHECK-NEXT: [[LINE:%.*]] = integer_literal $Builtin.Word,
@@ -118,7 +118,7 @@ func explicit_unwrap(_ value: Int?) {
118118
}
119119

120120
// CHECK-LABEL: sil hidden [ossa] @$s8optional19explicit_iuo_unwrap{{[_0-9a-zA-Z]*}}F
121-
// CHECK: [[FILESTR:%.*]] = string_literal utf8 "{{.*}}optional.swift"
121+
// CHECK: [[FILESTR:%.*]] = string_literal utf8 "optional/optional.swift"
122122
// CHECK-NEXT: [[FILESIZ:%.*]] = integer_literal $Builtin.Word,
123123
// CHECK-NEXT: [[FILEASC:%.*]] = integer_literal $Builtin.Int1,
124124
// CHECK-NEXT: [[LINE:%.*]] = integer_literal $Builtin.Word,
@@ -131,7 +131,7 @@ func explicit_iuo_unwrap(_ value: Int!) {
131131
}
132132

133133
// CHECK-LABEL: sil hidden [ossa] @$s8optional19implicit_iuo_unwrap{{[_0-9a-zA-Z]*}}F
134-
// CHECK: [[FILESTR:%.*]] = string_literal utf8 "{{.*}}optional.swift"
134+
// CHECK: [[FILESTR:%.*]] = string_literal utf8 "optional/optional.swift"
135135
// CHECK-NEXT: [[FILESIZ:%.*]] = integer_literal $Builtin.Word,
136136
// CHECK-NEXT: [[FILEASC:%.*]] = integer_literal $Builtin.Int1,
137137
// CHECK-NEXT: [[LINE:%.*]] = integer_literal $Builtin.Word,
@@ -144,7 +144,7 @@ func implicit_iuo_unwrap(_ value: Int!) {
144144
}
145145

146146
// CHECK-LABEL: sil hidden [ossa] @$s8optional34implicit_iuo_unwrap_sourceLocation{{[_0-9a-zA-Z]*}}F
147-
// CHECK: [[FILESTR:%.*]] = string_literal utf8 "custom.swuft"
147+
// CHECK: [[FILESTR:%.*]] = string_literal utf8 "optional/custom.swuft"
148148
// CHECK-NEXT: [[FILESIZ:%.*]] = integer_literal $Builtin.Word,
149149
// CHECK-NEXT: [[FILEASC:%.*]] = integer_literal $Builtin.Int1,
150150
// CHECK-NEXT: [[LINE:%.*]] = integer_literal $Builtin.Word, 2000

test/stdlib/Error.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ ErrorTests.test("try!/location")
121121
.skip(.custom({ _isFastAssertConfiguration() },
122122
reason: "trap is not guaranteed to happen in -Ounchecked"))
123123
.crashOutputMatches(_isDebugAssertConfiguration()
124-
? "test/stdlib/Error.swift, line 128"
124+
? "main/Error.swift, line 128"
125125
: "")
126126
.code {
127127
expectCrashLater()

0 commit comments

Comments
 (0)