|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: split-file %s %t |
| 3 | + |
| 4 | +/// Verify a function with a cast instruction with an internal decl as dst |
| 5 | +/// does not get serialized with PackageCMO in both scenarios below. |
| 6 | + |
| 7 | +/// Scenario 1. |
| 8 | +// RUN: %target-swift-frontend -emit-sil %t/Lib.swift -package-name pkg \ |
| 9 | +// RUN: -wmo -allow-non-resilient-access -package-cmo \ |
| 10 | +// RUN: -enable-library-evolution -swift-version 5 \ |
| 11 | +// RUN: -Xllvm -sil-print-function=topFunc -o %t/Lib.sil |
| 12 | +// RUN: %FileCheck %s < %t/Lib.sil |
| 13 | + |
| 14 | +/// Scenario 2. |
| 15 | +// RUN: %target-build-swift %t/Mod.swift \ |
| 16 | +// RUN: -module-name=Mod -package-name pkg \ |
| 17 | +// RUN: -parse-as-library -emit-module -emit-module-path %t/Mod.swiftmodule -I%t \ |
| 18 | +// RUN: -Xfrontend -experimental-package-cmo -Xfrontend -experimental-allow-non-resilient-access \ |
| 19 | +// RUN: -O -wmo -enable-library-evolution |
| 20 | +// RUN: %target-sil-opt -enable-sil-verify-all %t/Mod.swiftmodule -o %t/Mod.sil |
| 21 | +// RUN: %FileCheck %s --check-prefix=CHECK-MOD < %t/Mod.sil |
| 22 | + |
| 23 | +//--- Lib.swift |
| 24 | +public class Pub { |
| 25 | + public var pubVar: Int |
| 26 | + public init(_ arg: Int) { |
| 27 | + pubVar = arg |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +class InternalKlass: Pub {} |
| 32 | + |
| 33 | +/// Verify that `InternalKlass` is visited and the instruction containing it is not serialized. |
| 34 | +// CHECK: sil @$s3Lib7topFuncySiAA3PubCF : $@convention(thin) (@guaranteed Pub) -> Int { |
| 35 | +// CHECK: checked_cast_br Pub in {{.*}} to InternalKlass |
| 36 | +public func topFunc(_ arg: Pub) -> Int { |
| 37 | + let x = arg as? InternalKlass |
| 38 | + return x != nil ? 1 : 0 |
| 39 | +} |
| 40 | + |
| 41 | + |
| 42 | +//--- Mod.swift |
| 43 | +struct SymmetricTextChildQuery<Provider: PubProto> { |
| 44 | + var source: Text |
| 45 | + init(_ arg: Text) { |
| 46 | + source = arg |
| 47 | + } |
| 48 | + /// This function references isCollapsible(), which contains an internal decl. |
| 49 | + /// If isCollapsible() were serialized, building a client of this module would fail |
| 50 | + /// due to a linker error: undefined symbol `CollapsibleTextModifier`. |
| 51 | + mutating func updateValue() { |
| 52 | + let resolvedSource = ResolvedStyledText.styledText(canCollapse: source.isCollapsible()) |
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +@frozen |
| 57 | +public struct Text: Equatable, Sendable { |
| 58 | + public init() {} |
| 59 | + @frozen |
| 60 | + @usableFromInline |
| 61 | + package enum Modifier: Equatable { |
| 62 | + case font |
| 63 | + case anyTextModifier(AnyTextModifier) |
| 64 | + |
| 65 | + @usableFromInline |
| 66 | + package static func ==(lhs: Modifier, rhs: Modifier) -> Bool { |
| 67 | + return true |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + @usableFromInline |
| 72 | + package var modifiers = [Modifier]() |
| 73 | + |
| 74 | +} |
| 75 | + |
| 76 | +extension Text { |
| 77 | + /// Verify that function containing an internal decl CollapsibleTextModifier is |
| 78 | + /// not serialized with Package CMO. |
| 79 | + // CHECK-MOD-NOT: sil package [serialized_for_package] [canonical] @$s3Mod4TextV13isCollapsibleSbyF : $@convention(method) (@guaranteed Text) -> Bool { |
| 80 | + // CHECK-MOD-NOT: checked_cast_br AnyTextModifier in {{.*}} : $AnyTextModifier to CollapsibleTextModifier |
| 81 | + package func isCollapsible() -> Bool { |
| 82 | + modifiers.contains { modifier in |
| 83 | + guard case .anyTextModifier(let anyModifier) = modifier |
| 84 | + else { return false } |
| 85 | + return anyModifier is CollapsibleTextModifier |
| 86 | + } |
| 87 | + } |
| 88 | +} |
| 89 | + |
| 90 | +final class CollapsibleTextModifier: AnyTextModifier { |
| 91 | + override func isEqual(to other: AnyTextModifier) -> Bool { |
| 92 | + other is CollapsibleTextModifier |
| 93 | + } |
| 94 | +} |
| 95 | + |
| 96 | +public protocol PubProto { |
| 97 | + var pubVar: String { get set } |
| 98 | +} |
| 99 | + |
| 100 | +public struct PubStruct { |
| 101 | + public static func makeView<P: PubProto>(_ type: P.Type, _ arg: Text) { |
| 102 | + var child = SymmetricTextChildQuery<P>(arg) |
| 103 | + child.updateValue() |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +public class ResolvedStyledText { |
| 108 | + package var canCollapse: Bool |
| 109 | + package init(_ arg: Bool) { |
| 110 | + canCollapse = arg |
| 111 | + } |
| 112 | +} |
| 113 | + |
| 114 | +extension ResolvedStyledText { |
| 115 | + package static func styledText(canCollapse: Bool) -> ResolvedStyledText { |
| 116 | + return ResolvedStyledText(canCollapse) |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +@usableFromInline |
| 121 | +package class AnyTextModifier { |
| 122 | + func isEqual(to other: AnyTextModifier) -> Bool { fatalError() } |
| 123 | +} |
0 commit comments