Skip to content

Commit 0c75641

Browse files
committed
fixed name deduplication logic
1 parent 41bed08 commit 0c75641

File tree

8 files changed

+20
-11
lines changed

8 files changed

+20
-11
lines changed

.github/scripts/validate_samples.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ declare -r CI_VALIDATE_SCRIPT='ci-validate.sh'
1212
for samplePackage in ${SAMPLE_PACKAGES} ; do
1313
sampleDir=$(dirname "$samplePackage")
1414

15-
15+
echo ""
16+
echo ""
1617
echo "========================================================================"
1718
printf "Validate sample: '${BOLD}%s${RESET}' using: " "$sampleDir"
1819
cd "$sampleDir" || exit

Samples/JExtractPluginSampleApp/JExtractPluginSampleLibModule+SwiftJava.d

Lines changed: 0 additions & 1 deletion
This file was deleted.
Binary file not shown.

Samples/JExtractPluginSampleApp/MyCoolSwiftClass+SwiftJava.d

Lines changed: 0 additions & 1 deletion
This file was deleted.
-9.64 KB
Binary file not shown.

Sources/JExtractSwift/ThunkNameRegistry.swift

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,17 @@
1717
package struct ThunkNameRegistry {
1818
/// Maps base names such as "swiftjava_Module_Type_method_a_b_c" to the number of times we've seen them.
1919
/// This is used to de-duplicate symbols as we emit them.
20-
private var registry: [ImportedFunc: Int] = [:]
20+
private var registry: [ImportedFunc: String] = [:]
21+
private var duplicateNames: [String: Int] = [:]
2122

2223
package init() {}
2324

2425
package mutating func functionThunkName(
2526
module: String, decl: ImportedFunc,
2627
file: String = #fileID, line: UInt = #line) -> String {
27-
let emittedCount = self.registry[decl, default: 0]
28-
defer { self.registry[decl] = emittedCount + 1 }
28+
if let existingName = self.registry[decl] {
29+
return existingName
30+
}
2931

3032
let params = decl.effectiveParameters(paramPassingStyle: .swiftThunkSelf)
3133
var paramsPart = ""
@@ -42,10 +44,18 @@ package struct ThunkNameRegistry {
4244
"swiftjava_\(module)_\(decl.baseIdentifier)\(paramsPart)"
4345
}
4446

45-
if emittedCount == 0 {
46-
return name // first occurrence of a name we keep as-is
47-
} else {
48-
return "\(name)$\(emittedCount)"
49-
}
47+
let emittedCount = self.duplicateNames[name, default: 0]
48+
defer { self.duplicateNames[name] = emittedCount + 1 }
49+
50+
let deduplicatedName =
51+
if emittedCount == 0 {
52+
name // first occurrence of a name we keep as-is
53+
} else {
54+
"\(name)$\(emittedCount)"
55+
}
56+
57+
// Store the name we assigned to this specific decl.
58+
self.registry[decl] = deduplicatedName
59+
return deduplicatedName
5060
}
5161
}

0 commit comments

Comments
 (0)