Skip to content

Commit 15726fc

Browse files
committed
Adding a test.
1 parent cd6066d commit 15726fc

File tree

3 files changed

+44
-2
lines changed

3 files changed

+44
-2
lines changed

include/swift/Frontend/ModuleInterfaceLoader.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -628,6 +628,17 @@ struct SwiftInterfaceInfo {
628628
std::optional<version::Version> CompilerToolsVersion;
629629
};
630630

631+
/// A small helper class that expands the module name to a full output path
632+
/// with context hash.
633+
/// The cannonical way to use this class is the following:
634+
/// 1. Create an instance through the constructor.
635+
/// 2. Optional: prune the extra args if necessary.
636+
/// 3. Obtain the expanded name that contains a full path, and a hash.
637+
/// expandedName is computed only once, and never updated.
638+
/// Currently, there is no use case where we first obtain expandedName,
639+
/// then prune the extra args, and finally obtain expandedName again.
640+
/// Pruning always happens before the first time we call getExpandedName().
641+
/// Therefore it is correct to calculate expandedName only once.
631642
class InterfaceModuleNameExpander {
632643
public:
633644
using ArgListTy = std::vector<std::string>;

lib/DependencyScan/ScanDependencies.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ class ExplicitModuleDependencyResolver {
445445

446446
newArgs.push_back(*it);
447447
}
448-
args = newArgs;
448+
args = std::move(newArgs);
449449
return;
450450
};
451451

test/ScanDependencies/eliminate_unused_vfs.swift

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,16 @@
55
// RUN: split-file %s %t
66

77
// RUN: sed -e "s|OUT_DIR|%t/redirects|g" -e "s|IN_DIR|%S/Inputs/CHeaders|g" %t/overlay_template.yaml > %t/overlay.yaml
8+
// RUN: sed -e "s|OUT_DIR|%t/redirects|g" -e "s|IN_DIR|%S/Inputs/CHeaders1|g" %t/overlay_template.yaml > %t/overlay1.yaml
89

910
// RUN: %target-swift-frontend -scan-dependencies -module-load-mode prefer-interface -module-cache-path %t/module-cache %t/test.swift -o %t/deps.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -file-compilation-dir %t -Xcc -ivfsoverlay -Xcc %t/overlay.yaml
10-
// RUN: %validate-json %t/deps.json | %FileCheck %s
11+
// RUN: %validate-json %t/deps.json > %t/validated_deps.json
12+
// RUN: cat %t/validated_deps.json | %FileCheck %s
13+
14+
// RUN: %target-swift-frontend -scan-dependencies -module-load-mode prefer-interface -module-cache-path %t/module-cache %t/test.swift -o %t/deps1.json -I %S/Inputs/CHeaders -I %S/Inputs/Swift -disable-implicit-concurrency-module-import -disable-implicit-string-processing-module-import -file-compilation-dir %t -Xcc -ivfsoverlay -Xcc %t/overlay1.yaml
15+
// RUN: %validate-json %t/deps1.json > %t/validated_deps1.json
16+
// RUN: cat %t/validated_deps.json %t/validated_deps1.json \
17+
// RUN: | %FileCheck %s --check-prefix=MOD-HASH
1118

1219
//--- overlay_template.yaml
1320
{
@@ -61,3 +68,27 @@ import F
6168
// CHECK-LABEL: "modulePath": "{{.*}}{{/|\\}}F-{{.*}}.pcm",
6269
// CHECK-NOT: "-ivfsoverlay",
6370
// CHECK-NOT: "{{.*}}{{/|\\}}preserve_used_vfs.swift.tmp{{/|\\}}overlay.yaml",
71+
72+
/// Check that the dependency swift module hashes are identical when the vfs overlays are ignored.
73+
// MOD-HASH: "mainModuleName": "deps",
74+
// MOD-HASH: "linkLibraries": [],
75+
// MOD-HASH-NEXT: "details": {
76+
// MOD-HASH-NEXT: "swift": {
77+
// MOD-HASH-NEXT: "moduleInterfacePath": "{{.*}}{{/|\\}}F.swiftinterface",
78+
// MOD-HASH: "commandLine": [
79+
// MOD-HASH: "-o",
80+
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH:.*]].swiftmodule",
81+
// MOD-HASH: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-[[SHASH:.*]].swiftmodule",
82+
// MOD-HASH: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-[[SOSHASH:.*]].swiftmodule",
83+
// MOD-HASH: ],
84+
// MOD-HASH: "mainModuleName": "deps1",
85+
// MOD-HASH: "linkLibraries": [],
86+
// MOD-HASH: "details": {
87+
// MOD-HASH-NEXT: "swift": {
88+
// MOD-HASH-NEXT: "moduleInterfacePath": "{{.*}}{{/|\\}}F.swiftinterface",
89+
// MOD-HASH: "commandLine": [
90+
// MOD-HASH: "-o",
91+
// MOD-HASH-NEXT: "{{.*}}{{/|\\}}F-[[FHASH]].swiftmodule",
92+
// MOD-HASH: "-swift-module-file=Swift={{.*}}{{/|\\}}Swift-[[SHASH]].swiftmodule",
93+
// MOD-HASH: "-swift-module-file=SwiftOnoneSupport={{.*}}{{/|\\}}SwiftOnoneSupport-[[SOSHASH]].swiftmodule",
94+
// MOD-HASH: ],

0 commit comments

Comments
 (0)