Skip to content

Ship the SwiftUI/UIKit guest at the embedded tier, and make it instantiable there - #1

Open
Perronef5 wants to merge 1 commit into
patch-release:mainfrom
Perronef5:embedded-tier-guest
Open

Perronef5 wants to merge 1 commit into
patch-release:mainfrom
Perronef5:embedded-tier-guest

Conversation

@Perronef5

Copy link
Copy Markdown

The view-body guest is Foundation-free by design (GuestIR + EmbeddedJSON), but on a real app it always shipped at T2 (~11.7 MB brotli floor). Four things caused that; this PR fixes them together because each one alone still leaves the guest at T2 or un-instantiable.

  1. Tier pin. runSwiftUILowering (and the UIKit cell lowering) call converge(..., startTier: .t2Foundation). They now start at T0 and rely on the existing escalation on a real compile failure. PATCH_SWIFTUI_START_TIER / PATCH_SWIFTUI_MAX_TIER / PATCH_UIKIT_START_TIER / PATCH_UIKIT_MAX_TIER (t0|t1|t2) override per run for measurement and T0 isolation.
  2. FRONTIER_EMBEDDED never defined. The IR guards its Codable conformances behind #if !FRONTIER_EMBEDDED (see Conformance.swift), but neither T0 manifest passed the define, so every embedded build failed on 'Codable' is unavailable in embedded Swift.
  3. Unsatisfiable env imports at T0. With --allow-undefined, a guest that compares Strings or parses a Double links but imports _swift_stdlib_getNormData / getComposition / getDecompositionEntry and _swift_stdlib_strtod_clocale from env, which the SDK host never provides, so WasmKit refuses to instantiate. The T0 manifest now links libswiftUnicodeDataTables from the embedded SDK, and the CHost target carries a strtod shim written only at T0 (the full runtime defines it at T1/T2).
  4. PATCH_SWIFTUI_ONLY=1 skips the default function-thunk module, whose generated JSON-ABI wrappers force T2 for the merged artifact; with no primary module the guest is promoted to module.wasm through the existing promoteGuestToPrimary path. PATCH_UIKIT=0 skips cell lowering.

Measured on a 949-file SwiftUI app at d026e03:

scope before after
17-view subtree 13.2 MB brotli (T2 merge) 111 KB brotli, 17/17 views
whole app 30.1 MB 340 KB brotli, 702 views lowered, 802 exports, 5 isolated

The resulting module imports only wasi_snapshot_preview1.random_get. Verified on an iOS simulator with the unmodified PatchSDK at d026e03: the module downloaded, verified, activated, and its view_body exports overrode the native views.

Defaults changed by this PR: the guests now start at T0 (they escalate to T1/T2 exactly as the default module does, so nothing that compiled before stops compiling). The two PATCH_*_ONLY/PATCH_UIKIT knobs are opt-in.

…tiable there

The view-body guest is Foundation-free by design (GuestIR + EmbeddedJSON), but
four things kept it at T2 (~11.7 MB brotli floor) on a real app:

1. runSwiftUILowering (and the UIKit cell lowering) pinned the guest convergence
   to `startTier: .t2Foundation`. Both now start at T0 and rely on the existing
   escalation on a real compile failure. PATCH_SWIFTUI_START_TIER /
   PATCH_SWIFTUI_MAX_TIER / PATCH_UIKIT_START_TIER / PATCH_UIKIT_MAX_TIER
   (t0|t1|t2) override per run for measurement and isolation.
2. The T0 manifests never defined FRONTIER_EMBEDDED, so the IR's guarded Codable
   conformances were compiled and every embedded build failed on
   "'Codable' is unavailable in embedded Swift".
3. With --allow-undefined, an embedded module that compares Strings or parses a
   Double links but imports _swift_stdlib_getNormData / getComposition /
   getDecompositionEntry and _swift_stdlib_strtod_clocale from `env`, which the
   SDK host never provides, so WasmKit refuses to instantiate it. The T0
   manifest now links libswiftUnicodeDataTables from the embedded SDK, and the
   CHost target carries a strtod shim (T0 only; the full runtime defines it
   at T1/T2).
4. PATCH_SWIFTUI_ONLY=1 skips the default function-thunk module, whose
   generated JSON-ABI wrappers force T2 for the merged artifact; with no primary
   module the guest is promoted to module.wasm by the existing
   promoteGuestToPrimary path. PATCH_UIKIT=0 skips cell lowering.

Measured on a 949-file SwiftUI app at d026e03: a 17-view subtree went from
13.2 MB brotli (T2 merge) to 111 KB; the whole app (702 views lowered, 802
exports, 5 isolated) ships as 340 KB brotli with only
wasi_snapshot_preview1.random_get imported. Verified on an iOS simulator: the
module downloaded, verified, activated, and its view_body exports overrode the
native views.
@Perronef5

Copy link
Copy Markdown
Author

@jackguac Lmk if I should close this or can we get it in?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant