From b071bb200669e8e1ba81c63b4e1b0c4c5d534c97 Mon Sep 17 00:00:00 2001 From: Stephen Celis Date: Tue, 5 Nov 2024 10:54:50 -0800 Subject: [PATCH] Introduce `PerceptionCore` module (#105) Downstream libraries can avoid the overhead of swift-syntax and macros if they depend on `PerceptionCore` instead. --- Package.resolved | 16 ++++++++-------- Package.swift | 10 +++++++++- Sources/Perception/Exports.swift | 1 + .../Bindable.swift | 0 .../Environment.swift | 0 .../Internal/AnySendable.swift | 0 .../Internal/BetaChecking.swift | 0 .../Internal/Exports.swift | 0 .../Internal/Locking.swift | 0 .../Internal/ThreadLocal.swift | 0 .../Internal/UncheckedSendable.swift | 0 .../Internal/_PerceptionRegistrar.swift | 0 .../Perceptible.swift | 0 .../PerceptionChecking.swift | 0 .../PerceptionRegistrar.swift | 4 ++-- .../PerceptionTracking.swift | 0 .../WithPerceptionTracking.swift | 0 17 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 Sources/Perception/Exports.swift rename Sources/{Perception => PerceptionCore}/Bindable.swift (100%) rename Sources/{Perception => PerceptionCore}/Environment.swift (100%) rename Sources/{Perception => PerceptionCore}/Internal/AnySendable.swift (100%) rename Sources/{Perception => PerceptionCore}/Internal/BetaChecking.swift (100%) rename Sources/{Perception => PerceptionCore}/Internal/Exports.swift (100%) rename Sources/{Perception => PerceptionCore}/Internal/Locking.swift (100%) rename Sources/{Perception => PerceptionCore}/Internal/ThreadLocal.swift (100%) rename Sources/{Perception => PerceptionCore}/Internal/UncheckedSendable.swift (100%) rename Sources/{Perception => PerceptionCore}/Internal/_PerceptionRegistrar.swift (100%) rename Sources/{Perception => PerceptionCore}/Perceptible.swift (100%) rename Sources/{Perception => PerceptionCore}/PerceptionChecking.swift (100%) rename Sources/{Perception => PerceptionCore}/PerceptionRegistrar.swift (98%) rename Sources/{Perception => PerceptionCore}/PerceptionTracking.swift (100%) rename Sources/{Perception => PerceptionCore}/WithPerceptionTracking.swift (100%) diff --git a/Package.resolved b/Package.resolved index f470853..c1b3068 100644 --- a/Package.resolved +++ b/Package.resolved @@ -5,8 +5,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-macro-testing", "state" : { - "revision" : "a35257b7e9ce44e92636447003a8eeefb77b145c", - "version" : "0.5.1" + "revision" : "20c1a8f3b624fb5d1503eadcaa84743050c350f4", + "version" : "0.5.2" } }, { @@ -14,8 +14,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/swift-snapshot-testing", "state" : { - "revision" : "c097f955b4e724690f0fc8ffb7a6d4b881c9c4e3", - "version" : "1.17.2" + "revision" : "42a086182681cf661f5c47c9b7dc3931de18c6d7", + "version" : "1.17.6" } }, { @@ -23,8 +23,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/swiftlang/swift-syntax", "state" : { - "revision" : "4c6cc0a3b9e8f14b3ae2307c5ccae4de6167ac2c", - "version" : "600.0.0-prerelease-2024-06-12" + "revision" : "0687f71944021d616d34d922343dcef086855920", + "version" : "600.0.1" } }, { @@ -32,8 +32,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/pointfreeco/xctest-dynamic-overlay", "state" : { - "revision" : "357ca1e5dd31f613a1d43320870ebc219386a495", - "version" : "1.2.2" + "revision" : "770f990d3e4eececb57ac04a6076e22f8c97daeb", + "version" : "1.4.2" } } ], diff --git a/Package.swift b/Package.swift index 9b02aad..0ee2a75 100644 --- a/Package.swift +++ b/Package.swift @@ -12,7 +12,8 @@ let package = Package( .watchOS(.v6), ], products: [ - .library(name: "Perception", targets: ["Perception"]) + .library(name: "Perception", targets: ["Perception"]), + .library(name: "PerceptionCore", targets: ["PerceptionCore"]), ], dependencies: [ .package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.1.0"), @@ -22,6 +23,13 @@ let package = Package( targets: [ .target( name: "Perception", + dependencies: [ + "PerceptionCore", + "PerceptionMacros", + ] + ), + .target( + name: "PerceptionCore", dependencies: [ "PerceptionMacros", .product(name: "IssueReporting", package: "xctest-dynamic-overlay"), diff --git a/Sources/Perception/Exports.swift b/Sources/Perception/Exports.swift new file mode 100644 index 0000000..812b6ae --- /dev/null +++ b/Sources/Perception/Exports.swift @@ -0,0 +1 @@ +@_exported import PerceptionCore diff --git a/Sources/Perception/Bindable.swift b/Sources/PerceptionCore/Bindable.swift similarity index 100% rename from Sources/Perception/Bindable.swift rename to Sources/PerceptionCore/Bindable.swift diff --git a/Sources/Perception/Environment.swift b/Sources/PerceptionCore/Environment.swift similarity index 100% rename from Sources/Perception/Environment.swift rename to Sources/PerceptionCore/Environment.swift diff --git a/Sources/Perception/Internal/AnySendable.swift b/Sources/PerceptionCore/Internal/AnySendable.swift similarity index 100% rename from Sources/Perception/Internal/AnySendable.swift rename to Sources/PerceptionCore/Internal/AnySendable.swift diff --git a/Sources/Perception/Internal/BetaChecking.swift b/Sources/PerceptionCore/Internal/BetaChecking.swift similarity index 100% rename from Sources/Perception/Internal/BetaChecking.swift rename to Sources/PerceptionCore/Internal/BetaChecking.swift diff --git a/Sources/Perception/Internal/Exports.swift b/Sources/PerceptionCore/Internal/Exports.swift similarity index 100% rename from Sources/Perception/Internal/Exports.swift rename to Sources/PerceptionCore/Internal/Exports.swift diff --git a/Sources/Perception/Internal/Locking.swift b/Sources/PerceptionCore/Internal/Locking.swift similarity index 100% rename from Sources/Perception/Internal/Locking.swift rename to Sources/PerceptionCore/Internal/Locking.swift diff --git a/Sources/Perception/Internal/ThreadLocal.swift b/Sources/PerceptionCore/Internal/ThreadLocal.swift similarity index 100% rename from Sources/Perception/Internal/ThreadLocal.swift rename to Sources/PerceptionCore/Internal/ThreadLocal.swift diff --git a/Sources/Perception/Internal/UncheckedSendable.swift b/Sources/PerceptionCore/Internal/UncheckedSendable.swift similarity index 100% rename from Sources/Perception/Internal/UncheckedSendable.swift rename to Sources/PerceptionCore/Internal/UncheckedSendable.swift diff --git a/Sources/Perception/Internal/_PerceptionRegistrar.swift b/Sources/PerceptionCore/Internal/_PerceptionRegistrar.swift similarity index 100% rename from Sources/Perception/Internal/_PerceptionRegistrar.swift rename to Sources/PerceptionCore/Internal/_PerceptionRegistrar.swift diff --git a/Sources/Perception/Perceptible.swift b/Sources/PerceptionCore/Perceptible.swift similarity index 100% rename from Sources/Perception/Perceptible.swift rename to Sources/PerceptionCore/Perceptible.swift diff --git a/Sources/Perception/PerceptionChecking.swift b/Sources/PerceptionCore/PerceptionChecking.swift similarity index 100% rename from Sources/Perception/PerceptionChecking.swift rename to Sources/PerceptionCore/PerceptionChecking.swift diff --git a/Sources/Perception/PerceptionRegistrar.swift b/Sources/PerceptionCore/PerceptionRegistrar.swift similarity index 98% rename from Sources/Perception/PerceptionRegistrar.swift rename to Sources/PerceptionCore/PerceptionRegistrar.swift index 118edb3..d9924b4 100644 --- a/Sources/Perception/PerceptionRegistrar.swift +++ b/Sources/PerceptionCore/PerceptionRegistrar.swift @@ -22,7 +22,7 @@ public struct PerceptionRegistrar: Sendable { /// ``PerceptionRegistrar`` when using the /// ``Perception/Perceptible()`` macro to indicate observably /// of a type. - public init(isPerceptionCheckingEnabled: Bool = Perception.isPerceptionCheckingEnabled) { + public init(isPerceptionCheckingEnabled: Bool = PerceptionCore.isPerceptionCheckingEnabled) { if #available(iOS 17, macOS 14, tvOS 17, watchOS 10, *), !isObservationBeta { self._rawValue = AnySendable(ObservationRegistrar()) } else { @@ -199,7 +199,7 @@ extension PerceptionRegistrar: Hashable { column: UInt ) { if self.isPerceptionCheckingEnabled, - Perception.isPerceptionCheckingEnabled, + PerceptionCore.isPerceptionCheckingEnabled, !_PerceptionLocals.isInPerceptionTracking, !_PerceptionLocals.skipPerceptionChecking, self.isInSwiftUIBody(file: filePath, line: line) diff --git a/Sources/Perception/PerceptionTracking.swift b/Sources/PerceptionCore/PerceptionTracking.swift similarity index 100% rename from Sources/Perception/PerceptionTracking.swift rename to Sources/PerceptionCore/PerceptionTracking.swift diff --git a/Sources/Perception/WithPerceptionTracking.swift b/Sources/PerceptionCore/WithPerceptionTracking.swift similarity index 100% rename from Sources/Perception/WithPerceptionTracking.swift rename to Sources/PerceptionCore/WithPerceptionTracking.swift