Skip to content

Fix Xcode 15.3 Release Crash #108

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 27, 2024
Merged

Fix Xcode 15.3 Release Crash #108

merged 1 commit into from
Feb 27, 2024

Conversation

stephencelis
Copy link
Member

A SIL function we load seems to be unavailable, so let's limit old key path printing to DEBUG builds.

Fixes #107.

A SIL function we load seems to be unavailable, so let's limit old key
path printing to DEBUG builds.
@stephencelis stephencelis merged commit 3ce8317 into main Feb 27, 2024
@stephencelis stephencelis deleted the xcode-15-3-key-path-fix branch February 27, 2024 18:24
isthisjoe pushed a commit to isthisjoe/swift-custom-dump that referenced this pull request Mar 6, 2024
A SIL function we load seems to be unavailable, so let's limit old key
path printing to DEBUG builds.
@aschwaighofer
Copy link

@stephencelis

The use of _silgen_name with a Swift runtime function (or also importing a C header file with runtime functions) is unsupported and strongly discouraged.

internal func _allocObject(_: UnsafeMutableRawPointer, _: Int, _: Int) -> AnyObject?

Swift compilers starting with Xcode 15.3 allow for the use of the Builtin module. In your case, you can use the Builtin.allocWithTailElems_1 to mimic what the standard library does.

Something like the following should work (I have only tested that this compiles with Xcode 15.3):

diff --git a/Sources/CustomDump/Conformances/KeyPath.swift b/Sources/CustomDump/Conformances/KeyPath.swift
index 24dacbc..380109e 100644
--- a/Sources/CustomDump/Conformances/KeyPath.swift
+++ b/Sources/CustomDump/Conformances/KeyPath.swift
@@ -1,5 +1,9 @@
 import Foundation
 
+#if swift(>=5.10)
+import Builtin
+#endif
+
 extension AnyKeyPath: CustomDumpStringConvertible {
   public var customDumpDescription: String {
     // NB: We gate this to 5.9+ due to this crasher: https://github.com/apple/swift/issues/64865
@@ -721,12 +725,17 @@ extension AnyKeyPath: CustomDumpStringConvertible {
 
       let alignment = metadata.instanceAlignMask | tailAlignMask
 
+    #if swift(>=5.10)
+      let object = Builtin.allocWithTailElems_1(self, (bytes/4)._builtinWordValue,
+                                                Int32.self)
+      let base = UnsafeMutableRawPointer(Builtin.projectTailElems(object,
+                                                                  Int32.self))
+    #else
       let object = _allocObject(
         UnsafeMutableRawPointer(mutating: metadata.pointer),
         size,
         alignment
       )
-
       guard object != nil else {
         fatalError("Allocating \(self) instance failed for keypath reflection")
       }
@@ -736,6 +745,8 @@ extension AnyKeyPath: CustomDumpStringConvertible {
       let base =
         unsafeBitCast(object, to: UnsafeMutableRawPointer.self) + MemoryLayout<Int>.size * 2
 
+    #endif
+
       // The first word is the kvc string pointer. Set it to 0 (nil).
       base.storeBytes(of: 0, as: Int.self)
 

And probably a Package file like (not a swift package configuration expert by any means):

diff --git a/[email protected] b/[email protected]
new file mode 100644
index 0000000..73cd1b7
--- /dev/null
+++ b/[email protected]
+// swift-tools-version:5.10
+
+import PackageDescription
+
+let package = Package(
+  name: "swift-custom-dump",
+  platforms: [
+    .iOS(.v13),
+    .macOS(.v10_15),
+    .tvOS(.v13),
+    .watchOS(.v6),
+  ],
+  products: [
+    .library(
+      name: "CustomDump",
+      targets: ["CustomDump"]
+    )
+  ],
+  dependencies: [
+    .package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0")
+  ],
+  targets: [
+    .target(
+      name: "CustomDump",
+      dependencies: [
+        .product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay")
+      ],
+      swiftSettings: [.enableExperimentalFeature("BuiltinModule")]
+    ),
+    .testTarget(
+      name: "CustomDumpTests",
+      dependencies: [
+        "CustomDump"
+      ],
+      swiftSettings: [.enableExperimentalFeature("BuiltinModule")]
+    ),
+  ]
+)

@stephencelis
Copy link
Member Author

@aschwaighofer Thanks for chiming in! Good to know about that option. I'm not sure swiftSettings can be customized for distributed package releases, though (at the very least we've found that the presence of unsafeFlags can break a versioned release).

Luckily we think we can delete the original code path, since it was mainly there for Swift <5.9, and we don't mind degrading the debug info for earlier versions of Swift.

stephencelis added a commit that referenced this pull request Mar 19, 2024
A SIL function we load seems to be unavailable, so let's limit old key
path printing to DEBUG builds.
stephencelis added a commit that referenced this pull request Mar 19, 2024
A SIL function we load seems to be unavailable, so let's limit old key
path printing to DEBUG builds.
Chlup added a commit to Chlup/secant-ios-wallet that referenced this pull request Apr 20, 2024
Problem was in swift-custom-dump package. And it was fixed in this PR:
pointfreeco/swift-custom-dump#108.
LukasKorba pushed a commit to LukasKorba/secant-ios-wallet that referenced this pull request Apr 30, 2024
Problem was in swift-custom-dump package. And it was fixed in this PR:
pointfreeco/swift-custom-dump#108.
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.

Swift crash when building on Xcode 15.3 RC
3 participants