|
| 1 | +// RUN: %empty-directory(%t) |
| 2 | +// RUN: split-file %s %t |
| 3 | + |
| 4 | +// RUN: %target-swift-frontend -emit-module -wmo -enable-default-cmo -parse-as-library %t/Lib.swift -emit-module-path=%t/Lib.swiftmodule -module-name=Lib -enable-testing -I%t |
| 5 | +// RUN: %target-sil-opt %t/Lib.swiftmodule -sil-verify-all -o %t/Lib.sil |
| 6 | +// RUN: %FileCheck %s < %t/Lib.sil |
| 7 | + |
| 8 | +/// Deserializing Lib module should not cause an assert fail. |
| 9 | +// RUN: %target-swift-frontend -emit-sil -sil-verify-all -wmo %t/Client.swift -I%t |
| 10 | + |
| 11 | +// REQUIRES: swift_in_compiler |
| 12 | +// REQUIRES: asserts |
| 13 | + |
| 14 | +//--- Client.swift |
| 15 | +@testable import Lib |
| 16 | + |
| 17 | +//--- Lib.swift |
| 18 | +import Foundation |
| 19 | + |
| 20 | +public class PubKlass { |
| 21 | + var field = InternalStruct() |
| 22 | + |
| 23 | + // CHECK-NOT: sil [serialized] [ossa] @$s3Lib8PubKlassC3run4fromQrAA0B6StructV_tF : $@convention(method) (PubStruct, @guaranteed PubKlass) -> @out @_opaqueReturnTypeOf("$s3Lib8PubKlassC3run4fromQrAA0B6StructV_tF", 0) __ { |
| 24 | + // CHECK-NOT: function_ref @$s3Lib14InternalStructV3run4fromQrAA03PubC0V_tF : $@convention(method) (PubStruct, @guaranteed InternalStruct) -> @out LazyMapSequence<IteratorSequence<EntityIterator<PubStruct>>, InternalStruct.Klass> |
| 25 | + // CHECK: sil [canonical] @$s3Lib8PubKlassC3run4fromQrAA0B6StructV_tF : $@convention(method) (PubStruct, @guaranteed PubKlass) -> @out @_opaqueReturnTypeOf("$s3Lib8PubKlassC3run4fromQrAA0B6StructV_tF", 0) __ |
| 26 | + func run(from arg: PubStruct) -> some Sequence<InternalStruct.Klass> { |
| 27 | + field.run(from: arg) |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +public struct PubStruct: Hashable { } |
| 32 | + |
| 33 | +struct InternalStruct: Hashable { |
| 34 | + class Klass: Hashable { |
| 35 | + let data: PubStruct |
| 36 | + init(_ arg: PubStruct) { |
| 37 | + self.data = arg |
| 38 | + } |
| 39 | + func hash(into hasher: inout Hasher) { |
| 40 | + hasher.combine(data) |
| 41 | + } |
| 42 | + static func == (lhs: Klass, rhs: Klass) -> Bool { |
| 43 | + return lhs.data == rhs.data |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + var entities: [PubStruct: Klass] = [:] |
| 48 | + |
| 49 | + func run(from arg: PubStruct) -> some Sequence<Klass> { |
| 50 | + IteratorSequence(EntityIterator(from: arg)) |
| 51 | + .lazy.map { entities[$0]! } |
| 52 | + } |
| 53 | +} |
| 54 | + |
| 55 | + |
| 56 | +private struct EntityIterator<T: Hashable>: IteratorProtocol { |
| 57 | + private var list: [T] |
| 58 | + init(from start: T) { |
| 59 | + self.list = [start] |
| 60 | + } |
| 61 | + private mutating func pop() -> T? { |
| 62 | + return nil |
| 63 | + } |
| 64 | + mutating func next() -> T? { |
| 65 | + return nil |
| 66 | + } |
| 67 | +} |
| 68 | + |
| 69 | + |
0 commit comments