Skip to content
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

Emit runtime warnings via Issue Reporting #93

Merged
merged 8 commits into from
Jul 22, 2024
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
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
name: macOS
strategy:
matrix:
xcode: ['15.1']
xcode: ['15.4']
config: ['debug', 'release']
runs-on: macos-13
runs-on: macos-14
steps:
- uses: actions/checkout@v4
- name: Select Xcode ${{ matrix.xcode }}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{
"pins" : [
{
"identity" : "swift-issue-reporting",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-issue-reporting",
"state" : {
"revision" : "926f43898706eaa127db79ac42138e1ad7e85a3f",
"version" : "1.2.0"
}
},
{
"identity" : "swift-macro-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-macro-testing",
"state" : {
"revision" : "35acd9468d40ae87e75991a18af6271e8124c261",
"version" : "0.2.1"
"revision" : "a35257b7e9ce44e92636447003a8eeefb77b145c",
"version" : "0.5.1"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "bb0ea08db8e73324fe6c3727f755ca41a23ff2f4",
"version" : "1.14.2"
"revision" : "c097f955b4e724690f0fc8ffb7a6d4b881c9c4e3",
"version" : "1.17.2"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "74203046135342e4a4a627476dd6caf8b28fe11b",
"version" : "509.0.0"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "23cbf2294e350076ea4dbd7d5d047c1e76b03631",
"version" : "1.0.2"
"revision" : "4c6cc0a3b9e8f14b3ae2307c5ccae4de6167ac2c",
"version" : "600.0.0-prerelease-2024-06-12"
}
}
],
Expand Down
30 changes: 15 additions & 15 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,39 +1,39 @@
{
"pins" : [
{
"identity" : "swift-issue-reporting",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-issue-reporting",
"state" : {
"revision" : "926f43898706eaa127db79ac42138e1ad7e85a3f",
"version" : "1.2.0"
}
},
{
"identity" : "swift-macro-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-macro-testing",
"state" : {
"revision" : "851c8b6bde2000d8051dc9aca1efee04dcc37411",
"version" : "0.4.1"
"revision" : "a35257b7e9ce44e92636447003a8eeefb77b145c",
"version" : "0.5.1"
}
},
{
"identity" : "swift-snapshot-testing",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/swift-snapshot-testing",
"state" : {
"revision" : "8ddd519780452729c6634ad6bd0d2595938e9ea3",
"version" : "1.16.1"
"revision" : "c097f955b4e724690f0fc8ffb7a6d4b881c9c4e3",
"version" : "1.17.2"
}
},
{
"identity" : "swift-syntax",
"kind" : "remoteSourceControl",
"location" : "https://github.com/swiftlang/swift-syntax",
"state" : {
"revision" : "08a2f0a9a30e0f705f79c9cfaca1f68b71bdc775",
"version" : "510.0.0"
}
},
{
"identity" : "xctest-dynamic-overlay",
"kind" : "remoteSourceControl",
"location" : "https://github.com/pointfreeco/xctest-dynamic-overlay",
"state" : {
"revision" : "b13b1d1a8e787a5ffc71ac19dcaf52183ab27ba2",
"version" : "1.1.1"
"revision" : "4c6cc0a3b9e8f14b3ae2307c5ccae4de6167ac2c",
"version" : "600.0.0-prerelease-2024-06-12"
}
}
],
Expand Down
4 changes: 2 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ let package = Package(
.library(name: "Perception", targets: ["Perception"])
],
dependencies: [
.package(url: "https://github.com/pointfreeco/swift-issue-reporting", from: "1.2.0"),
.package(url: "https://github.com/pointfreeco/swift-macro-testing", from: "0.1.0"),
.package(url: "https://github.com/pointfreeco/xctest-dynamic-overlay", from: "1.0.0"),
.package(url: "https://github.com/swiftlang/swift-syntax", "509.0.0"..<"601.0.0-prerelease"),
],
targets: [
.target(
name: "Perception",
dependencies: [
"PerceptionMacros",
.product(name: "XCTestDynamicOverlay", package: "xctest-dynamic-overlay"),
.product(name: "IssueReporting", package: "swift-issue-reporting"),
]
),
.testTarget(
Expand Down
67 changes: 0 additions & 67 deletions Sources/Perception/Internal/RuntimeWarning.swift

This file was deleted.

25 changes: 19 additions & 6 deletions Sources/Perception/PerceptionRegistrar.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import IssueReporting

/// Provides storage for tracking and access to data changes.
///
Expand Down Expand Up @@ -78,11 +79,18 @@ extension PerceptionRegistrar {
public func access<Subject: Perceptible, Member>(
_ subject: Subject,
keyPath: KeyPath<Subject, Member>,
file: StaticString = #file,
line: UInt = #line
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column
) {
#if DEBUG && canImport(SwiftUI)
self.perceptionCheck(file: file, line: line)
self.perceptionCheck(
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
#endif
#if canImport(Observation)
if #available(iOS 17, macOS 14, tvOS 17, watchOS 10, *), !isObservationBeta {
Expand Down Expand Up @@ -191,14 +199,19 @@ extension PerceptionRegistrar: Hashable {

#if DEBUG && canImport(SwiftUI)
extension PerceptionRegistrar {
fileprivate func perceptionCheck(file: StaticString, line: UInt) {
fileprivate func perceptionCheck(
fileID: StaticString,
filePath: StaticString,
line: UInt,
column: UInt
) {
if self.isPerceptionCheckingEnabled,
Perception.isPerceptionCheckingEnabled,
!_PerceptionLocals.isInPerceptionTracking,
!_PerceptionLocals.skipPerceptionChecking,
self.isInSwiftUIBody(file: file, line: line)
self.isInSwiftUIBody(file: filePath, line: line)
{
runtimeWarn(
reportIssue(
"""
Perceptible state was accessed but is not being tracked. Track changes to state by \
wrapping your view in a 'WithPerceptionTracking' view.
Expand Down
15 changes: 12 additions & 3 deletions Sources/PerceptionMacros/PerceptibleMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,19 @@ public struct PerceptibleMacro {
"""
internal nonisolated func access<Member>(
keyPath: KeyPath<\(perceptibleType), Member>,
file: StaticString = #file,
line: UInt = #line
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column
) {
\(raw: registrarVariableName).access(self, keyPath: keyPath, file: file, line: line)
\(raw: registrarVariableName).access(
self,
keyPath: keyPath,
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
}
"""
}
Expand Down
15 changes: 12 additions & 3 deletions Tests/PerceptionMacrosTests/PerceptionMacrosTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,19 @@

internal nonisolated func access<Member>(
keyPath: KeyPath<Feature, Member>,
file: StaticString = #file,
line: UInt = #line
fileID: StaticString = #fileID,
filePath: StaticString = #filePath,
line: UInt = #line,
column: UInt = #column
) {
_$perceptionRegistrar.access(self, keyPath: keyPath, file: file, line: line)
_$perceptionRegistrar.access(
self,
keyPath: keyPath,
fileID: fileID,
filePath: filePath,
line: line,
column: column
)
}

internal nonisolated func withMutation<Member, MutationResult>(
Expand Down
4 changes: 2 additions & 2 deletions Tests/PerceptionTests/RuntimeWarningTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -612,8 +612,8 @@
private func expectRuntimeWarning<R>(failingBlock: () -> R) -> R {
XCTExpectFailure(failingBlock: failingBlock) {
$0.compactDescription == """
Perceptible state was accessed but is not being tracked. Track changes to state by \
wrapping your view in a 'WithPerceptionTracking' view.
failed - Perceptible state was accessed but is not being tracked. Track changes to state \
by wrapping your view in a 'WithPerceptionTracking' view.
"""
}
}
Expand Down