peachsim 0.1.1716 → 0.1.1728
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +21 -3
- package/cli/app-bundle-resources.ts +2 -1
- package/cli/app-fonts.ts +4 -4
- package/cli/app-splash.ts +4 -4
- package/cli/app-stubs.ts +17 -0
- package/cli/command-registry.ts +1 -0
- package/cli/commands/control.ts +82 -822
- package/cli/commands/daemon.ts +8 -0
- package/cli/commands/detox.ts +3 -0
- package/cli/commands/doctor.ts +19 -2
- package/cli/commands/inspect/actions.ts +74 -14
- package/cli/commands/inspect/core.ts +5 -1
- package/cli/commands/inspect/settling.ts +5 -2
- package/cli/commands/inspect/wait-ready.ts +6 -0
- package/cli/commands/inspect.ts +48 -45
- package/cli/commands/kotlin.ts +12 -2
- package/cli/commands/package.ts +750 -0
- package/cli/commands/serve.ts +6 -0
- package/cli/commands/shell-url.ts +834 -0
- package/cli/commands/swift.ts +42 -102
- package/cli/commands/test.ts +20 -0
- package/cli/commands/upload.ts +1 -1
- package/cli/device-option.ts +1 -1
- package/cli/main.ts +13 -1
- package/cli/native-input.ts +199 -0
- package/cli/outbound-endpoints.ts +26 -1
- package/cli/packaged-app-launcher.ts +95 -0
- package/cli/scene-video.ts +13 -6
- package/detox/index.ts +187 -23
- package/dist-lib/agent-daemon-client.cjs +1 -1
- package/dist-lib/agent-events.cjs +1 -1
- package/dist-lib/attached-projects.cjs +1 -1
- package/dist-lib/auth/shared-session.cjs +1 -1
- package/dist-lib/backend-origin.cjs +1 -1
- package/dist-lib/beta.cjs +1 -1
- package/dist-lib/beta.mjs +1 -1
- package/dist-lib/bridge-constants.cjs +1 -1
- package/dist-lib/bridge-contract-input.cjs +1 -1
- package/dist-lib/bridge-contract-input.mjs +1 -1
- package/dist-lib/bridge-contract.cjs +1 -1
- package/dist-lib/bridge-contract.mjs +1 -1
- package/dist-lib/bundle-channel.cjs +38000 -31658
- package/dist-lib/capture-contract.cjs +1 -1
- package/dist-lib/capture-contract.mjs +1 -1
- package/dist-lib/cloud-contract.cjs +1 -1
- package/dist-lib/cloud-contract.mjs +1 -1
- package/dist-lib/cloud-test-args.cjs +1 -1
- package/dist-lib/cloud-test-args.mjs +1 -1
- package/dist-lib/cloud.cjs +1 -1
- package/dist-lib/cloud.mjs +1 -1
- package/dist-lib/config.cjs +1 -1
- package/dist-lib/config.mjs +1 -1
- package/dist-lib/detox/index.cjs +184 -60
- package/dist-lib/dev-bundle-resolution.cjs +14 -13
- package/dist-lib/expo-swift-bundle.cjs +18199 -11834
- package/dist-lib/expo-swift-metadata.cjs +4 -1
- package/dist-lib/expo-swift-metadata.mjs +3 -1
- package/dist-lib/home-paths.cjs +21 -2
- package/dist-lib/host/bridge-host.cjs +26509 -23850
- package/dist-lib/host/fetch-proxy-handler.cjs +221 -222
- package/dist-lib/host/fetch-proxy-overrides.cjs +1 -1
- package/dist-lib/host/fetch-proxy-overrides.mjs +1 -1
- package/dist-lib/host/replacement-module-handler.cjs +1 -1
- package/dist-lib/host/websocket-proxy.cjs +1 -1
- package/dist-lib/index.cjs +876 -389
- package/dist-lib/jump-to-source-babel.cjs +1 -1
- package/dist-lib/jump-to-source-native.cjs +1 -1
- package/dist-lib/kotlin-host.cjs +127 -16
- package/dist-lib/menu.cjs +7 -1
- package/dist-lib/menu.mjs +7 -1
- package/dist-lib/metro-fingerprint-registry.cjs +1 -1
- package/dist-lib/metro-fingerprint-registry.mjs +1 -1
- package/dist-lib/metro-production-bundle.cjs +1 -1
- package/dist-lib/metro-production-bundle.mjs +1 -1
- package/dist-lib/metro.cjs +883 -404
- package/dist-lib/native-app-identity-project.cjs +694 -280
- package/dist-lib/native-app-identity-project.mjs +490 -83
- package/dist-lib/native-app-identity.cjs +13 -2
- package/dist-lib/native-app-identity.mjs +13 -2
- package/dist-lib/native-firebase-metadata.cjs +1 -1
- package/dist-lib/native-firebase-metadata.mjs +1 -1
- package/dist-lib/plist.cjs +1 -1
- package/dist-lib/plist.mjs +1 -1
- package/dist-lib/profiles.cjs +1 -1
- package/dist-lib/public-brand.cjs +1 -1
- package/dist-lib/public-origins-lib-esm.json +28 -23
- package/dist-lib/public-origins-lib.json +392 -224
- package/dist-lib/react-native-host-modules.cjs +32 -2
- package/dist-lib/react-native-host-modules.mjs +32 -2
- package/dist-lib/reap-browser.cjs +12 -4
- package/dist-lib/scripts/dev-server-scanner.cjs +15 -8
- package/dist-lib/sdk.cjs +17 -7
- package/dist-lib/sdk.mjs +16 -7
- package/dist-lib/skills.cjs +61838 -47851
- package/dist-lib/swift-compile.cjs +583 -360
- package/dist-lib/swift-compile.mjs +496 -275
- package/dist-lib/swift-package.cjs +1 -1
- package/dist-lib/swift-package.mjs +1 -1
- package/dist-lib/swift-submit.cjs +2 -2
- package/dist-lib/swift-submit.mjs +2 -2
- package/dist-lib/swift-toolchain.cjs +105 -17
- package/dist-lib/swift.cjs +1 -1
- package/dist-lib/vite-swift.cjs +4453 -2231
- package/dist-lib/vite.cjs +230 -228
- package/dist-lib/worklet-executable.cjs +1 -1
- package/dist-lib/worklet-executable.mjs +1 -1
- package/dist-types/packages/peach-compat/src/stubs/native-seams/react-native-cookies.d.ts +17 -8
- package/dist-types/packages/peach-engine/src/engine/canvaskit-renderer.d.ts +1 -0
- package/dist-types/packages/peach-engine/src/engine/image-loader.d.ts +7 -5
- package/dist-types/packages/peach-engine/src/engine/memory-counts.d.ts +3 -1
- package/dist-types/packages/peach-engine/src/engine/node.d.ts +1 -11
- package/dist-types/packages/peach-engine/src/engine/types.d.ts +3 -0
- package/dist-types/packages/peach-engine/src/render-worker/compositor-protocol.d.ts +9 -0
- package/dist-types/packages/peach-engine/src/render-worker/host-service-protocol.d.ts +3 -0
- package/dist-types/packages/peach-engine/src/render-worker/native-ui-commandContract.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/render-worker/shell-protocol.d.ts +4 -0
- package/dist-types/packages/peach-engine/src/render-worker/tree-sync-port.d.ts +1 -1
- package/dist-types/packages/peach-engine/src/render-worker/worklet-runtime.d.ts +23 -1
- package/dist-types/packages/peach-engine/src/shell-events.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/audioBridgeContract.d.ts +5 -0
- package/dist-types/packages/peach-globals/src/index.d.ts +1 -1
- package/dist-types/packages/peach-globals/src/keyboardBridgeContract.d.ts +11 -0
- package/dist-types/packages/peach-globals/src/shellBridgeContract.d.ts +1 -0
- package/dist-types/packages/peach-globals/src/testBridgeContract.d.ts +9 -2
- package/package.json +1 -1
- package/runtime-companion.json +1 -1
- package/scripts/dev-server-scanner.ts +12 -25
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASFoundation.h +52 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSession.h +128 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/ASWebAuthenticationSessionCallback.h +35 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Headers/AuthenticationServices.h +3 -0
- package/sdk/ios/System/Library/Frameworks/AuthenticationServices.framework/Modules/module.modulemap +5 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFHTTPMessage.h +724 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetwork.h +4 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Headers/CFNetworkDefs.h +27 -0
- package/sdk/ios/System/Library/Frameworks/CFNetwork.framework/Modules/module.modulemap +5 -0
- package/sdk/ios/System/Library/Frameworks/CoreFoundation.framework/Headers/CFURL.h +1301 -0
- package/sdk/ios/System/Library/Frameworks/CoreGraphics.framework/Headers/CoreGraphics.h +2 -0
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLLocationManager.h +21 -50
- package/sdk/ios/System/Library/Frameworks/CoreLocation.framework/Headers/CLRegion.h +6 -6
- package/sdk/ios/System/Library/Frameworks/Foundation.framework/Headers/Foundation.h +75 -9
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIApplication.h +12 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIInterface.h +23 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIKit.h +7 -9
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIOrientation.h +14 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIStringDrawing.h +12 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIView.h +14 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewAnimating.h +12 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIViewController.h +16 -0
- package/sdk/ios/System/Library/Frameworks/UIKit.framework/Headers/UIWindow.h +2 -0
- package/sdk/ios/usr/include/ConditionalMacros.h +619 -0
- package/sdk/ios/usr/include/module.modulemap +1 -0
- package/sdk/ios/usr/include/objc/objc-sync.h +59 -0
- package/sdk/ios/usr/include/os.modulemap +5 -0
- package/sdk/ios/usr/include/sys/cdefs.h +5 -0
- package/sdk/ios/usr/include/sys/ioccom.h +99 -0
- package/sdk/ios/usr/include/sys/syslog.h +236 -0
- package/sdk/ios/usr/include/syslog.h +24 -0
- package/sdk/ios/wasm/include/fcntl.h +4 -2
- package/sdk/ios/wasm/include/stdio.h +24 -0
- package/sdk/ios/wasm/include/stdlib.h +32 -7
- package/sdk/ios/wasm/include/sys/file.h +7 -0
- package/sdk/ios/wasm/include/sys/ioctl.h +6 -0
- package/sdk/ios/wasm/include/sys/syscall.h +9 -0
- package/sdk/ios/wasm/include/sys/time.h +10 -0
- package/sdk/ios/wasm/include/unistd.h +12 -3
- package/sdk/native-hashes.json +1 -0
- package/skills/contrast/SKILL.md +2 -1
- package/skills/peach-test/SKILL.md +7 -3
- package/src/admitted-mac-build.ts +3 -0
- package/src/android-app-identity.ts +18 -0
- package/src/android-root-module.ts +9 -9
- package/src/appPackageContract.ts +81 -0
- package/src/bridge-contract.ts +50 -0
- package/src/bundle-channel.mjs +21 -4
- package/src/dev-bundle-resolution.ts +7 -27
- package/src/dom-source-reference.ts +15 -0
- package/src/expo-discovery-cache.ts +127 -23
- package/src/expo-manifest-body.ts +33 -0
- package/src/expo-native-workspace.ts +38 -13
- package/src/expo-swift-host.ts +264 -62
- package/src/expoSwiftContract.ts +3 -0
- package/src/generated/swift-c-predefines.json +1 -1
- package/src/home-paths.ts +35 -1
- package/src/host/app-package-handler.ts +47 -0
- package/src/host/bridge-host.ts +3 -0
- package/src/host/staged-host-files.ts +18 -0
- package/src/index.ts +3 -0
- package/src/kotlin-host.ts +21 -18
- package/src/kotlin-instance-source.ts +126 -0
- package/src/menu.ts +7 -0
- package/src/native-app-identity-project.ts +7 -2
- package/src/native-app-identity.ts +11 -0
- package/src/native-firebase-config.ts +24 -1
- package/src/nitro-adapter.lock.json +268 -268
- package/src/nitro-bundle.ts +8 -0
- package/src/nitro-compile.ts +35 -9
- package/src/nitro-dependencies.ts +21 -19
- package/src/nitro-source.ts +4 -0
- package/src/nitroContract.ts +7 -0
- package/src/react-native-bridge-modules.ts +68 -42
- package/src/react-native-host-modules.ts +31 -1
- package/src/reactNativeConfigurationContract.ts +14 -0
- package/src/reap-browser.ts +15 -3
- package/src/sdk.ts +5 -0
- package/src/settingsContract.ts +27 -1
- package/src/sim-client.ts +4 -1
- package/src/storageSnapshotContract.ts +3 -0
- package/src/swift-compile.ts +221 -41
- package/src/swift-coverage/provenance.ts +1 -0
- package/src/swift-coverage/xcode-asset-symbols.ts +922 -0
- package/src/swift-coverage/xcode-assets.ts +89 -131
- package/src/swift-coverage/xcode.ts +1 -1
- package/src/swift-cxx-reachable.ts +2 -1
- package/src/swift-distribution.lock.json +14 -13
- package/src/swift-host.ts +95 -22
- package/src/swift-icu.ts +1 -1
- package/src/swift-link-roots.ts +118 -0
- package/src/swift-objc-compile.ts +144 -22
- package/src/swift-objc-import.ts +6 -0
- package/src/swift-objc-standin.ts +2 -14
- package/src/swift-package-manifest.ts +14 -6
- package/src/swift-packages.ts +75 -11
- package/src/swift-pdf-raster.ts +1 -0
- package/src/swift-root-lock.ts +17 -1
- package/src/swift-source-pods.ts +2 -10
- package/src/swift-standin-emit.ts +592 -57
- package/src/swift-standins.ts +430 -49
- package/src/swift-submit.ts +3 -1
- package/src/swift-toolchain.ts +140 -17
- package/src/turbo-codegen-intake.ts +91 -0
- package/src/vite-plugin-one.ts +13 -9
- package/src/vite-plugin.ts +28 -15
- package/src/xcode-project.ts +223 -22
|
@@ -21,6 +21,11 @@ export type GraphSymbol = {
|
|
|
21
21
|
declarationFragments?: SymbolFragment[]
|
|
22
22
|
accessLevel: string
|
|
23
23
|
functionSignature?: { returns?: SymbolFragment[] }
|
|
24
|
+
swiftExtension?: { extendedModule: string; typeKind: string }
|
|
25
|
+
swiftGenerics?: {
|
|
26
|
+
parameters?: { name: string }[]
|
|
27
|
+
constraints?: { kind: string; lhs: string; rhsPrecise?: string }[]
|
|
28
|
+
}
|
|
24
29
|
availability?: {
|
|
25
30
|
domain?: string
|
|
26
31
|
isUnconditionallyUnavailable?: boolean
|
|
@@ -32,6 +37,7 @@ export type GraphRelationship = {
|
|
|
32
37
|
source: string
|
|
33
38
|
target: string
|
|
34
39
|
targetFallback?: string
|
|
40
|
+
sourceOrigin?: { identifier: string; displayName: string }
|
|
35
41
|
}
|
|
36
42
|
export type SymbolGraph = {
|
|
37
43
|
module: { name: string }
|
|
@@ -48,6 +54,12 @@ export type StandinOptions = {
|
|
|
48
54
|
inert?: boolean
|
|
49
55
|
/** modules the source imports beside Foundation and UIKit. */
|
|
50
56
|
imports?: string[]
|
|
57
|
+
/** `@_exported import` lines a placeholder's sources declare, verbatim. */
|
|
58
|
+
exported?: string[]
|
|
59
|
+
/** for a placeholder package's target: the compiler gap that forces it. */
|
|
60
|
+
placeholder?: string
|
|
61
|
+
/** exact imported type identifier → module, established by the native compiler. */
|
|
62
|
+
importedTypeModules?: ReadonlyMap<string, string>
|
|
51
63
|
/** precise symbol id → swift literal for enum cases and option values. */
|
|
52
64
|
values?: ReadonlyMap<string, string>
|
|
53
65
|
/** measured behavior by declaration path (Type.member(label:)). */
|
|
@@ -56,6 +68,8 @@ export type StandinOptions = {
|
|
|
56
68
|
family?: string[]
|
|
57
69
|
/** paths left out, with why: the compiler rejected their declaration. */
|
|
58
70
|
omit?: ReadonlyMap<string, string>
|
|
71
|
+
/** inert paths whose return value the compiler rejected: their bodies trap. */
|
|
72
|
+
trapped?: ReadonlySet<string>
|
|
59
73
|
/** paths the graph says override but the compiler finds nothing to override */
|
|
60
74
|
plain?: ReadonlySet<string>
|
|
61
75
|
/** paths the compiler says must be marked override */
|
|
@@ -64,6 +78,8 @@ export type StandinOptions = {
|
|
|
64
78
|
operators?: ReadonlyMap<string, string>
|
|
65
79
|
/** class path → its generic superclass with arguments, from the swiftinterface */
|
|
66
80
|
superclasses?: ReadonlyMap<string, string>
|
|
81
|
+
/** clang property selectors keyed by the native protocol property USR. */
|
|
82
|
+
objcProperties?: ReadonlyMap<string, { getter: string; setter?: string }>
|
|
67
83
|
}
|
|
68
84
|
|
|
69
85
|
export type StandinBehavior = {
|
|
@@ -129,7 +145,8 @@ function splitAccessors(core: string) {
|
|
|
129
145
|
const KEEP_EXTERNAL = new Map([
|
|
130
146
|
['s:SH', 'Hashable'],
|
|
131
147
|
['s:SQ', 'Equatable'],
|
|
132
|
-
|
|
148
|
+
// qualified: a module's own `Error` type would otherwise shadow it
|
|
149
|
+
['s:s5ErrorP', 'Swift.Error'],
|
|
133
150
|
['s:s8SendableP', 'Sendable'],
|
|
134
151
|
['s:s12IdentifiableP', 'Identifiable'],
|
|
135
152
|
['s:SY', 'RawRepresentable'],
|
|
@@ -138,18 +155,27 @@ const KEEP_EXTERNAL = new Map([
|
|
|
138
155
|
['s:SE', 'Encodable'],
|
|
139
156
|
['s:Se', 'Decodable'],
|
|
140
157
|
['s:s23CustomStringConvertibleP', 'CustomStringConvertible'],
|
|
158
|
+
['s:s9CodingKeyP', 'CodingKey'],
|
|
141
159
|
])
|
|
142
160
|
const LEADING_ATTRS = /^((?:@\w+(?:\([^)]*\))?\s*|nonisolated\s+)*)(.*)$/s
|
|
143
161
|
|
|
144
|
-
//
|
|
162
|
+
// clang-imported protocols are adapted to swift protocols below. declarations
|
|
163
|
+
// originating in swift retain their objective-c attributes and selectors.
|
|
145
164
|
const OBJC_ONLY =
|
|
146
165
|
/@(?:objcMembers|objc|IBOutlet|IBInspectable|IBAction|IBSegueAction|GKInspectable|nonobjc|NSCopying|NSManaged)(?:\([^)]*\))?\s*|\bdynamic\s+/g
|
|
166
|
+
export const isSwiftDeclaration = (symbol: GraphSymbol) =>
|
|
167
|
+
symbol.identifier.precise.startsWith('s:') || /^c:@C?M@/.test(symbol.identifier.precise)
|
|
168
|
+
const isObjC = (symbol: GraphSymbol) =>
|
|
169
|
+
symbol.identifier.precise.startsWith('c:') && !isSwiftDeclaration(symbol)
|
|
147
170
|
const text = (symbol: GraphSymbol) =>
|
|
148
|
-
(symbol
|
|
149
|
-
.
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
171
|
+
(isObjC(symbol)
|
|
172
|
+
? (symbol.declarationFragments ?? [])
|
|
173
|
+
.map((fragment) => fragment.spelling)
|
|
174
|
+
.join('')
|
|
175
|
+
.replace(OBJC_ONLY, '')
|
|
176
|
+
.replace(/(^|\s)optional (?=func|var|init|subscript|static|class)/, '$1')
|
|
177
|
+
: (symbol.declarationFragments ?? []).map((fragment) => fragment.spelling).join('')
|
|
178
|
+
)
|
|
153
179
|
// swift-corelibs-foundation has no autoreleasing spelling; peach's own
|
|
154
180
|
// AVFoundation scaffolds the same alias onto a plain pointer.
|
|
155
181
|
.replace(/\bAutoreleasingUnsafeMutablePointer</g, 'UnsafeMutablePointer<')
|
|
@@ -169,7 +195,6 @@ const witnessKey = (symbol: GraphSymbol) =>
|
|
|
169
195
|
.trim()}`
|
|
170
196
|
const sideLeaf = (symbol: GraphSymbol) =>
|
|
171
197
|
`${symbol.kind.identifier.startsWith('swift.type.') ? 'type' : 'instance'}|leaf|${leaf(symbol)}`
|
|
172
|
-
const isObjC = (symbol: GraphSymbol) => symbol.identifier.precise.startsWith('c:')
|
|
173
198
|
// equality and hashing the compiler synthesizes from real state (a stored
|
|
174
199
|
// rawValue, or cases without payloads) under a declared conformance; a
|
|
175
200
|
// trapping spelling would shadow the working witness, so a set or dictionary
|
|
@@ -178,12 +203,10 @@ const synthesizedEquality = (symbol: GraphSymbol, conforms: string[]) =>
|
|
|
178
203
|
conforms.includes('Hashable')
|
|
179
204
|
? ['==(_:_:)', 'hash(into:)', 'hashValue'].includes(leaf(symbol))
|
|
180
205
|
: conforms.includes('Equatable') && leaf(symbol) === '==(_:_:)'
|
|
181
|
-
const trap = (path: string) =>
|
|
182
|
-
`fatalError("${path} is a binary framework peach cannot run")`
|
|
183
206
|
|
|
184
|
-
//
|
|
185
|
-
//
|
|
186
|
-
//
|
|
207
|
+
// graphs can drop imported type qualification, making equal leaves ambiguous.
|
|
208
|
+
// a swift usr identifies its top-level module; clang usrs need a mapping proven
|
|
209
|
+
// by the native compiler because they do not encode the swift module.
|
|
187
210
|
const swiftTopLevel = /^s:(\d+)(\D.*)$/s
|
|
188
211
|
const importedModule = (id: string) => {
|
|
189
212
|
const match = swiftTopLevel.exec(id)
|
|
@@ -195,13 +218,25 @@ const importedModule = (id: string) => {
|
|
|
195
218
|
? name
|
|
196
219
|
: null
|
|
197
220
|
}
|
|
198
|
-
function qualifyImportedTypes(
|
|
221
|
+
function qualifyImportedTypes(
|
|
222
|
+
graph: SymbolGraph,
|
|
223
|
+
imported: Set<string>,
|
|
224
|
+
importedTypeModules: ReadonlyMap<string, string>,
|
|
225
|
+
): SymbolGraph {
|
|
199
226
|
const qualify = (fragment: SymbolFragment) => {
|
|
227
|
+
const provenModule =
|
|
228
|
+
fragment.kind === 'typeIdentifier' && fragment.preciseIdentifier
|
|
229
|
+
? importedTypeModules.get(fragment.preciseIdentifier)
|
|
230
|
+
: undefined
|
|
200
231
|
const module =
|
|
201
232
|
fragment.kind === 'typeIdentifier' && fragment.preciseIdentifier
|
|
202
|
-
? importedModule(fragment.preciseIdentifier)
|
|
233
|
+
? (provenModule ?? importedModule(fragment.preciseIdentifier))
|
|
203
234
|
: null
|
|
204
|
-
|
|
235
|
+
// implicit imports can omit native swift types on the guest.
|
|
236
|
+
return module &&
|
|
237
|
+
(imported.has(module) ||
|
|
238
|
+
(provenModule === module && STANDIN_IMPORTS.includes(module))) &&
|
|
239
|
+
/^\w+$/.test(fragment.spelling)
|
|
205
240
|
? { ...fragment, spelling: `${module}.${fragment.spelling}` }
|
|
206
241
|
: fragment
|
|
207
242
|
}
|
|
@@ -218,12 +253,80 @@ function qualifyImportedTypes(graph: SymbolGraph, imported: Set<string>): Symbol
|
|
|
218
253
|
}
|
|
219
254
|
}
|
|
220
255
|
|
|
256
|
+
// find imported protocols reached through an @objc swift signature, including
|
|
257
|
+
// aliases, inherited protocols and other protocols named by their requirements.
|
|
258
|
+
export function objcProtocolsInSwiftSignatures(graphs: SymbolGraph[]): Set<string> {
|
|
259
|
+
const symbols = new Map<string, GraphSymbol>()
|
|
260
|
+
for (const graph of graphs)
|
|
261
|
+
for (const symbol of graph.symbols) symbols.set(symbol.identifier.precise, symbol)
|
|
262
|
+
const edges = new Map<string, string[]>()
|
|
263
|
+
for (const graph of graphs)
|
|
264
|
+
for (const edge of graph.relationships) {
|
|
265
|
+
if (edge.kind === 'conformsTo')
|
|
266
|
+
edges.set(edge.source, [...(edges.get(edge.source) ?? []), edge.target])
|
|
267
|
+
if (edge.kind === 'requirementOf' || edge.kind === 'optionalRequirementOf')
|
|
268
|
+
edges.set(edge.target, [...(edges.get(edge.target) ?? []), edge.source])
|
|
269
|
+
}
|
|
270
|
+
const result = new Set<string>()
|
|
271
|
+
const visited = new Set<string>()
|
|
272
|
+
const visit = (id: string) => {
|
|
273
|
+
if (visited.has(id)) return
|
|
274
|
+
visited.add(id)
|
|
275
|
+
const symbol = symbols.get(id)
|
|
276
|
+
if (!symbol) return
|
|
277
|
+
const protocol = symbol.kind.identifier === 'swift.protocol' && isObjC(symbol)
|
|
278
|
+
if (protocol) result.add(id)
|
|
279
|
+
if (protocol || symbol.kind.identifier === 'swift.typealias') {
|
|
280
|
+
for (const fragment of symbol.declarationFragments ?? [])
|
|
281
|
+
if (fragment.preciseIdentifier) visit(fragment.preciseIdentifier)
|
|
282
|
+
for (const child of edges.get(id) ?? []) visit(child)
|
|
283
|
+
} else if (MEMBER_KINDS.has(symbol.kind.identifier)) {
|
|
284
|
+
for (const fragment of symbol.declarationFragments ?? [])
|
|
285
|
+
if (fragment.preciseIdentifier) visit(fragment.preciseIdentifier)
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
for (const symbol of symbols.values())
|
|
289
|
+
if (
|
|
290
|
+
isSwiftDeclaration(symbol) &&
|
|
291
|
+
(symbol.declarationFragments ?? []).some((f) => /^@objc(?:\(|$)/.test(f.spelling))
|
|
292
|
+
)
|
|
293
|
+
for (const fragment of symbol.declarationFragments ?? [])
|
|
294
|
+
if (fragment.preciseIdentifier) visit(fragment.preciseIdentifier)
|
|
295
|
+
return result
|
|
296
|
+
}
|
|
297
|
+
|
|
221
298
|
export function emitSwiftStandin(
|
|
222
299
|
sourceGraphs: SymbolGraph[],
|
|
223
300
|
options: StandinOptions,
|
|
224
301
|
): StandinResult {
|
|
225
302
|
const imported = new Set(options.imports)
|
|
226
|
-
const
|
|
303
|
+
const importedTypeModules = options.importedTypeModules ?? new Map<string, string>()
|
|
304
|
+
const graphs = sourceGraphs.map((graph) =>
|
|
305
|
+
qualifyImportedTypes(graph, imported, importedTypeModules),
|
|
306
|
+
)
|
|
307
|
+
const nativeObjcProtocols = objcProtocolsInSwiftSignatures(graphs)
|
|
308
|
+
// clang enum graphs omit @objc even when the native compiler accepts that
|
|
309
|
+
// enum in an @objc swift declaration. preserve its original objc name when
|
|
310
|
+
// that declaration refers to the enum by its compiler identity.
|
|
311
|
+
const objcEnumReferences = new Set(
|
|
312
|
+
graphs.flatMap((graph) =>
|
|
313
|
+
graph.symbols.flatMap((symbol) => {
|
|
314
|
+
const fragments = symbol.declarationFragments ?? []
|
|
315
|
+
if (
|
|
316
|
+
!isSwiftDeclaration(symbol) ||
|
|
317
|
+
!fragments.some((fragment) => /^@objc(?:\(|$)/.test(fragment.spelling))
|
|
318
|
+
)
|
|
319
|
+
return []
|
|
320
|
+
return fragments.flatMap((fragment) =>
|
|
321
|
+
fragment.kind === 'typeIdentifier' && fragment.preciseIdentifier
|
|
322
|
+
? [fragment.preciseIdentifier]
|
|
323
|
+
: [],
|
|
324
|
+
)
|
|
325
|
+
}),
|
|
326
|
+
),
|
|
327
|
+
)
|
|
328
|
+
const trap = (path: string) =>
|
|
329
|
+
`fatalError("${path} is ${options.placeholder === undefined ? 'a binary framework' : 'a placeholder'} peach cannot run")`
|
|
227
330
|
const skipped: StandinResult['skipped'] = []
|
|
228
331
|
const behavior = options.behavior ?? new Map<string, StandinBehavior>()
|
|
229
332
|
const used = new Set<string>()
|
|
@@ -235,6 +338,7 @@ export function emitSwiftStandin(
|
|
|
235
338
|
const byId = new Map<string, GraphSymbol>()
|
|
236
339
|
const twins = new Map<string, GraphSymbol[]>()
|
|
237
340
|
const owner = new Map<string, string>()
|
|
341
|
+
const origins = new Map<string, string>()
|
|
238
342
|
for (const graph of graphs)
|
|
239
343
|
for (const symbol of graph.symbols) {
|
|
240
344
|
if (symbol.accessLevel !== 'public' && symbol.accessLevel !== 'open') continue
|
|
@@ -242,6 +346,15 @@ export function emitSwiftStandin(
|
|
|
242
346
|
if (!byId.has(id)) byId.set(id, symbol)
|
|
243
347
|
twins.set(id, [...(twins.get(id) ?? []), symbol])
|
|
244
348
|
}
|
|
349
|
+
for (const graph of graphs)
|
|
350
|
+
for (const edge of graph.relationships)
|
|
351
|
+
if (
|
|
352
|
+
(edge.kind === 'requirementOf' || edge.kind === 'optionalRequirementOf') &&
|
|
353
|
+
nativeObjcProtocols.has(edge.target)
|
|
354
|
+
)
|
|
355
|
+
for (const fragment of byId.get(edge.source)?.declarationFragments ?? [])
|
|
356
|
+
if (fragment.preciseIdentifier)
|
|
357
|
+
objcEnumReferences.add(fragment.preciseIdentifier)
|
|
245
358
|
const all = (id: string) => twins.get(id) ?? []
|
|
246
359
|
const children = new Map<string, GraphSymbol[]>()
|
|
247
360
|
const superclass = new Map<string, string>()
|
|
@@ -275,6 +388,7 @@ export function emitSwiftStandin(
|
|
|
275
388
|
for (const edge of graph.relationships) {
|
|
276
389
|
const source = byId.get(edge.source)
|
|
277
390
|
if (!source) continue
|
|
391
|
+
if (edge.sourceOrigin) origins.set(edge.source, edge.sourceOrigin.displayName)
|
|
278
392
|
switch (edge.kind) {
|
|
279
393
|
case 'memberOf': {
|
|
280
394
|
const parent = byId.get(edge.target)
|
|
@@ -299,12 +413,21 @@ export function emitSwiftStandin(
|
|
|
299
413
|
}
|
|
300
414
|
case 'conformsTo': {
|
|
301
415
|
const target = nameOf(edge.target, edge.targetFallback)
|
|
302
|
-
const kept =
|
|
416
|
+
const kept =
|
|
417
|
+
KEEP_EXTERNAL.get(edge.target) ??
|
|
418
|
+
(nativeObjcProtocols.has(edge.source) && edge.target === 'c:objc(pl)NSObject'
|
|
419
|
+
? nsObjectProtocol
|
|
420
|
+
: undefined)
|
|
303
421
|
const name =
|
|
304
422
|
kept ??
|
|
305
423
|
(target && (target.local || family.has(target.module ?? ''))
|
|
306
424
|
? target.name
|
|
307
425
|
: null)
|
|
426
|
+
if (nativeObjcProtocols.has(edge.source) && !name)
|
|
427
|
+
skipped.push({
|
|
428
|
+
path: pathOf(source),
|
|
429
|
+
reason: `unsupported Objective-C protocol parent ${edge.target}`,
|
|
430
|
+
})
|
|
308
431
|
if (name)
|
|
309
432
|
conforms.set(edge.source, [...(conforms.get(edge.source) ?? []), name])
|
|
310
433
|
if (byId.has(edge.target)) {
|
|
@@ -376,9 +499,65 @@ export function emitSwiftStandin(
|
|
|
376
499
|
])
|
|
377
500
|
}
|
|
378
501
|
|
|
379
|
-
// DEGRADED(swift-objc-runtime): source
|
|
380
|
-
// return values follow the
|
|
381
|
-
|
|
502
|
+
// DEGRADED(swift-objc-runtime): source targets retain their api with inert native bodies.
|
|
503
|
+
// return values follow the declaration, never the app's call sites. a module
|
|
504
|
+
// type builds through a hidden initializer that sets no state, so no sdk
|
|
505
|
+
// initializer runs with invented arguments; a value nothing can build traps.
|
|
506
|
+
const designated = (id: string) =>
|
|
507
|
+
(children.get(id) ?? []).some(
|
|
508
|
+
(member) =>
|
|
509
|
+
member.kind.identifier === 'swift.init' &&
|
|
510
|
+
!unavailable(member) &&
|
|
511
|
+
!/\bconvenience\b/.test(text(member)),
|
|
512
|
+
)
|
|
513
|
+
const hiddenInit = (id: string) => `${pathOf(byId.get(id)!)}.init(_peachInert:)`
|
|
514
|
+
// a class builds plainly (`T()`) when no class in its module chain declares a
|
|
515
|
+
// designated initializer, through its hidden one when each that does has it
|
|
516
|
+
const classBuilds = new Map<string, 'hidden' | 'plain' | null>()
|
|
517
|
+
const classBuild = (id: string): 'hidden' | 'plain' | null => {
|
|
518
|
+
if (classBuilds.has(id)) return classBuilds.get(id)!
|
|
519
|
+
classBuilds.set(id, null)
|
|
520
|
+
const parent = superId.get(id)
|
|
521
|
+
const inherited = parent && byId.has(parent) ? classBuild(parent) : 'plain'
|
|
522
|
+
const result = !designated(id)
|
|
523
|
+
? inherited
|
|
524
|
+
: inherited && !omit.has(hiddenInit(id))
|
|
525
|
+
? 'hidden'
|
|
526
|
+
: null
|
|
527
|
+
classBuilds.set(id, result)
|
|
528
|
+
return result
|
|
529
|
+
}
|
|
530
|
+
const superInit = (id: string) => {
|
|
531
|
+
const parent = superId.get(id)
|
|
532
|
+
if (!parent) return ''
|
|
533
|
+
return byId.has(parent) && classBuild(parent) === 'hidden'
|
|
534
|
+
? 'super.init(_peachInert: ())'
|
|
535
|
+
: 'super.init()'
|
|
536
|
+
}
|
|
537
|
+
const structBuilds = (id: string) => !omit.has(hiddenInit(id))
|
|
538
|
+
// top-level commas only: a tuple's elements or a case's payload
|
|
539
|
+
const splitTop = (list: string) => {
|
|
540
|
+
const parts: string[] = []
|
|
541
|
+
let depth = 0
|
|
542
|
+
let start = 0
|
|
543
|
+
for (let at = 0; at < list.length; at++) {
|
|
544
|
+
const char = list[at]!
|
|
545
|
+
if (char === '(' || char === '[' || char === '<') depth++
|
|
546
|
+
if (char === ')' || char === ']' || (char === '>' && list[at - 1] !== '-')) depth--
|
|
547
|
+
if (char === ',' && depth === 0) {
|
|
548
|
+
parts.push(list.slice(start, at).trim())
|
|
549
|
+
start = at + 1
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
const last = list.slice(start).trim()
|
|
553
|
+
return last ? [...parts, last] : parts
|
|
554
|
+
}
|
|
555
|
+
const building: string[] = []
|
|
556
|
+
const inertValue = (
|
|
557
|
+
type: string,
|
|
558
|
+
generics: ReadonlySet<string>,
|
|
559
|
+
scope: readonly string[],
|
|
560
|
+
): string | null => {
|
|
382
561
|
const value = type.trim().replace(/!$/, '?')
|
|
383
562
|
if (value.endsWith('?')) return 'nil'
|
|
384
563
|
if (value === 'Void' || value === '()') return '()'
|
|
@@ -392,29 +571,153 @@ export function emitSwiftStandin(
|
|
|
392
571
|
if (value === 'String') return '""'
|
|
393
572
|
if (value.startsWith('[')) return value.includes(':') ? '[:]' : '[]'
|
|
394
573
|
if (value === 'Any' || value === 'AnyObject') return 'NSObject()'
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
if (
|
|
398
|
-
const
|
|
399
|
-
(
|
|
574
|
+
if (/^(?:Foundation\.)?URL$/.test(value)) return 'URL(fileURLWithPath: "/")'
|
|
575
|
+
if (value.includes('->')) return null
|
|
576
|
+
if (value.startsWith('(') && value.endsWith(')')) {
|
|
577
|
+
const items = splitTop(value.slice(1, -1)).map((item) =>
|
|
578
|
+
inertValue(item.replace(/^\w+\s*:\s*/, ''), generics, scope),
|
|
400
579
|
)
|
|
401
|
-
|
|
580
|
+
return items.every((item) => item !== null) ? `(${items.join(', ')})` : null
|
|
402
581
|
}
|
|
403
|
-
|
|
582
|
+
const existential = /^(?:any|some)\s/.test(value)
|
|
583
|
+
const bare = value.replace(/^(?:any|some)\s+/, '')
|
|
584
|
+
if (/^(?:Swift\.)?Error$/.test(bare)) return 'NSError(domain: "", code: 0)'
|
|
585
|
+
const local = bare.startsWith(`${options.module}.`)
|
|
586
|
+
? bare.slice(options.module.length + 1)
|
|
587
|
+
: bare
|
|
588
|
+
const base = local.replace(/<.*>$/s, '')
|
|
589
|
+
const args = local.slice(base.length)
|
|
590
|
+
if (base === 'Self' || generics.has(base.split('.')[0]!)) return null
|
|
591
|
+
// a declaration spells a type as its own scope resolves it
|
|
592
|
+
let typeId: string | undefined
|
|
593
|
+
for (let depth = scope.length; depth >= 0 && !typeId; depth--)
|
|
594
|
+
typeId = typeByPath.get([...scope.slice(0, depth), base].join('.'))
|
|
595
|
+
const symbol = typeId ? byId.get(typeId) : undefined
|
|
596
|
+
if (!typeId || !symbol) return existential ? null : `${bare}()`
|
|
597
|
+
const qualified = `${pathOf(symbol)}${args}`
|
|
598
|
+
const inner = symbol.pathComponents.slice(0, -1)
|
|
599
|
+
if (building.includes(typeId) || omit.has(pathOf(symbol))) return null
|
|
600
|
+
building.push(typeId)
|
|
601
|
+
try {
|
|
602
|
+
switch (symbol.kind.identifier) {
|
|
603
|
+
case 'swift.typealias': {
|
|
604
|
+
const target = /=\s*(.+)$/s.exec(text(symbol))?.[1]
|
|
605
|
+
return target ? inertValue(target, generics, inner) : null
|
|
606
|
+
}
|
|
607
|
+
case 'swift.struct':
|
|
608
|
+
return structBuilds(typeId) ? `${qualified}(_peachInert: ())` : null
|
|
609
|
+
case 'swift.class': {
|
|
610
|
+
const build = classBuild(typeId)
|
|
611
|
+
return build === 'hidden'
|
|
612
|
+
? `${qualified}(_peachInert: ())`
|
|
613
|
+
: build === 'plain'
|
|
614
|
+
? `${qualified}()`
|
|
615
|
+
: null
|
|
616
|
+
}
|
|
617
|
+
case 'swift.enum': {
|
|
618
|
+
const cases = membersOf(typeId).filter(
|
|
619
|
+
(member) => member.kind.identifier === 'swift.enum.case',
|
|
620
|
+
)
|
|
621
|
+
const declared = cases.map((member) =>
|
|
622
|
+
LEADING_ATTRS.exec(text(member))![2]!.replace(/^(?:indirect\s+)?case\s+/, ''),
|
|
623
|
+
)
|
|
624
|
+
const plain = declared.find((spelled) => !spelled.includes('('))
|
|
625
|
+
if (plain) return `${qualified}.${plain.replace(/\s*=.*$/, '')}`
|
|
626
|
+
for (const spelled of declared) {
|
|
627
|
+
const open = spelled.indexOf('(')
|
|
628
|
+
const payload = splitTop(
|
|
629
|
+
spelled.slice(open + 1, spelled.lastIndexOf(')')),
|
|
630
|
+
).map((parameter) => {
|
|
631
|
+
const labeled = /^(\w+)\s*:\s*(.+)$/s.exec(parameter)
|
|
632
|
+
const argument = inertValue(labeled ? labeled[2]! : parameter, generics, [
|
|
633
|
+
...inner,
|
|
634
|
+
leaf(symbol),
|
|
635
|
+
])
|
|
636
|
+
return argument === null
|
|
637
|
+
? null
|
|
638
|
+
: labeled
|
|
639
|
+
? `${labeled[1]}: ${argument}`
|
|
640
|
+
: argument
|
|
641
|
+
})
|
|
642
|
+
if (payload.every((argument) => argument !== null))
|
|
643
|
+
return `${qualified}.${spelled.slice(0, open)}(${payload.join(', ')})`
|
|
644
|
+
}
|
|
645
|
+
return null
|
|
646
|
+
}
|
|
647
|
+
case 'swift.protocol': {
|
|
648
|
+
// a conformer the module declares, the way its own no-op types serve
|
|
649
|
+
const reaches = (id: string): boolean =>
|
|
650
|
+
id === typeId || (protocolParents.get(id) ?? []).some(reaches)
|
|
651
|
+
const conformers = [...conformIds]
|
|
652
|
+
.filter(
|
|
653
|
+
([id, targets]) =>
|
|
654
|
+
targets.some(reaches) &&
|
|
655
|
+
!byId.get(id)?.swiftGenerics?.parameters?.length &&
|
|
656
|
+
owner.get(id) === undefined,
|
|
657
|
+
)
|
|
658
|
+
.map(([id]) => pathOf(byId.get(id)!))
|
|
659
|
+
.sort()
|
|
660
|
+
for (const conformer of conformers) {
|
|
661
|
+
const built = inertValue(conformer, generics, [])
|
|
662
|
+
if (built !== null) return built
|
|
663
|
+
}
|
|
664
|
+
return null
|
|
665
|
+
}
|
|
666
|
+
}
|
|
667
|
+
return null
|
|
668
|
+
} finally {
|
|
669
|
+
building.pop()
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
const genericsOf = (symbol: GraphSymbol) => {
|
|
673
|
+
const names = new Set<string>()
|
|
674
|
+
for (let at: GraphSymbol | undefined = symbol; at; ) {
|
|
675
|
+
for (const parameter of at.swiftGenerics?.parameters ?? [])
|
|
676
|
+
names.add(parameter.name)
|
|
677
|
+
const parent = owner.get(at.identifier.precise)
|
|
678
|
+
at = parent ? byId.get(parent) : undefined
|
|
679
|
+
}
|
|
680
|
+
return names
|
|
404
681
|
}
|
|
682
|
+
const scopeOf = (symbol: GraphSymbol) => symbol.pathComponents.slice(0, -1)
|
|
405
683
|
const inertBody = (symbol: GraphSymbol): string => {
|
|
406
684
|
const declaration = text(symbol)
|
|
685
|
+
if (options.trapped?.has(pathOf(symbol))) return trap(pathOf(symbol))
|
|
686
|
+
const parent = owner.get(symbol.identifier.precise)
|
|
687
|
+
const parentKind = parent ? byId.get(parent)?.kind.identifier : undefined
|
|
407
688
|
if (symbol.kind.identifier === 'swift.init') {
|
|
689
|
+
if (/\binit[?!]/.test(declaration)) return 'return nil'
|
|
690
|
+
if (parentKind === 'swift.struct' && structBuilds(parent!))
|
|
691
|
+
return 'self.init(_peachInert: ())'
|
|
692
|
+
if (parentKind === 'swift.enum') {
|
|
693
|
+
const value = inertValue(pathOf(byId.get(parent!)!), genericsOf(symbol), [])
|
|
694
|
+
return value === null ? trap(pathOf(symbol)) : `self = ${value}`
|
|
695
|
+
}
|
|
696
|
+
if (parentKind === 'swift.class') {
|
|
697
|
+
if (/\bconvenience\b/.test(declaration))
|
|
698
|
+
return classBuild(parent!) === 'hidden'
|
|
699
|
+
? 'self.init(_peachInert: ())'
|
|
700
|
+
: 'self.init()'
|
|
701
|
+
return superInit(parent!)
|
|
702
|
+
}
|
|
408
703
|
if (/\bconvenience\b/.test(declaration)) return 'self.init()'
|
|
409
|
-
|
|
410
|
-
|
|
704
|
+
if (parent && superclass.has(parent)) return 'super.init()'
|
|
705
|
+
// an initializer extending another module's value type assigns its inert value
|
|
706
|
+
const value = inertValue(
|
|
707
|
+
symbol.pathComponents.slice(0, -1).join('.'),
|
|
708
|
+
genericsOf(symbol),
|
|
709
|
+
[],
|
|
710
|
+
)
|
|
711
|
+
return value === null ? trap(pathOf(symbol)) : `self = ${value}`
|
|
411
712
|
}
|
|
412
713
|
const type =
|
|
413
714
|
symbol.kind.identifier.includes('property') ||
|
|
414
715
|
symbol.kind.identifier === 'swift.var'
|
|
415
716
|
? /:\s*(.*?)\s*(?:\{|$)/.exec(declaration)?.[1]
|
|
416
717
|
: symbol.functionSignature?.returns?.map((fragment) => fragment.spelling).join('')
|
|
417
|
-
|
|
718
|
+
if (!type) return ''
|
|
719
|
+
const value = inertValue(type, genericsOf(symbol), scopeOf(symbol))
|
|
720
|
+
return value === null ? trap(pathOf(symbol)) : `return ${value}`
|
|
418
721
|
}
|
|
419
722
|
|
|
420
723
|
const lines: string[] = []
|
|
@@ -426,6 +729,33 @@ export function emitSwiftStandin(
|
|
|
426
729
|
lines.push(...physical)
|
|
427
730
|
owners.push(...physical.map(() => current))
|
|
428
731
|
}
|
|
732
|
+
// a declaration the graph does not carry runs under its own path too
|
|
733
|
+
const emitAt = (path: string, line: string) => {
|
|
734
|
+
if (omit.has(path)) return
|
|
735
|
+
const previous = current
|
|
736
|
+
current = path
|
|
737
|
+
emit(line)
|
|
738
|
+
current = previous
|
|
739
|
+
}
|
|
740
|
+
// inert state a module type needs: the hidden initializer inert values build
|
|
741
|
+
// through, and the coding witnesses a computed-only type cannot synthesize
|
|
742
|
+
const emitInertState = (id: string, indent: string, build: string) => {
|
|
743
|
+
const path = pathOf(byId.get(id)!)
|
|
744
|
+
emitAt(hiddenInit(id), `${indent}init(_peachInert: Void) { ${build} }`)
|
|
745
|
+
const list = conforms.get(id) ?? []
|
|
746
|
+
const has = (name: string) =>
|
|
747
|
+
(children.get(id) ?? []).some((member) => leaf(member) === name)
|
|
748
|
+
if (list.includes('Encodable') && !has('encode(to:)'))
|
|
749
|
+
emitAt(
|
|
750
|
+
`${path}.encode(to:)`,
|
|
751
|
+
`${indent}public func encode(to encoder: Encoder) throws {}`,
|
|
752
|
+
)
|
|
753
|
+
if (list.includes('Decodable') && !has('init(from:)'))
|
|
754
|
+
emitAt(
|
|
755
|
+
`${path}.init(from:)`,
|
|
756
|
+
`${indent}public init(from decoder: Decoder) throws { self.init(_peachInert: ()) }`,
|
|
757
|
+
)
|
|
758
|
+
}
|
|
429
759
|
// every declaration runs under its own path, so each line names it
|
|
430
760
|
const scoped =
|
|
431
761
|
<T extends unknown[]>(body: (symbol: GraphSymbol, ...rest: T) => void) =>
|
|
@@ -457,6 +787,27 @@ export function emitSwiftStandin(
|
|
|
457
787
|
const access = (symbol: GraphSymbol, openOwner: boolean) =>
|
|
458
788
|
symbol.accessLevel === 'open' && openOwner ? 'open' : 'public'
|
|
459
789
|
|
|
790
|
+
// an opaque result needs a concrete underlying type even when its body traps.
|
|
791
|
+
// a type parameter constrained to that protocol supplies one without executing it.
|
|
792
|
+
const opaqueParameter = (member: GraphSymbol) => {
|
|
793
|
+
if (!/:\s*some\s+[\w.]+\s*$/.test(splitAccessors(text(member)).decl)) return undefined
|
|
794
|
+
const fragments = member.declarationFragments ?? []
|
|
795
|
+
const some = fragments.findIndex((fragment) => fragment.spelling === 'some')
|
|
796
|
+
if (some < 0) return undefined
|
|
797
|
+
const protocol = fragments
|
|
798
|
+
.slice(some + 1)
|
|
799
|
+
.find((fragment) => fragment.kind === 'typeIdentifier')
|
|
800
|
+
const parent = owner.get(member.identifier.precise)
|
|
801
|
+
const generics = byId.get(parent ?? '')?.swiftGenerics
|
|
802
|
+
return generics?.constraints?.find(
|
|
803
|
+
(constraint) =>
|
|
804
|
+
constraint.kind === 'conformance' &&
|
|
805
|
+
constraint.rhsPrecise === protocol?.preciseIdentifier &&
|
|
806
|
+
constraint.rhsPrecise !== undefined &&
|
|
807
|
+
generics.parameters?.some((parameter) => parameter.name === constraint.lhs),
|
|
808
|
+
)?.lhs
|
|
809
|
+
}
|
|
810
|
+
|
|
460
811
|
const emitMember = scoped(
|
|
461
812
|
(
|
|
462
813
|
member: GraphSymbol,
|
|
@@ -465,6 +816,32 @@ export function emitSwiftStandin(
|
|
|
465
816
|
) => {
|
|
466
817
|
const path = pathOf(member)
|
|
467
818
|
if (TYPE_KINDS.has(member.kind.identifier)) {
|
|
819
|
+
// an opaque associated type from a protocol is inferred from its
|
|
820
|
+
// getter witness; `typealias X = some P` is not valid swift.
|
|
821
|
+
const origin = origins.get(member.identifier.precise)?.split('.')[0]
|
|
822
|
+
const parent = owner.get(member.identifier.precise)
|
|
823
|
+
if (
|
|
824
|
+
member.kind.identifier === 'swift.typealias' &&
|
|
825
|
+
/\btypealias\s+\w+\s*=\s*some\s/.test(text(member)) &&
|
|
826
|
+
origin &&
|
|
827
|
+
parent &&
|
|
828
|
+
membersOf(parent).some(
|
|
829
|
+
(candidate) =>
|
|
830
|
+
candidate.kind.identifier === 'swift.property' &&
|
|
831
|
+
!options.inert &&
|
|
832
|
+
!behavior.has(pathOf(candidate)) &&
|
|
833
|
+
!splitAccessors(text(candidate)).settable &&
|
|
834
|
+
origins.get(candidate.identifier.precise)?.split('.')[0] === origin &&
|
|
835
|
+
opaqueParameter(candidate) &&
|
|
836
|
+
text(member)
|
|
837
|
+
.split(/\bsome\s/)[1]
|
|
838
|
+
?.trim() ===
|
|
839
|
+
splitAccessors(text(candidate))
|
|
840
|
+
.decl.split(/\bsome\s/)[1]
|
|
841
|
+
?.trim(),
|
|
842
|
+
)
|
|
843
|
+
)
|
|
844
|
+
return
|
|
468
845
|
emitType(member, indent)
|
|
469
846
|
return
|
|
470
847
|
}
|
|
@@ -473,7 +850,14 @@ export function emitSwiftStandin(
|
|
|
473
850
|
skipped.push({ path, reason: `unhandled ${member.kind.identifier}` })
|
|
474
851
|
return
|
|
475
852
|
}
|
|
476
|
-
const { 1:
|
|
853
|
+
const { 1: spelledAttrs, 2: rest } = LEADING_ATTRS.exec(text(member))!
|
|
854
|
+
// a property wrapper is the module's own type; the property it wraps
|
|
855
|
+
// becomes computed here, which a wrapper cannot annotate
|
|
856
|
+
const attrs = member.kind.identifier.includes('property')
|
|
857
|
+
? spelledAttrs!.replace(/@(\w+)(?:\([^)]*\))?\s*/g, (attr, name: string) =>
|
|
858
|
+
typeByPath.has(name) ? '' : attr,
|
|
859
|
+
)
|
|
860
|
+
: spelledAttrs!
|
|
477
861
|
const modifiers =
|
|
478
862
|
/^((?:(?:required|final|override|convenience|unowned(?:\(\w+\))?|weak|lazy|nonisolated|mutating|nonmutating) )*)(.*)$/s.exec(
|
|
479
863
|
rest!,
|
|
@@ -523,6 +907,11 @@ export function emitSwiftStandin(
|
|
|
523
907
|
const decl = parsed.decl
|
|
524
908
|
const effects = parsed.effects
|
|
525
909
|
const settable = parsed.settable
|
|
910
|
+
const parameter =
|
|
911
|
+
!measured && !options.inert && !settable && /:\s*some\s/.test(decl)
|
|
912
|
+
? opaqueParameter(member)
|
|
913
|
+
: undefined
|
|
914
|
+
const getter = parameter ? `return ({ () -> ${parameter} in ${body} })()` : body
|
|
526
915
|
const computed = decl.replace(/^((?:static |class )*)let /, '$1var ')
|
|
527
916
|
if (measured?.stored !== undefined) {
|
|
528
917
|
// a read-only sdk property stays read-only outside the module
|
|
@@ -539,7 +928,7 @@ export function emitSwiftStandin(
|
|
|
539
928
|
return
|
|
540
929
|
}
|
|
541
930
|
emit(
|
|
542
|
-
`${head}${computed} { get${effects} { ${
|
|
931
|
+
`${head}${computed} { get${effects} { ${getter} }${settable && !effects ? ` ${parsed.nonmutating ? 'nonmutating ' : ''}set { ${measured?.set ?? (options.inert ? '' : trap(path))} }` : ''} }`,
|
|
543
932
|
)
|
|
544
933
|
return
|
|
545
934
|
}
|
|
@@ -594,7 +983,12 @@ export function emitSwiftStandin(
|
|
|
594
983
|
// one is left out; every argument the sdk accepts still satisfies the rest.
|
|
595
984
|
const objcProtocols = new Set(
|
|
596
985
|
[...byId.values()]
|
|
597
|
-
.filter(
|
|
986
|
+
.filter(
|
|
987
|
+
(s) =>
|
|
988
|
+
s.kind.identifier === 'swift.protocol' &&
|
|
989
|
+
isObjC(s) &&
|
|
990
|
+
!nativeObjcProtocols.has(s.identifier.precise),
|
|
991
|
+
)
|
|
598
992
|
.map(pathOf),
|
|
599
993
|
)
|
|
600
994
|
const selfConforming = (where: string) => {
|
|
@@ -738,6 +1132,8 @@ export function emitSwiftStandin(
|
|
|
738
1132
|
emitWitness(member, inner, path)
|
|
739
1133
|
}
|
|
740
1134
|
}
|
|
1135
|
+
if (options.inert && designated && classBuild(id) === 'hidden')
|
|
1136
|
+
emitAt(hiddenInit(id), `${inner}init(_peachInert: Void) { ${superInit(id)} }`)
|
|
741
1137
|
const coder = members.some((member) => leaf(member) === 'init(coder:)')
|
|
742
1138
|
if (
|
|
743
1139
|
designated &&
|
|
@@ -764,6 +1160,23 @@ export function emitSwiftStandin(
|
|
|
764
1160
|
if (raw) {
|
|
765
1161
|
emit(`${inner}public let rawValue: ${raw}`)
|
|
766
1162
|
emit(`${inner}public init(rawValue: ${raw}) { self.rawValue = rawValue }`)
|
|
1163
|
+
// a tuple raw value is neither equatable nor hashable, so its
|
|
1164
|
+
// elements are compared and hashed in place of the synthesized ones
|
|
1165
|
+
if (
|
|
1166
|
+
raw.startsWith('(') &&
|
|
1167
|
+
list.some((name) => name === 'Equatable' || name === 'Hashable')
|
|
1168
|
+
)
|
|
1169
|
+
emit(
|
|
1170
|
+
`${inner}public static func == (lhs: Self, rhs: Self) -> Bool { lhs.rawValue == rhs.rawValue }`,
|
|
1171
|
+
)
|
|
1172
|
+
if (raw.startsWith('(') && list.includes('Hashable'))
|
|
1173
|
+
emit(
|
|
1174
|
+
`${inner}public func hash(into hasher: inout Hasher) { ${splitTop(
|
|
1175
|
+
raw.slice(1, -1),
|
|
1176
|
+
)
|
|
1177
|
+
.map((_, index) => `hasher.combine(rawValue.${index})`)
|
|
1178
|
+
.join('; ')} }`,
|
|
1179
|
+
)
|
|
767
1180
|
}
|
|
768
1181
|
for (const member of members) {
|
|
769
1182
|
if (
|
|
@@ -787,6 +1200,12 @@ export function emitSwiftStandin(
|
|
|
787
1200
|
inClass: false,
|
|
788
1201
|
})
|
|
789
1202
|
}
|
|
1203
|
+
if (options.inert)
|
|
1204
|
+
emitInertState(
|
|
1205
|
+
id,
|
|
1206
|
+
inner,
|
|
1207
|
+
raw ? `self.rawValue = ${inertValue(raw, new Set(), [path]) ?? '0'}` : '',
|
|
1208
|
+
)
|
|
790
1209
|
emit(`${indent}}`)
|
|
791
1210
|
return
|
|
792
1211
|
}
|
|
@@ -798,16 +1217,20 @@ export function emitSwiftStandin(
|
|
|
798
1217
|
const cases = members.filter(
|
|
799
1218
|
(member) => member.kind.identifier === 'swift.enum.case',
|
|
800
1219
|
)
|
|
1220
|
+
const hasPayload = (member: GraphSymbol) =>
|
|
1221
|
+
LEADING_ATTRS.exec(text(member))![2]!.includes('(')
|
|
801
1222
|
// payload cases use a manual RawRepresentable witness, not a raw enum.
|
|
802
|
-
const raw = cases.some(
|
|
803
|
-
? null
|
|
804
|
-
: rawType(members)
|
|
1223
|
+
const raw = cases.some(hasPayload) ? null : rawType(members)
|
|
805
1224
|
const missing = raw
|
|
806
1225
|
? cases.filter((member) => !values.has(member.identifier.precise))
|
|
807
1226
|
: []
|
|
808
1227
|
// an objective-c enum's numbering is the header's; without it the
|
|
809
1228
|
// cases would invent values, so the enum is left out.
|
|
810
|
-
if (
|
|
1229
|
+
if (
|
|
1230
|
+
raw &&
|
|
1231
|
+
(isObjC(symbol) || /^c:@C?M@[^@]+@E@/.test(id)) &&
|
|
1232
|
+
missing.length > 0
|
|
1233
|
+
)
|
|
811
1234
|
return void skipped.push({
|
|
812
1235
|
path,
|
|
813
1236
|
reason: `no header value for ${missing.map(leaf).join(', ')}`,
|
|
@@ -815,8 +1238,12 @@ export function emitSwiftStandin(
|
|
|
815
1238
|
const list = inheritance(id, raw ?? undefined).filter(
|
|
816
1239
|
(name) => !raw || name !== 'RawRepresentable',
|
|
817
1240
|
)
|
|
1241
|
+
const objcName =
|
|
1242
|
+
raw && isObjC(symbol) && objcEnumReferences.has(id)
|
|
1243
|
+
? /^c:@E@(\w+)$/.exec(id)?.[1]
|
|
1244
|
+
: undefined
|
|
818
1245
|
emit(
|
|
819
|
-
`${indent}${shape.attrs}public enum ${shape.name}${shape.generics}${list.length ? `: ${list.join(', ')}` : ''}${shape.where} {`,
|
|
1246
|
+
`${indent}${shape.attrs}${objcName ? `@objc(${objcName}) ` : ''}public enum ${shape.name}${shape.generics}${list.length ? `: ${list.join(', ')}` : ''}${shape.where} {`,
|
|
820
1247
|
)
|
|
821
1248
|
const seenValues = new Map<string, string>()
|
|
822
1249
|
for (const member of cases) {
|
|
@@ -831,10 +1258,13 @@ export function emitSwiftStandin(
|
|
|
831
1258
|
continue
|
|
832
1259
|
}
|
|
833
1260
|
if (value !== undefined) seenValues.set(value, tick(leaf(member)))
|
|
834
|
-
const
|
|
835
|
-
|
|
1261
|
+
const { 1: attrs, 2: declaration } = LEADING_ATTRS.exec(text(member))!
|
|
1262
|
+
const caseText = declaration!.replace(/^case\s+/, '')
|
|
1263
|
+
emit(
|
|
1264
|
+
`${inner}${attrs}case ${caseText}${value !== undefined ? ` = ${value}` : ''}`,
|
|
1265
|
+
)
|
|
836
1266
|
}
|
|
837
|
-
const payloadFree = cases.every((member) => !
|
|
1267
|
+
const payloadFree = cases.every((member) => !hasPayload(member))
|
|
838
1268
|
for (const member of members) {
|
|
839
1269
|
if (member.kind.identifier === 'swift.enum.case') continue
|
|
840
1270
|
if (
|
|
@@ -848,6 +1278,12 @@ export function emitSwiftStandin(
|
|
|
848
1278
|
inClass: false,
|
|
849
1279
|
})
|
|
850
1280
|
}
|
|
1281
|
+
if (options.inert) {
|
|
1282
|
+
const value = options.trapped?.has(hiddenInit(id))
|
|
1283
|
+
? null
|
|
1284
|
+
: inertValue(path, new Set(), [])
|
|
1285
|
+
emitInertState(id, inner, value === null ? trap(path) : `self = ${value}`)
|
|
1286
|
+
}
|
|
851
1287
|
emit(`${indent}}`)
|
|
852
1288
|
return
|
|
853
1289
|
}
|
|
@@ -858,10 +1294,21 @@ export function emitSwiftStandin(
|
|
|
858
1294
|
path,
|
|
859
1295
|
reason: `unparsed protocol ${text(symbol)}`,
|
|
860
1296
|
})
|
|
861
|
-
|
|
862
|
-
const
|
|
1297
|
+
const native = nativeObjcProtocols.has(id)
|
|
1298
|
+
const objcName = native ? /^c:objc\(pl\)(\w+)$/.exec(id)?.[1] : undefined
|
|
1299
|
+
if (native && !objcName)
|
|
1300
|
+
return void skipped.push({
|
|
1301
|
+
path,
|
|
1302
|
+
reason: `unknown Objective-C protocol identity ${id}`,
|
|
1303
|
+
})
|
|
1304
|
+
// adapted objective-c protocols are class-bound; native ones are
|
|
1305
|
+
// class-bound by @objc itself.
|
|
1306
|
+
const list = [
|
|
1307
|
+
...(isObjC(symbol) && !native ? ['AnyObject'] : []),
|
|
1308
|
+
...inheritance(id),
|
|
1309
|
+
]
|
|
863
1310
|
emit(
|
|
864
|
-
`${indent}${shape.attrs}public protocol ${shape.name}${list.length ? `: ${list.join(', ')}` : ''}${shape.where} {`,
|
|
1311
|
+
`${indent}${shape.attrs}${objcName ? `@objc(${objcName}) ` : ''}public protocol ${shape.name}${list.length ? `: ${list.join(', ')}` : ''}${shape.where} {`,
|
|
865
1312
|
)
|
|
866
1313
|
const members = membersOf(id)
|
|
867
1314
|
const defaults: GraphSymbol[] = []
|
|
@@ -878,8 +1325,10 @@ export function emitSwiftStandin(
|
|
|
878
1325
|
defaults.push(member)
|
|
879
1326
|
continue
|
|
880
1327
|
}
|
|
881
|
-
emitRequirement(member, inner)
|
|
1328
|
+
emitRequirement(member, inner, native)
|
|
882
1329
|
if (
|
|
1330
|
+
isObjC(symbol) &&
|
|
1331
|
+
!native &&
|
|
883
1332
|
optional.has(member.identifier.precise) &&
|
|
884
1333
|
!hasDefault.has(member.identifier.precise)
|
|
885
1334
|
)
|
|
@@ -940,16 +1389,74 @@ export function emitSwiftStandin(
|
|
|
940
1389
|
})
|
|
941
1390
|
|
|
942
1391
|
// a protocol requirement: no access modifier, body, or default values
|
|
943
|
-
const emitRequirement = scoped(
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
1392
|
+
const emitRequirement = scoped(
|
|
1393
|
+
(member: GraphSymbol, indent: string, native: boolean) => {
|
|
1394
|
+
if (
|
|
1395
|
+
native &&
|
|
1396
|
+
(member.declarationFragments ?? []).some((f) =>
|
|
1397
|
+
f.spelling.includes('AutoreleasingUnsafeMutablePointer'),
|
|
1398
|
+
)
|
|
1399
|
+
) {
|
|
1400
|
+
skipped.push({
|
|
1401
|
+
path: pathOf(member),
|
|
1402
|
+
reason: 'unsupported native Objective-C autoreleasing pointer requirement',
|
|
1403
|
+
})
|
|
1404
|
+
return
|
|
1405
|
+
}
|
|
1406
|
+
const { 1: attrs, 2: rest } = LEADING_ATTRS.exec(text(member))!
|
|
1407
|
+
let declaration = stripDefaults(
|
|
1408
|
+
rest!.replace(/^(?:weak |unowned )/, '').replace(/^((?:static )?)let /, '$1var '),
|
|
1409
|
+
)
|
|
1410
|
+
let objc = ''
|
|
1411
|
+
if (native) {
|
|
1412
|
+
const id = member.identifier.precise
|
|
1413
|
+
if (
|
|
1414
|
+
member.kind.identifier === 'swift.property' ||
|
|
1415
|
+
member.kind.identifier === 'swift.type.property'
|
|
1416
|
+
) {
|
|
1417
|
+
const property = options.objcProperties?.get(id)
|
|
1418
|
+
const parsed = splitAccessors(declaration)
|
|
1419
|
+
if (!property || (parsed.settable && !property.setter)) {
|
|
1420
|
+
skipped.push({
|
|
1421
|
+
path: pathOf(member),
|
|
1422
|
+
reason: 'missing native Objective-C property selectors',
|
|
1423
|
+
})
|
|
1424
|
+
return
|
|
1425
|
+
}
|
|
1426
|
+
declaration = `${parsed.decl} { @objc(${property.getter}) get${parsed.settable ? ` @objc(${property.setter}) set` : ''} }`
|
|
1427
|
+
objc = '@objc '
|
|
1428
|
+
} else {
|
|
1429
|
+
const selector = /\((?:im|cm)\)([A-Za-z_][A-Za-z_0-9:]*)$/.exec(id)?.[1]
|
|
1430
|
+
if (!selector) {
|
|
1431
|
+
skipped.push({
|
|
1432
|
+
path: pathOf(member),
|
|
1433
|
+
reason: `unknown Objective-C selector ${id}`,
|
|
1434
|
+
})
|
|
1435
|
+
return
|
|
1436
|
+
}
|
|
1437
|
+
objc = `@objc(${selector}) `
|
|
1438
|
+
}
|
|
1439
|
+
}
|
|
1440
|
+
emit(
|
|
1441
|
+
`${indent}${attrs}${objc}${native && optional.has(member.identifier.precise) ? 'optional ' : ''}${declaration}`,
|
|
1442
|
+
)
|
|
1443
|
+
},
|
|
1444
|
+
)
|
|
949
1445
|
|
|
950
1446
|
const rawType = (members: GraphSymbol[]) => {
|
|
951
1447
|
const init = members.find((member) => leaf(member) === 'init(rawValue:)')
|
|
952
|
-
|
|
1448
|
+
if (!init) return null
|
|
1449
|
+
const spelled = text(init)
|
|
1450
|
+
const start = spelled.indexOf('rawValue:')
|
|
1451
|
+
if (start < 0) return null
|
|
1452
|
+
// a tuple raw value nests parentheses
|
|
1453
|
+
let depth = 0
|
|
1454
|
+
for (let at = start; at < spelled.length; at++) {
|
|
1455
|
+
if (spelled[at] === '(') depth++
|
|
1456
|
+
if (spelled[at] === ')' && depth-- === 0)
|
|
1457
|
+
return spelled.slice(start + 'rawValue:'.length, at).trim()
|
|
1458
|
+
}
|
|
1459
|
+
return null
|
|
953
1460
|
}
|
|
954
1461
|
// header values are clang's for 64-bit iOS. NSUIntegerMax, NSIntegerMax
|
|
955
1462
|
// and NSIntegerMin are the platform-width type's own extremes, which on
|
|
@@ -1004,8 +1511,26 @@ export function emitSwiftStandin(
|
|
|
1004
1511
|
} else skipped.push({ path, reason: `unhandled top-level ${kind}` })
|
|
1005
1512
|
})
|
|
1006
1513
|
|
|
1514
|
+
// clang imports a C declaration alongside the swift @_cdecl definition.
|
|
1515
|
+
// retain the definition, including its exported C name, for identical signatures.
|
|
1516
|
+
const cExports = new Set(
|
|
1517
|
+
[...byId.values()].flatMap((symbol) => {
|
|
1518
|
+
if (
|
|
1519
|
+
owner.has(symbol.identifier.precise) ||
|
|
1520
|
+
unavailable(symbol) ||
|
|
1521
|
+
omit.has(pathOf(symbol))
|
|
1522
|
+
)
|
|
1523
|
+
return []
|
|
1524
|
+
const match = /@_cdecl\("([^"]+)"\)/.exec(text(symbol))
|
|
1525
|
+
return match ? [`${match[1]}|${LEADING_ATTRS.exec(text(symbol))![2]}`] : []
|
|
1526
|
+
}),
|
|
1527
|
+
)
|
|
1007
1528
|
const roots = [...byId.values()]
|
|
1008
1529
|
.filter((symbol) => !owner.has(symbol.identifier.precise) && !unavailable(symbol))
|
|
1530
|
+
.filter((symbol) => {
|
|
1531
|
+
const name = /^c:@M@[^@]+@F@([^@]+)$/.exec(symbol.identifier.precise)?.[1]
|
|
1532
|
+
return !name || !cExports.has(`${name}|${text(symbol)}`)
|
|
1533
|
+
})
|
|
1009
1534
|
.sort((a, b) => pathOf(a).localeCompare(pathOf(b)))
|
|
1010
1535
|
for (const symbol of roots) {
|
|
1011
1536
|
const path = pathOf(symbol)
|
|
@@ -1025,6 +1550,8 @@ export function emitSwiftStandin(
|
|
|
1025
1550
|
for (const member of kept)
|
|
1026
1551
|
if (
|
|
1027
1552
|
member.kind.identifier === 'swift.init' &&
|
|
1553
|
+
(member.swiftExtension?.typeKind === 'swift.class' ||
|
|
1554
|
+
(owner.get(member.identifier.precise) ?? '').startsWith('c:objc(cs)')) &&
|
|
1028
1555
|
!text(member).startsWith('convenience')
|
|
1029
1556
|
)
|
|
1030
1557
|
emitMember(
|
|
@@ -1046,12 +1573,20 @@ export function emitSwiftStandin(
|
|
|
1046
1573
|
|
|
1047
1574
|
const imports = [...STANDIN_IMPORTS, ...(options.imports ?? [])]
|
|
1048
1575
|
const banner = [
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1576
|
+
...(options.placeholder
|
|
1577
|
+
? [
|
|
1578
|
+
`// placeholder for ${options.module}, generated from ${options.source}: ${options.placeholder}.`,
|
|
1579
|
+
'// its public interface with inert bodies; nothing it would send leaves the app.',
|
|
1580
|
+
]
|
|
1581
|
+
: [
|
|
1582
|
+
`// stand-in for the binary ${options.module} module, generated from ${options.source}.`,
|
|
1583
|
+
options.inert
|
|
1584
|
+
? '// generated from public headers; native behavior is inert in peach.'
|
|
1585
|
+
: '// unconfigured bodies trap because the vendor binary cannot run in peach.',
|
|
1586
|
+
]),
|
|
1053
1587
|
'',
|
|
1054
1588
|
...imports.map((name) => `import ${name}`),
|
|
1589
|
+
...(options.exported ?? []),
|
|
1055
1590
|
'#if os(WASI)',
|
|
1056
1591
|
'import UIKitCore',
|
|
1057
1592
|
`public protocol ${standinMarker}: _PeachGeneratedStandin {}`,
|