Repository navigation
Apple embedding point: ApplePlatformView, kind 28 Platform, sui_platform_set_view (#145) - #152
Merged
Merged
Conversation
…t_view, ApplePlatformView, gallery checks macOS gallery 228 ok, 0 FAIL (the 6 Platform checks included); shimGen/testFull 51/51. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… freed Falsified on macOS, each 223 ok / 1 failed on the matching check: release skipped, release after the shim dropped the view, empty 'not available' label, shim keeping the +1. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…12 and the gallery README macOS gallery 228 ok / 0 failed (224 with the screen locked); iOS simulator (iPhone 17e) 239 / 0 on the warm simulator. verify-apple.sh 19/20: ios-gallery failed only on the fresh boot's notifications 'not yet asked' check (known trap), Platform checks passing; alone it passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Note
Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.
🟡 Changes recommended
A moderate-severity active finding reports a memory leak and non-reentrant state in the Gallery platform self-test because weak-reference slots allocated with malloc are never freed and related buffers aren’t cleared.
1 open issue
What changed in this PR
This pull request adds Apple (AppKit/UIKit) support for Thicket’s “embedding point” (WidgetKind.Platform / Prop.View) by introducing an ApplePlatformView contract, a new shim host kind to embed externally-created native views, and gallery self-tests/docs to validate lifecycle and ownership behavior.
Changes:
- Introduces
ApplePlatformViewplus renderer-side lifecycle handling for creating/hosting/releasingNSView*/UIView*pointers. - Extends the Apple shim ABI with kind 28 (
PlatformHost) and a new functionsui_platform_set_view(host, view)implemented for both AppKit and UIKit. - Updates the Apple gallery to exercise the feature via a native label created in C, adds Platform self-tests, and updates related docs/build wiring.
Review comments to address:
GalleryPlatformChecks.scala: weak-reference slots allocated viathk_gallery_weak_neware not freed (thk_gallery_weak_free), and buffers are not cleared, causing leaks and non-reentrant checks (moderate, votes: 3).GalleryPlatformChecks.scala:NativeLabel.madegrows unbounded; consider capping to the last 2 entries and freeing dropped weak slots to avoid accumulating state and brittle assertions (moderate, votes: 1).
| File | Summary |
|---|---|
tools/shim-gen/src/main/scala/thicket/tools/shim/Abi.scala |
Adds kind 28 (Platform) and the sui_platform_set_view ABI definition/grouping. |
modules/renderer-apple/src/main/scala/thicket/renderer/apple/Shim.scala |
Exposes sui_platform_set_view and the new ShimKind.Platform constant to Scala Native. |
modules/renderer-apple/src/main/scala/thicket/renderer/apple/AppleRenderer.scala |
Maps WidgetKind.Platform to kind 28 and wires Prop.View handling/cleanup through the renderer. |
modules/renderer-apple/src/main/scala/thicket/renderer/apple/ApplePlatformView.scala |
Introduces ApplePlatformView and renderer-side bookkeeping for hosting/replacement/destroy sequencing. |
modules/renderer-apple/shim/Sources/Shim+UIKit.swift |
Implements PlatformHost and _cdecl("sui_platform_set_view") for UIKit, including ownership transfer behavior. |
modules/renderer-apple/shim/Sources/Shim+AppKit.swift |
Implements PlatformHost and _cdecl("sui_platform_set_view") for AppKit, including ownership transfer behavior. |
modules/renderer-apple/shim/include/thicket_apple.h |
Documents kind 28 and declares sui_platform_set_view in the generated C header. |
modules/renderer-apple/README.md |
Documents the Apple embedding contract and ownership/release expectations for modules implementing ApplePlatformView. |
examples/gallery/README.md |
Updates gallery documentation to include the new Apple Platform checks and measurements. |
examples/gallery/macos/src/main/scala/example/gallery/GalleryMac.scala |
Configures the macOS gallery to supply a native label factory for Platform hosting. |
examples/gallery/ios/src/main/scala/example/gallery/GalleryIos.scala |
Configures the iOS gallery to supply a native label factory for Platform hosting. |
examples/gallery/apple-shared/src/main/scala/example/gallery/GallerySelfTest.scala |
Inserts the Platform section into the Apple self-test sequence. |
examples/gallery/apple-shared/src/main/scala/example/gallery/GalleryPlatformChecks.scala |
Adds Apple-specific Platform embedding checks using weak refs/inspection to validate lifecycle behavior. |
examples/gallery/apple-shared/src/main/resources/scala-native/thicket_gallery_native_label.c |
Provides the externally-created NSTextField/UILabel and weak-ref helpers used by the self-test. |
docs/decisions.md |
Records the Apple embedding point decision and related measured/falsified results. |
docs/17-camera-preview.md |
Updates the camera preview step doc/status to reflect completion of the Apple embedding point. |
docs/12-component-status.md |
Updates component/prop status to reflect Platform support on Apple. |
build.sbt |
Adds the Apple gallery shared resources directory so the native C source under resources/scala-native is included. |
Review effort: Balanced
Added cleanup logic to free weak slots after observing NativeLabels. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Nov 8, 2026
rleibman
added a commit
that referenced
this pull request
Nov 9, 2026
* Regenerate thicket_apple.h: a merge left it broken, and main's CI red Merging #152 and #151 left the kind 8000 -table comment in the generated Apple header closed early (`*/` after the Stepper row) with a duplicate `25 Tab` row outside it, as bare text before `sui_create`. That is not C, and shimGen's consistency suite has failed on main since 9f2a3bd: 45 passed, 6 failed (Linux and Apple CI both red on the #151 push). `shimGen/run` regenerates it; this is its output, and the only file it changes. Also the two-line comment in AppleRenderer that the same merge left mis-indented, which `scalafmtAll` reflows. Measured: `sbt --error checkLinux` exit 0, 356 tests passed, 0 failed (on main, shimGen alone: 6 failed). Not verified here: the Swift build of the shim, which needs the Mac. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * POM descriptions for every published module; the release rehearsal in docs/14 (#157) * POM descriptions for every published module; the release rehearsal in docs/14 Each of the 50 published modules now sets `description` next to its `name`, so the POM's <description> (what Central's and Maven's search pages show) says what the module is instead of repeating its name. docs/14 §14.5 records what the practice release run on 2026-11-09 settled: a clean clone tagged v0.2.0 locally staged 62 modules (jar, sources, javadoc, POM, all signed, 56 MB), all 33 external dependencies resolve on Central, and sonaUpload reached VALIDATED (deployment 86b6f4e7, then dropped; nothing published). Also: which account owns net.leibman, where sbt 2 reads credentials, why the release must come from one machine (the Mac), and rehearse-then-Drop. Measured: `show coreJVM/description` etc. print the new descriptions; `sbt --error checkLinux` on this branch (stacked on the thicket_apple.h fix): exit 0, 356 tests passed, 0 failed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Update release instructions for Mac and Linux Clarified release process for Mac and non-Mac hosts, detailing module staging and potential upload collisions. Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> * Change Platform shim kind to match WidgetKind Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
This was referenced Nov 9, 2026
rleibman
added a commit
that referenced
this pull request
Nov 13, 2026
… step (#159) Two faults left on main after #151's merge and #156. Prop.View: #151's merge brought back the placeholder that set "<description>: not available" text, so a Platform host never got its view. Control on the macOS gallery without this line: 4 Platform checks fail (the NSTextField is not in the window, the "not available" label, the replacement, the release). Stepper: StepperView.show() printed NSDecimalNumber's stringValue, which drops trailing zeros, so a step of 0.25 showed "1.5", not "1.50", on AppKit and UIKit. It now rounds with NSDecimalNumber and prints exactly `digits` decimals, as Steps.format does. Before: both galleries failed "showing its value to its step's precision" and "- moves it back a step" (main's own CI on 9f2a3bd, and #158's run on its merge with main). Measured: bin/verify-apple.sh "iPhone 17e" on this tree, 20/20 steps, at a load average of 80-180 (Apple CI ran beside it). macOS gallery 237 ok per run, iOS 252 ok. Co-authored-by: Roberto Leibman <rleibman@magrathea.local> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Closes #145. This is the Apple half of
docs/17step 1, the embedding point. #148 (camera preview,-apple) builds on it.What
ApplePlatformView(modules/renderer-apple/.../ApplePlatformView.scala):-applemodule implements it and calls its own Swift library fromcreate, which returnsUnmanaged.passRetained(v).toOpaque(). The README's new section documents this.sui_platform_set_view(host, view)takes the caller's +1 over (takeRetainedValue), so the module never releases it. On destroy or replacement, the renderer callsreleasefirst, while the view is still alive and in its host. Thensui_platform_set_view(host, NULL)drops the view, which frees it.sui_destroyon a host empties it as well.Platform→PlatformHoston AppKit and UIKit, holding one child pinned to its four edges. I used 28 rather than 26 so that Apple RadioGroup and Stepper: radio NSButtons / an iOS checkmark list; NSStepper / UIStepper #150 (RadioGroup and Stepper) can take 26 and 27. There is one new function,sui_platform_set_view. When a view is not anApplePlatformView, orcreatereturnsnull,sui_set_texton the host shows<description>: not available on AppKit(orUIKit).NSTextFieldon macOS and aUILabelon iOS (apple-shared/src/main/resources/scala-native/thicket_gallery_native_label.c).build.sbtadds that resource directory. The Platform section has the same checks as GTK and Android, the heading plus 5 checks. Inrelease, the check asks a weak reference whether the view is alive, then reads its superview and its text. After the replacement, the weak reference must go nil.Measured
shimGen/testFull51/51;shimGen/run --check: current.verify-apple.sh. The first label is 1435×16 pt, the same size as its host. It was freed 337–368 ms after the replacement.bin/verify-apple.sh "iPhone 17e"at dda2bd5: 19/20 steps passed.ios-galleryfailed on one check only: "notifications start Denied, not yet asked", on a freshly booted simulator. That is the known trap, and the Platform checks passed in that run.Falsified (macOS; each run: 223 ok, 1 failed, on exactly the matching check)
releaseskipped → "released while still alive in its host, then freed" fails (released[]).releasecalled after the shim dropped the view → the same check fails (in its host:false).takeUnretainedValue) → the same check fails (old view still alive after 2015 ms).Not done or not measured
nullfromcreateis handled, but no check covers it.docs/17was given a status update even though CLAUDE.md doesn't list it as living. The embedding point: WidgetKind.Platform and Prop.View, on GTK and Android (docs/17 step 1) #146 had already edited it the same way.🤖 Generated with Claude Code