Skip to content

Commit 8f9a40d

Browse files
committed
[NFC] Avoid violating same-filename rule in tests
…and modify resolveFileIDConflicts() to diagnose any such violations instead of asserting. Swift does not allow any two files in the same module to have the same filename, even if they are in different directories. However, this is enforced in the driver, so tests that invoke the frontend directly can violate it. Turns out that a couple of those snuck into the test suite at various points. This commit updates those tests. It also causes the frontend to diagnose the duplicate filename error just as the driver would have, which should help us understand what happened more easily if this crops up again in the future. NFC, since invoking the frontend directly is unsupported.
1 parent 63f6951 commit 8f9a40d

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

include/swift/AST/DiagnosticsCommon.def

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ WARNING(pound_source_location_creates_pound_file_conflicts,none,
122122
NOTE(fixit_correct_source_location_file,none,
123123
"change file in '#sourceLocation' to '%0'", (StringRef))
124124

125+
// Usually, but not always, emitted from the driver
126+
ERROR(error_two_files_same_name,none,
127+
"filename \"%0\" used twice: '%1' and '%2'",
128+
(StringRef, StringRef, StringRef))
129+
NOTE(note_explain_two_files_same_name,none,
130+
"filenames are used to distinguish private declarations with the same "
131+
"name", ())
132+
125133
//------------------------------------------------------------------------------
126134
// MARK: Circular reference diagnostics
127135
//------------------------------------------------------------------------------

include/swift/AST/DiagnosticsDriver.def

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,6 @@ WARNING(warn_arclite_not_found_when_link_objc_runtime,none,
104104
"unable to find Objective-C runtime support library 'arclite'; "
105105
"pass '-no-link-objc-runtime' to silence this warning", ())
106106

107-
ERROR(error_two_files_same_name,none,
108-
"filename \"%0\" used twice: '%1' and '%2'",
109-
(StringRef, StringRef, StringRef))
110-
NOTE(note_explain_two_files_same_name,none,
111-
"filenames are used to distinguish private declarations with the same "
112-
"name", ())
113-
114107
WARNING(warn_cannot_stat_input,none,
115108
"unable to determine when '%0' was last modified: %1",
116109
(StringRef, StringRef))

lib/AST/Module.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2416,7 +2416,14 @@ resolveFileIDConflicts(const ModuleDecl *module, StringRef fileString,
24162416

24172417
// Don't diagnose #sourceLocations that match the physical file.
24182418
if (pathPair.second.physicalFileLoc.isValid()) {
2419-
assert(isWinner && "physical files should always win; duplicate name?");
2419+
if (!isWinner) {
2420+
// The driver is responsible for diagnosing this, but naughty people who
2421+
// have directly invoked the frontend could make it happen here instead.
2422+
StringRef filename = llvm::sys::path::filename(winner);
2423+
diags.diagnose(SourceLoc(), diag::error_two_files_same_name,
2424+
filename, winner, pathPair.first());
2425+
diags.diagnose(SourceLoc(), diag::note_explain_two_files_same_name);
2426+
}
24202427
continue;
24212428
}
24222429

test/SILOptimizer/specialize_inherited_multifile.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11

2-
// RUN: %target-swift-frontend -module-name specialize_inherited_multifile -primary-file %s %S/Inputs/specialize_inherited_multifile.swift -O -emit-sil -sil-verify-all | %FileCheck %s
2+
// RUN: %target-swift-frontend -module-name specialize_inherited_multifile -primary-file %s %S/Inputs/specialize_inherited_multifile_other.swift -O -emit-sil -sil-verify-all | %FileCheck %s
33

44
@_optimize(none) func takesBase<T : Base>(t: T) {}
55

test/Serialization/multi-file-type-eraser.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// REQUIRES: asserts
22
// RUN: %empty-directory(%t)
3-
// RUN: %target-swift-frontend -emit-module -module-name Multi -o %t/multi-file.swiftmodule -primary-file %s %S/Inputs/multi-file-type-eraser.swift
4-
// RUN: %target-swift-frontend -emit-module -module-name Multi -o %t/multi-file-2.swiftmodule %s -primary-file %S/Inputs/multi-file-type-eraser.swift
3+
// RUN: %target-swift-frontend -emit-module -module-name Multi -o %t/multi-file.swiftmodule -primary-file %s %S/Inputs/multi-file-type-eraser-other.swift
4+
// RUN: %target-swift-frontend -emit-module -module-name Multi -o %t/multi-file-2.swiftmodule %s -primary-file %S/Inputs/multi-file-type-eraser-other.swift
55

66
// RUN: %target-swift-frontend -emit-module -module-name Multi %t/multi-file.swiftmodule %t/multi-file-2.swiftmodule -o %t -print-stats 2>&1 | %FileCheck %s
77
// RUN: %target-swift-frontend -emit-module -module-name Multi %t/multi-file-2.swiftmodule %t/multi-file.swiftmodule -o %t -print-stats 2>&1 | %FileCheck %s

0 commit comments

Comments
 (0)