Skip to content

Commit e40a889

Browse files
committed
Make sure to call SIL default arg generator for a package func
or initializer so the mangled symbol is added to TBD. Resolves rdar://116184295
1 parent 1470023 commit e40a889

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

lib/SIL/IR/SILSymbolVisitor.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,8 @@ class SILSymbolVisitorImpl : public ASTVisitor<SILSymbolVisitorImpl> {
421421
void visitDefaultArguments(ValueDecl *VD, ParameterList *PL) {
422422
auto moduleDecl = VD->getModuleContext();
423423
auto publicDefaultArgGenerators = moduleDecl->isTestingEnabled() ||
424-
moduleDecl->arePrivateImportsEnabled();
424+
moduleDecl->arePrivateImportsEnabled() ||
425+
moduleDecl->getPackage() != nullptr;
425426
if (Ctx.getOpts().PublicSymbolsOnly && !publicDefaultArgGenerators)
426427
return;
427428

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: split-file %s %t
3+
4+
// RUN: %target-build-swift-dylib(%t/%target-library-name(Utils)) %t/Utils.swift -module-name Utils -package-name mypkg -emit-module -emit-module-path %t/Utils.swiftmodule -emit-tbd -emit-tbd-path %t/libUtils.tbd -emit-sil -o %t/utils.sil
5+
// RUN: %FileCheck %s --check-prefix CHECK-TBD < %t/libUtils.tbd
6+
// CHECK-TBD-NOT: _$s5Utils6pubBar3argS2i_tFfA_
7+
// CHECK-TBD: _$s5Utils6pkgBar3argS2i_tF
8+
// CHECK-TBD: _$s5Utils6pkgBar3argS2i_tFfA_
9+
// CHECK-TBD: _$s5Utils6pkgFoo3argS2i_tF
10+
// CHECK-TBD: _$s5Utils6pubBar3argS2i_tF
11+
// CHECK-TBD: _$s5Utils6pubFoo3argS2i_tF
12+
13+
// RUN: %target-build-swift -I %t -L %t -lUtils %s -o %t/main %target-rpath(%t) -package-name mypkg
14+
15+
// RUN: %target-run %t/main %t/%target-library-name(Utils) > %t/run-result.output
16+
// RUN: %FileCheck %s --check-prefix CHECK-RUN < %t/run-result.output
17+
18+
//--- Utils.swift
19+
public func pubBar(arg: Int = 1) -> Int { return arg + 11 }
20+
package func pkgBar(arg: Int = 1) -> Int { return arg + 12 }
21+
func internalBar(arg: Int = 1) -> Int { return arg + 13 }
22+
23+
public func pubFoo(arg: Int) -> Int { return arg + 1 }
24+
package func pkgFoo(arg: Int) -> Int { return arg + 2 }
25+
func internalFoo(arg: Int) -> Int { return arg + 3 }
26+
27+
//--- main.swift
28+
import Utils
29+
30+
let a = pubBar()
31+
let b = pkgBar()
32+
33+
let c = pubFoo(arg: 3)
34+
let d = pkgFoo(arg: 5)
35+
36+
print(a, b, c, d) // CHECK-RUN: 12 13 4 7

0 commit comments

Comments
 (0)