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

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 13 additions & 5 deletions Sources/OpenSwiftUICore/Log/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ package enum Log {

// Added in 6.4.41
package static let timelineScheduleSequences: Logger = Logger(subsystem: subsystem, category: "TimelineSchedule Sequences")

#if DEBUG
fileprivate static let development: Logger = Logger(subsystem: subsystem, category: "Development")
#endif
}

@available(*, unavailable)
Expand All @@ -235,7 +239,7 @@ package func precondition(_ condition: @autoclosure () -> Bool, _ message: @auto
package func preconditionFailure(_ message: @autoclosure () -> String, file: StaticString, line: UInt) -> Never {
#if DEBUG && OPENSWIFTUI_DEVELOPMENT
if message() == "TODO" {
print("💣 Hit unimplemented part of OpenSwiftUI at \(file):\(line).\nConsider adding a plain implementation to avoid crash.")
Log.development.warning("Hit unimplemented part of OpenSwiftUI at \(file):\(line).\nConsider adding a plain implementation to avoid crash.")
}
#endif
Swift.fatalError(message(), file: file, line: line)
Expand Down Expand Up @@ -284,16 +288,20 @@ package func _openSwiftUIPlatformUnimplementedFailure(_ function: String = #func

@_transparent
package func _openSwiftUIUnimplementedWarning(_ function: String = #function, file: StaticString = #fileID, line: UInt = #line) {
print("\(file):\(line): Warning: \(function) is unimplemented")
#if DEBUG && OPENSWIFTUI_DEVELOPMENT
#if DEBUG
Log.development.warning("\(file):\(line): Warning: \(function) is unimplemented")
#if OPENSWIFTUI_DEVELOPMENT
_openSwiftUIUnimplementedFailure(function, file: file, line: line)
#endif
#endif
}

@_transparent
package func _openSwiftUIPlatformUnimplementedWarning(_ function: String = #function, file: StaticString = #fileID, line: UInt = #line) {
print("\(file):\(line): Warning: \(function) is unimplemented on this platform")
#if DEBUG && OPENSWIFTUI_DEVELOPMENT
#if DEBUG
Log.development.warning("\(file):\(line): Warning: \(function) is unimplemented on this platform")
#if OPENSWIFTUI_DEVELOPMENT
_openSwiftUIPlatformUnimplementedFailure(function, file: file, line: line)
#endif
#endif
}
19 changes: 14 additions & 5 deletions Sources/OpenSwiftUI_SPI/Util/Interpose.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,19 @@

#include <stdbool.h>
#include <stdint.h>
#include <dispatch/dispatch.h>
#include <os/log.h>
#include <CoreFoundation/CoreFoundation.h>

static os_log_t interpose_log(void) {
static dispatch_once_t onceToken;
static os_log_t log = NULL;
dispatch_once(&onceToken, ^{
log = os_log_create("org.OpenSwiftUIProject.OpenSwiftUI", "Interpose");
});
return log;
}

// MARK: - Type Description Shim

// swift_getTypeName returns the module-qualified name (e.g. "OpenSwiftUI.CGDrawingView")
Expand Down Expand Up @@ -71,7 +81,6 @@ static inline CFStringRef _interpose_protocol_description(const void *protocol)
return result;
}
}

CFStringRef result = CFStringCreateWithCString(kCFAllocatorDefault, name, kCFStringEncodingUTF8);
CFAutorelease(result);
return result;
Expand Down Expand Up @@ -113,15 +122,15 @@ static bool my_swift_dynamicCast(void *dest, void *src, const void *srcType, con
CFStringHasPrefix(targetDescription, CFSTR("SwiftUICore."))) &&
(CFStringHasPrefix(srcDescription, CFSTR("OpenSwiftUI.")) ||
CFStringHasPrefix(srcDescription, CFSTR("OpenSwiftUICore.")))) {
os_log_info(OS_LOG_DEFAULT, "[OpenSwiftUI] swift_dynamicCast failed for target: %{public}@ src: %{public}@", targetDescription, srcDescription);
os_log_info(interpose_log(), "swift_dynamicCast failed for target: %{public}@ src: %{public}@", targetDescription, srcDescription);
}
// If dynamicCast check failed and the target is SwiftUI's Color.Resolved
// retry with OpenSwiftUI's Color.Resolved
if (targetType == &$s7SwiftUI5ColorV8ResolvedVN) {
result = swift_dynamicCast(dest, src, srcType, _OpenSwiftUI_ColorResolvedNTD(), flags);
if (result) {
CFStringRef description = _interpose_type_description(srcType);
os_log_info(OS_LOG_DEFAULT, "[OpenSwiftUI] swift_dynamicCast succeeded for %{public}@", description);
os_log_info(interpose_log(), "swift_dynamicCast succeeded for %{public}@", description);
}
}
return result;
Expand Down Expand Up @@ -152,15 +161,15 @@ static const void *my_swift_conformsToProtocol2(const void *type, const void *pr
CFStringHasPrefix(protocolDescription, CFSTR("SwiftUICore."))) &&
(CFStringHasPrefix(typeDescription, CFSTR("OpenSwiftUI.")) ||
CFStringHasPrefix(typeDescription, CFSTR("OpenSwiftUICore.")))) {
os_log_info(OS_LOG_DEFAULT, "[OpenSwiftUI] swift_conformsToProtocol2 failed for protocol: %{public}@ type: %{public}@", protocolDescription, typeDescription);
os_log_info(interpose_log(), "swift_conformsToProtocol2 failed for protocol: %{public}@ type: %{public}@", protocolDescription, typeDescription);
}
// If conformance check failed and the protocol is SwiftUI's PlatformDrawable,
// retry with OpenSwiftUI's PlatformDrawable
if (protocol == &$s7SwiftUI16PlatformDrawableMp) {
result = swift_conformsToProtocol2(type, _OpenSwiftUI_PlatformDrawablePD());
if (result != NULL) {
CFStringRef description = _interpose_type_description(type);
os_log_info(OS_LOG_DEFAULT, "[OpenSwiftUI] swift_conformsToProtocol2 succeeded via OpenSwiftUI fallback for %{public}@", description);
os_log_info(interpose_log(), "swift_conformsToProtocol2 succeeded via OpenSwiftUI fallback for %{public}@", description);
}
}
return result;
Expand Down
Loading