Skip to content

[Observation] Switch to peer instead of arbitrary macros #67289

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 4 commits into from
Jul 21, 2023
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
9 changes: 0 additions & 9 deletions lib/Macros/Sources/ObservationMacros/ObservableMacro.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,6 @@ extension ObservableMacro: MemberMacro {
declaration.addIfNeeded(ObservableMacro.accessFunction(observableType), to: &declarations)
declaration.addIfNeeded(ObservableMacro.withMutationFunction(observableType), to: &declarations)

#if !OBSERVATION_SUPPORTS_PEER_MACROS
let storedInstanceVariables = declaration.definedVariables.filter { $0.isValidForObservation }
for property in storedInstanceVariables {
if property.hasMacroApplication(ObservableMacro.ignoredMacroName) { continue }
let storage = DeclSyntax(property.privatePrefixed("_", addingAttribute: ObservableMacro.ignoredAttribute))
declaration.addIfNeeded(storage, to: &declarations)
}
#endif

return declarations
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,7 @@ public protocol Observable { }
/// }
/// }
@available(SwiftStdlib 5.9, *)
#if OBSERVATION_SUPPORTS_PEER_MACROS
@attached(member, names: named(_$observationRegistrar), named(access), named(withMutation))
#else
@attached(member, names: named(_$observationRegistrar), named(access), named(withMutation), arbitrary)
#endif
@attached(memberAttribute)
@attached(extension, conformances: Observable)
public macro Observable() =
Expand All @@ -56,9 +52,7 @@ public macro Observable() =
/// framework isn't necessary.
@available(SwiftStdlib 5.9, *)
@attached(accessor, names: named(init), named(get), named(set))
#if OBSERVATION_SUPPORTS_PEER_MACROS
@attached(peer, names: prefixed(_))
#endif
public macro ObservationTracked() =
#externalMacro(module: "ObservationMacros", type: "ObservationTrackedMacro")

Expand Down
4 changes: 4 additions & 0 deletions test/stdlib/Observation/Observable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,10 @@ struct Validator {


let suite = TestSuite("Observable")

suite.test("only instantiate") {
let test = MiddleNamePerson()
}

suite.test("unobserved value changes") {
let test = MiddleNamePerson()
Expand Down
1 change: 1 addition & 0 deletions test/stdlib/Observation/ObservableDiagnostics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
// REQUIRES: objc_interop
// UNSUPPORTED: use_os_stdlib
// UNSUPPORTED: back_deployment_runtime
// REQUIRES: rdar112623492

import Observation

Expand Down