Skip to content

Commit 6cb0c20

Browse files
committed
cross-module-optimiations: Fix an compiler crash and a wrong linkage
In case a property is more visible than its container, an assert was triggering in ValueDecl::isUsableFromInline(). rdar://problem/62403317
1 parent b2ba0e8 commit 6cb0c20

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

lib/SILOptimizer/IPO/CrossModuleSerializationSetup.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ static void makeDeclUsableFromInline(ValueDecl *decl, SILModule &M) {
129129
if (decl->getEffectiveAccess() >= AccessLevel::Public)
130130
return;
131131

132-
if (!decl->isUsableFromInline()) {
132+
if (decl->getFormalAccess() < AccessLevel::Public &&
133+
!decl->isUsableFromInline()) {
133134
// Mark the nominal type as "usableFromInline".
134135
// TODO: find a way to do this without modifying the AST. The AST should be
135136
// immutable at this point.
@@ -244,15 +245,15 @@ prepareInstructionForSerialization(SILInstruction *inst) {
244245
void CrossModuleSerializationSetup::handleReferencedFunction(SILFunction *func) {
245246
if (!func->isDefinition() || func->isAvailableExternally())
246247
return;
248+
if (func->isSerialized() == IsSerialized)
249+
return;
250+
247251
if (func->getLinkage() == SILLinkage::Shared) {
248252
assert(func->isThunk() != IsNotThunk &&
249253
"only thunks are accepted to have shared linkage");
250254
assert(canSerialize(func, /*lookIntoThunks*/ false) &&
251255
"we should already have checked that the thunk is serializable");
252256

253-
if (func->isSerialized() == IsSerialized)
254-
return;
255-
256257
// We cannot make shared functions "usableFromInline", i.e. make them Public
257258
// because this could result in duplicate-symbol errors. Instead we make
258259
// them "@alwaysEmitIntoClient"

test/SILOptimizer/Inputs/cross-module.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,25 @@ public class FooClass: PrivateProto {
162162
}
163163
}
164164

165+
final class Internalclass {
166+
public var publicint: Int = 27
167+
}
168+
169+
final public class Outercl {
170+
var ic: Internalclass = Internalclass()
171+
}
172+
173+
@inline(never)
174+
public func classWithPublicProperty<T>(_ t: T) -> Int {
175+
return createInternal().ic.publicint
176+
}
177+
178+
@inline(never)
179+
func createInternal() -> Outercl {
180+
return Outercl()
181+
}
182+
183+
165184
@inline(never)
166185
@_semantics("optimize.sil.specialize.generic.never")
167186
fileprivate func callProtocolFoo<T: PrivateProto>(_ t: T) {

test/SILOptimizer/cross-module-optimization.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,9 @@ func testMisc() {
118118
// CHECK-OUTPUT: 42
119119
// CHECK-SIL-DAG: sil shared {{.*}} @$s4Test13callUnrelatedyxxlFSi_Tg5
120120
print(callUnrelated(42))
121+
122+
// CHECK-OUTPUT: 27
123+
print(classWithPublicProperty(33))
121124
}
122125

123126
testNestedTypes()

0 commit comments

Comments
 (0)