Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion Example/Example.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@
/* End PBXFileReference section */

/* Begin PBXFileSystemSynchronizedBuildFileExceptionSet section */
27240CFE2E8FFBC900E9DABD /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
kdebug_interpose.c,
);
target = 27CD0B482AFC8D37003665EB /* Example */;
};
275751CC2DEE136C003E467C /* PBXFileSystemSynchronizedBuildFileExceptionSet */ = {
isa = PBXFileSystemSynchronizedBuildFileExceptionSet;
membershipExceptions = (
Expand Down Expand Up @@ -88,7 +95,7 @@
275751F62DEE1456003E467C /* OpenSwiftUIUITests */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = OpenSwiftUIUITests; sourceTree = "<group>"; };
279FEC572DF450D200320390 /* ReferenceImages */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = ReferenceImages; sourceTree = "<group>"; };
27E6C4F62D2842D80010502F /* Configurations */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); name = Configurations; path = ../Configurations; sourceTree = "<group>"; };
27FFF0422E08850C0060A4DA /* SharedExample */ = {isa = PBXFileSystemSynchronizedRootGroup; explicitFileTypes = {}; explicitFolders = (); path = SharedExample; sourceTree = "<group>"; };
27FFF0422E08850C0060A4DA /* SharedExample */ = {isa = PBXFileSystemSynchronizedRootGroup; exceptions = (27240CFE2E8FFBC900E9DABD /* PBXFileSystemSynchronizedBuildFileExceptionSet */, ); explicitFileTypes = {}; explicitFolders = (); path = SharedExample; sourceTree = "<group>"; };
/* End PBXFileSystemSynchronizedRootGroup section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -310,6 +317,7 @@
};
27D49DF72BA604FB00F6E2E2 = {
CreatedOnToolsVersion = 15.2;
LastSwiftMigration = 1640;
};
};
};
Expand Down Expand Up @@ -508,6 +516,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -529,6 +538,8 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
XROS_DEPLOYMENT_TARGET = 2.0;
};
Expand Down Expand Up @@ -915,6 +926,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -936,6 +948,8 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
XROS_DEPLOYMENT_TARGET = 2.0;
};
Expand Down Expand Up @@ -1040,6 +1054,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -1061,6 +1076,8 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
XROS_DEPLOYMENT_TARGET = 2.0;
};
Expand Down Expand Up @@ -1255,6 +1272,7 @@
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor;
CLANG_ENABLE_MODULES = YES;
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = "";
GENERATE_INFOPLIST_FILE = YES;
Expand All @@ -1276,6 +1294,8 @@
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 6.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
XROS_DEPLOYMENT_TARGET = 2.0;
};
Expand Down
31 changes: 31 additions & 0 deletions Example/SharedExample/kdebug_interpose.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// kdebug_interpose.c
// SharedExample
//
// Created by Kyle on 2025/10/3.
//

// Interpose kdebug_is_enabled to always return true to perform Signpost testing with Instruments

#include <stdbool.h>
#include <stdint.h>
#include <dlfcn.h>

// Forward declare the original
extern bool kdebug_is_enabled(uint32_t debugid);

// Our replacement
static bool my_kdebug_is_enabled(uint32_t debugid) {
return true;
}

// Interpose using Mach-O section
typedef struct interpose_s {
const void *replacement;
const void *original;
} interpose_t;

__attribute__((used)) static const interpose_t interposers[]
__attribute__((section("__DATA, __interpose"))) = {
{ (const void *)my_kdebug_is_enabled, (const void *)kdebug_is_enabled },
};
4 changes: 3 additions & 1 deletion Sources/OpenSwiftUICore/Data/Binding/Binding.swift
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ public struct Binding<Value> {
/// The transaction captures the information needed to update the view when
/// the binding value changes.
public var transaction: Transaction

package var location: AnyLocation<Value>
private var _value: Value

var _value: Value

/// Creates a binding with closures that read and write the binding value.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ package struct DynamicPropertyCache {
}

struct Field {
var type: DynamicProperty.Type
var type: any DynamicProperty.Type
var offset: Int
var name: UnsafePointer<Int8>?
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//
// DynamicPropertyBuffer.swift
// OpenSwiftUI
// OpenSwiftUICore
//
// Audited for 6.5.4
// Status: Blocked by Tracing
// Status: Complete
// ID: 68550FF604D39F05971FE35A26EE75B0 (SwiftUI)
// ID: F3A89CF4357225EF49A7DD673FDFEE02 (SwiftUICore)

Expand Down Expand Up @@ -92,7 +92,11 @@ public struct _DynamicPropertyBuffer {
}

package func destroy() {
// TODO: trace
if Signpost.linkCreate.isEnabled {
for element in contents {
traceLinkDestroy(address: element.address)
}
}
contents.destroy()
}

Expand All @@ -107,8 +111,27 @@ public struct _DynamicPropertyBuffer {
to graphValue: _GraphValue<T>,
fields: DynamicPropertyCache.Fields
) {
// TODO: trace
_openSwiftUIUnimplementedWarning()
if Signpost.linkCreate.isEnabled {
let type = String(describing: T.self)
let typeLibrary = Tracing.libraryName(defining: T.self)
let identifier = graphValue.value.identifier.rawValue
let identity = graphValue.value.graph.graphIdentity()
if case let .product(fieldsArray) = fields.layout {
for (index, element) in contents.enumerated() {
guard index != fieldsArray.count else {
return
}
traceLinkCreate(
field: fieldsArray[index],
address: element.address,
type: type,
typeLibrary: typeLibrary,
identifier: identifier,
identity: identity
)
}
}
}
}

package func update(container: UnsafeMutableRawPointer, phase: ViewPhase) -> Bool {
Expand Down Expand Up @@ -277,8 +300,10 @@ public struct _DynamicPropertyBuffer {
while count > 0 {
let itemPointer = pointer.assumingMemoryBound(to: Item.self)
let boxPointer = pointer.advanced(by: MemoryLayout<Item>.size)
if Signpost.linkDestroy.isEnabled {
traceLinkDestroy(address: boxPointer)
}
itemPointer.pointee.vtable.deinitialize(ptr: boxPointer)
// TODO: OSSignpost
pointer += Int(itemPointer.pointee.size)
count &-= 1
}
Expand Down Expand Up @@ -390,9 +415,34 @@ public struct _DynamicPropertyBuffer {
return allocatedBuffer.advanced(by: oldBuffer.distance(to: ptr))
}

package func traceMountedProperties<Value>(to value: _GraphValue<Value>, fields: DynamicPropertyCache.Fields) {
// TODO: Signpost related
_openSwiftUIUnimplementedWarning()
package func traceMountedProperties<Value>(
to value: _GraphValue<Value>,
fields: DynamicPropertyCache.Fields
) {
if Signpost.linkCreate.isEnabled {
let type = String(describing: Value.self)
let typeLibrary = Tracing.libraryName(defining: Value.self)
let identifier = value.value.identifier.rawValue
let identity = value.value.graph.graphIdentity()
if case let .product(fieldsArray) = fields.layout {
var index = 0
var pointer = buf
while index < _count && index < fieldsArray.count {
let itemPointer = pointer.assumingMemoryBound(to: Item.self)
let boxPointer = pointer.advanced(by: MemoryLayout<Item>.size)
traceLinkCreate(
field: fieldsArray[index],
address: boxPointer,
type: type,
typeLibrary: typeLibrary,
identifier: identifier,
identity: identity
)
pointer += Int(itemPointer.pointee.size)
index &+= 1
}
}
}
}

package func applyChanged(to body: (Int) -> Void) {
Expand Down Expand Up @@ -511,7 +561,7 @@ private class BoxVTableBase {

#if OPENSWIFTUI_SUPPORT_2024_API

// MARK: - BoxVTable [6.5.4] [WIP]
// MARK: - BoxVTable [6.5.4]

private class BoxVTable<Box: DynamicPropertyBox>: BoxVTableBase {
override class func moveInitialize(
Expand Down Expand Up @@ -543,7 +593,7 @@ private class BoxVTable<Box: DynamicPropertyBox>: BoxVTableBase {
let propertyPointer = property.assumingMemoryBound(to: Box.Property.self)
let changed = boxPointer.pointee.update(property: &propertyPointer.pointee, phase: phase)
if changed {
// TODO: OSSignpost
traceLinkUpdate(property: propertyPointer.pointee, address: elt.address)
}
return changed
}
Expand All @@ -559,7 +609,7 @@ private class BoxVTable<Box: DynamicPropertyBox>: BoxVTableBase {

#else

// MARK: - BoxVTable [3.5.2] [WIP]
// MARK: - BoxVTable [3.5.2]

private class BoxVTable<Box: DynamicPropertyBox>: BoxVTableBase {
override class func moveInitialize(ptr destination: UnsafeMutableRawPointer, from: UnsafeMutableRawPointer) {
Expand Down Expand Up @@ -588,7 +638,7 @@ private class BoxVTable<Box: DynamicPropertyBox>: BoxVTableBase {
let propertyPointer = property.assumingMemoryBound(to: Box.Property.self)
let changed = boxPointer.pointee.update(property: &propertyPointer.pointee, phase: phase)
if changed {
// TODO: OSSignpost
traceLinkUpdate(property: propertyPointer.pointee, address: ptr)
}
return changed
}
Expand Down
39 changes: 36 additions & 3 deletions Sources/OpenSwiftUICore/Log/Signpost.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ import OpenSwiftUI_SPI
import OpenAttributeGraphShims
#if canImport(os)
package import os.signpost
#else
public struct OSSignpostType: Hashable, Equatable, RawRepresentable {
public init(_ rawValue: UInt8) {
self.rawValue = rawValue
}

public init(rawValue: UInt8) {
self.rawValue = rawValue
}

public var rawValue: UInt8
}

extension OSSignpostType {
public static let event: OSSignpostType = .init(0)
public static let begin: OSSignpostType = .init(1)
public static let end: OSSignpostType = .init(2)
}
#endif

extension Signpost {
Expand Down Expand Up @@ -179,7 +197,6 @@ package struct Signpost {
#endif
}

#if canImport(Darwin)
@_transparent
package func traceEvent(
type: OSSignpostType,
Expand All @@ -190,6 +207,7 @@ package struct Signpost {
guard isEnabled else {
return
}
#if canImport(Darwin)
let id = OSSignpostID.makeExclusiveID(object)
let args = args()
switch style {
Expand All @@ -198,12 +216,11 @@ package struct Signpost {
case let .os_log(name):
os_signpost(type, log: _signpostLog, name: name, signpostID: id, message, args)
}
#endif
}
#endif


#if canImport(Darwin)

@inline(__always)
private var styleCode: UInt8 {
switch style {
Expand Down Expand Up @@ -251,6 +268,22 @@ extension OSSignpostID {
}
}
}

@inline(__always)
func os_signpost(
_ type: OSSignpostType,
dso: UnsafeRawPointer = #dsohandle,
log: OSLog,
name: StaticString,
signpostID: OSSignpostID = .exclusive,
_ format: StaticString,
_ arguments: [any CVarArg]
) {
unsafeBitCast(
os_signpost as (OSSignpostType, UnsafeRawPointer, OSLog, StaticString, OSSignpostID, StaticString, CVarArg...) -> Void,
to: ((OSSignpostType, UnsafeRawPointer, OSLog, StaticString, OSSignpostID, StaticString, [CVarArg]) -> Void).self
)(type, dso, log, name, signpostID, format, arguments)
}
#endif

#if canImport(Darwin)
Expand Down
Loading