File: package-cmo-disallow-bypass-resilience-on-deserialization-fail.swift

package info (click to toggle)
swiftlang 6.1.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,791,532 kB
  • sloc: cpp: 9,901,743; ansic: 2,201,431; asm: 1,091,827; python: 308,252; objc: 82,166; f90: 80,126; lisp: 38,358; pascal: 25,559; sh: 20,429; ml: 5,058; perl: 4,745; makefile: 4,484; awk: 3,535; javascript: 3,018; xml: 918; fortran: 664; cs: 573; ruby: 396
file content (173 lines) | stat: -rw-r--r-- 5,216 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/src)
// RUN: %empty-directory(%t/artifacts)
// RUN: %empty-directory(%t/artifacts/ObjcBuilds)
// RUN: %empty-directory(%t/artifacts/SwiftBuilds)
// RUN: split-file %s %t/src

/// Build a clang module with `INCLUDE_FOO`
// RUN: cp %t/src/ObjCAPI.modulemap %t/artifacts/ObjcBuilds/module.modulemap
// RUN: cp %t/src/ObjCAPI.h %t/artifacts/ObjcBuilds/ObjCAPI.h
// RUN: %target-clang -dynamiclib %t/src/ObjCAPI.m -I %t/src -fobjc-arc \
// RUN: -o %t/artifacts/ObjcBuilds/libObjCAPI.dylib -isysroot %sdk -framework Foundation \
// RUN: -fmodules -fmodule-map-file=%t/artifacts/ObjcBuilds/module.modulemap -DINCLUDE_FOO

/// Build a swift module that depends on the clang module with `INCLUDE_FOO`
// RUN: %target-build-swift-dylib(%t/artifacts/SwiftBuilds/%target-library-name(MyCore)) %t/src/Core.swift \
// RUN: -module-name MyCore -emit-module -package-name pkg \
// RUN: -Xfrontend -experimental-package-cmo -Xfrontend -experimental-allow-non-resilient-access \
// RUN: -enable-library-evolution -O -wmo \
// RUN: -I %t/artifacts/ObjcBuilds -L %t/artifacts/ObjcBuilds \
// RUN: -lObjCAPI -Xcc -DINCLUDE_FOO

/// Build a swift module that depends on the above Core swift module without `INCLUDE_FOO`;
/// it should fail and diagnose that there was a deserialization failure.
// RUN: %target-build-swift-dylib(%t/artifacts/SwiftBuilds/%target-library-name(MyUIA)) %t/src/UIA.swift \
// RUN: -module-name MyUIA -emit-module -package-name pkg \
// RUN: -enable-library-evolution -O -wmo \
// RUN: -I %t/artifacts/SwiftBuilds -L %t/artifacts/SwiftBuilds \
// RUN: -I %t/artifacts/ObjcBuilds -L %t/artifacts/ObjcBuilds \
// RUN: -lMyCore -lObjCAPI -Rmodule-loading \
// RUN: 2>&1 | %FileCheck %s --check-prefix=CHECK
// CHECK-DAG: warning: cannot bypass resilience due to member deserialization failure while attempting to access missing member of 'PkgStructA' in module 'MyCore' from module 'MyCore'

/// Build a swift module that depends on Core without `INCLUDE_FOO` but
/// opt out of deserialization checks; it builds even though deserialization failed.
// RUN: %target-build-swift-dylib(%t/artifacts/SwiftBuilds/%target-library-name(MyUIA)) %t/src/UIA.swift \
// RUN: -module-name MyUIA -emit-module -package-name pkg \
// RUN: -enable-library-evolution -O -wmo \
// RUN: -Xfrontend -experimental-skip-deserialization-checks-for-package-cmo \
// RUN: -I %t/artifacts/SwiftBuilds -L %t/artifacts/SwiftBuilds \
// RUN: -I %t/artifacts/ObjcBuilds -L %t/artifacts/ObjcBuilds \
// RUN: -lMyCore -lObjCAPI -Rmodule-loading

/// Build another swift module that depends on Core; since FooObjc is not referenced
/// in the call chain, there's no deserialization failure, and bypassing resilience is allowed.
// RUN: %target-build-swift-dylib(%t/artifacts/SwiftBuilds/%target-library-name(MyUIB)) %t/src/UIB.swift \
// RUN: -module-name MyUIB -emit-module -package-name pkg \
// RUN: -enable-library-evolution -O -wmo \
// RUN: -I %t/artifacts/SwiftBuilds -L %t/artifacts/SwiftBuilds \
// RUN: -I %t/artifacts/ObjcBuilds -L %t/artifacts/ObjcBuilds \
// RUN: -lMyCore -lObjCAPI -Rmodule-loading

// REQUIRES: swift_in_compiler
// REQUIRES: objc_interop


//--- UIA.swift
package import MyCore
package import ObjCAPI

package func testWrapperA(_ arg: WrapperA) {
  print(arg.varA, arg.varAdict, arg.varAarray)
}

package func testKlass(_ arg: Klass) {
  print(arg.kStr, arg.kVar)
}

//--- UIB.swift
public import MyCore
public import ObjCAPI

package func testWrapperB(_ arg: WrapperB) {
  let v = arg.varB
  print(v)
}

package func testKlass(_ arg: Klass) {
  print(arg.kStr, arg.kVar)
}

//--- Core.swift
package import ObjCAPI

package struct WrapperA {
  package var varA: PkgStructA?
  package var varAdict: [String: PkgStructA]?
  package var varAarray: [PkgStructA]?
}

package struct WrapperB {
  package var varB: PkgStructB?
  package var varBstr: String?
}

public protocol PubProto {}

package struct PkgStructA: PubProto {
  package var _pkgVar: FooObjc
  package var pkgVar: AnyObject { _pkgVar.propObjc as AnyObject }
}

package struct PkgStructB: PubProto {
  package var _pkgVar: BarObjc
  package var pkgVar: AnyObject { _pkgVar.propObjc as AnyObject }
}


open class Klass {
  package var kVar: Klass
  package var kStr: String
  package init(arg: Klass) {
    self.kVar = arg
    self.kStr = "asdf"
  }
}

//--- ObjCAPI.h
#import <Foundation/Foundation.h>

@interface BazObjc: NSObject
@end

@interface BarObjc: NSObject
@property (nonatomic, strong) BazObjc *propObjc;
@end

#if INCLUDE_FOO
@interface FooObjc: NSObject
@property (nonatomic, strong) BazObjc *propObjc;
@end
#endif

//--- ObjCAPI.m
#include "ObjCAPI.h"

@implementation BazObjc
- (instancetype)init {
  return [super init];
}
@end

@implementation BarObjc
@synthesize propObjc = _propObjc;

- (instancetype)init {
  self = [super init];
  if (self) {
    _propObjc = [BazObjc new];
  }
  return self;
}
@end

#if INCLUDE_FOO
@implementation FooObjc
@synthesize propObjc = _propObjc;

- (instancetype)init {
  self = [super init];
  if (self) {
    _propObjc = [BazObjc new];
  }
  return self;
}
@end
#endif

//--- ObjCAPI.modulemap
module ObjCAPI {
  header "ObjCAPI.h"
  export *
}