Skip to content

Commit b9bda84

Browse files
committed
SIL: Fix calls of @_weakLinked functions from serialized SIL
We have to set the SILFunction's 'weakLinked' flag in the defining module too, so that it can be serialized. Otherwise when we deserialize it we are not weak linking calls to the function.
1 parent 2633c9d commit b9bda84

File tree

4 files changed

+37
-2
lines changed

4 files changed

+37
-2
lines changed

lib/AST/Decl.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,8 @@ bool Decl::isWeakImported(ModuleDecl *fromModule,
548548
return false;
549549

550550
auto containingContext =
551-
AvailabilityInference::availableRange(this, fromModule->getASTContext());
551+
AvailabilityInference::availableRange(this,
552+
containingModule->getASTContext());
552553
if (!fromContext.isContainedIn(containingContext))
553554
return true;
554555

lib/SIL/SILFunctionBuilder.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ SILFunctionBuilder::getOrCreateFunction(SILLocation loc, SILDeclRef constant,
155155
if (constant.isForeign && decl->hasClangNode())
156156
F->setClangNodeOwner(decl);
157157

158-
if (decl->isWeakImported(mod.getSwiftModule(), availCtx))
158+
if (decl->isWeakImported(/*forModule=*/nullptr, availCtx))
159159
F->setWeakLinked();
160160

161161
if (auto *accessor = dyn_cast<AccessorDecl>(decl)) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
public func getVersion() -> Int {
2+
#if BEFORE
3+
return 0
4+
#else
5+
return 1
6+
#endif
7+
}
8+
9+
#if AFTER
10+
@_weakLinked @usableFromInline func weakFunction() -> String {
11+
return "new"
12+
}
13+
14+
@_alwaysEmitIntoClient public func serializedFunction() -> String {
15+
if getVersion() == 1 {
16+
return weakFunction()
17+
}
18+
return "old"
19+
}
20+
#endif
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %target-resilience-test --backward-deployment
2+
// REQUIRES: executable_test
3+
4+
import StdlibUnittest
5+
import backward_deploy_always_emit_into_client
6+
7+
8+
var BackwardDeployTopLevelTest = TestSuite("BackwardDeployAlwaysEmitIntoClient")
9+
10+
BackwardDeployTopLevelTest.test("BackwardDeployAlwaysEmitIntoClient") {
11+
expectEqual(serializedFunction(), getVersion() == 1 ? "new" : "old")
12+
}
13+
14+
runAllTests()

0 commit comments

Comments
 (0)